This commit is contained in:
Francesco Mangiacrapa 2017-07-06 14:16:37 +00:00
parent 42ca87a692
commit db424b5cc9
25 changed files with 2808 additions and 1071 deletions

View File

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
@ -28,5 +23,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,6 +1,6 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error

View File

@ -1,4 +1,9 @@
<ReleaseNotes>
<Changeset component="portlets-widgets.workspace-explorer.1-7-0"
date="2017-07-06">
<Change>[Feature #9114] Add pagination to Workspace Explorer
</Change>
</Changeset>
<Changeset component="portlets-widgets.workspace-explorer.1-6-1"
date="2017-02-06">
<Change>[Bug #6601] fixed
@ -12,7 +17,8 @@
<Changeset component="portlets-widgets.workspace-explorer.1-5-0"
date="2016-09-21">
<Change>[Feature #5091] Added load for folder ID to SelectDialog and
SelectPanel</Change>
SelectPanel
</Change>
<Change>Bug fixed on breadcrumb when item is null</Change>
</Changeset>
<Changeset component="portlets-widgets.workspace-explorer.1-4-0"

View File

@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-explorer</artifactId>
<version>1.6.1-SNAPSHOT</version>
<version>1.7.0-SNAPSHOT</version>
<name>gCube Workspace Explorer</name>
<description>
gCube Workspace Explorer widget allows to navigate (gCube) Workspace
@ -27,7 +27,7 @@
<distroDirectory>distro</distroDirectory>
<!-- GWT needs at least java 1.6 -->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

View File

@ -16,7 +16,7 @@
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<!-- Specify the app entry point class. -->
<!-- <entry-point class='org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorer'/> -->
<!-- <entry-point class='org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerEntryPoint'/> -->
<!-- Specify the paths for translatable code -->
<source path='client' />

View File

@ -43,6 +43,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.view.client.ListDataProvider;
/**
@ -68,7 +69,7 @@ public class WorkspaceExplorerController implements EventHandler {
public WorkspaceExplorerController(String heightPanel){
bindEvents();
//As default all items are showable and selectable
wsExplorer = new WorkspaceExplorer(eventBus, ItemType.values(), ItemType.values());
wsExplorer = new WorkspaceExplorer(eventBus, ItemType.values(), ItemType.values(), new ListDataProvider<Item>());
workspaceExplorerPanel = new WorkspaceExplorerPanel(5, wsExplorer.getPanel(), breadcrumbs, navigation, heightPanel);
}
@ -83,7 +84,7 @@ public class WorkspaceExplorerController implements EventHandler {
public WorkspaceExplorerController(FilterCriteria filterCriteria, String heightPanel) {
bindEvents();
//As default all items are showable and selectable
wsExplorer = new WorkspaceExplorer(eventBus, filterCriteria, ItemType.values(), ItemType.values(), null, false, null);
wsExplorer = new WorkspaceExplorer(eventBus, filterCriteria, ItemType.values(), ItemType.values(), null, false, null, new ListDataProvider<Item>());
workspaceExplorerPanel = new WorkspaceExplorerPanel(5, wsExplorer.getPanel(), breadcrumbs, navigation, heightPanel);
}
@ -101,7 +102,7 @@ public class WorkspaceExplorerController implements EventHandler {
public WorkspaceExplorerController(FilterCriteria filterCriteria, List<String> showProperties, String heightPanel) {
bindEvents();
//As default all items are showable and selectable
wsExplorer = new WorkspaceExplorer(eventBus, filterCriteria, ItemType.values(), ItemType.values(), showProperties, false, null);
wsExplorer = new WorkspaceExplorer(eventBus, filterCriteria, ItemType.values(), ItemType.values(), showProperties, false, null, new ListDataProvider<Item>());
workspaceExplorerPanel = new WorkspaceExplorerPanel(5, wsExplorer.getPanel(), breadcrumbs, navigation, heightPanel);
}

View File

@ -1,6 +1,13 @@
package org.gcube.portlets.widgets.wsexplorer.client;
//package org.gcube.portlets.widgets.wsexplorer.client;
//
//import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener;
//import org.gcube.portlets.widgets.wsexplorer.client.select.WorkspaceExplorerSelectDialog;
//import org.gcube.portlets.widgets.wsexplorer.shared.Item;
//
//import com.google.gwt.core.client.EntryPoint;
//import com.google.gwt.core.shared.GWT;
//
//
///**
// * Entry point classes define <code>onModuleLoad()</code>.
// */
@ -11,16 +18,36 @@ package org.gcube.portlets.widgets.wsexplorer.client;
// */
// public void onModuleLoad() {
//
//// WorkspaceExplorer wsExplorer = new WorkspaceExplorer(ItemType.values(), ItemType.values());
////
//// Item item = new Item("9d031962-4678-4e6b-a687-2be532b8e974", "D&D", true);
////
//// RootPanel.get("workspace_explorer").add(wsExplorer.getPanel());
//// try {
//// wsExplorer.loadFolder(item);
//// } catch (Exception e) {
//// // TODO Auto-generated catch block
//// e.printStackTrace();
//// }
// final WorkspaceExplorerSelectDialog navigator = new WorkspaceExplorerSelectDialog("WorkpspaceExplorer", false);
//
// WorskpaceExplorerSelectNotificationListener listener = new WorskpaceExplorerSelectNotificationListener() {
//
// @Override
// public void onSelectedItem(Item item) {
// GWT.log("onSelectedItem: "+item);
// navigator.hide();
// }
//
// @Override
// public void onFailed(Throwable throwable) {
// GWT.log("onFailed..");
//
// }
//
// @Override
// public void onAborted() {
// GWT.log("onAborted..");
//
// }
//
// @Override
// public void onNotValidSelection() {
// GWT.log("onNotValidSelection..");
//
// }
// };
//
// navigator.addWorkspaceExplorerSelectNotificationListener(listener);
// navigator.show();
// }
//}

View File

@ -17,7 +17,7 @@ import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplor
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener;
import org.gcube.portlets.widgets.wsexplorer.client.view.Breadcrumbs;
import org.gcube.portlets.widgets.wsexplorer.client.view.WorkspaceExplorer;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
@ -30,6 +30,7 @@ import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.view.client.ListDataProvider;
/**
@ -41,19 +42,19 @@ import com.google.gwt.user.client.ui.VerticalPanel;
public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWorskpaceExplorerSelectNotificationListener{
public final HandlerManager eventBus = new HandlerManager(null);
private Breadcrumbs breadcrumbs = new Breadcrumbs(eventBus);
private boolean isSelect = false;
private String captionTxt;
private List<WorskpaceExplorerSelectNotificationListener> listeners = new ArrayList<WorskpaceExplorerSelectNotificationListener>();
private WorkspaceExplorer wsExplorer;
private VerticalPanel centerScrollable = new VerticalPanel();
protected Breadcrumbs breadcrumbs = new Breadcrumbs(eventBus);
protected boolean isSelect = false;
protected String captionTxt;
protected List<WorskpaceExplorerSelectNotificationListener> listeners = new ArrayList<WorskpaceExplorerSelectNotificationListener>();
protected WorkspaceExplorer wsExplorer;
protected VerticalPanel centerScrollable = new VerticalPanel();
// private ScrollPanel southPanel = new ScrollPanel();
private String folderId;
private String folderName;
private List<String> showProperties;
private FilterCriteria filterCriteria;
protected String folderId;
protected String folderName;
protected List<String> showProperties;
protected FilterCriteria filterCriteria;
private final int offsetBreadcrumb = 40;
protected final int offsetBreadcrumb = 40;
/* (non-Javadoc)
@ -91,6 +92,14 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor
}
}
/**
* Instantiates a new workspace resources explorer panel.
*/
public WorkspaceResourcesExplorerPanel(){
}
/**
* Instantiates a new workspace folder explorer panel.
*
@ -172,22 +181,36 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor
* @param showableTypes the showable types
* @param showProperties the show properties
* @param filter the filter
* @param showGcubeInfo the show gcube info - shows all the properties associated to a file (or a gcube item) stored into related gcube item by opening a popup window when clicking on the item
* @param showGcubeInfo the show gcube info
* @param sortByColumn the sort by column
* @throws Exception the exception
*/
private void initExplorer(String folderId, String folderName, ItemType[] selectableTypes, ItemType[] showableTypes, List<String> showProperties, FilterCriteria filter, boolean showGcubeInfo, DISPLAY_FIELD sortByColumn) throws Exception{
this.folderId = folderId;
this.folderName = folderName;
this.showProperties = showProperties;
this.filterCriteria = filter;
protected void initExplorer(String folderId, String folderName, ItemType[] selectableTypes, ItemType[] showableTypes, List<String> showProperties, FilterCriteria filter, boolean showGcubeInfo, DISPLAY_FIELD sortByColumn) throws Exception{
setParameters(folderId, folderName, showProperties, filter);
bindEvents();
wsExplorer = new WorkspaceExplorer(eventBus, filter, showableTypes, selectableTypes, showProperties, showGcubeInfo, sortByColumn, new DISPLAY_FIELD[]{DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME, DISPLAY_FIELD.CREATION_DATE});
wsExplorer = new WorkspaceExplorer(eventBus, filter, showableTypes, selectableTypes, showProperties, showGcubeInfo, sortByColumn, new ListDataProvider<Item>(), new DISPLAY_FIELD[]{DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME,DISPLAY_FIELD.CREATION_DATE});
Item item = new Item(folderId, folderName, true);
wsExplorer.loadFolder(item, true);
initPanel("");
}
/**
* Sets the parameters.
*
* @param folderId the folder id
* @param folderName the folder name
* @param showProperties the show properties
* @param filterCriteria the filter criteria
*/
protected void setParameters(
String folderId, String folderName, List<String> showProperties,
FilterCriteria filterCriteria) {
this.folderId = folderId;
this.folderName = folderName;
this.showProperties = showProperties;
this.filterCriteria = filterCriteria;
}
/**
* Bind events.
*/
@ -251,7 +274,7 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor
* @param itemIdentifier the item identifier
* @param includeItemAsParent the include item as parent
*/
private void loadParentBreadcrumbByItemId(final String itemIdentifier, boolean includeItemAsParent){
protected void loadParentBreadcrumbByItemId(final String itemIdentifier, boolean includeItemAsParent){
GWT.log("Reload Parent Breadcrumb: [Item id: "+itemIdentifier+"]");
@ -285,7 +308,7 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor
/**
* Clear more info.
*/
private void clearMoreInfo(){
protected void clearMoreInfo(){
// southPanel.clear();
}
@ -294,7 +317,7 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor
*
* @param captionTxt the caption txt is the tool-tip
*/
private void initPanel(String captionTxt) {
protected void initPanel(String captionTxt) {
this.captionTxt = captionTxt;
if(this.captionTxt!=null && !this.captionTxt.isEmpty())
setTitle(this.captionTxt);
@ -318,7 +341,7 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor
*
* @param selected the selected
*/
private void notifySelectedItem(Item selected){
protected void notifySelectedItem(Item selected){
for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) {
worskpaceExplorerNotificationListener.onSelectedItem(selected);
@ -328,7 +351,7 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor
/**
* Notify aborted.
*/
private void notifyAborted(){
protected void notifyAborted(){
for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) {
worskpaceExplorerNotificationListener.onAborted();
@ -339,20 +362,21 @@ public class WorkspaceResourcesExplorerPanel extends DockPanel implements HasWor
/**
* Notify not valid selection.
*/
private void notifyNotValidSelection(){
protected void notifyNotValidSelection(){
for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) {
worskpaceExplorerNotificationListener.onNotValidSelection();
}
}
/**
* Notify failed.
*
* @param t the t
*/
@SuppressWarnings("unused")
private void notifyFailed(Throwable t){
protected void notifyFailed(Throwable t){
for (WorskpaceExplorerSelectNotificationListener worskpaceExplorerNotificationListener : listeners) {
worskpaceExplorerNotificationListener.onFailed(t);

View File

@ -0,0 +1,183 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.explore;
import java.util.List;
import org.gcube.portlets.widgets.wsexplorer.client.event.BreadcrumbClickEvent;
import org.gcube.portlets.widgets.wsexplorer.client.event.BreadcrumbClickEventHandler;
import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEvent;
import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEventHandler;
import org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent;
import org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEventHandler;
import org.gcube.portlets.widgets.wsexplorer.client.view.WorkspaceExplorerPaginated;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.ui.DockPanel;
/**
* The Class WorkspaceResourcesExplorerPanelPaginated.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 5, 2017
*/
public class WorkspaceResourcesExplorerPanelPaginated extends WorkspaceResourcesExplorerPanel {
protected WorkspaceExplorerPaginated wsExplorer;
public static int ITEMS_PER_PAGE = 10;
public static int ITEM_START_INDEX = 0;
/**
* Instantiates a new workspace resources explorer panel paginated.
*
* @param folderId the folder id
* @param showOnlyFolders the show only folders
* @throws Exception the exception
*/
public WorkspaceResourcesExplorerPanelPaginated(String folderId, boolean showOnlyFolders) throws Exception {
super(folderId, showOnlyFolders);
}
/**
* Instantiates a new workspace resources explorer panel paginated.
*
* @param folderId the folder id
* @param folderName the folder name
* @throws Exception the exception
*/
public WorkspaceResourcesExplorerPanelPaginated(String folderId, String folderName) throws Exception {
super(folderId, folderName);
}
/**
* Instantiates a new workspace resources explorer panel paginated.
*
* @param folderId the folder id
* @param showOnlyFolders the show only folders
* @param showProperties the show properties
* @param filter the filter
* @throws Exception the exception
*/
public WorkspaceResourcesExplorerPanelPaginated(String folderId, boolean showOnlyFolders, List<String> showProperties, FilterCriteria filter) throws Exception {
super(folderId, showOnlyFolders, showProperties, filter);
}
/**
* Instantiates a new workspace resources explorer panel paginated.
*
* @param folderId the folder id
* @param showOnlyFolders the show only folders
* @param showProperties the show properties
* @param filter the filter
* @param showGcubeInfo the show gcube info
* @param sortByColumn the sort by column
* @throws Exception the exception
*/
public WorkspaceResourcesExplorerPanelPaginated(String folderId, boolean showOnlyFolders, List<String> showProperties, FilterCriteria filter, boolean showGcubeInfo, DISPLAY_FIELD sortByColumn) throws Exception {
super(folderId, showOnlyFolders, showProperties, filter, showGcubeInfo, sortByColumn);
}
/**
* Inits the explorer.
*
* @param folderId the folder id
* @param folderName the folder name
* @param selectableTypes the selectable types
* @param showableTypes the showable types
* @param showProperties the show properties
* @param filter the filter
* @param showGcubeInfo the show gcube info - shows all the properties associated to a file (or a gcube item) stored into related gcube item by opening a popup window when clicking on the item
* @param sortByColumn the sort by column
* @throws Exception the exception
*/
@Override
protected void initExplorer(String folderId, String folderName, ItemType[] selectableTypes, ItemType[] showableTypes, List<String> showProperties, FilterCriteria filter, boolean showGcubeInfo, DISPLAY_FIELD sortByColumn) throws Exception{
setParameters(folderId, folderName, showProperties, filter);
bindEvents();
wsExplorer = new WorkspaceExplorerPaginated(eventBus, filter, showableTypes, selectableTypes, showProperties, showGcubeInfo, sortByColumn, new DISPLAY_FIELD[]{DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME, DISPLAY_FIELD.CREATION_DATE});
wsExplorer.initPagination(ITEMS_PER_PAGE);
Item item = new Item(folderId, folderName, true);
wsExplorer.loadFolder(item, true, ITEM_START_INDEX, ITEMS_PER_PAGE);
initPanel("");
}
/**
* Inits the panel.
*
* @param captionTxt the caption txt is the tool-tip
*/
protected void initPanel(String captionTxt) {
super.captionTxt = captionTxt;
if(super.captionTxt!=null && !super.captionTxt.isEmpty())
setTitle(super.captionTxt);
add(breadcrumbs, DockPanel.NORTH);
setCellHeight(breadcrumbs, offsetBreadcrumb+"px");
centerScrollable.add(wsExplorer.getPagerPanel());
add(centerScrollable, DockPanel.CENTER);
}
/**
* Bind events.
*/
private void bindEvents(){
eventBus.addHandler(ClickItemEvent.TYPE, new ClickItemEventHandler() {
@Override
public <T> void onClick(final ClickItemEvent<T> clickItemEvent) {
isSelect = false;
Item item = wsExplorer.getItemSelected();
//Return if item is not selectable
if(!itemIsSelectable(item)){
notifyNotValidSelection();
return;
}
notifySelectedItem(wsExplorer.getItemSelected());
isSelect = true;
}
});
eventBus.addHandler(LoadFolderEvent.TYPE, new LoadFolderEventHandler() {
@Override
public <T> void onLoadFolder(LoadFolderEvent<T> loadFolderEvent) {
if(loadFolderEvent.getTargetItem()!=null){
if(loadFolderEvent.getTargetItem() instanceof Item){
Item item = (Item) loadFolderEvent.getTargetItem();
if(item.isFolder()){
try {
wsExplorer.loadFolder(item, true, ITEM_START_INDEX, ITEMS_PER_PAGE);
loadParentBreadcrumbByItemId(item.getId(), true);
clearMoreInfo();
} catch (Exception e) {
GWT.log(e.getMessage());
}
}
}
}
}
});
eventBus.addHandler(BreadcrumbClickEvent.TYPE, new BreadcrumbClickEventHandler() {
@Override
public void onBreadcrumbClick(BreadcrumbClickEvent breadcrumbClickEvent) {
eventBus.fireEvent(new LoadFolderEvent<Item>(breadcrumbClickEvent.getTargetItem()));
}
});
}
}

View File

@ -196,4 +196,12 @@ public interface WorkspaceExplorerService extends RemoteService {
* @throws Exception the exception
*/
Map<String, String> getGcubePropertiesForWorspaceId(String id) throws Exception;
Item getFolder(
Item item, List<ItemType> showableTypesParam, boolean purgeEmpyFolders,
FilterCriteria filterCriteria, boolean loadGcubeProperties,
int startIndex, int limit) throws WorkspaceNavigatorServiceException;
int getFolderChildrenCount(Item item) throws WorkspaceNavigatorServiceException;
}

View File

@ -198,4 +198,28 @@ public interface WorkspaceExplorerServiceAsync {
*/
void getGcubePropertiesForWorspaceId(String id, AsyncCallback<Map<String, String>> callback);
/**
* Gets the folder.
*
* @param item the item
* @param showableTypesParam the showable types param
* @param purgeEmpyFolders the purge empy folders
* @param filterCriteria the filter criteria
* @param loadGcubeProperties the load gcube properties
* @param startIndex the start index
* @param limit the limit
* @param asyncCallback the async callback
* @return the folder
*/
public void getFolder(
Item item, List<ItemType> showableTypesParam, boolean purgeEmpyFolders,
FilterCriteria filterCriteria, boolean loadGcubeProperties,
int startIndex, int limit, AsyncCallback<Item> asyncCallback);
/**
* @param item
*/
public void getFolderChildrenCount(Item item, AsyncCallback<Integer> asyncCallback);
}

View File

@ -0,0 +1,37 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
/**
* The Interface FolderLoader.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 5, 2017
*/
public interface FolderLoader {
/**
* 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;
/**
* Load folder.
*
* @param item the item
* @param loadGcubeProperties the load gcube properties
* @param startIdx the start idx
* @param limit the limit
* @throws Exception the exception
*/
public void loadFolder(final Item item, boolean loadGcubeProperties, int startIdx, int limit) throws Exception;
}

View File

@ -8,8 +8,8 @@ import org.gcube.portlets.widgets.wsexplorer.client.Util;
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants;
import org.gcube.portlets.widgets.wsexplorer.client.event.RootLoadedEvent;
import org.gcube.portlets.widgets.wsexplorer.client.resources.WorkspaceExplorerResources;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.ItemsTable;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
@ -25,6 +25,7 @@ import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.view.client.AbstractDataProvider;
/**
@ -33,7 +34,7 @@ import com.google.gwt.user.client.ui.ScrollPanel;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Aug 4, 2015
*/
public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
public class WorkspaceExplorer implements ShowableTypes, SelectableTypes, FolderLoader{
protected static final HorizontalPanel LOADING_PANEL = new HorizontalPanel();
@ -56,11 +57,14 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
protected ScrollPanel explorerPanel;
private ItemsTable<Item> itTables;
private DISPLAY_FIELD[] displayFields;
private DISPLAY_FIELD sortByColumn;
private HandlerManager eventBus;
private Item displayingFolderItem;
private boolean showGcubeItemsInfo;
private List<String> displayProperties;
private AbstractDataProvider<Item> dataProvider;
/**
* Instantiates a new workspace explorer - This is the base constructor.
@ -72,29 +76,37 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
* @param showGcubeInfo the show gcube info
* @param sortByColumn the sort by column
* @param fields the columns to display
* @param dataProvider the data provider
*/
private WorkspaceExplorer(HandlerManager eventBus, ItemType[] showableTypes, ItemType[] selectableTypes, List<String> displayProperties, boolean showGcubeInfo, DISPLAY_FIELD sortByColumn, DISPLAY_FIELD[] fields){
private WorkspaceExplorer(HandlerManager eventBus, ItemType[] showableTypes, ItemType[] selectableTypes, List<String> displayProperties, boolean showGcubeInfo, DISPLAY_FIELD sortByColumn, DISPLAY_FIELD[] fields, AbstractDataProvider<Item> dataProvider){
this.eventBus = eventBus;
this.showGcubeItemsInfo = showGcubeInfo;
this.displayFields = fields;
this.sortByColumn = sortByColumn;
this.displayProperties = displayProperties;
this.dataProvider = dataProvider;
this.explorerPanel = new ScrollPanel();
setShowableTypes(showableTypes);
setSelectableTypes(selectableTypes);
explorerPanel = new ScrollPanel();
itTables = new ItemsTable<Item>(eventBus, true, fields, displayProperties, showGcubeItemsInfo, sortByColumn);
this.itTables = new ItemsTable<Item>(eventBus, true, displayFields, displayProperties, showGcubeItemsInfo, sortByColumn, dataProvider);
}
/**
* Instantiates a new workspace explorer.
*
* @param eventBus the event bus
* @param showableTypes the showable types
* @param selectableTypes the selectable types
* @param fields the columns to display
* @param dataProvider the data provider
* @param fields the fields
*/
public WorkspaceExplorer(HandlerManager eventBus, ItemType[] showableTypes, ItemType[] selectableTypes, DISPLAY_FIELD...fields) {
this(eventBus, showableTypes, selectableTypes, null, false, null, fields);
public WorkspaceExplorer(HandlerManager eventBus, ItemType[] showableTypes, ItemType[] selectableTypes, AbstractDataProvider<Item> dataProvider, DISPLAY_FIELD...fields) {
this(eventBus, showableTypes, selectableTypes, null, false, null, fields, dataProvider);
// itTables = new ItemsTable<Item>(eventBus, true, fields, null, showGcubeItemsInfo);
}
/**
* Instantiates a new workspace explorer.
*
@ -102,13 +114,15 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
* @param showableTypes the showable types
* @param selectableTypes the selectable types
* @param displayProperties the display properties
* @param fields the columns to display
* @param dataProvider the data provider
* @param fields the fields
*/
public WorkspaceExplorer(HandlerManager eventBus, ItemType[] showableTypes, ItemType[] selectableTypes, List<String> displayProperties, DISPLAY_FIELD...fields) {
this(eventBus, showableTypes, selectableTypes, displayProperties, false, null, fields);
public WorkspaceExplorer(HandlerManager eventBus, ItemType[] showableTypes, ItemType[] selectableTypes, List<String> displayProperties, AbstractDataProvider<Item> dataProvider, DISPLAY_FIELD...fields) {
this(eventBus, showableTypes, selectableTypes, displayProperties, false, null, fields, dataProvider);
}
/**
* Instantiates a new workspace explorer.
*
@ -119,10 +133,11 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
* @param displayProperties the display properties
* @param showGcubeInfo the show gcube info
* @param sortByColumn the sort by column
* @param fields the columns to display
* @param dataProvider the data provider
* @param fields the fields
*/
public WorkspaceExplorer(HandlerManager eventBus, FilterCriteria filterCriteria, ItemType[] showableTypes, ItemType[] selectableTypes, List<String> displayProperties, boolean showGcubeInfo, DISPLAY_FIELD sortByColumn, DISPLAY_FIELD...fields) {
this(eventBus, showableTypes, selectableTypes, displayProperties, showGcubeInfo, sortByColumn, fields);
public WorkspaceExplorer(HandlerManager eventBus, FilterCriteria filterCriteria, ItemType[] showableTypes, ItemType[] selectableTypes, List<String> displayProperties, boolean showGcubeInfo, DISPLAY_FIELD sortByColumn, AbstractDataProvider<Item> dataProvider, DISPLAY_FIELD...fields) {
this(eventBus, showableTypes, selectableTypes, displayProperties, showGcubeInfo, sortByColumn, fields, dataProvider);
this.filterCriteria = filterCriteria;
}
@ -192,7 +207,7 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
*
* @param item the new displaying folder item
*/
private void setDisplayingFolderItem(Item item) {
protected void setDisplayingFolderItem(Item item) {
this.displayingFolderItem = item;
}
@ -286,12 +301,13 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
});
}
/**
* Update explorer.
*
* @param items the items
*/
private void updateExplorer(ArrayList<Item> items){
protected void updateExplorer(ArrayList<Item> items){
GWT.log("workspace explorer updating..");
explorerPanel.clear();
// itTables = new ItemsTable(true, displayFields);
@ -428,6 +444,17 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
}
/**
* Gets the data provider.
*
* @return the dataProvider
*/
public AbstractDataProvider<Item> getDataProvider() {
return dataProvider;
}
/**
* Sets the new show properties.
*
@ -437,4 +464,22 @@ public class WorkspaceExplorer implements ShowableTypes, SelectableTypes{
this.itTables.setDisplayProperties(displayProperties);
itTables.reInitColumnsTable();
}
/*
* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.view.FolderLoader#loadFolder(org.gcube.portlets.widgets.wsexplorer.shared.Item, boolean, int, int)
*/
/**
* This constructor is never used here. Use {@link WorkspaceExplorerPaginated} class if you want paginate the results
*
* @param item the item
* @param loadGcubeProperties the load gcube properties
* @param startIdx the start idx
* @param limit the limit
* @throws Exception the exception
*/
@Override
public void loadFolder(Item item, boolean loadGcubeProperties, int startIdx, int limit) throws Exception {
this.loadFolder(item, loadGcubeProperties);
}
}

View File

@ -0,0 +1,279 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.wsexplorer.client.Util;
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.ItemsTable.DISPLAY_FIELD;
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.SortedCellTable;
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.SimplePager.TextLocation;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.view.client.AsyncDataProvider;
import com.google.gwt.view.client.HasData;
import com.google.gwt.view.client.Range;
/**
* The Class WorkspaceExplorerPaginated.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 5, 2017
*/
public class WorkspaceExplorerPaginated extends WorkspaceExplorer{
private VerticalPanel vPanel = new VerticalPanel();
private static WorkspaceExplorerPaginated INSTANCE;
//private ListDataProvider<Item> dataProvider = new ListDataProvider<Item>();
private static MyCustomDataProvider<Item> dataProvider = new MyCustomDataProvider<Item>();
protected boolean loadGcubeProperties = false;
/**
* Instantiates a new workspace explorer paginated.
*
* @param eventBus the event bus
* @param filterCriteria the filter criteria
* @param showableTypes the showable types
* @param selectableTypes the selectable types
* @param displayProperties the display properties
* @param showGcubeInfo the show gcube info
* @param sortByColumn the sort by column
* @param fields the fields
*/
public WorkspaceExplorerPaginated(
HandlerManager eventBus, FilterCriteria filterCriteria,
ItemType[] showableTypes, ItemType[] selectableTypes,
List<String> displayProperties, boolean showGcubeInfo,
DISPLAY_FIELD sortByColumn, DISPLAY_FIELD[] fields) {
super(eventBus, filterCriteria, showableTypes, selectableTypes, displayProperties, showGcubeInfo, sortByColumn, dataProvider);
INSTANCE = this;
}
/**
* Gets the asycn data provider.
*
* @return the asycn data provider
*/
public AsyncDataProvider<Item> getAsycnDataProvider(){
return (AsyncDataProvider<Item>) getCellTable().getDataProvider();
//return new MyCustomDataProvider<Item>();
}
/**
* Gets the cell tale.
*
* @return the cell tale
*/
public SortedCellTable<Item> getCellTable(){
return getItTables().getCellTable();
}
/**
* Load folder.
*
* @param item the item
* @param loadGcubeProperties the load gcube properties
* @param startIdx the start idx
* @param limit the limit
* @throws Exception the exception
*/
public void loadFolder(final Item item, final boolean loadGcubeProperties, final int startIdx, final int limit) throws Exception {
GWT.log("loading folder data");
//super.loadFolder(item, loadGcubeProperties);
this.loadGcubeProperties = loadGcubeProperties;
setLoading();
if(!item.isFolder())
throw new Exception("Item is not a folder");
if(item.getId()==null || item.getId().isEmpty())
throw new Exception("Item id is null or empty");
// we make a copy of showable types
final List<ItemType> showableTypesParam = new ArrayList<ItemType>(showableTypes);
// we get sure that folders are displayed
for (ItemType folder : Util.FOLDERS) {
if (!showableTypesParam.contains(folder))
showableTypesParam.add(folder);
}
final boolean purgeEmpyFolders = !showEmptyFolders;
if(getDisplayingFolderItem()==null || getDisplayingFolderItem().getId()!=item.getId()){
WorkspaceExplorerConstants.workspaceNavigatorService.getFolderChildrenCount(item, new AsyncCallback<Integer>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(Integer result) {
GWT.log("Folder Children count: "+result);
getAsycnDataProvider().updateRowCount(result, false);
//final Range range = display.getVisibleRange();
perfomGetFolderChildren(item, loadGcubeProperties, startIdx, limit, purgeEmpyFolders, showableTypesParam);
}
});
}else
perfomGetFolderChildren(item, loadGcubeProperties, startIdx, limit, purgeEmpyFolders, showableTypesParam);
}
/**
* Perfom get folder children.
*
* @param item the item
* @param loadGcubeProperties the load gcube properties
* @param startIdx the start idx
* @param limit the limit
* @param purgeEmpyFolders the purge empy folders
* @param showableTypesParam the showable types param
*/
private void perfomGetFolderChildren(final Item item, boolean loadGcubeProperties, final int startIdx, int limit, boolean purgeEmpyFolders, List<ItemType> showableTypesParam){
GWT.log("loading workspace folder by item id from server: "+item.getId());
WorkspaceExplorerConstants.workspaceNavigatorService.getFolder(item, showableTypesParam, purgeEmpyFolders, filterCriteria, loadGcubeProperties, startIdx, limit, new AsyncCallback<Item>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
setAlert(caught.getMessage(), AlertType.ERROR);
GWT.log("Error loading workspace folder from server",caught);
}
@Override
public void onSuccess(Item result) {
if(item.getName()==null || item.getName().isEmpty())
item.setName(result.getName());
GWT.log("Returned "+result.getChildren().size() +" children");
//getItTables().updateItems(result.getChildren(), true);
getAsycnDataProvider().updateRowData(startIdx, result.getChildren());
getCellTable().setPageSize(result.getChildren().size()+1);
//cellList.setVisibleRange(startIdx, result.getChildren().size());
getCellTable().redraw();
GWT.log("cellList size: "+getCellTable().getRowCount());
setDisplayingFolderItem(result);
}
});
}
/**
* Inits the pagination.
*
* @param itemsPerPage the items per page
*/
public void initPagination(int itemsPerPage){
//dataProvider.updateRowCount(100, true);
// Add the cellList to the dataProvider.
//asyncDataProvider.addDataDisplay(cellTable);
// Create paging controls.
SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
SimplePager pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
pager.setPageSize(itemsPerPage);
pager.setDisplay(getCellTable());
vPanel.add(getCellTable());
vPanel.add(pager);
}
/**
* Gets the pager panel.
*
* @return the pager panel
*/
public VerticalPanel getPagerPanel(){
return vPanel;
}
/**
* A custom {@link AsyncDataProvider}.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 5, 2017
* @param <T> the generic type
*/
public static class MyCustomDataProvider<T> extends AsyncDataProvider<T> {
/**
* {@link #onRangeChanged(HasData)} is called when the table requests a
* new range of data. You can push data back to the displays using
* {@link #updateRowData(int, List)}.
*
* @param display the display
*/
@Override
public void onRangeChanged(HasData<T> display) {
// Get the new range.
final Range range = display.getVisibleRange();
// We are creating fake data. Normally, the data will come
// from a
// server.
// int start = range.getStart();
// int length = range.getLength();
// List<Item> newData = new ArrayList<Item>();
// for (int i = start; i < start + length; i++) {
// newData.add(new Item("Item "+i, "Item "+i, false));
// }
// // Push the data to the displays. AsyncDataProvider will
// // only update
// // displays that are within range of the data.
// updateRowData(start, newData);
int start = range.getStart();
int length = range.getLength();
GWT.log("Range changed: "+start +" "+length);
// try {
// GWT.log("qui");
// INSTANCE.loadFolder(INSTANCE.getItemSelected(), INSTANCE.loadGcubeProperties, start, length);
// GWT.log("qua");
// }
// catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// Item item = new Item(WorkspaceExplorerPaginated.this.getF, folderName, true);
// WorkspaceExplorerPaginated.this.loadFolder(WorkspaceExplorerPaginated.this.getItemSelected(), super.get,start, length);
}
/**
*
*/
public MyCustomDataProvider() {
// TODO Auto-generated constructor stub
}
}
}

View File

@ -1,184 +1,191 @@
package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
import java.util.List;
import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEvent;
import com.github.gwtbootstrap.client.ui.CellTable;
import com.github.gwtbootstrap.client.ui.Pagination;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.event.dom.client.ContextMenuEvent;
import com.google.gwt.event.dom.client.ContextMenuHandler;
import com.google.gwt.event.dom.client.DoubleClickEvent;
import com.google.gwt.event.dom.client.DoubleClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
import com.google.gwt.view.client.SingleSelectionModel;
/**
* The Class AbstractItemTable.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 19, 2015
*/
public abstract class AbstractItemsCellTable<T> {
protected SortedCellTable<T> sortedCellTable;
// protected ListDataProvider<T> dataProvider = new ListDataProvider<>();
protected T itemContextMenu = null;
protected boolean showMoreInfo;
protected final SingleSelectionModel<T> ssm;
private final HandlerManager eventBus;
/**
* Inits the table.
*
* @param pager the pager
* @param pagination the pagination
*/
public abstract void initTable(final SimplePager pager, final Pagination pagination);
/**
* Instantiates a new abstract items cell table.
*
* @param eventBus the event bus
* @param fireOnClick the fire on click
*/
public AbstractItemsCellTable(HandlerManager eventBus, boolean fireOnClick) {
this.eventBus = eventBus;
this.showMoreInfo = fireOnClick;
sortedCellTable = new SortedCellTable<T>();
sortedCellTable.addStyleName("table-explorer");
// cellTable.getElement().getStyle().setOverflow(Overflow.HIDDEN);
sortedCellTable.addStyleName("table-explorer-vertical-middle");
sortedCellTable.setStriped(true);
sortedCellTable.setCondensed(true);
sortedCellTable.setWidth("100%", true);
// dataProvider.addDataDisplay(sortedCellTable);
// initTable(cellTable, null, null);
sortedCellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
ssm = new SingleSelectionModel<T>();
sortedCellTable.setSelectionModel(ssm);
ssm.addSelectionChangeHandler(new Handler() {
@Override
public void onSelectionChange(final SelectionChangeEvent event)
{
final T selectedObject = ssm.getSelectedObject();
if(selectedObject!=null){
GWT.log("Clicked: "+selectedObject);
// selectedItem(selectedObject);
if(showMoreInfo)
AbstractItemsCellTable.this.eventBus.fireEvent(new ClickItemEvent<T>(selectedObject));
}
}
});
sortedCellTable.addDomHandler(new DoubleClickHandler() {
@Override
public void onDoubleClick(final DoubleClickEvent event) {
T selected = ssm.getSelectedObject();
if (selected != null) {
GWT.log("Double Click: "+selected);
AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(selected));
}
}
},
DoubleClickEvent.getType());
MenuBar options = new MenuBar(true);
ScheduledCommand openCommand = new ScheduledCommand() {
@Override
public void execute() {
AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(itemContextMenu));
}
};
MenuItem openItem = new MenuItem("Open", openCommand);
options.addItem(openItem);
final DialogBox menuWrapper = new DialogBox(true);
menuWrapper.getElement().getStyle().setBorderStyle(BorderStyle.NONE);
menuWrapper.getElement().getStyle().setZIndex(10000);
menuWrapper.add(options);
sortedCellTable.sinkEvents(Event.ONCONTEXTMENU);
sortedCellTable.addHandler(new ContextMenuHandler() {
@Override
public void onContextMenu(ContextMenuEvent event) {
/*
GWT.log("On Context Menu: " + event.getNativeEvent().getEventTarget().toString());
Item selectedObject = (Item) event.getSource();
itemContextMenu = selectedObject;
if (selectedObject != null && selectedObject.isFolder()) {
event.preventDefault();
event.stopPropagation();
menuWrapper.setPopupPosition(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
menuWrapper.show();
}*/
}
}, ContextMenuEvent.getType());
// ssm.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
//package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
//
//import java.util.List;
//
//import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEvent;
//import org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy.SortedCellTable;
//
//import com.github.gwtbootstrap.client.ui.Pagination;
//import com.google.gwt.core.client.Scheduler.ScheduledCommand;
//import com.google.gwt.core.shared.GWT;
//import com.google.gwt.dom.client.Style.BorderStyle;
//import com.google.gwt.event.dom.client.ContextMenuEvent;
//import com.google.gwt.event.dom.client.ContextMenuHandler;
//import com.google.gwt.event.dom.client.DoubleClickEvent;
//import com.google.gwt.event.dom.client.DoubleClickHandler;
//import com.google.gwt.event.shared.HandlerManager;
//import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
//import com.google.gwt.user.cellview.client.SimplePager;
//import com.google.gwt.user.client.Event;
//import com.google.gwt.user.client.ui.DialogBox;
//import com.google.gwt.user.client.ui.MenuBar;
//import com.google.gwt.user.client.ui.MenuItem;
//import com.google.gwt.view.client.SelectionChangeEvent;
//import com.google.gwt.view.client.SelectionChangeEvent.Handler;
//import com.google.gwt.view.client.SingleSelectionModel;
//
///**
// * The Class AbstractItemTable.
// *
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 19, 2015
// * @param <T> the generic type
// */
//public abstract class AbstractItemsCellTable<T> {
//
// protected SortedCellTable<T> sortedCellTable;
//// protected ListDataProvider<T> dataProvider = new ListDataProvider<>();
// protected T itemContextMenu = null;
// protected boolean showMoreInfo;
// protected final SingleSelectionModel<T> ssm;
// private final HandlerManager eventBus;
//
// /**
// * Inits the table.
// *
// * @param pager the pager
// * @param pagination the pagination
// */
// public abstract void initTable(final SimplePager pager, final Pagination pagination);
//
//
// /**
// * Instantiates a new abstract items cell table.
// *
// * @param eventBus the event bus
// * @param fireOnClick the fire on click
// */
// public AbstractItemsCellTable(HandlerManager eventBus, boolean fireOnClick) {
// this.eventBus = eventBus;
// this.showMoreInfo = fireOnClick;
// sortedCellTable = new SortedCellTable<T>();
// sortedCellTable.addStyleName("table-explorer");
//// cellTable.getElement().getStyle().setOverflow(Overflow.HIDDEN);
// sortedCellTable.addStyleName("table-explorer-vertical-middle");
// sortedCellTable.setStriped(true);
// sortedCellTable.setCondensed(true);
// sortedCellTable.setWidth("100%", true);
//// dataProvider.addDataDisplay(sortedCellTable);
//// initTable(cellTable, null, null);
// sortedCellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
//
// ssm = new SingleSelectionModel<T>();
// sortedCellTable.setSelectionModel(ssm);
// ssm.addSelectionChangeHandler(new Handler() {
// @Override
// public void onSelectionChange(final SelectionChangeEvent event)
// {
// final T selectedObject = ssm.getSelectedObject();
// if(selectedObject!=null){
// GWT.log("Clicked: "+selectedObject);
//// selectedItem(selectedObject);
// if(showMoreInfo)
// AbstractItemsCellTable.this.eventBus.fireEvent(new ClickItemEvent<T>(selectedObject));
// }
// }
// });
//
// sortedCellTable.addDomHandler(new DoubleClickHandler() {
//
// @Override
// public void onDoubleClick(final DoubleClickEvent event) {
// T selected = ssm.getSelectedObject();
// if (selected != null) {
// GWT.log("Double Click: "+selected);
// AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(selected));
// }
// }
// },
// DoubleClickEvent.getType());
//
// MenuBar options = new MenuBar(true);
// ScheduledCommand openCommand = new ScheduledCommand() {
//
// @Override
// public void onSelectionChange(SelectionChangeEvent event) {
// // changed the context menu selection
// GWT.log("Selected item is" + ssm.getSelectedObject());
//
// public void execute() {
// AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(itemContextMenu));
// }
// });
}
/**
* Update items.
*
* @param items the items
* @param removeOldItems the remove old items
*/
public void updateItems(List<T> items, boolean removeOldItems) {
if(removeOldItems){
// dataProvider.getList().clear();
ssm.clear();
}
sortedCellTable.setList(items);
// dataProvider.flush();
// dataProvider.refresh();
sortedCellTable.setPageSize(items.size()+1);
sortedCellTable.redraw();
}
/**
* Gets the cell tables.
*
* @return the cell tables
*/
public CellTable<T> getCellTable() {
return sortedCellTable;
}
/**
* Gets the data provider.
*
* @return the data provider
*/
public ListDataProvider<T> getDataProvider() {
return sortedCellTable.getDataProvider();
}
}
// };
//
// MenuItem openItem = new MenuItem("Open", openCommand);
// options.addItem(openItem);
// final DialogBox menuWrapper = new DialogBox(true);
// menuWrapper.getElement().getStyle().setBorderStyle(BorderStyle.NONE);
// menuWrapper.getElement().getStyle().setZIndex(10000);
// menuWrapper.add(options);
// sortedCellTable.sinkEvents(Event.ONCONTEXTMENU);
//
// sortedCellTable.addHandler(new ContextMenuHandler() {
// @Override
// public void onContextMenu(ContextMenuEvent event) {
// /*
// GWT.log("On Context Menu: " + event.getNativeEvent().getEventTarget().toString());
// Item selectedObject = (Item) event.getSource();
// itemContextMenu = selectedObject;
// if (selectedObject != null && selectedObject.isFolder()) {
// event.preventDefault();
// event.stopPropagation();
// menuWrapper.setPopupPosition(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
// menuWrapper.show();
// }*/
// }
// }, ContextMenuEvent.getType());
//
//// ssm.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
////
//// @Override
//// public void onSelectionChange(SelectionChangeEvent event) {
//// // changed the context menu selection
//// GWT.log("Selected item is" + ssm.getSelectedObject());
////
//// }
//// });
//
// }
//
//
// /**
// * Update items.
// *
// * @param items the items
// * @param removeOldItems the remove old items
// */
// public void updateItems(List<T> items, boolean removeOldItems) {
//
// if(removeOldItems){
//// dataProvider.getList().clear();
// ssm.clear();
// }
//
// sortedCellTable.setList(items);
//// dataProvider.flush();
//// dataProvider.refresh();
//
// sortedCellTable.setPageSize(items.size()+1);
// sortedCellTable.redraw();
// }
//
//
// /**
// * Adds the items.
// *
// * @param items the items
// */
// public void addItems(List<T> items){
//
// for (int i=0; i<items.size(); i++) {
// sortedCellTable.getDataProvider().getList().add(i, items.get(i));
// }
//
// sortedCellTable.setPageSize(items.size()+1);
// sortedCellTable.redraw();
// }
//
// /**
// * Gets the cell tables.
// *
// * @return the cell tables
// */
// public SortedCellTable<T> getCellTable() {
// return sortedCellTable;
// }
//}

View File

@ -1,41 +1,41 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.Column;
public abstract class MyToolTipColumn<T, C> extends Column<T, C> {
interface Templates extends SafeHtmlTemplates {
@Template("<div title=\"{0}\">")
SafeHtml startToolTip(String toolTipText);
@Template("</div>")
SafeHtml endToolTip();
}
private static final Templates TEMPLATES = GWT.create(Templates.class);
private final String toolTipText;
public MyToolTipColumn(final Cell<C> cell, final String toolTipText) {
super(cell);
this.toolTipText = toolTipText;
}
@Override
public void render(final Context context, final T object, final SafeHtmlBuilder sb) {
sb.append(TEMPLATES.startToolTip(toolTipText));
super.render(context, object, sb);
sb.append(TEMPLATES.endToolTip());
}
}
///**
// *
// */
//
//package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
//
//import com.google.gwt.cell.client.Cell;
//import com.google.gwt.cell.client.Cell.Context;
//import com.google.gwt.core.client.GWT;
//import com.google.gwt.safehtml.client.SafeHtmlTemplates;
//import com.google.gwt.safehtml.shared.SafeHtml;
//import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
//import com.google.gwt.user.cellview.client.Column;
//
//public abstract class MyToolTipColumn<T, C> extends Column<T, C> {
//
// interface Templates extends SafeHtmlTemplates {
//
// @Template("<div title=\"{0}\">")
// SafeHtml startToolTip(String toolTipText);
//
// @Template("</div>")
// SafeHtml endToolTip();
// }
// private static final Templates TEMPLATES = GWT.create(Templates.class);
// private final String toolTipText;
//
// public MyToolTipColumn(final Cell<C> cell, final String toolTipText) {
//
// super(cell);
// this.toolTipText = toolTipText;
// }
//
// @Override
// public void render(final Context context, final T object, final SafeHtmlBuilder sb) {
//
// sb.append(TEMPLATES.startToolTip(toolTipText));
// super.render(context, object, sb);
// sb.append(TEMPLATES.endToolTip());
// }
//}

View File

@ -1,240 +1,240 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.widgets.wsexplorer.client.resources.CellTableResources;
import com.github.gwtbootstrap.client.ui.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortEvent;
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo;
import com.google.gwt.user.cellview.client.Header;
import com.google.gwt.view.client.ListDataProvider;
/**
* The Class SortedCellTable.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 6, 2016
* @param <T> the generic type
*/
public class SortedCellTable<T> extends CellTable<T> {
/**
* To keep track of the currently sorted column
*/
private Column<T, ?> currentlySortedColumn;
/**
* Tells us which way to sort a column initially
*/
private Map<Column<T, ?>, Boolean> defaultSortOrderMap = new HashMap<Column<T, ?>, Boolean>();
/**
* Comparators associated with their columns
*/
private Map<Column<T, ?>, Comparator<T>> comparators = new HashMap<Column<T, ?>, Comparator<T>>();
/**
* Column to sort when the data provider's list is refreshed using
* {@link SortedCellTable#setList(List)}
*/
private Column<T, ?> initialSortColumn;
/**
* Data provider we will attach to this table
*/
private ListDataProvider<T> dataProvider;
/**
* Special column sorting handler that will allow us to do more controlled
* sorting
*/
ListHandler<T> columnSortHandler;
/**
* Instantiates a new sorted cell table.
*/
public SortedCellTable() {
super(1,CellTableResources.INSTANCE);
dataProvider = new ListDataProvider<T>();
dataProvider.addDataDisplay(this);
columnSortHandler = new ListHandler<T>(dataProvider.getList()) {
@Override
public void onColumnSort(ColumnSortEvent event) {
@SuppressWarnings("unchecked")
Column<T, ?> column = (Column<T, ?>) event.getColumn();
if (column == null) {
return;
}
if (column.equals(currentlySortedColumn)) {
// Default behavior
super.onColumnSort(event);
}
else {
// Initial sort; look up which direction we need
final Comparator<T> comparator = comparators.get(column);
if (comparator == null) {
return;
}
Boolean ascending = defaultSortOrderMap.get(column);
if (ascending == null || ascending) {
// Default behavior
super.onColumnSort(event);
}
else {
// Sort the column descending
Collections.sort(getList(), new Comparator<T>() {
public int compare(T o1, T o2) {
return -comparator.compare(o1, o2);
}
});
// Set the proper arrow in the header
getColumnSortList().push(new ColumnSortInfo(column, false));
}
currentlySortedColumn = column;
}
}
@Override
public void setComparator(Column<T, ?> column, Comparator<T> comparator) {
comparators.put(column, comparator);
super.setComparator(column, comparator);
}
};
addColumnSortHandler(columnSortHandler);
}
/**
* Adds a column to the table and sets its sortable state.
*
* @param column the column
* @param headerName the header name
* @param sortable the sortable
*/
public void addColumn(Column<T, ?> column, String headerName, boolean sortable) {
addColumn(column, headerName);
column.setSortable(sortable);
if (sortable) {
defaultSortOrderMap.put(column, true);
}
}
/* (non-Javadoc)
* @see com.google.gwt.user.cellview.client.AbstractCellTable#addColumn(com.google.gwt.user.cellview.client.Column, java.lang.String)
*/
public void addColumn(Column<T, ?> column, String headerName) {
super.addColumn(column, headerName);
}
/**
* Adds a column to the table and sets its sortable state.
*
* @param column the column
* @param header the header
* @param sortable the sortable
*/
public void addColumn(Column<T, ?> column, Header<?> header, boolean sortable) {
addColumn(column, header);
column.setSortable(sortable);
if (sortable) {
defaultSortOrderMap.put(column, true);
}
}
/**
* Sets the column to sort when the data list is reset using
* {@link SortedCellTable#setList(List)}.
*
* @param column the column
*/
public void setInitialSortColumn(Column<T, ?> column) {
initialSortColumn = column;
}
/**
* Sets a comparator to use when sorting the given column.
*
* @param column the column
* @param comparator the comparator
*/
public void setComparator(Column<T, ?> column, Comparator<T> comparator) {
columnSortHandler.setComparator(column, comparator);
}
/**
* Sets the sort order to use when this column is clicked and it was not
* previously sorted.
*
* @param column the column
* @param ascending the ascending
*/
public void setDefaultSortOrder(Column<T, ?> column, boolean ascending) {
defaultSortOrderMap.put(column, ascending);
}
/**
* Sets the table's data provider list and sorts the table based on the
* column given in {@link SortedCellTable#setInitialSortColumn(Column)}.
*
* @param list the new list
*/
public void setList(List<T> list) {
dataProvider.getList().clear();
if (list != null) {
/*for (T t : list) {
dataProvider.getList().add(t);
}*/
dataProvider.getList().addAll(list);
}
// Do a first-time sort based on which column was set in
// setInitialSortColumn()
if (initialSortColumn != null) {
Collections.sort(dataProvider.getList(), new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
return (defaultSortOrderMap.get(initialSortColumn) ? 1 : -1) * comparators.get(initialSortColumn).compare(o1, o2);
}
});
// Might as well get the little arrow on the header to make it
// official
getColumnSortList().push(
new ColumnSortInfo(
initialSortColumn,
defaultSortOrderMap.get(initialSortColumn)));
currentlySortedColumn = initialSortColumn;
}
}
/**
* @return the dataProvider
*/
public ListDataProvider<T> getDataProvider() {
return dataProvider;
}
}
///**
// *
// */
//
//package org.gcube.portlets.widgets.wsexplorer.client.view.grid;
//
//import java.util.Collections;
//import java.util.Comparator;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import org.gcube.portlets.widgets.wsexplorer.client.resources.CellTableResources;
//
//import com.github.gwtbootstrap.client.ui.CellTable;
//import com.google.gwt.user.cellview.client.Column;
//import com.google.gwt.user.cellview.client.ColumnSortEvent;
//import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
//import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo;
//import com.google.gwt.user.cellview.client.Header;
//import com.google.gwt.view.client.ListDataProvider;
//
//
///**
// * The Class SortedCellTable.
// *
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
// * Jun 6, 2016
// * @param <T> the generic type
// */
//public class SortedCellTable<T> extends CellTable<T> {
//
// /**
// * To keep track of the currently sorted column
// */
// private Column<T, ?> currentlySortedColumn;
// /**
// * Tells us which way to sort a column initially
// */
// private Map<Column<T, ?>, Boolean> defaultSortOrderMap = new HashMap<Column<T, ?>, Boolean>();
// /**
// * Comparators associated with their columns
// */
// private Map<Column<T, ?>, Comparator<T>> comparators = new HashMap<Column<T, ?>, Comparator<T>>();
// /**
// * Column to sort when the data provider's list is refreshed using
// * {@link SortedCellTable#setList(List)}
// */
// private Column<T, ?> initialSortColumn;
// /**
// * Data provider we will attach to this table
// */
// private ListDataProvider<T> dataProvider;
//
// /**
// * Special column sorting handler that will allow us to do more controlled
// * sorting
// */
// private ListHandler<T> columnSortHandler;
//
// /**
// * Instantiates a new sorted cell table.
// */
// public SortedCellTable() {
//
// super(1,CellTableResources.INSTANCE);
// dataProvider = new ListDataProvider<T>();
// dataProvider.addDataDisplay(this);
//
// columnSortHandler = new ListHandler<T>(dataProvider.getList()) {
//
// @Override
// public void onColumnSort(ColumnSortEvent event) {
//
// @SuppressWarnings("unchecked")
// Column<T, ?> column = (Column<T, ?>) event.getColumn();
// if (column == null) {
// return;
// }
// if (column.equals(currentlySortedColumn)) {
// // Default behavior
// super.onColumnSort(event);
// }
// else {
// // Initial sort; look up which direction we need
// final Comparator<T> comparator = comparators.get(column);
// if (comparator == null) {
// return;
// }
// Boolean ascending = defaultSortOrderMap.get(column);
// if (ascending == null || ascending) {
// // Default behavior
// super.onColumnSort(event);
// }
// else {
// // Sort the column descending
// Collections.sort(getList(), new Comparator<T>() {
//
// public int compare(T o1, T o2) {
//
// return -comparator.compare(o1, o2);
// }
// });
// // Set the proper arrow in the header
// getColumnSortList().push(new ColumnSortInfo(column, false));
// }
// currentlySortedColumn = column;
// }
// }
//
// @Override
// public void setComparator(Column<T, ?> column, Comparator<T> comparator) {
//
// comparators.put(column, comparator);
// super.setComparator(column, comparator);
// }
// };
//
// addColumnSortHandler(columnSortHandler);
// }
//
// /**
// * Adds a column to the table and sets its sortable state.
// *
// * @param column the column
// * @param headerName the header name
// * @param sortable the sortable
// */
// public void addColumn(Column<T, ?> column, String headerName, boolean sortable) {
//
// addColumn(column, headerName);
// column.setSortable(sortable);
// if (sortable) {
// defaultSortOrderMap.put(column, true);
// }
// }
//
// /* (non-Javadoc)
// * @see com.google.gwt.user.cellview.client.AbstractCellTable#addColumn(com.google.gwt.user.cellview.client.Column, java.lang.String)
// */
// public void addColumn(Column<T, ?> column, String headerName) {
//
// super.addColumn(column, headerName);
// }
//
// /**
// * Adds a column to the table and sets its sortable state.
// *
// * @param column the column
// * @param header the header
// * @param sortable the sortable
// */
// public void addColumn(Column<T, ?> column, Header<?> header, boolean sortable) {
//
// addColumn(column, header);
// column.setSortable(sortable);
// if (sortable) {
// defaultSortOrderMap.put(column, true);
// }
// }
//
// /**
// * Sets the column to sort when the data list is reset using
// * {@link SortedCellTable#setList(List)}.
// *
// * @param column the column
// */
// public void setInitialSortColumn(Column<T, ?> column) {
//
// initialSortColumn = column;
// }
//
// /**
// * Sets a comparator to use when sorting the given column.
// *
// * @param column the column
// * @param comparator the comparator
// */
// public void setComparator(Column<T, ?> column, Comparator<T> comparator) {
//
// columnSortHandler.setComparator(column, comparator);
// }
//
// /**
// * Sets the sort order to use when this column is clicked and it was not
// * previously sorted.
// *
// * @param column the column
// * @param ascending the ascending
// */
// public void setDefaultSortOrder(Column<T, ?> column, boolean ascending) {
//
// defaultSortOrderMap.put(column, ascending);
// }
//
// /**
// * Sets the table's data provider list and sorts the table based on the
// * column given in {@link SortedCellTable#setInitialSortColumn(Column)}.
// *
// * @param list the new list
// */
// public void setList(List<T> list) {
//
// dataProvider.getList().clear();
// if (list != null) {
// /*for (T t : list) {
// dataProvider.getList().add(t);
// }*/
// dataProvider.getList().addAll(list);
// }
// // Do a first-time sort based on which column was set in
// // setInitialSortColumn()
// if (initialSortColumn != null) {
// Collections.sort(dataProvider.getList(), new Comparator<T>() {
//
// @Override
// public int compare(T o1, T o2) {
//
// return (defaultSortOrderMap.get(initialSortColumn) ? 1 : -1) * comparators.get(initialSortColumn).compare(o1, o2);
// }
// });
// // Might as well get the little arrow on the header to make it
// // official
// getColumnSortList().push(
// new ColumnSortInfo(
// initialSortColumn,
// defaultSortOrderMap.get(initialSortColumn)));
// currentlySortedColumn = initialSortColumn;
// }
// }
//
//
// /**
// * @return the dataProvider
// */
// public ListDataProvider<T> getDataProvider() {
//
// return dataProvider;
// }
//}

View File

@ -0,0 +1,185 @@
package org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy;
import java.util.List;
import org.gcube.portlets.widgets.wsexplorer.client.event.ClickItemEvent;
import com.github.gwtbootstrap.client.ui.Pagination;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.BorderStyle;
import com.google.gwt.event.dom.client.ContextMenuEvent;
import com.google.gwt.event.dom.client.ContextMenuHandler;
import com.google.gwt.event.dom.client.DoubleClickEvent;
import com.google.gwt.event.dom.client.DoubleClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.view.client.AbstractDataProvider;
import com.google.gwt.view.client.AsyncDataProvider;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
import com.google.gwt.view.client.SingleSelectionModel;
/**
* The Class AbstractItemTable.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 19, 2015
* @param <T> the generic type
*/
public abstract class AbstractItemsCellTable<T> {
protected SortedCellTable<T> sortedCellTable;
// protected ListDataProvider<T> dataProvider = new ListDataProvider<>();
protected T itemContextMenu = null;
protected boolean showMoreInfo;
protected SingleSelectionModel<T> ssm;
private HandlerManager eventBus;
/**
* Inits the table.
*
* @param pager the pager
* @param pagination the pagination
*/
public abstract void initTable(final SimplePager pager, final Pagination pagination);
/**
* Inits the abstract table.
*
* @param eventBus the event bus
* @param fireOnClick the fire on click
* @param dataProvider the data provider
*/
public void initAbstractTable(HandlerManager eventBus, boolean fireOnClick, AbstractDataProvider<T> dataProvider){
this.eventBus = eventBus;
this.showMoreInfo = fireOnClick;
sortedCellTable = new SortedCellTable<T>(dataProvider);
sortedCellTable.addStyleName("table-explorer");
// cellTable.getElement().getStyle().setOverflow(Overflow.HIDDEN);
sortedCellTable.addStyleName("table-explorer-vertical-middle");
sortedCellTable.setStriped(true);
sortedCellTable.setCondensed(true);
sortedCellTable.setWidth("100%", true);
// dataProvider.addDataDisplay(sortedCellTable);
// initTable(cellTable, null, null);
sortedCellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
ssm = new SingleSelectionModel<T>();
sortedCellTable.setSelectionModel(ssm);
ssm.addSelectionChangeHandler(new Handler() {
@Override
public void onSelectionChange(final SelectionChangeEvent event)
{
final T selectedObject = ssm.getSelectedObject();
if(selectedObject!=null){
GWT.log("Clicked: "+selectedObject);
// selectedItem(selectedObject);
if(showMoreInfo)
AbstractItemsCellTable.this.eventBus.fireEvent(new ClickItemEvent<T>(selectedObject));
}
}
});
sortedCellTable.addDomHandler(new DoubleClickHandler() {
@Override
public void onDoubleClick(final DoubleClickEvent event) {
T selected = ssm.getSelectedObject();
if (selected != null) {
GWT.log("Double Click: "+selected);
AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(selected));
}
}
},
DoubleClickEvent.getType());
MenuBar options = new MenuBar(true);
ScheduledCommand openCommand = new ScheduledCommand() {
@Override
public void execute() {
AbstractItemsCellTable.this.eventBus.fireEvent(new org.gcube.portlets.widgets.wsexplorer.client.event.LoadFolderEvent<T>(itemContextMenu));
}
};
MenuItem openItem = new MenuItem("Open", openCommand);
options.addItem(openItem);
final DialogBox menuWrapper = new DialogBox(true);
menuWrapper.getElement().getStyle().setBorderStyle(BorderStyle.NONE);
menuWrapper.getElement().getStyle().setZIndex(10000);
menuWrapper.add(options);
sortedCellTable.sinkEvents(Event.ONCONTEXTMENU);
sortedCellTable.addHandler(new ContextMenuHandler() {
@Override
public void onContextMenu(ContextMenuEvent event) {
}
}, ContextMenuEvent.getType());
}
/**
* Update items.
*
* @param items the items
* @param removeOldItems the remove old items
*/
public void updateItems(List<T> items, boolean removeOldItems) {
if(removeOldItems){
// dataProvider.getList().clear();
ssm.clear();
}
sortedCellTable.setList(items);
// dataProvider.flush();
// dataProvider.refresh();
sortedCellTable.setPageSize(items.size()+1);
sortedCellTable.redraw();
}
/**
* Gets the cell tables.
*
* @return the cell tables
*/
public SortedCellTable<T> getCellTable() {
return sortedCellTable;
}
/**
* Adds the items.
*
* @param items the items
*/
public void addItems(List<T> items){
AbstractDataProvider<T> dataProvider = sortedCellTable.getDataProvider();
if(dataProvider instanceof ListDataProvider){
List<T> ldp = ((ListDataProvider<T>) dataProvider).getList();
for (int i=0; i<items.size(); i++) {
ldp.add(i, items.get(i));
}
sortedCellTable.setPageSize(items.size()+1);
sortedCellTable.redraw();
}else if (dataProvider instanceof AsyncDataProvider){
//TODO ???
}
}
}

View File

@ -0,0 +1,470 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.gcube.portlets.widgets.wsexplorer.client.Util;
import org.gcube.portlets.widgets.wsexplorer.client.resources.WorkspaceExplorerResources;
import org.gcube.portlets.widgets.wsexplorer.client.view.SelectionItem;
import org.gcube.portlets.widgets.wsexplorer.client.view.gcubeitem.DialogShowGcubeItem;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import com.github.gwtbootstrap.client.ui.Pagination;
import com.google.gwt.cell.client.ButtonCell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.cell.client.DateCell;
import com.google.gwt.cell.client.ImageResourceCell;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortEvent;
import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.view.client.AbstractDataProvider;
/**
* The Class PackagesTable.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 19, 2015
* @param <T> the generic type
*/
public class ItemsTable<T extends Item> extends AbstractItemsCellTable<T> implements SelectionItem{
private Column<T, ImageResource> icon;
private TextColumn<T> name;
private TextColumn<T> owner;
public DateTimeFormat dtformat = DateTimeFormat.getFormat("dd MMM hh:mm aaa yyyy");
public ImageResource info = WorkspaceExplorerResources.ICONS.infoSquare();
public AbstractDataProvider<T> dataProvider;
/**
* The Enum DISPLAY_FIELD.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 1, 2016
*/
public static enum DISPLAY_FIELD{ICON, NAME, OWNER, CREATION_DATE};
private List<DISPLAY_FIELD> displayFields;
private Column<T, Date> dateColumn;
private List<String> displayProperties;
private boolean showGcubeItemsInfo;
private DISPLAY_FIELD startSortByColumn;
private boolean isAsyncronusTable;
/**
* Instantiates a new items table.
*
* @param eventBus the event bus
* @param showMoreInfo the show more info
* @param fields the fields
* @param displayProperties the display properties
* @param showGcubeItemsInfo the show gcube items info
* @param startSortByColumn the start sort by column
* @param asyncDataProvider the async data provider
*/
public ItemsTable(HandlerManager eventBus, boolean showMoreInfo, DISPLAY_FIELD[] fields, List<String> displayProperties, boolean showGcubeItemsInfo, DISPLAY_FIELD startSortByColumn, AbstractDataProvider<T> dataProvider) {
this.dataProvider = dataProvider;
initAbstractTable(eventBus, showMoreInfo, dataProvider);
this.dataProvider.addDataDisplay(sortedCellTable);
this.startSortByColumn = startSortByColumn;
setDisplayFields(fields);
setDisplayProperties(displayProperties);
setShowGcubeItemsInfo(showGcubeItemsInfo);
this.isAsyncronusTable = dataProvider instanceof AbstractDataProvider?true:false;
initTable(null, null);
}
/**
* Sets the show gcube items info.
*
* @param showGcubeItemsInfo the new show gcube items info
*/
private void setShowGcubeItemsInfo(boolean showGcubeItemsInfo) {
this.showGcubeItemsInfo = showGcubeItemsInfo;
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.view.grid.AbstractItemsCellTable#updateItems(java.util.List, boolean)
*/
public void updateItems(List<T> items, boolean removeOldItems) {
super.updateItems(items, removeOldItems);
}
/**
* Adds the items.
*
* @param items the items
*/
public void addItems(List<T> items) {
super.addItems(items);
}
/* (non-Javadoc)
* @see org.gcube.portlets.admin.gcubereleases.client.view.AbstractPackageTable#initTable(com.google.gwt.user.cellview.client.AbstractCellTable, com.google.gwt.user.cellview.client.SimplePager, com.github.gwtbootstrap.client.ui.Pagination)
*/
@Override
public void initTable(final SimplePager pager, final Pagination pagination) {
sortedCellTable.setEmptyTableWidget(new Label("No data."));
if(this.displayFields.contains(DISPLAY_FIELD.ICON)){
//ICONS
ImageResourceCell iconResourceCell = new ImageResourceCell() {
public Set<String> getConsumedEvents() {
HashSet<String> events = new HashSet<String>();
events.add("click");
return events;
}
};
icon = new Column<T, ImageResource>(iconResourceCell) {
@Override
public ImageResource getValue(T dataObj) {
return Util.getImage(dataObj);
}
/* (non-Javadoc)
* @see com.google.gwt.user.cellview.client.Column#render(com.google.gwt.cell.client.Cell.Context, java.lang.Object, com.google.gwt.safehtml.shared.SafeHtmlBuilder)
*/
@Override
public void render(Context context, T object, SafeHtmlBuilder sb) {
super.render(context, object, sb);
}
};
// icon.setSortable(false);
sortedCellTable.addColumn(icon, "", false);
sortedCellTable.setColumnWidth(icon, 25.0, Unit.PX);
}
if(this.displayFields.contains(DISPLAY_FIELD.NAME)){
//NAME
name = new TextColumn<T>() {
@Override
public String getValue(T object) {
return ((Item) object).getName();
}
//ADDING TOOLTIP
@Override
public void render(com.google.gwt.cell.client.Cell.Context context, T object, SafeHtmlBuilder sb) {
sb.appendHtmlConstant("<div title=\""+((Item) object).getName()+"\">");
super.render(context, object, sb);
sb.appendHtmlConstant("</div>");
};
};
sortedCellTable.addColumn(name, "Name", true);
if(!isAsyncronusTable){
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
return ((Item) o1).getName().compareTo(((Item) o2).getName());
}
};
sortedCellTable.setComparator(name, c);
}
}
if(this.displayFields.contains(DISPLAY_FIELD.OWNER)){
owner = new TextColumn<T>() {
@Override
public String getValue(T object) {
return ((Item) object).getOwner() != null ? ((Item) object).getOwner() : "";
}
};
sortedCellTable.addColumn(owner, "Owner", true);
if(!isAsyncronusTable){
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
return ((Item) o1).getOwner().compareTo(((Item) o2).getOwner());
}
};
sortedCellTable.setComparator(owner, c);
}
}
if(this.displayFields.contains(DISPLAY_FIELD.CREATION_DATE)){
DateCell date = new DateCell(dtformat);
dateColumn = new Column<T, Date>(date){
@Override
public Date getValue(T object) {
return ((Item) object).getCreationDate();
}
};
sortedCellTable.addColumn(dateColumn, "Created", true);
if(!isAsyncronusTable){
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
if(o1 == null || o1.getCreationDate()==null)
return -1;
if(o2 == null || o2.getCreationDate()==null)
return 1;
Date d1 = ((Item) o1).getCreationDate();
Date d2 = ((Item) o2).getCreationDate();
// GWT.log(d1.toString() + "is after "+d2.toString() +" ? "+d2.after(d1));
if(d1.after(d2))
return 1;
else
return -1;
}
};
sortedCellTable.setComparator(dateColumn,c);
}
}
if(displayProperties!=null){
for (final String column : displayProperties) {
//NAME
TextColumn<T> textColumn = new TextColumn<T>() {
@Override
public String getValue(T object) {
Item extensionItem;
String value = null;
if(object instanceof Item){
extensionItem = object;
value = extensionItem.getGcubeProperties().get(column);
}
return value==null?"":value;
}
};
sortedCellTable.addColumn(textColumn, column, true);
if(!isAsyncronusTable){
Comparator<T> c = new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
if(!(o1 instanceof Item))
return -1;
if(!(o2 instanceof Item))
return 1;
Item e1 = o1;
Item e2 = o2;
String v1 = e1.getGcubeProperties().get(column);
String v2 = e2.getGcubeProperties().get(column);
if(v1==null)
return 1;
if(v2==null)
return -1;
return v1.compareToIgnoreCase(v2);
}
};
sortedCellTable.setComparator(textColumn, c);
}
}
}
if(showGcubeItemsInfo){
//ICONS
ImageResourceCell showGcubeInfo = new ImageResourceCell() {
public Set<String> getConsumedEvents() {
HashSet<String> events = new HashSet<String>();
events.add("click");
return events;
}
};
MyToolTipColumn<T, ImageResource> showGcubeInfoClm = new MyToolTipColumn<T, ImageResource>(showGcubeInfo, "Show gcube properties") {
@Override
public ImageResource getValue(T object) {
return info;
}
@Override
public void render(Context context, T object, SafeHtmlBuilder sb) {
super.render(context, object, sb);
}
/* (non-Javadoc)
* @see com.google.gwt.user.cellview.client.Column#onBrowserEvent(com.google.gwt.cell.client.Cell.Context, com.google.gwt.dom.client.Element, java.lang.Object, com.google.gwt.dom.client.NativeEvent)
*/
@Override
public void onBrowserEvent(
Context context, Element elem, T object, NativeEvent event) {
super.onBrowserEvent(context, elem, object, event);
if ("click".equals(event.getType())) {
Item item = object;
DialogShowGcubeItem dg = new DialogShowGcubeItem("Gcube Properties for: "+item.getName(), null, item, true);
// dg.setPopupPosition(event.getClientX()-Integer.parseInt(dg.getElement().getStyle().getWidth()), event.getClientY());
dg.center();
}
}
};
sortedCellTable.addColumn(showGcubeInfoClm, "", false);
sortedCellTable.setColumnWidth(showGcubeInfoClm, 32.0, Unit.PX);
}
if(startSortByColumn!=null)
switch (startSortByColumn) {
case NAME:
if(this.displayFields.contains(DISPLAY_FIELD.NAME)){
sortedCellTable.setInitialSortColumn(name);
}
break;
case OWNER:
if(this.displayFields.contains(DISPLAY_FIELD.OWNER)){
sortedCellTable.setInitialSortColumn(owner);
}
break;
case CREATION_DATE:
if(this.displayFields.contains(DISPLAY_FIELD.CREATION_DATE)){
sortedCellTable.setDefaultSortOrder(dateColumn, false); // sorts ascending on first click
sortedCellTable.setInitialSortColumn(dateColumn);
}
break;
default:
break;
}
/*final SingleSelectionModel<Item> selectionModel = new SingleSelectionModel<Item>();
selectionModel.addSelectionChangeHandler(new Handler() {
@Override
public void onSelectionChange(SelectionChangeEvent event) {
}
});*/
}
/**
* Displays the appropriate sorted icon in the header of the column for the given index.
*
* @param columnIndex
* of the column to mark as sorted
* @param ascending
* <code>true</code> for ascending icon, <code>false</code> for descending icon
*/
public void setSortedColumn(int columnIndex, boolean ascending) {
GWT.log("Column index: "+columnIndex);
GWT.log("ascending: "+ascending);
Column<T, ?> column = sortedCellTable.getColumn(columnIndex);
if (column != null && column.isSortable()) {
ColumnSortInfo info = sortedCellTable.getColumnSortList().push(column);
// ColumnSortEvent.fire(cellTable, cellTable.getColumnSortList());
GWT.log("info.isAscending(): "+info.isAscending());
if (info.isAscending() != ascending) {
sortedCellTable.getColumnSortList().push(column);
ColumnSortEvent.fire(sortedCellTable, sortedCellTable.getColumnSortList());
}
}
}
/**
* Sets the display fields.
*
* @param fields the new display fields
*/
public void setDisplayFields(DISPLAY_FIELD[] fields) {
this.displayFields = fields!=null && fields.length>0?Arrays.asList(fields):Arrays.asList(DISPLAY_FIELD.values());
}
/**
* Sets the display properties.
*
* @param properties the new display properties
*/
public void setDisplayProperties(List<String> properties){
this.displayProperties = properties;
}
/**
* Reset columns table.
*/
public void reInitColumnsTable(){
int count = sortedCellTable.getColumnCount();
for(int i=0;i<count;i++){
sortedCellTable.removeColumn(0);
}
initTable(null, null);
}
/**
* Gets the display fields.
*
* @return the displayFields
*/
public List<DISPLAY_FIELD> getDisplayFields() {
return displayFields;
}
/**
* The Class ButtonImageCell.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Feb 1, 2016
*/
public class ButtonImageCell extends ButtonCell{
/* (non-Javadoc)
* @see com.google.gwt.cell.client.AbstractSafeHtmlCell#render(com.google.gwt.cell.client.Cell.Context, java.lang.Object, com.google.gwt.safehtml.shared.SafeHtmlBuilder)
*/
@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
String value, SafeHtmlBuilder sb) {
SafeHtml html = SafeHtmlUtils.fromTrustedString(new Image(value).toString());
sb.append(html);
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.notification.SelectionItemHandler#getSelectionItem()
*/
@Override
public T getSelectedItem() {
return ssm.getSelectedObject();
}
}

View File

@ -0,0 +1,41 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.cellview.client.Column;
public abstract class MyToolTipColumn<T, C> extends Column<T, C> {
interface Templates extends SafeHtmlTemplates {
@Template("<div title=\"{0}\">")
SafeHtml startToolTip(String toolTipText);
@Template("</div>")
SafeHtml endToolTip();
}
private static final Templates TEMPLATES = GWT.create(Templates.class);
private final String toolTipText;
public MyToolTipColumn(final Cell<C> cell, final String toolTipText) {
super(cell);
this.toolTipText = toolTipText;
}
@Override
public void render(final Context context, final T object, final SafeHtmlBuilder sb) {
sb.append(TEMPLATES.startToolTip(toolTipText));
super.render(context, object, sb);
sb.append(TEMPLATES.endToolTip());
}
}

View File

@ -0,0 +1,250 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client.view.grid.copy;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.widgets.wsexplorer.client.resources.CellTableResources;
import com.github.gwtbootstrap.client.ui.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.ColumnSortEvent;
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo;
import com.google.gwt.user.cellview.client.Header;
import com.google.gwt.view.client.AbstractDataProvider;
import com.google.gwt.view.client.ListDataProvider;
/**
* The Class SortedCellTable.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 6, 2016
* @param <T> the generic type
*/
public class SortedCellTable<T> extends CellTable<T> {
/**
* To keep track of the currently sorted column
*/
private Column<T, ?> currentlySortedColumn;
/**
* Tells us which way to sort a column initially
*/
private Map<Column<T, ?>, Boolean> defaultSortOrderMap = new HashMap<Column<T, ?>, Boolean>();
/**
* Comparators associated with their columns
*/
private Map<Column<T, ?>, Comparator<T>> comparators = new HashMap<Column<T, ?>, Comparator<T>>();
/**
* Column to sort when the data provider's list is refreshed using
* {@link SortedCellTable#setList(List)}
*/
private Column<T, ?> initialSortColumn;
/**
* Data provider we will attach to this table
*/
private AbstractDataProvider<T> dataProvider;
/**
* Special column sorting handler that will allow us to do more controlled
* sorting
*/
private ListHandler<T> columnSortHandler;
/**
* Instantiates a new sorted cell table.
*
* @param dataProv the data provider
*/
public SortedCellTable(AbstractDataProvider<T> dataProv) {
super(1,CellTableResources.INSTANCE);
this.dataProvider = dataProv;
if(this.dataProvider instanceof ListDataProvider){
columnSortHandler = new ListHandler<T>(((ListDataProvider<T>) this.dataProvider).getList()) {
@Override
public void onColumnSort(ColumnSortEvent event) {
@SuppressWarnings("unchecked")
Column<T, ?> column = (Column<T, ?>) event.getColumn();
if (column == null) {
return;
}
if (column.equals(currentlySortedColumn)) {
// Default behavior
super.onColumnSort(event);
}
else {
// Initial sort; look up which direction we need
final Comparator<T> comparator = comparators.get(column);
if (comparator == null) {
return;
}
Boolean ascending = defaultSortOrderMap.get(column);
if (ascending == null || ascending) {
// Default behavior
super.onColumnSort(event);
}
else {
// Sort the column descending
Collections.sort(getList(), new Comparator<T>() {
public int compare(T o1, T o2) {
return -comparator.compare(o1, o2);
}
});
// Set the proper arrow in the header
getColumnSortList().push(new ColumnSortInfo(column, false));
}
currentlySortedColumn = column;
}
}
@Override
public void setComparator(Column<T, ?> column, Comparator<T> comparator) {
comparators.put(column, comparator);
super.setComparator(column, comparator);
}
};
addColumnSortHandler(columnSortHandler);
}
}
/**
* Adds a column to the table and sets its sortable state.
*
* @param column the column
* @param headerName the header name
* @param sortable the sortable
*/
public void addColumn(Column<T, ?> column, String headerName, boolean sortable) {
addColumn(column, headerName);
column.setSortable(sortable);
if (sortable) {
defaultSortOrderMap.put(column, true);
}
}
/* (non-Javadoc)
* @see com.google.gwt.user.cellview.client.AbstractCellTable#addColumn(com.google.gwt.user.cellview.client.Column, java.lang.String)
*/
public void addColumn(Column<T, ?> column, String headerName) {
super.addColumn(column, headerName);
}
/**
* Adds a column to the table and sets its sortable state.
*
* @param column the column
* @param header the header
* @param sortable the sortable
*/
public void addColumn(Column<T, ?> column, Header<?> header, boolean sortable) {
addColumn(column, header);
column.setSortable(sortable);
if (sortable) {
defaultSortOrderMap.put(column, true);
}
}
/**
* Sets the column to sort when the data list is reset using
* {@link SortedCellTable#setList(List)}.
*
* @param column the column
*/
public void setInitialSortColumn(Column<T, ?> column) {
initialSortColumn = column;
}
/**
* Sets a comparator to use when sorting the given column.
*
* @param column the column
* @param comparator the comparator
*/
public void setComparator(Column<T, ?> column, Comparator<T> comparator) {
columnSortHandler.setComparator(column, comparator);
}
/**
* Sets the sort order to use when this column is clicked and it was not
* previously sorted.
*
* @param column the column
* @param ascending the ascending
*/
public void setDefaultSortOrder(Column<T, ?> column, boolean ascending) {
defaultSortOrderMap.put(column, ascending);
}
/**
* Sets the table's data provider list and sorts the table based on the
* column given in {@link SortedCellTable#setInitialSortColumn(Column)}.
*
* @param list the new list
*/
public void setList(List<T> list) {
if(dataProvider instanceof ListDataProvider){
List<T> myData = ((ListDataProvider) dataProvider).getList();
myData.clear();
if (list != null) {
/*for (T t : list) {
dataProvider.getList().add(t);
}*/
myData.addAll(list);
}
// Do a first-time sort based on which column was set in
// setInitialSortColumn()
if (initialSortColumn != null) {
Collections.sort(myData, new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
return (defaultSortOrderMap.get(initialSortColumn) ? 1 : -1) * comparators.get(initialSortColumn).compare(o1, o2);
}
});
// Might as well get the little arrow on the header to make it
// official
getColumnSortList().push(
new ColumnSortInfo(
initialSortColumn,
defaultSortOrderMap.get(initialSortColumn)));
currentlySortedColumn = initialSortColumn;
}
}
}
/**
* Gets the data provider.
*
* @return the data provider
*/
public AbstractDataProvider<T> getDataProvider() {
return dataProvider;
}
}

View File

@ -151,6 +151,83 @@ public class ItemBuilder {
return item;
}
/**
* Gets the item.
*
* @param parent the parent
* @param workspaceItem the workspace item
* @param workspaceItemPath the workspace item path
* @param showableTypes the showable types
* @param filterCriteria the filter criteria
* @param loadChildren the load children
* @param loadGcubeProperties the load gcube properties
* @param startIdx the start idx
* @param limit the limit
* @return the item
* @throws InternalErrorException the internal error exception
*/
public static Item getItem(Item parent, WorkspaceItem workspaceItem, String workspaceItemPath, List<ItemType> showableTypes, FilterCriteria filterCriteria, boolean loadChildren, boolean loadGcubeProperties, int startIdx, int limit) throws InternalErrorException {
ItemType type = getItemType(workspaceItem);
if (!showableTypes.contains(type)) {
return null;
}
if (!filterItem(type, workspaceItem, filterCriteria)) {
return null;
}
// //TODO ADD CONTROL ON THE PATH WHEN WILL BE MORE FAST
// if (itemName.equals(WorkspaceExplorerConstants.SPECIAL_FOLDERS_LABEL))
// itemName = WorkspaceExplorerConstants.VRE_FOLDERS_LABEL;
boolean isFolder = type.equals(ItemType.FOLDER)?true:false;
boolean isSharedFolder = workspaceItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)?true:false;
String itemName = workspaceItem.getName();
if(isSharedFolder){
logger.debug("Is shared folder: "+workspaceItem.getName());
WorkspaceSharedFolder shared = (WorkspaceSharedFolder) workspaceItem;
itemName = shared.isVreFolder()?shared.getDisplayName():workspaceItem.getName();
}
// _log.debug("Building Item for: "+itemName);
Item item = null;
try{
//THIS CALL IS VERY SLOW!!
// String storageID = null;
// if(workspaceItem instanceof FolderItem){
// storageID = workspaceItem.getStorageID();
// }
item = new Item(parent, workspaceItem.getId(), itemName, type, workspaceItemPath, UserUtil.getUserFullName(workspaceItem.getOwner().getPortalLogin()), toDate(workspaceItem.getCreationTime()), isFolder, false);
item.setSharedFolder(isSharedFolder);
if(loadGcubeProperties){
Map<String, String> itemProperties = getGcubePropertiesForItem(workspaceItem);
item.setGcubeProperties(itemProperties);
}
}catch(Exception e){
logger.error("Error on getting item: "+itemName+" with id: "+workspaceItem.getId()+", from HL, so skipping item");
return null;
}
if(loadChildren){
WorkspaceFolder folder = (WorkspaceFolder) workspaceItem;
for (WorkspaceItem child: folder.getChildren(limit, startIdx, false)){
String itemPath = workspaceItemPath+"/"+child.getName();
Item itemChild = getItem(item, child, itemPath, showableTypes, filterCriteria, false, loadGcubeProperties, startIdx, limit);
if (itemChild!=null){
item.addChild(itemChild);
}
}
}
return item;
}
/**
* Gets the item type.
*
@ -429,4 +506,5 @@ public class ItemBuilder {
String fileName = "t";
System.out.println(checkFileExtension(fileName, allowedFileExtension));
}*/
}

View File

@ -52,7 +52,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
// public static final String PRODUCTION_SCOPE = "/d4science.research-infrastructures.eu/gCubeApps"; //PRODUCTION
/**
/**
* Gets the workspace.
*
@ -179,7 +179,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
switch(category){
case HOME:{
WorkspaceItem root = workspace.getRoot();
PortalContext pContext = PortalContext.getConfiguration();
PortalContext pContext = PortalContext.getConfiguration();
String fullName = pContext.getCurrentUser(getThreadLocalRequest()).getFullname();
if(fullName.indexOf(" ")>0){
fullName = fullName.substring(0, fullName.indexOf(" "));
@ -691,4 +691,78 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get folder");
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getFolder(org.gcube.portlets.widgets.wsexplorer.shared.Item, java.util.List, boolean, org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria, boolean, int, int)
*/
@Override
public Item getFolder(
Item item, List<ItemType> showableTypes, boolean purgeEmpyFolders,
FilterCriteria filterCriteria, boolean loadGcubeProperties,
int startIndex, int limit) throws WorkspaceNavigatorServiceException {
logger.trace("getFolder folderId: "+item.getId()+" showableTypes: "+showableTypes+" purgeEmpyFolders: "+purgeEmpyFolders+" filterCriteria: "+filterCriteria);
try {
Workspace workspace = getWorkspace();
WorkspaceItem folder = workspace.getItem(item.getId());
logger.trace("GetFolder - Replyiing folder");
long startTime = System.currentTimeMillis();
logger.trace("start time - " + startTime);
//TO AVOID SLOW CALL getPATH()
String folderPath = item.getPath()!=null && !item.getPath().isEmpty()?item.getPath():folder.getPath();
//folder.get
Item itemFolder = ItemBuilder.getItem(null, folder, folderPath, showableTypes, filterCriteria, true, loadGcubeProperties, startIndex, limit);
// _log.trace("Only showable types:");
if (purgeEmpyFolders) {
itemFolder = ItemBuilder.purgeEmptyFolders(itemFolder);
}
logger.debug("Returning: "+itemFolder.getChildren().size() + " items");
Long endTime = System.currentTimeMillis() - startTime;
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
logger.debug("end time - " + time);
Collections.sort(itemFolder.getChildren(), new ItemComparator());
return itemFolder;
} catch (Exception e) {
logger.error("Error during folder retrieving", e);
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get folder");
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getFolderChildrenCount(org.gcube.portlets.widgets.wsexplorer.shared.Item)
*/
@Override
public int getFolderChildrenCount(Item item) throws WorkspaceNavigatorServiceException {
try {
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(item.getId());
if(wsItem.isFolder()){
WorkspaceFolder folder = (WorkspaceFolder) wsItem;
int count = folder.getChildrenCount(false);
//count = folder.getChildrenCount();
logger.debug("returning children count time - " + count);
//return count = 100;
return count;
}
return 0;
} catch (Exception e) {
logger.error("Error during folder retrieving", e);
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get count on folder children");
}
}
}

View File

@ -7,16 +7,16 @@
<set-configuration-property name='xsiframe.failIfScriptTag'
value='FALSE' />
<!-- <script src="jquery-1.10.1.min.js"></script> -->
<!-- <script src="bootstrap.min.js"></script> -->
<!-- <script src="jquery-1.10.1.min.js"></script> -->
<!-- <script src="bootstrap.min.js"></script> -->
<!-- <stylesheet src='workspaceExplorer.css' /> -->
<!-- <stylesheet src='workspaceExplorer.css' /> -->
<!-- Inherit the default GWT style sheet. You can change -->
<inherits name="com.github.gwtbootstrap.Bootstrap" />
<!-- Specify the app entry point class. -->
<!-- <entry-point class='org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerEntryPoint'/> -->
<!-- <entry-point class='org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerEntryPoint' /> -->
<!-- Specify the paths for translatable code -->
<source path='client' />
@ -24,7 +24,8 @@
<!--pay attention in this part -->
<source path='resources' />
<replace-with class="org.gcube.portlets.widgets.wsexplorer.resources.BootstrapConfigurator">
<replace-with
class="org.gcube.portlets.widgets.wsexplorer.resources.BootstrapConfigurator">
<when-type-is class="com.github.gwtbootstrap.client.ui.config.Configurator" />
</replace-with>
<public path="resources">