134 lines
3.8 KiB
Java
134 lines
3.8 KiB
Java
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;
|
|
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;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
|
|
|
/**
|
|
* Entry point classes define <code>onModuleLoad()</code>.
|
|
*/
|
|
public class WorkspaceNavigator {
|
|
|
|
private final WorkspaceExplorerServiceAsync workspaceNavigatorService = GWT.create(WorkspaceExplorerService.class);
|
|
protected static final HorizontalPanel LOADING_PANEL = new HorizontalPanel();
|
|
|
|
static {
|
|
LOADING_PANEL.setSpacing(3);
|
|
// LOADING_PANEL.add(LOADING_IMAGE);
|
|
LOADING_PANEL.add(new HTML("Loading..."));
|
|
}
|
|
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;
|
|
|
|
public WorkspaceNavigator() {
|
|
// 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);
|
|
}
|
|
|
|
public void onSuccess(Item root) {
|
|
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);
|
|
itTables.addItems(root.getChildren());
|
|
explorerPanel.add(itTables.getCellTable());
|
|
|
|
GWT.log("workspace tree loaded");
|
|
// DataLoadEvent.fireLoadDataSuccess(WorkspaceLightTreePanel.this);
|
|
}
|
|
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @return the explorerPanel
|
|
*/
|
|
public ScrollPanel getExplorerPanel() {
|
|
return explorerPanel;
|
|
}
|
|
|
|
|
|
}
|