182 lines
4.5 KiB
Java
182 lines
4.5 KiB
Java
/**
|
|
*
|
|
*/
|
|
|
|
package org.gcube.portlets.user.workspaceexplorerapp.client;
|
|
|
|
import gwt.material.design.client.ui.MaterialToast;
|
|
|
|
import org.gcube.portlets.user.workspaceexplorerapp.client.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener;
|
|
import org.gcube.portlets.user.workspaceexplorerapp.client.grid.DisplayField;
|
|
import org.gcube.portlets.user.workspaceexplorerapp.shared.Item;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
import com.google.gwt.dom.client.Style.Unit;
|
|
import com.google.gwt.event.dom.client.ContextMenuEvent;
|
|
import com.google.gwt.event.dom.client.ContextMenuHandler;
|
|
import com.google.gwt.event.shared.HandlerManager;
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
import com.google.gwt.user.client.ui.RootPanel;
|
|
|
|
/**
|
|
* The Class WorkspaceExplorerAppController.
|
|
*
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
* @Oct 8, 2014
|
|
*/
|
|
public class WorkspaceExplorerAppController {
|
|
|
|
// private VerticalPanel mainPanel = new VerticalPanel();
|
|
|
|
private WorkspaceExplorerAppPanel mainPanel;
|
|
private WorkspaceResourcesExplorerPanel wsResourcesExplorerPanel;
|
|
private final HandlerManager eventBus = new HandlerManager(null);
|
|
private WorkspaceExplorerApp app;
|
|
|
|
/**
|
|
* Instantiates a new workspace explorer app controller.
|
|
*/
|
|
public WorkspaceExplorerAppController() {
|
|
}
|
|
|
|
|
|
/**
|
|
* Go.
|
|
*
|
|
* @param app the app
|
|
*/
|
|
public void go(WorkspaceExplorerApp app) {
|
|
this.app = app;
|
|
RootPanel.getBodyElement().getStyle().setPadding(0, Unit.PX);
|
|
// mainPanel.setWidth("100%");
|
|
|
|
try {
|
|
String folderId = Window.Location.getParameter("folderId");
|
|
|
|
//TODO CHECK FOLDER ID
|
|
if(folderId==null){
|
|
Window.alert("Folder Id not found, It is not possible to retrieve a folder without a valid id");
|
|
//return;
|
|
}
|
|
|
|
RootPanel.get().addDomHandler(new ContextMenuHandler() {
|
|
|
|
@Override
|
|
public void onContextMenu(ContextMenuEvent event) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
}, ContextMenuEvent.getType());
|
|
|
|
MaterialToast.fireToast("Checking permissions...");
|
|
WorkspaceExplorerAppConstants.workspaceNavigatorService.getFolderIdFromEncrypted(folderId, new AsyncCallback<String>() {
|
|
|
|
@Override
|
|
public void onSuccess(String folderId) {
|
|
|
|
if(folderId!=null && !folderId.isEmpty())
|
|
try {
|
|
initWorkspaceExplorer(folderId);
|
|
}
|
|
catch (Exception e) {
|
|
Window.alert("Folder Id not valid. An occurred when converting folder id");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
Window.alert(caught.getMessage());
|
|
}
|
|
});
|
|
}
|
|
catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Inits the workspace explorer.
|
|
*
|
|
* @param folderId the folder id
|
|
* @throws Exception the exception
|
|
*/
|
|
private void initWorkspaceExplorer(String folderId) throws Exception{
|
|
|
|
wsResourcesExplorerPanel = new WorkspaceResourcesExplorerPanel(eventBus, folderId, false);
|
|
wsResourcesExplorerPanel.loadParentBreadcrumbByItemId(folderId, true);
|
|
WorskpaceExplorerSelectNotificationListener listener = new WorskpaceExplorerSelectNotificationListener() {
|
|
|
|
@Override
|
|
public void onSelectedItem(Item item) {
|
|
|
|
GWT.log("Listener Selected Item " + item);
|
|
}
|
|
|
|
@Override
|
|
public void onFailed(Throwable throwable) {
|
|
|
|
GWT.log("There are networks problem, please check your connection.");
|
|
}
|
|
|
|
@Override
|
|
public void onAborted() {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onNotValidSelection() {
|
|
|
|
}
|
|
};
|
|
wsResourcesExplorerPanel.addWorkspaceExplorerSelectNotificationListener(listener);
|
|
|
|
/*new com.google.gwt.user.client.Timer() {
|
|
|
|
@Override
|
|
public void run() {
|
|
|
|
//TODO //IS A TEST REMOVE
|
|
ArrayList<Item> tests = new ArrayList<Item>();
|
|
for (int i = 0; i < 50; i++) {
|
|
tests.add(new Item(i+""+Random.nextInt(), "name"+i, false));
|
|
}
|
|
wsResourcesExplorerPanel.getWsExplorer().updateExplorer(tests);
|
|
}
|
|
}.schedule(1000);*/
|
|
|
|
mainPanel = new WorkspaceExplorerAppPanel(wsResourcesExplorerPanel);
|
|
app.updateExplorerPanel(mainPanel);
|
|
}
|
|
|
|
|
|
// /**
|
|
// * Gets the main panel.
|
|
// *
|
|
// * @return the mainPanel
|
|
// */
|
|
// public WorkspaceExplorerAppPanel getMainPanel() {
|
|
// return mainPanel;
|
|
// }
|
|
|
|
|
|
/**
|
|
* Gets the event bus.
|
|
*
|
|
* @return the event bus
|
|
*/
|
|
public HandlerManager getEventBus(){
|
|
return eventBus;
|
|
}
|
|
|
|
/**
|
|
* Gets the display fields.
|
|
*
|
|
* @return the display fields
|
|
*/
|
|
public DisplayField[] getDisplayFields(){
|
|
return new DisplayField[]{DisplayField.ICON, DisplayField.NAME, DisplayField.OWNER, DisplayField.CREATION_DATE};
|
|
}
|
|
}
|