From 19c9117877691bf0daac28a29dcdffb875f52669 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 3 May 2016 15:35:06 +0000 Subject: [PATCH] 2546: Endow Workspace Resources Explorer with filtering and display features Task-Url: https://support.d4science.org/issues/2546 Added code to change properties and filters on-the-fly git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@128437 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../WorkspaceResourcesExplorerPanel.java | 84 +++++++++++++++++++ .../client/view/WorkspaceExplorer.java | 61 +++++++++++++- .../client/view/grid/ItemsTable.java | 18 +++- .../wsexplorer/shared/ExtensionItem.java | 75 ----------------- 4 files changed, 157 insertions(+), 81 deletions(-) delete mode 100644 src/main/java/org/gcube/portlets/widgets/wsexplorer/shared/ExtensionItem.java diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/explore/WorkspaceResourcesExplorerPanel.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/explore/WorkspaceResourcesExplorerPanel.java index d25d030..a9b2394 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/explore/WorkspaceResourcesExplorerPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/explore/WorkspaceResourcesExplorerPanel.java @@ -59,6 +59,10 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor private ScrollPanel southPanel = new ScrollPanel(); private String folderId; private String folderName; + private List showProperties; + private FilterCriteria filterCriteria; + + /** * Instantiates a new workspace folder explorer select panel. @@ -123,6 +127,8 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor private void initExplorer(String folderId, String folderName, ItemType[] selectableTypes, ItemType[] showableTypes, List showProperties, FilterCriteria filter) throws Exception{ this.folderId = folderId; this.folderName = folderName; + this.showProperties = showProperties; + this.filterCriteria = filter; bindEvents(); wsExplorer = new WorkspaceExplorer(eventBus, filter, showableTypes, selectableTypes, showProperties, new DISPLAY_FIELD[]{DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME, DISPLAY_FIELD.CREATION_DATE}); Item item = new Item(folderId, folderName, true); @@ -399,4 +405,82 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor } return false; } + + + + /** + * Gets the filter criteria. + * + * @return the filterCriteria + */ + public FilterCriteria getFilterCriteria() { + + return filterCriteria; + } + + + /** + * Updates filter criteria. + * + * @param filterCriteria the filter criteria + */ + public void updatesFilterCriteria(FilterCriteria filterCriteria) { + + this.filterCriteria = filterCriteria; + wsExplorer.setNewFilterCriteria(filterCriteria); + try { + wsExplorer.loadFolder(wsExplorer.getDisplayingFolderItem(), true); + } + catch (Exception e) { + wsExplorer.setAlert("Sorry, an error occurred during filter update", AlertType.ERROR); + } + } + + /** + * Updates filter criteria. + * + * @param showProperties the show properties + */ + public void updatesShowProperties(List showProperties) { + + this.showProperties = showProperties; + wsExplorer.setNewShowProperties(showProperties); + try { + wsExplorer.loadFolder(wsExplorer.getDisplayingFolderItem(), true); + } + catch (Exception e) { + wsExplorer.setAlert("Sorry, an error occurred during show properties update", AlertType.ERROR); + } + } + + /** + * Updates filters and properties. + * + * @param filterCriteria the filter criteria + * @param showProperties the show properties + */ + public void updatesFiltersAndProperties(FilterCriteria filterCriteria, List showProperties) { + + this.filterCriteria = filterCriteria; + this.showProperties = showProperties; + wsExplorer.setNewFilterCriteria(filterCriteria); + wsExplorer.setNewShowProperties(showProperties); + try { + wsExplorer.loadFolder(wsExplorer.getDisplayingFolderItem(), true); + } + catch (Exception e) { + wsExplorer.setAlert("Sorry, an error occurred during filters or properties update", AlertType.ERROR); + } + } + + + /** + * Gets the show properties. + * + * @return the showProperties + */ + public List getShowProperties() { + + return showProperties; + } } diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/view/WorkspaceExplorer.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/view/WorkspaceExplorer.java index 6cc44a9..2b91764 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/view/WorkspaceExplorer.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/view/WorkspaceExplorer.java @@ -58,7 +58,15 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{ private DISPLAY_FIELD[] displayFields; private HandlerManager eventBus; + private Item displayingFolderItem; + /** + * Instantiates a new workspace explorer. + * + * @param eventBus the event bus + * @param showableTypes the showable types + * @param selectableTypes the selectable types + */ private WorkspaceExplorer(HandlerManager eventBus, ItemType[] showableTypes, ItemType[] selectableTypes){ this.eventBus = eventBus; setShowableTypes(showableTypes); @@ -162,15 +170,27 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{ public void onSuccess(Item item) { eventBus.fireEvent(new RootLoadedEvent(item)); updateExplorer(item.getChildren()); + + setDisplayingFolderItem(item); } }); } + /** + * Sets the displaying folder item. + * + * @param item the new displaying folder item + */ + private void setDisplayingFolderItem(Item item) { + this.displayingFolderItem = item; + } + /** * Load folder. * * @param item the item + * @param loadGcubeProperties the load gcube properties * @throws Exception the exception */ public void loadFolder(final Item item, boolean loadGcubeProperties) throws Exception { @@ -211,6 +231,8 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{ item.setName(result.getName()); updateExplorer(result.getChildren()); + + setDisplayingFolderItem(result); } }); } @@ -246,8 +268,10 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{ } @Override - public void onSuccess(Item items) { - updateExplorer(items.getChildren()); + public void onSuccess(Item item) { + updateExplorer(item.getChildren()); + + setDisplayingFolderItem(item); } }); } @@ -270,7 +294,7 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{ /** * Adds the item to explorer. * - * @param items the items + * @param item the item */ public void addItemToExplorer(Item item){ GWT.log("workspace explorer add item.."+item); @@ -372,4 +396,35 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{ this.showableTypes.clear(); if (showableTypes!=null) for (ItemType type:showableTypes) this.showableTypes.add(type); } + + /** + * Sets the new filter criteria. + * + * @param filterCriteria the new new filter criteria + */ + public void setNewFilterCriteria(FilterCriteria filterCriteria) { + this.filterCriteria = filterCriteria; + } + + + /** + * Gets the displaying folder item. + * + * @return the displayingFolderItem + */ + public Item getDisplayingFolderItem() { + + return displayingFolderItem; + } + + + /** + * Sets the new show properties. + * + * @param displayProperties the new new show properties + */ + public void setNewShowProperties(List displayProperties) { + this.itTables.setDisplayProperties(displayProperties); + itTables.reInitColumnsTable(); + } } diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/view/grid/ItemsTable.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/view/grid/ItemsTable.java index 2c79cb5..2564fc1 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/view/grid/ItemsTable.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/view/grid/ItemsTable.java @@ -219,7 +219,7 @@ public class ItemsTable extends AbstractItemsCellTable implem Item extensionItem; String value = null; if(object instanceof Item){ - extensionItem = (Item) object; + extensionItem = object; value = extensionItem.getGcubeProperties().get(column); } return value==null?"":value; @@ -241,8 +241,8 @@ public class ItemsTable extends AbstractItemsCellTable implem return 1; - Item e1 = (Item) o1; - Item e2 = (Item) o2; + Item e1 = o1; + Item e2 = o2; String v1 = e1.getGcubeProperties().get(column); String v2 = e2.getGcubeProperties().get(column); @@ -286,6 +286,18 @@ public class ItemsTable extends AbstractItemsCellTable implem this.displayProperties = properties; } + + /** + * Reset columns table. + */ + public void reInitColumnsTable(){ + int count = cellTable.getColumnCount(); + for(int i=0;i gcubeProperties; -// -// /** -// * Instantiates a new extension item. -// * -// * @param id the id -// * @param name the name -// * @param isFolder the is folder -// * @param gcubeProperties the gcube properties -// */ -// public ExtensionItem(String id, String name, boolean isFolder, Map gcubeProperties) { -// super(id,name,isFolder); -// this.gcubeProperties = new HashMap(1); -// this.gcubeProperties = gcubeProperties; -// } -// -// -// /** -// * Gets the gcube properties. -// * -// * @return the gcubeProperties -// */ -// public Map getGcubeProperties() { -// -// return gcubeProperties; -// } -// -// -// /** -// * Sets the gcube properties. -// * -// * @param gcubeProperties the gcubeProperties to set -// */ -// public void setGcubeProperties(Map gcubeProperties) { -// -// this.gcubeProperties = gcubeProperties; -// } -// -// -// /* (non-Javadoc) -// * @see java.lang.Object#toString() -// */ -// @Override -// public String toString() { -// -// StringBuilder builder = new StringBuilder(); -// builder.append("ExtensionItem [gcubeProperties="); -// builder.append(gcubeProperties); -// builder.append("]"); -// return builder.toString(); -// } -//}