496 lines
14 KiB
Java
496 lines
14 KiB
Java
package org.gcube.portlets.user.workspace.client.view.version;
|
|
|
|
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.interfaces.GXTFolderItemTypeEnum;
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
|
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.ColumnData;
|
|
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.GridCellRenderer;
|
|
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 buttonRestoreAll;
|
|
private Button buttonEmptyTrash;
|
|
private FileModel fileVersioned;
|
|
|
|
/**
|
|
* Instantiates a new versioning info container.
|
|
*
|
|
* @param file the versioning files
|
|
*/
|
|
public VersioningInfoContainer(FileModel file) {
|
|
|
|
initContentPanel();
|
|
initGrid();
|
|
createToolBar();
|
|
this.fileVersioned = file;
|
|
|
|
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, grid.getSelectionModel().getSelectedItems().get(0)));
|
|
}
|
|
});
|
|
|
|
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, grid.getSelectionModel().getSelectedItems().get(0)));
|
|
|
|
}
|
|
});
|
|
|
|
bar.add(buttonDelete);
|
|
|
|
|
|
bar.add(new SeparatorMenuItem());
|
|
|
|
buttonRestoreAll = new Button(WorkspaceVersioningOperation.DOWNLOAD.getLabel(),Resources.getIconRecycle());
|
|
buttonRestoreAll.setToolTip(WorkspaceVersioningOperation.DOWNLOAD.getOperationDescription());
|
|
buttonRestoreAll.setScale(ButtonScale.SMALL);
|
|
buttonRestoreAll.setIconAlign(IconAlign.TOP);
|
|
buttonRestoreAll.addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
@Override
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
if(checkSelection())
|
|
AppController.getEventBus().fireEvent(new FileVersioningEvent(WorkspaceVersioningOperation.DOWNLOAD, grid.getSelectionModel().getSelectedItems().get(0)));
|
|
}
|
|
});
|
|
|
|
bar.add(buttonRestoreAll);
|
|
|
|
|
|
buttonEmptyTrash = new Button(WorkspaceVersioningOperation.EMPTY_OLDER_VERSIONS.getLabel(),Resources.getTrashEmpty());
|
|
buttonEmptyTrash.setToolTip(WorkspaceVersioningOperation.EMPTY_OLDER_VERSIONS.getOperationDescription());
|
|
buttonEmptyTrash.setScale(ButtonScale.SMALL);
|
|
buttonEmptyTrash.setIconAlign(IconAlign.TOP);
|
|
buttonEmptyTrash.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 older versions of: "+ fileVersioned.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, fileVersioned));
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
bar.add(buttonEmptyTrash);
|
|
|
|
|
|
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, null));
|
|
}
|
|
});
|
|
|
|
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(FileTrashedModel.STOREINFO.ORIGINALPATH.toString(), "Original Path", 200);
|
|
//ColumnConfig deleteDate = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEDATE.toString(), "Deleted Date", 90);
|
|
//deleteDate.setDateTimeFormat(DateTimeFormat.getFormat("dd MMM hh:mm aaa yyyy"));
|
|
//ColumnConfig deleteUser = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEUSER.toString(), "Deleted By", 150);
|
|
|
|
//ColumnModel cm = new ColumnModel(Arrays.asList(icon, name, type, originalPath, deleteDate, deleteUser));
|
|
|
|
ColumnModel cm = new ColumnModel(Arrays.asList(name));
|
|
|
|
final ColumnModel columnModel = cm;
|
|
|
|
grid = new Grid<FileModel>(this.store, cm);
|
|
|
|
GroupingView view = new GroupingView();
|
|
view.setShowGroupedColumn(false);
|
|
|
|
this.grid.setView(view);
|
|
this.grid.setContextMenu(null);
|
|
|
|
|
|
GridCellRenderer<FileModel> folderRender = new GridCellRenderer<FileModel>() {
|
|
@Override
|
|
public String render(FileModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<FileModel> store, Grid<FileModel> grid) {
|
|
String val = model.get(property);
|
|
String color = "black";
|
|
|
|
if(val != null && val.equals(GXTFolderItemTypeEnum.FOLDER.toString())){
|
|
// color = "#EEC900";
|
|
return "<span qtitle='" + columnModel.getColumnById(property).getHeader() + "' qtip='" + val + "' style='font-weight: bold;color:" + color + "'>" + val + "</span>";
|
|
}else{
|
|
if(val==null)
|
|
val = "";
|
|
return "<span qtitle='" + columnModel.getColumnById(property).getHeader() + "' qtip='" + val + "' style='color:" + color + "'>" + val + "</span>";
|
|
}
|
|
}
|
|
};
|
|
|
|
type.setRenderer(folderRender);
|
|
|
|
GridFilters filters = new GridFilters();
|
|
filters.setLocal(true);
|
|
|
|
|
|
StringFilter nameFilter = new StringFilter(FileModel.NAME);
|
|
StringFilter typeFilter = new StringFilter(FileModel.TYPE);
|
|
|
|
//DateFilter dateFilter = new DateFilter(FileModel.STOREINFO.DELETEDATE.toString());
|
|
|
|
filters.addFilter(nameFilter);
|
|
filters.addFilter(typeFilter);
|
|
//filters.addFilter(dateFilter);
|
|
|
|
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);
|
|
// grid.setSize(width, height);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Update versions.
|
|
*
|
|
* @param versioningFiles the versioning files
|
|
*/
|
|
public void updateVersions(List<FileModel> versioningFiles) {
|
|
|
|
store.removeAll();
|
|
typeStoreOperation.removeAll();
|
|
|
|
// for (FileModel fileTrashedModel : trashFiles) {
|
|
// fileTrashedModel.setIcon();
|
|
// }
|
|
|
|
store.add(versioningFiles);
|
|
activeButtonsOnNotEmtpy(store.getModels().size()>0);
|
|
}
|
|
|
|
/**
|
|
* Active buttons on not emtpy.
|
|
*
|
|
* @param isNotEmpty the is not empty
|
|
*/
|
|
private void activeButtonsOnNotEmtpy(boolean isNotEmpty) {
|
|
buttonRestoreAll.setEnabled(isNotEmpty);
|
|
buttonEmptyTrash.setEnabled(isNotEmpty);
|
|
}
|
|
|
|
/**
|
|
* Active button on selection.
|
|
*
|
|
* @param bool the bool
|
|
*/
|
|
protected void activeButtonOnSelection(boolean bool) {
|
|
buttonDelete.setEnabled(bool);
|
|
buttonRestore.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;
|
|
}
|
|
|
|
} |