/** * */ package org.gcube.portlets.user.td.codelistmappingimportwidget.client; import org.gcube.portlets.user.td.codelistmappingimportwidget.client.workspace.WorkspacePanel; import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; 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; import org.gcube.portlets.widgets.lighttree.client.Item; import org.gcube.portlets.widgets.lighttree.client.ItemType; import org.gcube.portlets.widgets.lighttree.client.event.ItemSelectionEvent; import org.gcube.portlets.widgets.lighttree.client.event.ItemSelectionHandler; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.rpc.AsyncCallback; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; /** * * @author "Giancarlo Panichi" g.panichi@isti.cnr.it * */ public class CodelistMappingWorkSpaceSelectionCard extends WizardCard { protected CodelistMappingSession codelistMappingSession; protected CodelistMappingWorkSpaceSelectionCard thisCard; protected Item item; protected VerticalLayoutContainer p; protected WorkspacePanel wpanel; public CodelistMappingWorkSpaceSelectionCard( final CodelistMappingSession codelistMappingSession) { super("CSV Import From Workspace", ""); this.codelistMappingSession = codelistMappingSession; thisCard = this; p = new VerticalLayoutContainer(); Log.debug("Set Workspace Panel"); wpanel = new WorkspacePanel(); wpanel.setSpWidth("536px"); wpanel.setSpHeight("384px"); // wpanel.setShowableTypes(ItemType.EXTERNAL_FILE); wpanel.setSelectableTypes(ItemType.EXTERNAL_FILE); wpanel.getSelectableTypes().remove(ItemType.ROOT); wpanel.getSelectableTypes().remove(ItemType.FOLDER); wpanel.setAllowedMimeTypes("application/xml", "application/zip", "application/x-zip", "application/x-zip-compressed", "application/octet", "application/octet-stream"); wpanel.addSelectionHandler(new ItemSelectionHandler() { public void onSelection(ItemSelectionEvent event) { item = event.getSelectedItem(); 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()); codelistMappingSession.setItemId(item.getId()); getWizardWindow().setEnableNextButton(true); } else { Log.debug("Item name null or empty"); getWizardWindow().setEnableNextButton(false); } } else { Log.debug("Item type:" + item.getType()); getWizardWindow().setEnableNextButton(false); } } }); p.add(wpanel); wpanel.loadTree(); setContent(p); } @Override public void setup() { Log.debug("CodelistMappingWorkSpaceSelectionCard Call Setup "); Command sayNextCard = new Command() { public void execute() { Log.debug("CodelistMappingWorkSpaceSelectionCard Call sayNextCard wpanel:" + wpanel); wpanel.disable(); wpanel.startWaiting(); getWizardWindow().setEnableNextButton(false); getWizardWindow().setEnableBackButton(false); getFileFromWorkspace(); } }; getWizardWindow().setNextButtonCommand(sayNextCard); Command sayPreviousCard = new Command() { public void execute() { try { getWizardWindow().previousCard(); getWizardWindow().removeCard(thisCard); Log.debug("Remove CodelistMappingWorkSpaceSelectionCard"); } catch (Exception e) { Log.error("sayPreviousCard :" + e.getLocalizedMessage()); } } }; getWizardWindow().setPreviousButtonCommand(sayPreviousCard); getWizardWindow().setEnableNextButton(false); } protected void getFileFromWorkspace() { TDGWTServiceAsync tdGwtServiceAsync = TDGWTServiceAsync.INSTANCE; tdGwtServiceAsync.getFileFromWorkspace(codelistMappingSession, new AsyncCallback() { public void onFailure(Throwable caught) { wpanel.endWaiting(); if (caught instanceof TDGWTSessionExpiredException) { getEventBus() .fireEvent( new SessionExpiredEvent( SessionExpiredType.EXPIREDONSERVER)); } else { if (caught instanceof TDGWTIsLockedException) { Log.error(caught.getLocalizedMessage()); showErrorAndHide("Error Locked", caught.getLocalizedMessage(), "", caught); } else { if (caught instanceof TDGWTIsFinalException) { Log.error(caught.getLocalizedMessage()); showErrorAndHide("Error Final", caught.getLocalizedMessage(), "", caught); } else { showErrorAndHide( "Error", "Error retrieving the file from the workspace: ", caught.getLocalizedMessage(), caught); } } } } public void onSuccess(Void result) { wpanel.endWaiting(); goNext(); } }); } protected void goNext() { 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(); } } }