2016-04-06 18:28:32 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-04-08 20:34:05 +02:00
|
|
|
package org.gcube.portlets.user.dataminermanager.client.parametersfield;
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2016-04-11 20:27:14 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.client.events.TabularFldChangeEvent;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.client.events.TabularFldChangeEvent.TabularFldChangeEventHandler;
|
2016-04-06 18:28:32 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.client.properties.ColumnItemPropertiesCombo;
|
2018-05-03 16:24:26 +02:00
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.data.ColumnItem;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.data.TableItemSimple;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.ColumnParameter;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.parameters.Parameter;
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2016-06-10 15:06:52 +02:00
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
2016-04-06 18:28:32 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
|
2016-04-11 20:27:14 +02:00
|
|
|
import com.sencha.gxt.core.client.util.Format;
|
|
|
|
import com.sencha.gxt.core.client.util.Margins;
|
2016-04-06 18:28:32 +02:00
|
|
|
import com.sencha.gxt.data.shared.ListStore;
|
2016-04-11 20:27:14 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.HtmlLayoutContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
|
2016-04-06 18:28:32 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
2016-04-11 20:27:14 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
2016-04-06 18:28:32 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.form.ComboBox;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2017-05-12 11:58:15 +02:00
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
2016-04-06 18:28:32 +02:00
|
|
|
*
|
|
|
|
*/
|
2016-04-11 20:27:14 +02:00
|
|
|
public class ColumnFld extends AbstractFld implements
|
|
|
|
TabularFldChangeEventHandler {
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
private String defaultColumn;
|
|
|
|
private ComboBox<ColumnItem> comboBox;
|
|
|
|
private ListStore<ColumnItem> store;
|
|
|
|
private String referredTabularParameterName;
|
|
|
|
|
2016-04-11 20:27:14 +02:00
|
|
|
private SimpleContainer fieldContainer;
|
|
|
|
private SimpleContainer vContainer;
|
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
/**
|
2017-05-12 11:58:15 +02:00
|
|
|
* @param parameter parameter
|
2016-04-06 18:28:32 +02:00
|
|
|
*/
|
|
|
|
public ColumnFld(Parameter parameter) {
|
|
|
|
super(parameter);
|
|
|
|
|
2016-04-12 18:01:14 +02:00
|
|
|
ColumnParameter columnParameter = (ColumnParameter) parameter;
|
|
|
|
|
|
|
|
referredTabularParameterName = columnParameter
|
|
|
|
.getReferredTabularParameterName();
|
|
|
|
defaultColumn = columnParameter.getDefaultColumn();
|
2016-04-11 20:27:14 +02:00
|
|
|
|
|
|
|
fieldContainer = new SimpleContainer();
|
|
|
|
HBoxLayoutContainer horiz = new HBoxLayoutContainer();
|
|
|
|
horiz.setPack(BoxLayoutPack.START);
|
|
|
|
horiz.setEnableOverflow(false);
|
2016-04-12 18:01:14 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
ColumnItemPropertiesCombo props = GWT
|
|
|
|
.create(ColumnItemPropertiesCombo.class);
|
|
|
|
|
|
|
|
store = new ListStore<ColumnItem>(props.id());
|
|
|
|
|
|
|
|
comboBox = new ComboBox<ColumnItem>(store, props.label());
|
|
|
|
comboBox.setAllowBlank(false);
|
|
|
|
comboBox.setForceSelection(true);
|
|
|
|
comboBox.setEditable(false);
|
|
|
|
comboBox.setTriggerAction(TriggerAction.ALL);
|
|
|
|
comboBox.setEnabled(false);
|
2016-04-11 20:27:14 +02:00
|
|
|
HtmlLayoutContainer descr;
|
|
|
|
|
2016-04-12 18:01:14 +02:00
|
|
|
if (columnParameter.getDescription() == null) {
|
2016-06-27 10:07:43 +02:00
|
|
|
descr = new HtmlLayoutContainer("<p style='margin-left:5px !important;'></p>");
|
2016-04-11 20:27:14 +02:00
|
|
|
descr.addStyleName("workflow-fieldDescription");
|
|
|
|
|
|
|
|
} else {
|
2016-05-02 19:58:14 +02:00
|
|
|
//comboBox.setToolTip(columnParameter.getDescription());
|
2016-06-27 10:07:43 +02:00
|
|
|
descr = new HtmlLayoutContainer("<p style='margin-left:5px !important;'>"
|
2016-04-12 18:01:14 +02:00
|
|
|
+ columnParameter.getDescription() + "</p>");
|
2016-04-11 20:27:14 +02:00
|
|
|
descr.addStyleName("workflow-fieldDescription");
|
|
|
|
}
|
|
|
|
|
2016-04-12 18:01:14 +02:00
|
|
|
vContainer = new SimpleContainer();
|
2016-04-06 18:28:32 +02:00
|
|
|
showNoSelectionField();
|
2016-04-11 20:27:14 +02:00
|
|
|
horiz.add(vContainer, new BoxLayoutData(new Margins()));
|
|
|
|
horiz.add(descr, new BoxLayoutData(new Margins()));
|
|
|
|
|
|
|
|
fieldContainer.add(horiz);
|
|
|
|
fieldContainer.forceLayout();
|
2016-04-12 18:01:14 +02:00
|
|
|
|
2016-04-11 20:27:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void showNoSelectionField() {
|
|
|
|
vContainer.clear();
|
|
|
|
VerticalLayoutContainer vField = new VerticalLayoutContainer();
|
2016-04-12 18:01:14 +02:00
|
|
|
HtmlLayoutContainer typeDescription = new HtmlLayoutContainer(
|
2016-04-11 20:27:14 +02:00
|
|
|
"<div class='workflow-parameters-description'><p>Select table from parameter "
|
2016-04-12 18:01:14 +02:00
|
|
|
+ Format.ellipse(referredTabularParameterName, 30)
|
|
|
|
+ "</p></div>");
|
2016-04-11 20:27:14 +02:00
|
|
|
typeDescription.setStylePrimaryName("workflow-parameters-description");
|
2016-04-12 18:01:14 +02:00
|
|
|
vField.add(comboBox, new VerticalLayoutData(1, -1, new Margins(0)));
|
|
|
|
vField.add(typeDescription, new VerticalLayoutData(-1, -1, new Margins(
|
|
|
|
0)));
|
2016-04-11 20:27:14 +02:00
|
|
|
vContainer.add(vField);
|
|
|
|
}
|
2016-04-12 18:01:14 +02:00
|
|
|
|
2016-04-11 20:27:14 +02:00
|
|
|
private void showFieldWithSelection(TableItemSimple tableItem) {
|
|
|
|
vContainer.clear();
|
|
|
|
VerticalLayoutContainer vField = new VerticalLayoutContainer();
|
2016-04-12 18:01:14 +02:00
|
|
|
HtmlLayoutContainer typeDescription = new HtmlLayoutContainer(
|
2016-04-11 20:27:14 +02:00
|
|
|
"<div class='workflow-parameters-description'><p>Columns of Table "
|
2016-04-12 18:01:14 +02:00
|
|
|
+ Format.ellipse(tableItem.getName(), 30)
|
|
|
|
+ "</p></div>");
|
2016-04-11 20:27:14 +02:00
|
|
|
typeDescription.setStylePrimaryName("workflow-parameters-description");
|
2016-04-12 18:01:14 +02:00
|
|
|
vField.add(comboBox, new VerticalLayoutData(1, -1, new Margins(0)));
|
|
|
|
vField.add(typeDescription, new VerticalLayoutData(-1, -1, new Margins(
|
|
|
|
0)));
|
2016-04-11 20:27:14 +02:00
|
|
|
vContainer.add(vField);
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String getValue() {
|
|
|
|
ColumnItem columnItem = comboBox.getCurrentValue();
|
|
|
|
return columnItem != null ? columnItem.getName() : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public Widget getWidget() {
|
2016-04-11 20:27:14 +02:00
|
|
|
return fieldContainer;
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 18:01:14 +02:00
|
|
|
@Override
|
|
|
|
public boolean isValid() {
|
|
|
|
return comboBox.isValid();
|
|
|
|
}
|
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
@Override
|
2016-04-11 20:27:14 +02:00
|
|
|
public void onChange(TabularFldChangeEvent event) {
|
|
|
|
TableItemSimple tableItemSimple = event.getTableItemSimple();
|
|
|
|
if (tableItemSimple == null) {
|
2016-04-06 18:28:32 +02:00
|
|
|
store.clear();
|
|
|
|
store.commitChanges();
|
|
|
|
comboBox.clear();
|
|
|
|
comboBox.setEnabled(false);
|
|
|
|
showNoSelectionField();
|
|
|
|
} else {
|
|
|
|
store.clear();
|
|
|
|
store.commitChanges();
|
2016-06-10 15:06:52 +02:00
|
|
|
comboBox.clear();
|
2016-04-11 20:27:14 +02:00
|
|
|
ArrayList<ColumnItem> columns = tableItemSimple.getColumns();
|
2016-04-06 18:28:32 +02:00
|
|
|
if (columns != null) {
|
|
|
|
store.addAll(columns);
|
2016-06-10 15:06:52 +02:00
|
|
|
store.commitChanges();
|
|
|
|
Log.debug("DefaultColumn: "+defaultColumn);
|
2016-04-06 18:28:32 +02:00
|
|
|
for (ColumnItem columnItem : columns) {
|
2016-06-10 15:06:52 +02:00
|
|
|
Log.debug("ColumnItem: "+ columnItem);
|
|
|
|
if (columnItem.getName().compareToIgnoreCase(defaultColumn) == 0) {
|
2016-04-06 18:28:32 +02:00
|
|
|
comboBox.setValue(columnItem);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-06-10 15:06:52 +02:00
|
|
|
|
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
comboBox.setEnabled(true);
|
2016-04-11 20:27:14 +02:00
|
|
|
showFieldWithSelection(tableItemSimple);
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
2016-04-11 20:27:14 +02:00
|
|
|
fieldContainer.forceLayout();
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|