tabular-data-extractcodelis.../src/main/java/org/gcube/portlets/user/td/extractcodelistwidget/client/ExtractCodelistDetailsCard....

207 lines
6.2 KiB
Java

package org.gcube.portlets.user.td.extractcodelistwidget.client;
import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession;
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.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.sencha.gxt.core.client.util.Margins;
import com.sencha.gxt.core.client.util.ToggleGroup;
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.Radio;
import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.tips.ToolTip;
import com.sencha.gxt.widget.core.client.tips.ToolTipConfig;
/**
*
* @author "Giancarlo Panichi" <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class ExtractCodelistDetailsCard extends WizardCard {
//private static DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd");
private static final String TABLEDETAILPANELWIDTH = "100%";
private static final String TABLEDETAILPANELHEIGHT = "100%";
private static final String FORMWIDTH = "538px";
private static final int LABEL_WIDTH = 128;
private static final int LABEL_PAD_WIDTH = 2;
private ExtractCodelistSession extractCodelistSession;
private ExtractCodelistDetailsCard thisCard;
private VerticalLayoutContainer p;
private VerticalPanel tableDetailPanel;
private TextField name;
private Radio automaticallyAttachTrue;
private Radio automaticallyAttachFalse;
private TabResource detail;
public ExtractCodelistDetailsCard(final ExtractCodelistSession extractCodelistSession) {
super("Codelist Detail", "");
this.extractCodelistSession = extractCodelistSession;
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.setAllowBlank(false);
p.add(new FieldLabel(name, "Name"), new VerticalLayoutData(1, -1,new Margins(0)));
///
automaticallyAttachTrue = new Radio();
automaticallyAttachTrue.setBoxLabel("True");
automaticallyAttachTrue.setValue(true);
automaticallyAttachFalse = new Radio();
automaticallyAttachFalse.setBoxLabel("False");
ToggleGroup automticallyAttachGroup = new ToggleGroup();
automticallyAttachGroup.add(automaticallyAttachTrue);
automticallyAttachGroup.add(automaticallyAttachFalse);
HorizontalPanel automaticallyAttachPanel = new HorizontalPanel();
automaticallyAttachPanel.add(automaticallyAttachTrue);
automaticallyAttachPanel.add(automaticallyAttachFalse);
new ToolTip(automaticallyAttachPanel, new ToolTipConfig(
"Automatically attach the generated codelist"));
FieldLabel fieldAttach=new FieldLabel(automaticallyAttachPanel, "Attach");
fieldAttach.setLabelWidth(LABEL_WIDTH);
fieldAttach.setLabelPad(LABEL_PAD_WIDTH);
p.add(fieldAttach, new VerticalLayoutData(1, -1, new Margins(0)));
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 ExtractCodelistDetailsCard");
} 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()
|| rights.getValue() == null || rights.getValue().isEmpty()
|| !rights.isValid()*/
) {
d = new AlertMessageBox("Attention!", "Fill name fields");
d.addHideHandler(hideHandler);
d.show();
} else {
name.setReadOnly(true);
/*description.setReadOnly(true);
rights.setReadOnly(true);*/
goNext();
}
}
protected boolean getAutomaticallyAttach() {
if(automaticallyAttachTrue.getValue()){
return true;
} else {
return false;
}
}
protected void goNext() {
try {
detail= new TabResource();
detail.setName(name.getCurrentValue());
extractCodelistSession.setTabResource(detail);
extractCodelistSession.setAutomaticallyAttach(getAutomaticallyAttach());
ExtractCodelistOperationInProgressCard extractCodelistOperationInProgressCard = new ExtractCodelistOperationInProgressCard(
extractCodelistSession);
getWizardWindow().addCard(extractCodelistOperationInProgressCard);
Log.info("NextCard ExtractCodelistOperationInProgressCard");
getWizardWindow().nextCard();
} catch (Exception e) {
Log.error("sayNextCard :" + e.getLocalizedMessage());
}
}
}