2015-06-24 15:16:13 +02:00
|
|
|
package org.gcube.portlets.widgets.wsexplorer.client.view;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.Util;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.grid.ItemsTable;
|
2015-06-24 18:43:36 +02:00
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.resources.Resources;
|
2015-06-25 12:56:41 +02:00
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.resources.old.WorkspaceLightTreeResources;
|
2015-06-24 15:16:13 +02:00
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerServiceAsync;
|
|
|
|
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.client.GWT;
|
2015-06-24 18:43:36 +02:00
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
2015-06-25 12:56:41 +02:00
|
|
|
import com.google.gwt.resources.client.ImageResource;
|
2015-06-24 15:16:13 +02:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
2015-06-24 18:43:36 +02:00
|
|
|
import com.google.gwt.user.client.ui.Image;
|
2015-06-24 15:16:13 +02:00
|
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point classes define <code>onModuleLoad()</code>.
|
|
|
|
*/
|
2015-06-24 15:18:42 +02:00
|
|
|
public class WorkspaceExplorer {
|
2015-06-24 15:16:13 +02:00
|
|
|
|
|
|
|
private final WorkspaceExplorerServiceAsync workspaceNavigatorService = GWT.create(WorkspaceExplorerService.class);
|
|
|
|
protected static final HorizontalPanel LOADING_PANEL = new HorizontalPanel();
|
2015-06-24 18:43:36 +02:00
|
|
|
protected static final Image LOADING_IMAGE = Resources.getIconLoading().createImage();
|
2015-06-24 15:16:13 +02:00
|
|
|
|
|
|
|
static {
|
2015-06-24 18:43:36 +02:00
|
|
|
LOADING_PANEL.getElement().getStyle().setMargin(5.0, Unit.PX);
|
|
|
|
// LOADING_PANEL.setSpacing(3);
|
|
|
|
LOADING_PANEL.add(LOADING_IMAGE);
|
|
|
|
HTML loading = new HTML("Loading...");
|
|
|
|
loading.getElement().getStyle().setPaddingLeft(5.0, Unit.PX);
|
|
|
|
LOADING_PANEL.add(loading);
|
2015-06-24 15:16:13 +02:00
|
|
|
}
|
|
|
|
protected List<ItemType> selectableTypes = new ArrayList<ItemType>();
|
|
|
|
protected List<ItemType> showableTypes = new ArrayList<ItemType>();
|
|
|
|
protected List<String> allowedMimeTypes = new ArrayList<String>();
|
|
|
|
protected boolean showEmptyFolders = true;
|
|
|
|
protected Map<String, String> requiredProperties = new HashMap<String, String>();
|
|
|
|
/**
|
|
|
|
* Create a remote service proxy to talk to the server-side Greeting
|
|
|
|
* service.
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected ScrollPanel explorerPanel;
|
|
|
|
|
2015-06-24 15:18:42 +02:00
|
|
|
public WorkspaceExplorer() {
|
2015-06-24 15:16:13 +02:00
|
|
|
// as default all items are showable and selectable
|
|
|
|
for (ItemType type : ItemType.values()) {
|
|
|
|
showableTypes.add(type);
|
|
|
|
selectableTypes.add(type);
|
|
|
|
}
|
|
|
|
explorerPanel = new ScrollPanel();
|
|
|
|
|
|
|
|
// sp.setWidth(width+"px");
|
|
|
|
// sp.setHeight(height+"px");
|
|
|
|
|
|
|
|
loadTree();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the panel in loading mode.
|
|
|
|
*/
|
|
|
|
protected void setLoading() {
|
|
|
|
explorerPanel.clear();
|
|
|
|
explorerPanel.add(LOADING_PANEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the Workspace Tree.
|
|
|
|
*/
|
|
|
|
public void loadTree() {
|
|
|
|
GWT.log("loading tree data");
|
|
|
|
setLoading();
|
|
|
|
|
|
|
|
// we make a copy of showable types
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean purgeEmpyFolders = !showEmptyFolders;
|
|
|
|
|
|
|
|
FilterCriteria filterCriteria = new FilterCriteria(allowedMimeTypes,
|
|
|
|
requiredProperties);
|
|
|
|
|
|
|
|
GWT.log("loading workspace tree from server");
|
|
|
|
|
|
|
|
workspaceNavigatorService.getRoot(showableTypesParam, purgeEmpyFolders,
|
|
|
|
filterCriteria, new AsyncCallback<Item>() {
|
|
|
|
|
|
|
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
GWT.log("Error loading workspace tree from server",
|
|
|
|
caught);
|
|
|
|
// showErrorPanel(caught);
|
|
|
|
// DataLoadEvent.fireLoadDataFailed(WorkspaceLightTreePanel.this,
|
|
|
|
// caught);
|
|
|
|
}
|
|
|
|
|
2015-06-25 12:56:41 +02:00
|
|
|
public void onSuccess(Item item) {
|
2015-06-24 15:16:13 +02:00
|
|
|
GWT.log("workspace tree retrieved.");
|
|
|
|
// tree.setRootItem(root);
|
|
|
|
|
|
|
|
// we select the root
|
|
|
|
// tree.selectItem(root.getId());
|
|
|
|
|
|
|
|
// then we remove the loading icon
|
|
|
|
explorerPanel.clear();
|
|
|
|
ItemsTable itTables = new ItemsTable(false);
|
2015-06-25 12:56:41 +02:00
|
|
|
itTables.addItems(item.getChildren());
|
2015-06-24 15:16:13 +02:00
|
|
|
explorerPanel.add(itTables.getCellTable());
|
|
|
|
|
|
|
|
GWT.log("workspace tree loaded");
|
|
|
|
// DataLoadEvent.fireLoadDataSuccess(WorkspaceLightTreePanel.this);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the explorerPanel
|
|
|
|
*/
|
|
|
|
public ScrollPanel getExplorerPanel() {
|
|
|
|
return explorerPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|