2015-12-04 18:45:47 +01:00
|
|
|
package org.gcube.portlets.user.statisticalalgorithmsimporter.client.project;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.ProjectStatusEvent;
|
2015-12-09 18:15:10 +01:00
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.event.SessionExpiredEvent;
|
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.maindata.ItemDescription;
|
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.rpc.StatAlgoImporterServiceAsync;
|
2015-12-04 18:45:47 +01:00
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.ProjectStatusEventType;
|
2015-12-09 18:15:10 +01:00
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.type.SessionExpiredType;
|
2015-12-04 18:45:47 +01:00
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.utils.UtilsGXT3;
|
2015-12-09 18:15:10 +01:00
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterSessionExpiredException;
|
2015-12-04 18:45:47 +01:00
|
|
|
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 org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
|
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.event.shared.EventBus;
|
2015-12-09 18:15:10 +01:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2015-12-04 18:45:47 +01:00
|
|
|
import com.sencha.gxt.core.client.dom.XDOM;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2015-12-09 18:15:10 +01:00
|
|
|
* @author Giancarlo Panichi email: <a
|
|
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
2015-12-04 18:45:47 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ProjectManager {
|
|
|
|
private EventBus eventBus;
|
|
|
|
private String projectFolderId;
|
2015-12-09 18:15:10 +01:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private ItemDescription mainCodeDescription;
|
|
|
|
|
|
|
|
public ProjectManager(EventBus eventBus) {
|
|
|
|
this.eventBus = eventBus;
|
2015-12-04 18:45:47 +01:00
|
|
|
}
|
2015-12-09 18:15:10 +01:00
|
|
|
|
|
|
|
public void createProject() {
|
|
|
|
|
2015-12-04 18:45:47 +01:00
|
|
|
WorkspaceExplorerSelectDialog wselectDialog = new WorkspaceExplorerSelectDialog(
|
2015-12-09 18:15:10 +01:00
|
|
|
"Select Project Folder", true);
|
2015-12-04 18:45:47 +01:00
|
|
|
|
|
|
|
WorskpaceExplorerSelectNotificationListener handler = new WorskpaceExplorerSelectNotificationListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSelectedItem(Item item) {
|
|
|
|
|
|
|
|
if (item.getType() == ItemType.FOLDER) {
|
2015-12-09 18:15:10 +01:00
|
|
|
createProjectOnServer(item);
|
2015-12-04 18:45:47 +01:00
|
|
|
|
|
|
|
} else {
|
2015-12-09 18:15:10 +01:00
|
|
|
UtilsGXT3.info("Attention",
|
|
|
|
"Select a valid project folder!");
|
2015-12-04 18:45:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailed(Throwable throwable) {
|
|
|
|
throwable.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAborted() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNotValidSelection() {
|
|
|
|
UtilsGXT3.info("Attention", "Select a valid project folder!");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
wselectDialog.addWorkspaceExplorerSelectNotificationListener(handler);
|
2015-12-09 18:15:10 +01:00
|
|
|
wselectDialog.setZIndex(XDOM.getTopZIndex());
|
2015-12-04 18:45:47 +01:00
|
|
|
wselectDialog.show();
|
|
|
|
}
|
2015-12-09 18:15:10 +01:00
|
|
|
|
|
|
|
protected void createProjectOnServer(Item item) {
|
|
|
|
Log.debug("Item selected: " + item);
|
|
|
|
projectFolderId = item.getId();
|
|
|
|
StatAlgoImporterServiceAsync.INSTANCE.createProjectOnWorkspace(
|
|
|
|
item.getId(), new AsyncCallback<Void>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Void result) {
|
|
|
|
fireProjectStatusOpenEvent();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
Log.debug(caught.getLocalizedMessage());
|
|
|
|
caught.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMainCode(ItemDescription mainCodeDescription) {
|
|
|
|
this.mainCodeDescription = mainCodeDescription;
|
|
|
|
Log.debug("Main: " + mainCodeDescription);
|
|
|
|
StatAlgoImporterServiceAsync.INSTANCE.setMainCode(
|
|
|
|
mainCodeDescription.getId(), new AsyncCallback<Void>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
if (caught instanceof StatAlgoImporterSessionExpiredException) {
|
|
|
|
eventBus.fireEvent(new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
|
|
|
Log.error("Error setting main code: "
|
|
|
|
+ caught.getLocalizedMessage());
|
|
|
|
UtilsGXT3.alert("Error",
|
|
|
|
caught.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
caught.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Void result) {
|
|
|
|
fireProjectStatusEventUpdate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void deleteItem(ItemDescription itemDescription) {
|
2015-12-04 18:45:47 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-09 18:15:10 +01:00
|
|
|
protected void fireProjectStatusOpenEvent() {
|
|
|
|
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
|
|
|
|
ProjectStatusEventType.OPEN, projectFolderId);
|
2015-12-04 18:45:47 +01:00
|
|
|
eventBus.fireEvent(projectStatusEvent);
|
|
|
|
Log.debug("ProjectStatusEvent fired");
|
2015-12-09 18:15:10 +01:00
|
|
|
|
2015-12-04 18:45:47 +01:00
|
|
|
}
|
|
|
|
|
2015-12-09 18:15:10 +01:00
|
|
|
protected void fireProjectStatusEventUpdate() {
|
|
|
|
ProjectStatusEvent projectStatusEvent = new ProjectStatusEvent(
|
|
|
|
ProjectStatusEventType.UPDATE, projectFolderId);
|
2015-12-04 18:45:47 +01:00
|
|
|
eventBus.fireEvent(projectStatusEvent);
|
|
|
|
Log.debug("ProjectStatusEvent fired");
|
|
|
|
}
|
2015-12-09 18:15:10 +01:00
|
|
|
|
2015-12-04 18:45:47 +01:00
|
|
|
}
|