461 lines
13 KiB
Java
461 lines
13 KiB
Java
package org.gcube.portlets.user.workspace.client.view.versioning;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
import org.gcube.portlets.user.workspace.client.AppController;
|
|
import org.gcube.portlets.user.workspace.client.event.FileVersioningEvent;
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
|
import org.gcube.portlets.user.workspace.client.model.FileVersionModel;
|
|
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
|
import org.gcube.portlets.user.workspace.client.view.windows.DialogConfirm;
|
|
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation;
|
|
import org.gcube.portlets.user.workspace.shared.WorkspaceVersioningOperation;
|
|
|
|
import com.extjs.gxt.ui.client.Style.ButtonScale;
|
|
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
|
|
import com.extjs.gxt.ui.client.Style.IconAlign;
|
|
import com.extjs.gxt.ui.client.Style.Scroll;
|
|
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
|
|
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
|
|
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
import com.extjs.gxt.ui.client.store.GroupingStore;
|
|
import com.extjs.gxt.ui.client.store.ListStore;
|
|
import com.extjs.gxt.ui.client.store.Record;
|
|
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
|
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
|
import com.extjs.gxt.ui.client.widget.MessageBox;
|
|
import com.extjs.gxt.ui.client.widget.button.Button;
|
|
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
|
|
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
|
|
import com.extjs.gxt.ui.client.widget.grid.Grid;
|
|
import com.extjs.gxt.ui.client.widget.grid.GroupingView;
|
|
import com.extjs.gxt.ui.client.widget.grid.filters.GridFilters;
|
|
import com.extjs.gxt.ui.client.widget.grid.filters.StringFilter;
|
|
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
|
import com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem;
|
|
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
|
|
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
/**
|
|
* The Class VersioningInfoContainer.
|
|
*
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
* Feb 17, 2017
|
|
*/
|
|
public class VersioningInfoContainer extends LayoutContainer {
|
|
|
|
private Grid<FileModel> grid;
|
|
private ContentPanel cp;
|
|
private GroupingStore<FileModel> store = new GroupingStore<FileModel>();
|
|
private ListStore<FileModel> typeStoreOperation = new ListStore<FileModel>();
|
|
//private GridDropTarget gridDropTarget;
|
|
private Button buttonDelete;
|
|
private Button buttonRestore;
|
|
private Button buttonDownload;
|
|
private Button buttonEmptyVersions;
|
|
private FileModel currentVersion;
|
|
private WindowVersioning windowVersioning;
|
|
|
|
/**
|
|
* Instantiates a new versioning info container.
|
|
*
|
|
* @param file the versioning files
|
|
*/
|
|
public VersioningInfoContainer(FileModel file, WindowVersioning windowVersioning) {
|
|
|
|
initContentPanel();
|
|
initGrid();
|
|
createToolBar();
|
|
this.currentVersion = file;
|
|
this.windowVersioning = windowVersioning;
|
|
|
|
activeButtonOnSelection(false);
|
|
//updateVersions(file);
|
|
}
|
|
|
|
/**
|
|
* Inits the content panel.
|
|
*/
|
|
private void initContentPanel() {
|
|
setLayout(new FitLayout());
|
|
getAriaSupport().setPresentation(true);
|
|
cp = new ContentPanel();
|
|
cp.setHeaderVisible(false);
|
|
cp.setBodyBorder(true);
|
|
cp.setLayout(new FitLayout());
|
|
cp.setButtonAlign(HorizontalAlignment.CENTER);
|
|
cp.setScrollMode(Scroll.AUTOY);
|
|
add(cp);
|
|
}
|
|
|
|
/**
|
|
* Check selection.
|
|
*
|
|
* @return true, if successful
|
|
*/
|
|
private boolean checkSelection(){
|
|
|
|
if(grid.getSelectionModel().getSelectedItems().size()==0){
|
|
MessageBox.info("Attention", "You must pick at least one item", null);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Creates the tool bar.
|
|
*/
|
|
private void createToolBar() {
|
|
|
|
ToolBar bar = new ToolBar();
|
|
|
|
buttonRestore = new Button(WorkspaceVersioningOperation.RESTORE.getLabel(),Resources.getIconUndo());
|
|
buttonRestore.setToolTip(WorkspaceVersioningOperation.RESTORE.getOperationDescription());
|
|
buttonRestore.setScale(ButtonScale.SMALL);
|
|
buttonRestore.setIconAlign(IconAlign.TOP);
|
|
|
|
buttonRestore.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
if(checkSelection())
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.RESTORE, currentVersion, grid.getSelectionModel().getSelectedItems().get(0), windowVersioning));
|
|
}
|
|
});
|
|
|
|
bar.add(buttonRestore);
|
|
|
|
|
|
buttonDelete = new Button(WorkspaceVersioningOperation.DELETE_PERMANENTLY.getLabel(),Resources.getIconDeleteItem());
|
|
buttonDelete.setToolTip(WorkspaceVersioningOperation.DELETE_PERMANENTLY.getOperationDescription());
|
|
buttonDelete.setScale(ButtonScale.SMALL);
|
|
buttonDelete.setIconAlign(IconAlign.TOP);
|
|
buttonDelete.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
if(checkSelection())
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.DELETE_PERMANENTLY,currentVersion, grid.getSelectionModel().getSelectedItems().get(0), windowVersioning));
|
|
|
|
}
|
|
});
|
|
|
|
bar.add(buttonDelete);
|
|
|
|
|
|
bar.add(new SeparatorMenuItem());
|
|
|
|
buttonDownload = new Button(WorkspaceVersioningOperation.DOWNLOAD.getLabel(),Resources.getIconRecycle());
|
|
buttonDownload.setToolTip(WorkspaceVersioningOperation.DOWNLOAD.getOperationDescription());
|
|
buttonDownload.setScale(ButtonScale.SMALL);
|
|
buttonDownload.setIconAlign(IconAlign.TOP);
|
|
buttonDownload.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
if(checkSelection())
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.DOWNLOAD, currentVersion, grid.getSelectionModel().getSelectedItems().get(0), windowVersioning));
|
|
}
|
|
});
|
|
|
|
bar.add(buttonDownload);
|
|
|
|
|
|
buttonEmptyVersions = new Button(WorkspaceVersioningOperation.EMPTY_OLDER_VERSIONS.getLabel(),Resources.getTrashEmpty());
|
|
buttonEmptyVersions.setToolTip(WorkspaceVersioningOperation.EMPTY_OLDER_VERSIONS.getOperationDescription());
|
|
buttonEmptyVersions.setScale(ButtonScale.SMALL);
|
|
buttonEmptyVersions.setIconAlign(IconAlign.TOP);
|
|
buttonEmptyVersions.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
// if(checkSelection())
|
|
// AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.EMPTY_OLDER_VERSIONS, null));
|
|
|
|
DialogConfirm box = new DialogConfirm(null, "Confirm Delete?", "Are you sure you want delete the older versions of: "+ currentVersion.getName());
|
|
box.setModal(true);
|
|
box.center();
|
|
box.getYesButton().addClickHandler(new ClickHandler() {
|
|
|
|
@Override
|
|
public void onClick(ClickEvent event) {
|
|
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.EMPTY_OLDER_VERSIONS, currentVersion, null, windowVersioning));
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
bar.add(buttonEmptyVersions);
|
|
|
|
|
|
bar.add(new FillToolItem());
|
|
|
|
Button buttonRefresh = new Button(WorkspaceTrashOperation.REFRESH.getLabel(),Resources.getIconRefresh());
|
|
buttonRefresh.setToolTip(WorkspaceTrashOperation.REFRESH.getOperationDescription());
|
|
buttonRefresh.setScale(ButtonScale.SMALL);
|
|
buttonRefresh.setIconAlign(IconAlign.TOP);
|
|
buttonRefresh.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.REFRESH, currentVersion, null, windowVersioning));
|
|
}
|
|
});
|
|
|
|
bar.add(buttonRefresh);
|
|
|
|
|
|
cp.setTopComponent(bar);
|
|
|
|
}
|
|
|
|
/**
|
|
* Inits the grid.
|
|
*/
|
|
public void initGrid() {
|
|
|
|
//ColumnConfig icon = new ColumnConfig(FileGridModel.ICON, "", 25);
|
|
ColumnConfig name = createSortableColumnConfig(FileModel.NAME, FileModel.NAME, 200);
|
|
//ColumnConfig type = createSortableColumnConfig(FileModel.TYPE, FileModel.TYPE, 80);
|
|
ColumnConfig originalPath = createSortableColumnConfig(FileVersionModel.PATH, "Original Path", 200);
|
|
//ColumnConfig deleteDate = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEDATE.toString(), "Deleted Date", 90);
|
|
//deleteDate.setDateTimeFormat(DateTimeFormat.getFormat("dd MMM hh:mm aaa yyyy"));
|
|
ColumnConfig user = createSortableColumnConfig(FileVersionModel.USER_VERSIONING, "User", 150);
|
|
|
|
//ColumnModel cm = new ColumnModel(Arrays.asList(icon, name, type, originalPath, deleteDate, deleteUser));
|
|
|
|
ColumnModel cm = new ColumnModel(Arrays.asList(name, originalPath, user));
|
|
|
|
grid = new Grid<FileModel>(this.store, cm);
|
|
|
|
GroupingView view = new GroupingView();
|
|
view.setShowGroupedColumn(false);
|
|
|
|
this.grid.setView(view);
|
|
this.grid.setContextMenu(null);
|
|
|
|
GridFilters filters = new GridFilters();
|
|
filters.setLocal(true);
|
|
|
|
StringFilter nameFilter = new StringFilter(FileModel.NAME);
|
|
StringFilter pathFilter = new StringFilter("Original Path");
|
|
StringFilter userFilter = new StringFilter("User");
|
|
|
|
filters.addFilter(nameFilter);
|
|
filters.addFilter(pathFilter);
|
|
filters.addFilter(userFilter);
|
|
|
|
grid.addPlugin(filters);
|
|
|
|
grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<FileModel>() {
|
|
|
|
@Override
|
|
public void selectionChanged(SelectionChangedEvent<FileModel> se) {
|
|
|
|
boolean selection = grid.getSelectionModel().getSelectedItems().size()>0;
|
|
activeButtonOnSelection(selection);
|
|
}
|
|
});
|
|
|
|
grid.getView().setAutoFill(true);
|
|
grid.setBorders(true);
|
|
grid.setStripeRows(true);
|
|
grid.getView().setShowDirtyCells(false);
|
|
grid.setColumnLines(true);
|
|
grid.setColumnReordering(true);
|
|
grid.setStyleAttribute("borderTop", "none");
|
|
cp.add(grid);
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Sets the panel size.
|
|
*
|
|
* @param width the width
|
|
* @param height the height
|
|
*/
|
|
public void setPanelSize(int width, int height) {
|
|
|
|
if (width > 0 && height > 0 && grid != null) {
|
|
cp.setSize(width, height);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update versions.
|
|
*
|
|
* @param versioningFiles the versioning files
|
|
*/
|
|
public void updateVersions(List<FileVersionModel> versioningFiles) {
|
|
|
|
store.removeAll();
|
|
typeStoreOperation.removeAll();
|
|
store.add(versioningFiles);
|
|
activeButtonsOnNotEmtpy(store.getModels().size()>0);
|
|
}
|
|
|
|
/**
|
|
* Active buttons on not emtpy.
|
|
*
|
|
* @param isNotEmpty the is not empty
|
|
*/
|
|
private void activeButtonsOnNotEmtpy(boolean isNotEmpty) {
|
|
buttonEmptyVersions.setEnabled(isNotEmpty);
|
|
}
|
|
|
|
/**
|
|
* Active button on selection.
|
|
*
|
|
* @param bool the bool
|
|
*/
|
|
protected void activeButtonOnSelection(boolean bool) {
|
|
buttonDelete.setEnabled(bool);
|
|
buttonRestore.setEnabled(bool);
|
|
buttonDownload.setEnabled(bool);
|
|
}
|
|
|
|
/**
|
|
* Update store.
|
|
*
|
|
* @param store the store
|
|
*/
|
|
private void updateStore(ListStore<FileModel> store) {
|
|
|
|
resetStore();
|
|
this.grid.getStore().add(store.getModels());
|
|
}
|
|
|
|
/**
|
|
* Reset store.
|
|
*/
|
|
public void resetStore() {
|
|
this.grid.getStore().removeAll();
|
|
}
|
|
|
|
/**
|
|
* Creates the sortable column config.
|
|
*
|
|
* @param id the id
|
|
* @param name the name
|
|
* @param width the width
|
|
* @return the column config
|
|
*/
|
|
public ColumnConfig createSortableColumnConfig(String id, String name,
|
|
int width) {
|
|
ColumnConfig columnConfig = new ColumnConfig(id, name, width);
|
|
columnConfig.setSortable(true);
|
|
|
|
return columnConfig;
|
|
}
|
|
|
|
/**
|
|
* Sets the header title.
|
|
*
|
|
* @param title the new header title
|
|
*/
|
|
public void setHeaderTitle(String title) {
|
|
cp.setHeading(title);
|
|
// cp.layout();
|
|
}
|
|
|
|
/**
|
|
* Gets the file model by identifier.
|
|
*
|
|
* @param identifier the identifier
|
|
* @return the file model by identifier
|
|
*/
|
|
public FileModel getFileModelByIdentifier(String identifier){
|
|
|
|
return store.findModel(FileModel.IDENTIFIER, identifier);
|
|
|
|
}
|
|
|
|
/**
|
|
* Delete item.
|
|
*
|
|
* @param identifier (MANDATORY)
|
|
* @return true, if successful
|
|
*/
|
|
public boolean deleteItem(String identifier) {
|
|
|
|
FileModel fileTarget = getFileModelByIdentifier(identifier);
|
|
|
|
|
|
if(fileTarget!=null){
|
|
return deleteItem(fileTarget);
|
|
}
|
|
else
|
|
System.out.println("Delete Error: file target with " + identifier + " identifier not exist in store" );
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Delete item.
|
|
*
|
|
* @param fileTarget (MANDATORY)
|
|
* @return true, if successful
|
|
*/
|
|
private boolean deleteItem(FileModel fileTarget) {
|
|
|
|
Record record = store.getRecord(fileTarget);
|
|
|
|
if (record != null) {
|
|
|
|
FileModel item = (FileModel) record.getModel();
|
|
store.remove(item);
|
|
|
|
return true;
|
|
} else
|
|
System.out.println("Record Error: file target with "
|
|
+ fileTarget.getIdentifier()
|
|
+ " identifier not exist in store");
|
|
|
|
activeButtonsOnNotEmtpy(store.getModels().size()>0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Versioning items.
|
|
*
|
|
* @return the int
|
|
*/
|
|
public int versioningItems(){
|
|
return store.getCount();
|
|
}
|
|
|
|
/**
|
|
* Gets the store.
|
|
*
|
|
* @return the store
|
|
*/
|
|
protected GroupingStore<FileModel> getStore() {
|
|
return store;
|
|
}
|
|
|
|
/**
|
|
* Gets the cp.
|
|
*
|
|
* @return the cp
|
|
*/
|
|
public ContentPanel getCp() {
|
|
return cp;
|
|
}
|
|
|
|
} |