306 lines
9.3 KiB
Java
306 lines
9.3 KiB
Java
package org.gcube.portlets.user.td.extractcodelistwidget.client;
|
|
|
|
import org.gcube.portlets.user.td.columnwidget.client.properties.ColumnDataPropertiesCombo;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.extract.ExtractCodelistSession;
|
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
|
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.core.client.GWT;
|
|
import com.google.gwt.event.logical.shared.SelectionEvent;
|
|
import com.google.gwt.event.logical.shared.SelectionHandler;
|
|
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
|
import com.google.gwt.user.client.Command;
|
|
import com.google.gwt.user.client.ui.HasValue;
|
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
|
|
import com.sencha.gxt.core.client.util.Margins;
|
|
import com.sencha.gxt.core.client.util.ToggleGroup;
|
|
import com.sencha.gxt.data.shared.LabelProvider;
|
|
import com.sencha.gxt.data.shared.ListStore;
|
|
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.ComboBox;
|
|
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.info.Info;
|
|
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 ExtractCodelistSession extractCodelistSession;
|
|
private ExtractCodelistDetailsCard thisCard;
|
|
|
|
private VerticalLayoutContainer p;
|
|
private VerticalPanel tableDetailPanel;
|
|
|
|
private TextField name;
|
|
private Radio automaticallyAttachTrue;
|
|
private Radio automaticallyAttachFalse;
|
|
|
|
private TabResource detail;
|
|
private ComboBox<ColumnData> comboAttachToColumn;
|
|
private ColumnData attachColumn;
|
|
private FieldLabel attachToColumnField;
|
|
|
|
public ExtractCodelistDetailsCard(
|
|
final ExtractCodelistSession extractCodelistSession) {
|
|
super("Codelist Detail", "");
|
|
|
|
this.extractCodelistSession = extractCodelistSession;
|
|
thisCard = this;
|
|
attachColumn = null;
|
|
|
|
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 automaticallyAttachGroup = new ToggleGroup();
|
|
automaticallyAttachGroup.add(automaticallyAttachTrue);
|
|
automaticallyAttachGroup.add(automaticallyAttachFalse);
|
|
|
|
automaticallyAttachGroup
|
|
.addValueChangeHandler(new ValueChangeHandler<HasValue<Boolean>>() {
|
|
|
|
@Override
|
|
public void onValueChange(
|
|
ValueChangeEvent<HasValue<Boolean>> event) {
|
|
try {
|
|
if (automaticallyAttachTrue.getValue()) {
|
|
attachToColumnField.setVisible(true);
|
|
} else {
|
|
attachToColumnField.setVisible(false);
|
|
}
|
|
|
|
thisCard.forceLayout();
|
|
|
|
} catch (Exception e) {
|
|
Log.error("ToggleGroup: onValueChange "
|
|
+ e.getLocalizedMessage());
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
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");
|
|
p.add(fieldAttach, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
|
|
// //
|
|
|
|
// Column Data
|
|
ColumnDataPropertiesCombo propsColumnData = GWT
|
|
.create(ColumnDataPropertiesCombo.class);
|
|
ListStore<ColumnData> storeCombo = new ListStore<ColumnData>(
|
|
propsColumnData.id());
|
|
storeCombo.addAll(extractCodelistSession.getSourceColumns());
|
|
|
|
comboAttachToColumn = new ComboBox<ColumnData>(storeCombo,
|
|
propsColumnData.label());
|
|
|
|
Log.trace("Combo AttachToColumn created");
|
|
addHandlersForComboAttachToColumn(propsColumnData.label());
|
|
|
|
comboAttachToColumn.setEmptyText("Select a column...");
|
|
comboAttachToColumn.setWidth(191);
|
|
comboAttachToColumn.setTypeAhead(false);
|
|
comboAttachToColumn.setEditable(false);
|
|
comboAttachToColumn.setTriggerAction(TriggerAction.ALL);
|
|
|
|
attachToColumnField = new FieldLabel(comboAttachToColumn,
|
|
"Attach To Column");
|
|
|
|
p.add(attachToColumnField,
|
|
new VerticalLayoutData(1, -1, new Margins(0)));
|
|
|
|
// /
|
|
tableDetailPanel.add(form);
|
|
|
|
setContent(tableDetailPanel);
|
|
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param label
|
|
*/
|
|
private void addHandlersForComboAttachToColumn(
|
|
final LabelProvider<ColumnData> label) {
|
|
comboAttachToColumn
|
|
.addSelectionHandler(new SelectionHandler<ColumnData>() {
|
|
public void onSelection(SelectionEvent<ColumnData> event) {
|
|
Info.display(
|
|
"Column Selected",
|
|
"You selected "
|
|
+ (event.getSelectedItem() == null ? "nothing"
|
|
: label.getLabel(event
|
|
.getSelectedItem())
|
|
+ "!"));
|
|
Log.debug("ComboAttachToColumn selected: "
|
|
+ event.getSelectedItem());
|
|
ColumnData column = event.getSelectedItem();
|
|
updateAttachColumn(column);
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private void updateAttachColumn(ColumnData column) {
|
|
|
|
}
|
|
|
|
@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()) {
|
|
d = new AlertMessageBox("Attention!", "Fill name fields");
|
|
d.addHideHandler(hideHandler);
|
|
d.show();
|
|
} else {
|
|
if (getAutomaticallyAttach()) {
|
|
attachColumn = comboAttachToColumn.getCurrentValue();
|
|
if (attachColumn == null) {
|
|
d = new AlertMessageBox("Attention!",
|
|
"Select column to attach codelist!");
|
|
d.addHideHandler(hideHandler);
|
|
d.show();
|
|
} else {
|
|
name.setReadOnly(true);
|
|
goNext();
|
|
}
|
|
} else {
|
|
name.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());
|
|
extractCodelistSession.setAttachColumn(attachColumn);
|
|
ExtractCodelistOperationInProgressCard extractCodelistOperationInProgressCard = new ExtractCodelistOperationInProgressCard(
|
|
extractCodelistSession);
|
|
getWizardWindow().addCard(extractCodelistOperationInProgressCard);
|
|
Log.info("NextCard ExtractCodelistOperationInProgressCard");
|
|
getWizardWindow().nextCard();
|
|
} catch (Exception e) {
|
|
Log.error("sayNextCard :" + e.getLocalizedMessage());
|
|
name.setReadOnly(false);
|
|
}
|
|
}
|
|
|
|
}
|