2014-06-03 16:33:12 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.user.td.codelistmappingimportwidget.client;
|
|
|
|
|
2015-08-03 18:56:14 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-06-03 16:33:12 +02:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
|
2014-06-04 15:11:21 +02:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession;
|
2014-09-26 16:38:15 +02:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException;
|
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException;
|
2014-06-03 16:33:12 +02:00
|
|
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
2014-06-04 15:11:21 +02:00
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
|
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
|
|
|
|
import org.gcube.portlets.user.td.wizardwidget.client.WizardCard;
|
2015-08-03 18:56:14 +02:00
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.select.WorkspaceExplorerSelectPanel;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
|
|
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
|
2014-06-03 16:33:12 +02:00
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.user.client.Command;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2015-08-03 18:56:14 +02:00
|
|
|
import com.sencha.gxt.core.client.util.Margins;
|
2014-06-03 16:33:12 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
2015-08-03 18:56:14 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
2014-06-03 16:33:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author "Giancarlo Panichi" <a
|
|
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class CodelistMappingWorkSpaceSelectionCard extends WizardCard {
|
|
|
|
|
2015-08-03 18:56:14 +02:00
|
|
|
/*
|
|
|
|
public interface HtmlLayoutContainerTemplate extends XTemplates {
|
|
|
|
@XTemplate("<div class=\"wspaceSelectionCard\" style=\"margin:auto;padding:auto;\"></div>")
|
|
|
|
SafeHtml getTemplate();
|
|
|
|
}*/
|
|
|
|
|
|
|
|
private CodelistMappingSession codelistMappingSession;
|
|
|
|
private CodelistMappingWorkSpaceSelectionCard thisCard;
|
2014-06-03 16:33:12 +02:00
|
|
|
|
2015-08-03 18:56:14 +02:00
|
|
|
private VerticalLayoutContainer p;
|
|
|
|
private WorkspaceExplorerSelectPanel wpanel;
|
2014-06-03 16:33:12 +02:00
|
|
|
|
|
|
|
public CodelistMappingWorkSpaceSelectionCard(
|
2014-06-04 15:11:21 +02:00
|
|
|
final CodelistMappingSession codelistMappingSession) {
|
2014-06-03 16:33:12 +02:00
|
|
|
super("CSV Import From Workspace", "");
|
|
|
|
|
2014-06-04 15:11:21 +02:00
|
|
|
this.codelistMappingSession = codelistMappingSession;
|
2014-06-03 16:33:12 +02:00
|
|
|
thisCard = this;
|
|
|
|
|
2015-08-03 18:56:14 +02:00
|
|
|
|
|
|
|
/*HtmlLayoutContainerTemplate templates = GWT
|
|
|
|
.create(HtmlLayoutContainerTemplate.class);
|
|
|
|
|
|
|
|
HtmlLayoutContainer htmlLayoutContainer = new HtmlLayoutContainer(
|
|
|
|
templates.getTemplate());
|
|
|
|
htmlLayoutContainer.add(button1, new HtmlData(".wspaceSelectionCard"));*/
|
|
|
|
|
2014-06-03 16:33:12 +02:00
|
|
|
p = new VerticalLayoutContainer();
|
|
|
|
|
|
|
|
Log.debug("Set Workspace Panel");
|
2015-08-03 18:56:14 +02:00
|
|
|
List<ItemType> selectableTypes = new ArrayList<ItemType>();
|
|
|
|
selectableTypes.add(ItemType.EXTERNAL_FILE);
|
|
|
|
List<ItemType> showableTypes = new ArrayList<ItemType>();
|
|
|
|
showableTypes.addAll(Arrays.asList(ItemType.values()));
|
|
|
|
|
|
|
|
List<String> allowedMimeTypes = Arrays.asList("application/xml",
|
|
|
|
"application/zip", "application/x-zip",
|
|
|
|
"application/x-zip-compressed", "application/octet",
|
|
|
|
"application/octet-stream");
|
|
|
|
List<String> allowedFileExtensions = Arrays.asList("xml", "zip");
|
|
|
|
|
|
|
|
FilterCriteria filterCriteria = new FilterCriteria(allowedMimeTypes,
|
|
|
|
allowedFileExtensions, new HashMap<String, String>());
|
|
|
|
|
|
|
|
wpanel = new WorkspaceExplorerSelectPanel(new String(
|
|
|
|
"Workspace Selection"), filterCriteria);
|
|
|
|
|
|
|
|
WorskpaceExplorerSelectNotificationListener handler = new WorskpaceExplorerSelectNotificationListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSelectedItem(Item item) {
|
2014-06-03 16:33:12 +02:00
|
|
|
Log.debug("Selected Item:" + item);
|
|
|
|
if (item.getType() == ItemType.EXTERNAL_FILE) {
|
|
|
|
String filename = item.getName();
|
|
|
|
if (filename != null && !filename.isEmpty()) {
|
|
|
|
Log.debug("Item name: " + filename);
|
|
|
|
Log.debug("Item path: " + item.getPath());
|
|
|
|
|
2014-06-04 15:11:21 +02:00
|
|
|
codelistMappingSession.setItemId(item.getId());
|
2014-06-03 16:33:12 +02:00
|
|
|
getWizardWindow().setEnableNextButton(true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Log.debug("Item name null or empty");
|
|
|
|
getWizardWindow().setEnableNextButton(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Log.debug("Item type:" + item.getType());
|
|
|
|
getWizardWindow().setEnableNextButton(false);
|
|
|
|
}
|
2015-08-03 18:56:14 +02:00
|
|
|
|
2014-06-03 16:33:12 +02:00
|
|
|
}
|
2015-08-03 18:56:14 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailed(Throwable throwable) {
|
|
|
|
Log.error("Error in workspaceExplorer: "
|
|
|
|
+ throwable.getLocalizedMessage());
|
|
|
|
throwable.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAborted() {
|
|
|
|
Log.debug("WorkspaceExplorer Aborted");
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
wpanel.addWorkspaceExplorerSelectNotificationListener(handler);
|
|
|
|
|
|
|
|
p.add(wpanel, new VerticalLayoutData(1, 1, new Margins(0)));
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-03 16:33:12 +02:00
|
|
|
setContent(p);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setup() {
|
2014-06-04 15:11:21 +02:00
|
|
|
Log.debug("CodelistMappingWorkSpaceSelectionCard Call Setup ");
|
2014-06-03 16:33:12 +02:00
|
|
|
Command sayNextCard = new Command() {
|
|
|
|
|
|
|
|
public void execute() {
|
2014-06-04 15:11:21 +02:00
|
|
|
Log.debug("CodelistMappingWorkSpaceSelectionCard Call sayNextCard wpanel:"
|
2014-06-03 16:33:12 +02:00
|
|
|
+ wpanel);
|
|
|
|
getWizardWindow().setEnableNextButton(false);
|
|
|
|
getWizardWindow().setEnableBackButton(false);
|
|
|
|
getFileFromWorkspace();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
getWizardWindow().setNextButtonCommand(sayNextCard);
|
|
|
|
|
|
|
|
Command sayPreviousCard = new Command() {
|
|
|
|
public void execute() {
|
|
|
|
try {
|
|
|
|
getWizardWindow().previousCard();
|
|
|
|
getWizardWindow().removeCard(thisCard);
|
2014-06-04 15:11:21 +02:00
|
|
|
Log.debug("Remove CodelistMappingWorkSpaceSelectionCard");
|
2014-06-03 16:33:12 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.error("sayPreviousCard :" + e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
getWizardWindow().setPreviousButtonCommand(sayPreviousCard);
|
|
|
|
getWizardWindow().setEnableNextButton(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void getFileFromWorkspace() {
|
|
|
|
TDGWTServiceAsync tdGwtServiceAsync = TDGWTServiceAsync.INSTANCE;
|
2014-06-04 15:11:21 +02:00
|
|
|
tdGwtServiceAsync.getFileFromWorkspace(codelistMappingSession,
|
2014-06-03 16:33:12 +02:00
|
|
|
new AsyncCallback<Void>() {
|
|
|
|
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
if (caught instanceof TDGWTSessionExpiredException) {
|
|
|
|
getEventBus()
|
|
|
|
.fireEvent(
|
|
|
|
new SessionExpiredEvent(
|
|
|
|
SessionExpiredType.EXPIREDONSERVER));
|
|
|
|
} else {
|
2014-09-26 16:38:15 +02:00
|
|
|
if (caught instanceof TDGWTIsLockedException) {
|
|
|
|
Log.error(caught.getLocalizedMessage());
|
|
|
|
showErrorAndHide("Error Locked",
|
2014-12-04 17:41:34 +01:00
|
|
|
caught.getLocalizedMessage(), "",
|
|
|
|
caught);
|
2014-09-26 16:38:15 +02:00
|
|
|
} else {
|
|
|
|
if (caught instanceof TDGWTIsFinalException) {
|
|
|
|
Log.error(caught.getLocalizedMessage());
|
|
|
|
showErrorAndHide("Error Final",
|
2014-12-04 17:41:34 +01:00
|
|
|
caught.getLocalizedMessage(), "",
|
2014-09-26 16:38:15 +02:00
|
|
|
caught);
|
|
|
|
} else {
|
|
|
|
showErrorAndHide(
|
|
|
|
"Error",
|
2014-12-04 17:41:34 +01:00
|
|
|
"Error retrieving the file from the workspace: ",
|
|
|
|
caught.getLocalizedMessage(),
|
2014-09-26 16:38:15 +02:00
|
|
|
caught);
|
|
|
|
}
|
|
|
|
}
|
2014-06-03 16:33:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onSuccess(Void result) {
|
2014-06-04 15:11:21 +02:00
|
|
|
goNext();
|
2014-06-03 16:33:12 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:11:21 +02:00
|
|
|
protected void goNext() {
|
2014-07-01 18:56:33 +02:00
|
|
|
try {
|
|
|
|
TabResourcesSelectionCard tabResourceSelectionCard = new TabResourcesSelectionCard(
|
|
|
|
codelistMappingSession);
|
|
|
|
getWizardWindow().addCard(tabResourceSelectionCard);
|
|
|
|
Log.info("NextCard TabResourceSelectionCard");
|
|
|
|
getWizardWindow().nextCard();
|
|
|
|
} catch (Throwable e) {
|
|
|
|
Log.error("goNext: " + e.getLocalizedMessage());
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2014-06-03 16:33:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|