/** * */ package org.gcube.portlets.user.td.codelistmappingimportwidget.client; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVImportSession; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.wizardwidget.client.WizardCard; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.ui.VerticalPanel; import com.sencha.gxt.widget.core.client.FramedPanel; import com.sencha.gxt.widget.core.client.box.AlertMessageBox; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData; import com.sencha.gxt.widget.core.client.event.HideEvent; import com.sencha.gxt.widget.core.client.event.HideEvent.HideHandler; import com.sencha.gxt.widget.core.client.form.FieldLabel; import com.sencha.gxt.widget.core.client.form.FieldSet; import com.sencha.gxt.widget.core.client.form.TextArea; import com.sencha.gxt.widget.core.client.form.TextField; /** * * @author "Giancarlo Panichi" g.panichi@isti.cnr.it * */ public class CodelistMappingTableDetailCard extends WizardCard { protected final String TABLEDETAILPANELWIDTH = "100%"; protected final String TABLEDETAILPANELHEIGHT = "100%"; protected final String FORMWIDTH = "538px"; protected CSVImportSession importSession; protected CodelistMappingTableDetailCard thisCard; protected VerticalLayoutContainer p; protected VerticalPanel tableDetailPanel; protected TextField name; protected TextArea description; protected TextArea rights; protected TabResource detail = new TabResource(); public CodelistMappingTableDetailCard(final CSVImportSession importSession) { super("Codelist Mapping Detail", ""); this.importSession = importSession; thisCard = this; tableDetailPanel = new VerticalPanel(); tableDetailPanel.setSpacing(4); tableDetailPanel.setWidth(TABLEDETAILPANELWIDTH); tableDetailPanel.setHeight(TABLEDETAILPANELHEIGHT); FramedPanel form = new FramedPanel(); form.setHeadingText("Details"); form.setWidth(FORMWIDTH); FieldSet fieldSet = new FieldSet(); fieldSet.setHeadingText("Information"); fieldSet.setCollapsible(false); form.add(fieldSet); p = new VerticalLayoutContainer(); fieldSet.add(p); name = new TextField(); name.setAllowBlank(false); name.setEmptyText("Enter a name..."); name.setValue(importSession.getLocalFileName()); name.setAllowBlank(false); p.add(new FieldLabel(name, "Name"), new VerticalLayoutData(1, -1)); description = new TextArea(); description.setAllowBlank(false); description.setEmptyText("Enter a description..."); description.setValue("File CSV"); description.setAllowBlank(false); p.add(new FieldLabel(description, "Description"), new VerticalLayoutData(1, -1)); tableDetailPanel.add(form); setContent(tableDetailPanel); } @Override public void setup() { Command sayNextCard = new Command() { public void execute() { checkData(); } }; getWizardWindow().setNextButtonCommand(sayNextCard); Command sayPreviousCard = new Command() { public void execute() { try { getWizardWindow().previousCard(); getWizardWindow().removeCard(thisCard); Log.info("Remove CodelistMappingTableDetailCard"); } catch (Exception e) { Log.error("sayPreviousCard :" + e.getLocalizedMessage()); } } }; getWizardWindow().setPreviousButtonCommand(sayPreviousCard); getWizardWindow().setEnableNextButton(true); } protected void checkData() { getWizardWindow().setEnableNextButton(false); getWizardWindow().setEnableBackButton(false); AlertMessageBox d; HideHandler hideHandler = new HideHandler() { public void onHide(HideEvent event) { getWizardWindow().setEnableNextButton(true); getWizardWindow().setEnableBackButton(false); } }; if (name.getValue() == null || name.getValue().isEmpty() || !name.isValid() || description.getValue() == null || description.getValue().isEmpty() || !description.isValid() ) { d = new AlertMessageBox("Attention!", "Fill in all fields"); d.addHideHandler(hideHandler); d.show(); } else { name.setReadOnly(true); description.setReadOnly(true); rights.setReadOnly(true); goNext(); } } protected void goNext() { try { detail.setName(name.getCurrentValue()); detail.setDescription(description.getCurrentValue()); detail.setRight(rights.getCurrentValue()); importSession.setTabResource(detail); CodelistMappingOperationInProgressCard csvOperationInProgressCard = new CodelistMappingOperationInProgressCard( importSession); getWizardWindow().addCard(csvOperationInProgressCard); Log.info("NextCard CodelistMappingOperationInProgressCard"); getWizardWindow().nextCard(); } catch (Exception e) { Log.error("sayNextCard :" + e.getLocalizedMessage()); } } }