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;
|
2015-11-02 19:01:12 +01:00
|
|
|
import org.gcube.portlets.user.td.widgetcommonevent.client.CommonMessages;
|
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;
|
2015-11-02 19:01:12 +01:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2014-06-03 16:33:12 +02:00
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2018-06-27 14:28:07 +02:00
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
2014-06-03 16:33:12 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class CodelistMappingWorkSpaceSelectionCard extends WizardCard {
|
2015-11-02 19:01:12 +01:00
|
|
|
private static CodelistMappingMessages msgs = GWT
|
|
|
|
.create(CodelistMappingMessages.class);
|
|
|
|
private CommonMessages msgsCommon;
|
2015-08-03 18:56:14 +02:00
|
|
|
|
|
|
|
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) {
|
2015-11-02 19:01:12 +01:00
|
|
|
super(msgs.codelistMappingWorkSpaceSelectionCardHead(), "");
|
2014-06-04 15:11:21 +02:00
|
|
|
this.codelistMappingSession = codelistMappingSession;
|
2014-06-03 16:33:12 +02:00
|
|
|
thisCard = this;
|
2015-11-02 19:01:12 +01:00
|
|
|
initMessages();
|
|
|
|
create();
|
|
|
|
}
|
2014-06-03 16:33:12 +02:00
|
|
|
|
2015-11-02 19:01:12 +01:00
|
|
|
protected void initMessages() {
|
|
|
|
msgsCommon = GWT.create(CommonMessages.class);
|
|
|
|
}
|
2015-08-03 18:56:14 +02:00
|
|
|
|
2015-11-02 19:01:12 +01:00
|
|
|
protected void create() {
|
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>());
|
|
|
|
|
2015-11-02 19:01:12 +01:00
|
|
|
wpanel = new WorkspaceExplorerSelectPanel(
|
|
|
|
msgs.workspaceExplorerSelectPanelHead(), filterCriteria, selectableTypes);
|
2015-08-03 18:56:14 +02:00
|
|
|
|
|
|
|
WorskpaceExplorerSelectNotificationListener handler = new WorskpaceExplorerSelectNotificationListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSelectedItem(Item item) {
|
2014-06-03 16:33:12 +02:00
|
|
|
Log.debug("Selected Item:" + item);
|
2018-06-29 17:32:54 +02:00
|
|
|
if (item.getType() != ItemType.FOLDER&&item.getType() != ItemType.PRIVATE_FOLDER
|
|
|
|
&&item.getType() != ItemType.SHARED_FOLDER&&item.getType() != ItemType.VRE_FOLDER) {
|
2014-06-03 16:33:12 +02:00
|
|
|
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");
|
|
|
|
|
|
|
|
}
|
2015-08-04 12:00:57 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNotValidSelection() {
|
|
|
|
codelistMappingSession.setItemId(null);
|
|
|
|
getWizardWindow().setEnableNextButton(false);
|
|
|
|
|
|
|
|
}
|
2015-08-03 18:56:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
wpanel.addWorkspaceExplorerSelectNotificationListener(handler);
|
|
|
|
|
2015-08-04 12:00:57 +02:00
|
|
|
p.add(wpanel, new VerticalLayoutData(1, 1, new Margins(0, 0, 0, 44)));
|
2015-08-03 18:56:14 +02:00
|
|
|
|
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);
|
2015-10-30 19:04:39 +01:00
|
|
|
setEnableNextButton(false);
|
|
|
|
setNextButtonVisible(true);
|
|
|
|
setEnableBackButton(true);
|
|
|
|
setBackButtonVisible(true);
|
2014-06-03 16:33:12 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2015-11-02 19:01:12 +01:00
|
|
|
showErrorAndHide(msgsCommon.errorLocked(),
|
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());
|
2015-11-02 19:01:12 +01:00
|
|
|
showErrorAndHide(msgsCommon.errorFinal(),
|
2014-12-04 17:41:34 +01:00
|
|
|
caught.getLocalizedMessage(), "",
|
2014-09-26 16:38:15 +02:00
|
|
|
caught);
|
|
|
|
} else {
|
|
|
|
showErrorAndHide(
|
2015-11-02 19:01:12 +01:00
|
|
|
msgsCommon.error(),
|
|
|
|
msgs.errorRetrievingTheFileFromWorkspaceFixed(),
|
2014-12-04 17:41:34 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|