From 543a3eb0d15312ecbe4822c0e724b1f7c8b70e6e Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Mon, 17 Feb 2014 18:20:45 +0000 Subject: [PATCH] enhancements on ACLs git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace@91804 82a268e6-3cf1-43bd-a215-b396298e98cf --- .settings/com.google.gdt.eclipse.core.prefs | 2 +- .settings/org.eclipse.wst.common.component | 2 +- .../user/workspace/client/AppController.java | 85 ++-- .../client/view/WorskpacePortlet.java | 8 +- .../client/view/dialog/DialogPermission.java | 1 + .../client/view/toolbars/ACLDivInfo.java | 59 +++ .../view/toolbars/GxtBottomToolBarItem.java | 28 +- ...Panel.java => GxtBreadcrumbPathPanel.java} | 4 +- .../client/view/trash/TrashInfoContainer.java | 386 ++++++++++++++++++ .../client/view/trash/WindowTrash.java | 119 ++++++ 10 files changed, 656 insertions(+), 38 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/ACLDivInfo.java rename src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/{GxtPathPanel.java => GxtBreadcrumbPathPanel.java} (98%) create mode 100644 src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java create mode 100644 src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs index 96df978..e64b49f 100644 --- a/.settings/com.google.gdt.eclipse.core.prefs +++ b/.settings/com.google.gdt.eclipse.core.prefs @@ -1,5 +1,5 @@ eclipse.preferences.version=1 jarsExcludedFromWebInfLib= -lastWarOutDir=/home/francesco/workspace/workspace/target/workspace-6.6.1-SNAPSHOT +lastWarOutDir=/home/francesco-mangiacrapa/wseclipse/workspace/target/workspace-6.6.1-SNAPSHOT warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index b2eeab1..99f9c8e 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -5,7 +5,7 @@ - + uses diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppController.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppController.java index 4770601..d5669fd 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppController.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppController.java @@ -74,7 +74,6 @@ import org.gcube.portlets.user.workspace.client.event.SendMessageEventHandler; import org.gcube.portlets.user.workspace.client.event.SettingPermissionEvent; import org.gcube.portlets.user.workspace.client.event.SettingPermissionEventHandler; import org.gcube.portlets.user.workspace.client.event.TrashEvent; -import org.gcube.portlets.user.workspace.client.event.TrashEvent.TRASHOPERATION; import org.gcube.portlets.user.workspace.client.event.TrashEventHandler; import org.gcube.portlets.user.workspace.client.event.WebDavUrlEvent; import org.gcube.portlets.user.workspace.client.event.WebDavUrlEventHandler; @@ -88,12 +87,16 @@ import org.gcube.portlets.user.workspace.client.view.WorskpacePortlet; import org.gcube.portlets.user.workspace.client.view.dialog.DialogPermission; import org.gcube.portlets.user.workspace.client.view.panels.GxtBorderLayoutPanel; import org.gcube.portlets.user.workspace.client.view.panels.GxtItemsPanel; +import org.gcube.portlets.user.workspace.client.view.toolbars.GxtBreadcrumbPathPanel; import org.gcube.portlets.user.workspace.client.view.trash.WindowTrash; import org.gcube.portlets.user.workspace.client.view.windows.DialogGetInfo; import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplay; import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert; import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxConfirm; import org.gcube.portlets.user.workspace.shared.SessionExpiredException; +import org.gcube.portlets.user.workspace.shared.TrashOperationResult; +import org.gcube.portlets.user.workspace.shared.WorkspaceACL; +import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation; import org.gcube.portlets.widgets.wsmail.client.forms.MailForm; import com.extjs.gxt.ui.client.event.Listener; @@ -175,19 +178,28 @@ public class AppController implements SubscriberInterface { switch (trashEvent.getTrashOperation()) { case SHOW: - WindowTrash.getInstance().show(); - break; - - case MOVETO: - - break; - - case RESTOREFROM: - break; - default: + + if(trashEvent.getTrashOperation()!=null){ + WindowTrash.getInstance().mask("Submitting Operation"); + AppControllerExplorer.rpcWorkspaceService.executeOperationOnTrash(trashEvent.getTargetFileModel().getIdentifier(), trashEvent.getTrashOperation(), new AsyncCallback() { + + @Override + public void onFailure(Throwable arg0) { + WindowTrash.getInstance().unmask(); + + } + + @Override + public void onSuccess(TrashOperationResult operationResult) { + WindowTrash.getInstance().unmask(); + WindowTrash.getInstance().updateTrashContainer(operationResult.getTrashContent()); + } + }); + + } break; } @@ -887,12 +899,7 @@ public class AppController implements SubscriberInterface { }); } } - }); - - - - - + }); } } @@ -1015,7 +1022,7 @@ public class AppController implements SubscriberInterface { result.add(item); } - setPathInView(result); //Set file path in tab panel on current item selected + updateBreadcrumb(result); //Set file path in tab panel on current item selected } @@ -1042,18 +1049,45 @@ public class AppController implements SubscriberInterface { @Override public void onSuccess(List result) { - setPathInView(result); //Set file path in tab panel on current item selected + updateBreadcrumb(result); //Set file path in tab panel on current item selected } }); } - private void setPathInView(List parents){ + private void updateBreadcrumb(List parents){ - //this.wsPortlet.getBasicTabContainer().setLabelPath(path); //Set path in tab view panel + //this.wsPortlet.getBasicTabContainer().setLabelPath(path); //Set path in breadcrumb - this.wsPortlet.getToolBarPath().setPath(parents); //Set path in tab view panel + GxtBreadcrumbPathPanel breadCrumb = this.wsPortlet.getToolBarPath(); + + breadCrumb.setPath(parents); //Set path in breadcrumb + + FileModel parent = breadCrumb.getLastParent(); + + if(parent!=null && parent.isDirectory() && parent.isShared()) + setACLInfo(parent.getIdentifier()); + + } + + + private void setACLInfo(String parentId){ + + AppControllerExplorer.rpcWorkspaceService.getACLForFolderId(parentId, new AsyncCallback>() { + + @Override + public void onFailure(Throwable arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void onSuccess(List res) { + if(res!=null && res.size()>0) + wsPortlet.getToolBarItemDetails().updateACLInfo(res.get(0)); + } + }); } /** @@ -1302,7 +1336,7 @@ public class AppController implements SubscriberInterface { if(item.isDirectory()) //ADDED 11-06-2013 parents.add(item); - setPathInView(parents); //set path + updateBreadcrumb(parents); //set path //CASE IS A SEARCH if(wsPortlet.getSearchAndFilterContainer().isSearchActive()){ //ADDED 12-04-12 @@ -1377,7 +1411,7 @@ public class AppController implements SubscriberInterface { @Override public void setParentItemSelected(ArrayList listParents){ - setPathInView(listParents); + updateBreadcrumb(listParents); } @Override @@ -1605,8 +1639,7 @@ public class AppController implements SubscriberInterface { * @see org.gcube.portlets.user.workspace.client.interfaces.SubscriberInterface#trashEvent(org.gcube.portlets.user.workspace.client.event.TrashEvent.TRASHOPERATION, org.gcube.portlets.user.workspace.client.model.FileModel) */ @Override - public void trashEvent(TRASHOPERATION trashOperation, FileModel targetFileModel) { - + public void trashEvent(WorkspaceTrashOperation trashOperation, FileModel targetFileModel) { } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/WorskpacePortlet.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/WorskpacePortlet.java index 646fbfe..a13959c 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/WorskpacePortlet.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/WorskpacePortlet.java @@ -6,7 +6,7 @@ import org.gcube.portlets.user.workspace.client.view.panels.GxtBorderLayoutPanel import org.gcube.portlets.user.workspace.client.view.panels.GxtCardLayoutResultPanel; import org.gcube.portlets.user.workspace.client.view.panels.GxtSeachAndFilterPanel; import org.gcube.portlets.user.workspace.client.view.toolbars.GxtBottomToolBarItem; -import org.gcube.portlets.user.workspace.client.view.toolbars.GxtPathPanel; +import org.gcube.portlets.user.workspace.client.view.toolbars.GxtBreadcrumbPathPanel; /** @@ -21,7 +21,7 @@ public class WorskpacePortlet { private ExplorerPanel explorerPanel = null; private GxtBottomToolBarItem toolBarItemDetails; private GxtListView listViewContainer; - private GxtPathPanel toolBarPathPanel; + private GxtBreadcrumbPathPanel toolBarPathPanel; private GxtGridFilterGroupPanel gridFilterGroupContainer; private GxtSeachAndFilterPanel searchAndFilterContainer; private GxtCardLayoutResultPanel gxtCardLayoutResultPanel; @@ -30,7 +30,7 @@ public class WorskpacePortlet { // Log.trace("Initializing WorskpacePortlet"); this.basicTabContainer = new GxtBasicTabPanel(); - this.toolBarPathPanel = new GxtPathPanel(); + this.toolBarPathPanel = new GxtBreadcrumbPathPanel(); this.searchAndFilterContainer = new GxtSeachAndFilterPanel(this.toolBarPathPanel.getToolBarPathPanel()); this.gridFilterGroupContainer = new GxtGridFilterGroupPanel(activeGroup); @@ -67,7 +67,7 @@ public class WorskpacePortlet { } - public GxtPathPanel getToolBarPath() { + public GxtBreadcrumbPathPanel getToolBarPath() { return toolBarPathPanel; } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/dialog/DialogPermission.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/dialog/DialogPermission.java index 1f2e1cc..0212982 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/dialog/DialogPermission.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/dialog/DialogPermission.java @@ -90,6 +90,7 @@ public class DialogPermission extends Dialog { getOwner(folder.getIdentifier(), callcack); + //TODO GET ACL FOR USER AppControllerExplorer.rpcWorkspaceService.getACLs(new AsyncCallback>() { @Override diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/ACLDivInfo.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/ACLDivInfo.java new file mode 100644 index 0000000..7890fc2 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/ACLDivInfo.java @@ -0,0 +1,59 @@ +package org.gcube.portlets.user.workspace.client.view.toolbars; + +import com.extjs.gxt.ui.client.widget.HorizontalPanel; +import com.extjs.gxt.ui.client.widget.LayoutContainer; +import com.google.gwt.user.client.ui.AbstractImagePrototype; +import com.google.gwt.user.client.ui.HTML; + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * @Feb 17, 2014 + * + */ +public class ACLDivInfo extends LayoutContainer { + + private HorizontalPanel hpPanel = new HorizontalPanel(); + + private HTML text = new HTML(); + + public ACLDivInfo(String caption, AbstractImagePrototype img) { + super(); + super.setWidth(80); + text.setPixelSize(50, 30); + hpPanel.setWidth("100%"); + + updateInfo(caption,img); + } + + public void updateInfo(String caption, AbstractImagePrototype img){ + + String html = "
"; + + if(img!=null) + html+=addImage(img); + + if(caption!=null) + html+=addCaption(caption); + + + html+="
"; + + text.setHTML(html); + + hpPanel.layout(); + } + + private String addImage(AbstractImagePrototype img){ + + return "" + img.getHTML() + ""; + + } + + private String addCaption(String caption){ + + return ""+ caption+""; + + } +} + diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBottomToolBarItem.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBottomToolBarItem.java index fa02a04..eb13fec 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBottomToolBarItem.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBottomToolBarItem.java @@ -5,16 +5,21 @@ import org.gcube.portlets.user.workspace.client.event.AccountingHistoryEvent; import org.gcube.portlets.user.workspace.client.event.AccountingReadersEvent; import org.gcube.portlets.user.workspace.client.event.GetInfoEvent; import org.gcube.portlets.user.workspace.client.event.TrashEvent; -import org.gcube.portlets.user.workspace.client.event.TrashEvent.TRASHOPERATION; import org.gcube.portlets.user.workspace.client.resources.Resources; +import org.gcube.portlets.user.workspace.client.util.GetPermissionIconByACL; +import org.gcube.portlets.user.workspace.shared.WorkspaceACL; +import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation; import com.extjs.gxt.ui.client.event.ButtonEvent; import com.extjs.gxt.ui.client.event.SelectionListener; +import com.extjs.gxt.ui.client.widget.Label; import com.extjs.gxt.ui.client.widget.Text; import com.extjs.gxt.ui.client.widget.button.Button; import com.extjs.gxt.ui.client.widget.form.TextField; +import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem; import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem; import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; +import com.google.gwt.user.client.ui.AbstractImagePrototype; /** * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it @@ -43,6 +48,7 @@ public class GxtBottomToolBarItem extends ToolBar{ private Button bHistory; private Button bRead; private Button btnGetTrash; + private ACLDivInfo aclDivInfo; public GxtBottomToolBarItem(){ super(); @@ -98,6 +104,11 @@ public class GxtBottomToolBarItem extends ToolBar{ // add(bRead); + + add(new FillToolItem()); + aclDivInfo = new ACLDivInfo("", null); + add(aclDivInfo); + btnGetTrash = new Button("Trash"); btnGetTrash.setIcon(Resources.getTrash()); btnGetTrash.addSelectionListener(new SelectionListener() { @@ -105,17 +116,19 @@ public class GxtBottomToolBarItem extends ToolBar{ @Override public void componentSelected(ButtonEvent ce) { - AppController.getEventBus().fireEvent(new TrashEvent(TRASHOPERATION.SHOW, null)); + AppController.getEventBus().fireEvent(new TrashEvent(WorkspaceTrashOperation.SHOW, null)); } }); // add(new FillToolItem()); // add(btnGetTrash); + + + enableButtons(false); - - + } public void resetDetails(){ @@ -154,4 +167,11 @@ public class GxtBottomToolBarItem extends ToolBar{ bRead.setEnabled(markAsRead); } + + + public void updateACLInfo(WorkspaceACL acl){ + + AbstractImagePrototype img = GetPermissionIconByACL.getImage(acl); + aclDivInfo.updateInfo(acl.getLabel(), img); + } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtPathPanel.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBreadcrumbPathPanel.java similarity index 98% rename from src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtPathPanel.java rename to src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBreadcrumbPathPanel.java index 508ff51..258cf69 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtPathPanel.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/toolbars/GxtBreadcrumbPathPanel.java @@ -22,7 +22,7 @@ import com.google.gwt.user.client.ui.Image; * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * */ -public class GxtPathPanel { +public class GxtBreadcrumbPathPanel { private static final String ROOT_NAME = "Workspace"; @@ -34,7 +34,7 @@ public class GxtPathPanel { private FileModel lastParent; - public GxtPathPanel() { + public GxtBreadcrumbPathPanel() { toolBar = new HorizontalPanel(); toolBar.setHeight("25px"); initToolbar(); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java new file mode 100644 index 0000000..f37e966 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/TrashInfoContainer.java @@ -0,0 +1,386 @@ +package org.gcube.portlets.user.workspace.client.view.trash; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.gcube.portlets.user.workspace.client.ConstantsExplorer; +import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum; +import org.gcube.portlets.user.workspace.client.model.FileGridModel; +import org.gcube.portlets.user.workspace.client.model.FileModel; +import org.gcube.portlets.user.workspace.client.model.FileTrashedModel; +import org.gcube.portlets.user.workspace.client.resources.Resources; + +import com.extjs.gxt.ui.client.Style.ButtonScale; +import com.extjs.gxt.ui.client.Style.HorizontalAlignment; +import com.extjs.gxt.ui.client.data.BaseModelData; +import com.extjs.gxt.ui.client.dnd.GridDropTarget; +import com.extjs.gxt.ui.client.event.ButtonEvent; +import com.extjs.gxt.ui.client.event.DNDEvent; +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.store.TreeStoreModel; +import com.extjs.gxt.ui.client.widget.ContentPanel; +import com.extjs.gxt.ui.client.widget.LayoutContainer; +import com.extjs.gxt.ui.client.widget.button.ToggleButton; +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.toolbar.ToolBar; +import com.google.gwt.i18n.client.NumberFormat; + +public class TrashInfoContainer extends LayoutContainer { + + /** + * + */ + + + private Grid grid; + private ContentPanel cp; + private GroupingStore store = new GroupingStore(); + private boolean groupingEnabled; + private ListStore typeStoreOperation = new ListStore(); + private NumberFormat number = ConstantsExplorer.numberFormatterKB; + private GridDropTarget gridDropTarget; + + public TrashInfoContainer() { + initContentPanel(); + initGrid(); + createToolBar(); + initDropTarget(); + } + + /** + * + */ + private void initDropTarget() { + + this.gridDropTarget = new GridDropTarget(grid){ + + /* (non-Javadoc) + * @see com.extjs.gxt.ui.client.dnd.GridDropTarget#onDragDrop(com.extjs.gxt.ui.client.event.DNDEvent) + */ + + @Override + protected void onDragDrop(DNDEvent e) { + // TODO Auto-generated method stub + + List listFileModel = getDragSource(e); + + List ids = new ArrayList(); + + for (FileModel fileModel : listFileModel) { + fileModel.setIcon(); + ids.add(fileModel.getIdentifier()); + } + + System.out.println("** Trash Event move handleInsertDrop is completed"); + + super.onDragDrop(e); + + + } + + private List getDragSource(DNDEvent event){ + + List listDraggedFile = new ArrayList(); + + if(event.getData() != null){ + + List listItemsSource = event.getData(); + + System.out.println("Trash - Number of move " + listItemsSource.size()); + +// FileModel sourceFileModel = null; //for print + + for(int i=0; i() { + + @Override + public void componentSelected(ButtonEvent ce) { + + if (buttonGrouping.isPressed()) + enableGrouping(); + else + disableGrouping(); + } + }); + +// bar.add(buttonGrouping); + cp.setTopComponent(bar); + + } + + public void initGrid() { + +// store.groupBy(ConstantsExplorer.SHORTCUTCATEGORY); +// groupingEnabled = true; + + ColumnConfig icon = new ColumnConfig(ConstantsExplorer.ICON, "", 25); + ColumnConfig name = createSortableColumnConfig(ConstantsExplorer.NAME, ConstantsExplorer.NAME, 200); + ColumnConfig type = createSortableColumnConfig(ConstantsExplorer.TYPE, ConstantsExplorer.TYPE, 50); + ColumnConfig originalPath = createSortableColumnConfig(FileTrashedModel.STOREINFO.ORIGINALPATH.toString(), "Original Path", 200); + ColumnConfig deleteDate = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEDATE.toString(), "Delete Date", 50); + ColumnConfig deleteUser = createSortableColumnConfig(FileTrashedModel.STOREINFO.DELETEUSER.toString(), "Delete User", 150); +// ColumnConfig category = createSortableColumnConfig(ConstantsExplorer.SHORTCUTCATEGORY, ConstantsExplorer.SHORTCUTCATEGORY, 100); +// ColumnConfig ownerFullName = createSortableColumnConfig(ConstantsExplorer.OWNERFULLNAME, ConstantsExplorer.OWNER, 100); +// ColumnConfig ownerFullName = createSortableColumnConfig(ConstantsExplorer.OWNERFULLNAME, ConstantsExplorer.OWNER, 100); + + ColumnModel cm = new ColumnModel(Arrays.asList(icon, name, type, originalPath, deleteDate, deleteUser)); + + final ColumnModel columnModel = cm; + + grid = new Grid(this.store, cm); + + GroupingView view = new GroupingView(); + view.setShowGroupedColumn(true); + this.grid.setView(view); + +// view.setGroupRenderer(new GridGroupRenderer() { +// public String render(GroupColumnData data) { +// String f = columnModel.getColumnById(data.field).getHeader(); +// String l = data.models.size() == 1 ? "Item" : "Items"; +// return f + ": " + data.group + " (" + data.models.size() + " " +// + l + ")"; +// } +// }); + + + GridCellRenderer folderRender = new GridCellRenderer() { + @Override + public String render(FileModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore store, Grid grid) { + String val = model.get(property); + String color = "black"; + + if(val != null && val.equals(GXTFolderItemTypeEnum.FOLDER.toString())){ +// color = "#EEC900"; + return "" + val + ""; + }else{ + if(val==null) + val = ""; + return "" + val + ""; + } + } + }; + + type.setRenderer(folderRender); + + GridFilters filters = new GridFilters(); + filters.setLocal(true); + + + StringFilter nameFilter = new StringFilter(ConstantsExplorer.NAME); + StringFilter authorFilter = new StringFilter(ConstantsExplorer.TYPE); + + filters.addFilter(nameFilter); + filters.addFilter(authorFilter); + + grid.addPlugin(filters); + + grid.setBorders(true); + grid.setStripeRows(true); + grid.getView().setAutoFill(true); + grid.setColumnLines(true); + grid.setColumnReordering(true); + grid.setStyleAttribute("borderTop", "none"); + cp.add(grid); + + + } + + public void setPanelSize(int width, int height) { + + if (width > 0 && height > 0 && grid != null) { + cp.setSize(width, height); + // grid.setSize(width, height); + } + } + + public TrashInfoContainer(List trashFiles) { + + initContentPanel(); + initGrid(); + updateTrash(trashFiles); + } + + public void disableGrouping() { + GroupingStore groupingStore = null; + if (store instanceof GroupingStore) { + groupingStore = (GroupingStore) store; + if (groupingStore != null) { + groupingStore.clearGrouping(); + } + this.groupingEnabled = false; + } + } + + public void enableGrouping() { + GroupingStore groupingStore = null; + if (store instanceof GroupingStore) { + groupingStore = (GroupingStore) store; + if (groupingStore != null) { + groupingStore.groupBy(ConstantsExplorer.SHORTCUTCATEGORY); + } + this.groupingEnabled = true; + } + } + + public void updateTrash(List trashFiles) { + + store.removeAll(); + typeStoreOperation.removeAll(); + store.add(trashFiles); + } + + private void updateStore(ListStore store) { + + resetStore(); + this.grid.getStore().add(store.getModels()); + } + + public void resetStore() { + this.grid.getStore().removeAll(); + } + + public ColumnConfig createSortableColumnConfig(String id, String name, + int width) { + ColumnConfig columnConfig = new ColumnConfig(id, name, width); + columnConfig.setSortable(true); + + return columnConfig; + } + + public void setHeaderTitle(String title) { + cp.setHeading(title); + // cp.layout(); + } + + public boolean isGroupingEnabled() { + return groupingEnabled; + } + + public void setGroupingEnabled(boolean groupingEnabled) { + this.groupingEnabled = groupingEnabled; + } + + + /** + * + * @param identifier + * @return + */ + public FileTrashedModel getFileModelByIdentifier(String identifier){ + + return store.findModel(ConstantsExplorer.IDENTIFIER, identifier); + + } + + /** + * + * @param identifier (MANDATORY) + * @return + */ + public boolean deleteItem(String identifier) { + + FileTrashedModel 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; + } + + /** + * + * @param fileTarget (MANDATORY) + * @return + */ + private boolean deleteItem(FileTrashedModel fileTarget) { + + Record record = store.getRecord(fileTarget); + + if (record != null) { + + FileTrashedModel item = (FileTrashedModel) record.getModel(); + store.remove(item); + + return true; + } else + System.out.println("Record Error: file target with " + + fileTarget.getIdentifier() + + " identifier not exist in store"); + + return false; + + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java new file mode 100644 index 0000000..ceaa3c3 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/trash/WindowTrash.java @@ -0,0 +1,119 @@ +package org.gcube.portlets.user.workspace.client.view.trash; + +import java.util.List; + +import org.gcube.portlets.user.workspace.client.ConstantsExplorer; +import org.gcube.portlets.user.workspace.client.model.FileTrashedModel; +import org.gcube.portlets.user.workspace.client.resources.Resources; + +import com.extjs.gxt.ui.client.widget.Window; +import com.extjs.gxt.ui.client.widget.layout.FitLayout; + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * @May 23, 2013 + * + * Singleton + */ +public class WindowTrash extends Window { + + private List trashedFiles; + private TrashInfoContainer trashContainers; + private static WindowTrash INSTANCE = null; + + + private WindowTrash() { + initAccounting(); + setIcon(Resources.getTrash()); //TODO + setHeading("Trash"); +// addResizeListner(); + } + + /** + * + * @return + */ + public static synchronized WindowTrash getInstance(){ + if(INSTANCE==null) + INSTANCE = new WindowTrash(); + + return INSTANCE; + } + +// public void addResizeListner(){ +// +// this.addListener(Events.Resize, new Listener() { +// +// @Override +// public void handleEvent(WindowEvent we ) +// { +// +// if(trashContainers!=null){ +//// System.out.println("Size in event: " + we.getWidth() + "x" + we.getHeight() ); +//// accountingsContainers.setPanelSize(we.getWidth()-14, we.getHeight()-30); +// } +// } +// +// }); +// } + +// public WindowTrash(List trashFiles) { +// updateTrashContainer(trashFiles); +// } + + private void initAccounting() { +// setModal(true); + setLayout(new FitLayout()); + setSize(700, 350); + setResizable(true); + setMaximizable(true); +// setCollapsible(true); + this.trashContainers = new TrashInfoContainer(); + add(trashContainers); + } + + public void setWindowTitle(String title) { + this.setHeading(title); + + } + + + /** + * + * @param fileModelId + * @return + */ + public boolean deleteFileFromTrash(String fileModelId){ + return this.trashContainers.deleteItem(fileModelId); + } + + + public void updateTrashContainer(List trashFiles) { + + this.trashContainers.resetStore(); + this.trashedFiles = trashFiles; + this.trashContainers.updateTrash(trashFiles); + } + + public List getTrashedFiles() { + return trashedFiles; + } + + public void maskAccountingInfo(boolean bool){ + +// if(accountingsContainers!=null){ +// +// if(bool) +// accountingsContainers.mask(ConstantsExplorer.LOADING, ConstantsExplorer.LOADINGSTYLE); +// else +// accountingsContainers.unmask(); +// } + + if(bool) + this.mask(ConstantsExplorer.LOADING, ConstantsExplorer.LOADINGSTYLE); + else + this.unmask(); + } + +}