tabular-data-codelistmappin.../src/main/java/org/gcube/portlets/user/td/codelistmappingimportwidget/client/CodelistMappingTableDetailC...

154 lines
4.4 KiB
Java

/**
*
*/
package org.gcube.portlets.user.td.codelistmappingimportwidget.client;
import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor;
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.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.TextArea;
import com.sencha.gxt.widget.core.client.form.TextField;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class CodelistMappingTableDetailCard extends WizardCard {
protected CodelistMappingSession codelistMappingSession;
protected CodelistMappingTableDetailCard thisCard;
protected VerticalLayoutContainer p;
protected TextField name;
protected TextArea description;
protected ResourceTDDescriptor resourceDetails = new ResourceTDDescriptor();
public CodelistMappingTableDetailCard(
final CodelistMappingSession codelistMappingSession) {
super("Codelist Mapping Detail", "");
this.codelistMappingSession = codelistMappingSession;
thisCard = this;
FramedPanel form = new FramedPanel();
form.setHeaderVisible(false);
p = new VerticalLayoutContainer();
form.add(p);
name = new TextField();
name.setAllowBlank(false);
name.setEmptyText("Enter a name...");
if (codelistMappingSession.getLocalFileName() != null
&& !codelistMappingSession.getLocalFileName().isEmpty()) {
name.setValue(codelistMappingSession.getLocalFileName());
} else {
}
p.add(new FieldLabel(name, "Name"), new VerticalLayoutData(1, -1));
description = new TextArea();
description.setAllowBlank(false);
description.setEmptyText("Enter a description...");
description.setValue("XML map");
p.add(new FieldLabel(description, "Description"),
new VerticalLayoutData(1, -1));
setContent(form);
}
@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() {
Log.debug("checkData()");
getWizardWindow().setEnableNextButton(false);
getWizardWindow().setEnableBackButton(false);
AlertMessageBox d;
HideHandler hideHandler = new HideHandler() {
public void onHide(HideEvent event) {
getWizardWindow().setEnableNextButton(true);
getWizardWindow().setEnableBackButton(true);
}
};
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);
goNext();
}
}
protected void goNext() {
Log.debug("goNext()");
try {
resourceDetails.setName(name.getCurrentValue());
resourceDetails.setDescription(description.getCurrentValue());
codelistMappingSession.setResourceTDDescriptor(resourceDetails);
CodelistMappingOperationInProgressCard codelistMappingOperationInProgressCard = new CodelistMappingOperationInProgressCard(
codelistMappingSession);
getWizardWindow().addCard(codelistMappingOperationInProgressCard);
Log.info("NextCard CodelistMappingOperationInProgressCard");
getWizardWindow().nextCard();
} catch (Throwable e) {
Log.error("sayNextCard :" + e.getLocalizedMessage());
}
}
}