From 876bbf6f8c5dc0965ea68c27591ee79dc2c32174 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 6 May 2015 16:48:49 +0000 Subject: [PATCH] AddedConditionOnMultiColumn git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@114699 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../ConditionOnMultiColumnWidget.java | 946 ++++++++++++++++++ .../multicolumn/DepthOfExpressionType.java | 48 + 2 files changed, 994 insertions(+) create mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/client/expression/ConditionOnMultiColumnWidget.java create mode 100644 src/main/java/org/gcube/portlets/user/td/expressionwidget/client/multicolumn/DepthOfExpressionType.java diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/expression/ConditionOnMultiColumnWidget.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/expression/ConditionOnMultiColumnWidget.java new file mode 100644 index 0000000..77dba91 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/expression/ConditionOnMultiColumnWidget.java @@ -0,0 +1,946 @@ +package org.gcube.portlets.user.td.expressionwidget.client.expression; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import org.gcube.portlets.user.td.expressionwidget.client.custom.IconButton; +import org.gcube.portlets.user.td.expressionwidget.client.operation.Operation; +import org.gcube.portlets.user.td.expressionwidget.client.operation.OperationProperties; +import org.gcube.portlets.user.td.expressionwidget.client.properties.ColumnDataPropertiesCombo; +import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; +import org.gcube.portlets.user.td.expressionwidget.client.threshold.Threshold; +import org.gcube.portlets.user.td.expressionwidget.client.threshold.ThresholdProperties; +import org.gcube.portlets.user.td.expressionwidget.client.threshold.ThresholdStore; +import org.gcube.portlets.user.td.expressionwidget.shared.condition.ConditionTypeMap; +import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException; +import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; +import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData; +import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.logical.shared.SelectionEvent; +import com.google.gwt.event.logical.shared.SelectionHandler; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.Widget; +import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction; +import com.sencha.gxt.core.client.util.Margins; +import com.sencha.gxt.data.shared.ListStore; +import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData; +import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer; +import com.sencha.gxt.widget.core.client.container.SimpleContainer; +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.BeforeShowEvent; +import com.sencha.gxt.widget.core.client.form.ComboBox; +import com.sencha.gxt.widget.core.client.form.DateField; +import com.sencha.gxt.widget.core.client.form.TextField; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class ConditionOnMultiColumnWidget extends SimpleContainer { + + private static final String SIGN = "ConditionOnMultiColumns"; + private static final String HEIGHT = "210px"; + private static final String WIDTH = "612px"; + + private String itemIdComboIndent; + private String itemIdFirstElementColumn; + + private String itemIdComboOperation; + + private String itemIdFirstArgType; + private String itemIdFirstArgColumn; + private String itemIdFirstArgValue; + private String itemIdFirstArgDate; + + private String itemIdSecondArgType; + private String itemIdSecondArgColumn; + private String itemIdSecondArgValue; + private String itemIdSecondArgDate; + + private String itemIdComboThreshold; + + private String itemIdBtnAdd; + private String itemIdBtnDel; + private VerticalLayoutContainer vert; + private ArrayList columns; + + private String readableExpression; + private ConditionOnMultiColumnWidget thisCont; + + public ConditionOnMultiColumnWidget(ArrayList columns) { + super(); + init(WIDTH, HEIGHT); + create(columns); + } + + public ConditionOnMultiColumnWidget(ArrayList columns, + String width, String height) { + super(); + init(width, height); + create(columns); + } + + public void update(ArrayList newColumns) { + vert.clear(); + this.columns = newColumns; + setup(); + } + + protected void init(String width, String height) { + setWidth(width); + setHeight(height); + setBorders(true); + forceLayoutOnResize = true; + thisCont = this; + + } + + protected void create(ArrayList columns) { + this.columns = columns; + + itemIdComboIndent = "ComboIndent" + SIGN; + itemIdFirstElementColumn = "FirstElementColumn" + SIGN; + itemIdComboOperation = "ComboOperation" + SIGN; + + itemIdFirstArgType = "FirstArgType" + SIGN; + itemIdFirstArgColumn = "FirstArgColumn" + SIGN; + itemIdFirstArgValue = "FirstArgValue" + SIGN; + itemIdFirstArgDate = "FirstArgDate" + SIGN; + + itemIdSecondArgType = "SecondArgType" + SIGN; + + itemIdSecondArgColumn = "SecondArgColumn" + SIGN; + itemIdSecondArgValue = "SecondArgValue" + SIGN; + itemIdSecondArgDate = "SecondArgDate" + SIGN; + + itemIdComboThreshold = "ComboThreshold" + SIGN; + itemIdBtnAdd = "BtnAdd" + SIGN; + itemIdBtnDel = "BtnDel" + SIGN; + + vert = new VerticalLayoutContainer(); + // vert.setScrollMode(ScrollMode.AUTO); Set In GXT 3.0.1 + vert.setAdjustForScroll(true); + + setup(); + + add(vert); + + } + + protected void setup() { + final HBoxLayoutContainer horiz = new HBoxLayoutContainer(); + + // Combo Indent + ColumnDataPropertiesCombo propsIndent = GWT + .create(ColumnDataPropertiesCombo.class); + Log.debug("Props: " + propsIndent); + final ListStore storeIndent = new ListStore( + propsIndent.id()); + Log.debug("StoreIndent: " + storeIndent); + + Log.debug("StoreIndent created"); + final ComboBox comboIndent = new ComboBox( + storeIndent, propsIndent.label()); + + Log.debug("Combo Indent created"); + + comboIndent.setEmptyText("Select a type..."); + comboIndent.setItemId(itemIdComboIndent); + comboIndent.setWidth("100px"); + comboIndent.setEditable(false); + comboIndent.setTriggerAction(TriggerAction.ALL); + comboIndent.setVisible(false); + + // Combo FirstElementColumn + ColumnDataPropertiesCombo propsFirstElementColumn = GWT + .create(ColumnDataPropertiesCombo.class); + Log.debug("Props: " + propsFirstElementColumn); + final ListStore storeFirstElementColumn = new ListStore( + propsFirstElementColumn.id()); + Log.debug("StoreFirstElementColumn: " + storeFirstElementColumn); + + Log.debug("StoreFirstElementColumn created"); + final ComboBox comboFirstElementColumn = new ComboBox( + storeFirstElementColumn, propsFirstElementColumn.label()); + + Log.debug("Combo FirstElementColumn created"); + + comboFirstElementColumn.setEmptyText("Select a column..."); + comboFirstElementColumn.setItemId(itemIdFirstElementColumn); + comboFirstElementColumn.setWidth("100px"); + comboFirstElementColumn.setEditable(false); + comboFirstElementColumn.setTriggerAction(TriggerAction.ALL); + comboFirstElementColumn.setVisible(false); + + // Combo FirstArgColumn + ColumnDataPropertiesCombo propsFirstArgColumn = GWT + .create(ColumnDataPropertiesCombo.class); + Log.debug("Props: " + propsFirstArgColumn); + final ListStore storeFirstArgColumn = new ListStore( + propsFirstArgColumn.id()); + Log.debug("StoreFirstArgColumn: " + storeFirstArgColumn); + + Log.debug("StoreFirstArgColumn created"); + final ComboBox comboFirstArgColumn = new ComboBox( + storeFirstArgColumn, propsFirstArgColumn.label()); + + Log.debug("Combo FirstArgColumn created"); + + comboFirstArgColumn.setEmptyText("Select a column..."); + comboFirstArgColumn.setItemId(itemIdFirstArgColumn); + comboFirstArgColumn.setWidth("100px"); + comboFirstArgColumn.setEditable(false); + comboFirstArgColumn.setTriggerAction(TriggerAction.ALL); + comboFirstArgColumn.setVisible(false); + + final TextField firstArgValue = new TextField(); + firstArgValue.setItemId(itemIdFirstArgValue); + firstArgValue.setVisible(false); + + final DateField firstArgDate = new DateField(); + firstArgDate.setItemId(itemIdFirstArgDate); + firstArgDate.setVisible(false); + + // And + final HTML andText = new HTML( + "
and
"); + andText.setVisible(false); + + // Combo SecondArgColumn + ColumnDataPropertiesCombo propsSecondArgColumn = GWT + .create(ColumnDataPropertiesCombo.class); + Log.debug("Props: " + propsSecondArgColumn); + final ListStore storeSecondArgColumn = new ListStore( + propsSecondArgColumn.id()); + Log.debug("StoreSecondArgColumn: " + storeSecondArgColumn); + + Log.debug("StoreSecondArgColumn created"); + final ComboBox comboSecondArgColumn = new ComboBox( + storeSecondArgColumn, propsSecondArgColumn.label()); + + Log.debug("Combo SecondArgColumn created"); + + comboSecondArgColumn.setEmptyText("Select a column..."); + comboSecondArgColumn.setItemId(itemIdSecondArgColumn); + comboSecondArgColumn.setWidth("100px"); + comboSecondArgColumn.setEditable(false); + comboSecondArgColumn.setTriggerAction(TriggerAction.ALL); + comboSecondArgColumn.setVisible(false); + + final TextField secondArgValue = new TextField(); + secondArgValue.setItemId(itemIdSecondArgValue); + secondArgValue.setVisible(false); + + final DateField secondArgDate = new DateField(); + secondArgDate.setItemId(itemIdSecondArgDate); + secondArgDate.setVisible(false); + + // Combo Similarity and Levenshtein threshold + ThresholdProperties propsThreshold = GWT + .create(ThresholdProperties.class); + Log.debug("Props: " + propsThreshold); + final ListStore storeThreshold = new ListStore( + propsThreshold.id()); + Log.debug("StoreThreshold: " + storeThreshold); + storeThreshold.addAll(ThresholdStore.thresholdsLevenshtein); + + Log.debug("StoreThreshold created"); + final ComboBox comboThreshold = new ComboBox( + storeThreshold, propsThreshold.label()); + + Log.debug("Combo Threshold created"); + + comboThreshold.setEmptyText("Select a threshold..."); + comboThreshold.setItemId(itemIdComboThreshold); + comboThreshold.setWidth("100px"); + comboThreshold.setEditable(false); + comboThreshold.setTriggerAction(TriggerAction.ALL); + comboThreshold.setVisible(false); + + final HTML thresholdText = new HTML( + "
Threshold:
"); + thresholdText.setVisible(false); + + // Operation + OperationProperties props = GWT.create(OperationProperties.class); + Log.debug("Props: " + props); + ListStore storeOp = new ListStore(props.id()); + Log.debug("Store: " + storeOp); + + Log.debug("Store created"); + ComboBox comboOp = new ComboBox(storeOp, + props.label()); + + Log.debug("Combo created"); + + comboOp.addSelectionHandler(new SelectionHandler() { + + public void onSelection(SelectionEvent event) { + if (event.getSelectedItem() != null) { + ColumnData column = comboFirstElementColumn + .getCurrentValue(); + Operation op = event.getSelectedItem(); + Log.debug("Condition selected:" + op.toString()); + switch (op.getOperatorType()) { + case EQUALS: + case GREATER: + case GREATER_OR_EQUALS: + case LESSER: + case LESSER_OR_EQUALS: + case NOT_EQUALS: + case NOT_GREATER: + case NOT_LESSER: + case BEGINS_WITH: + case ENDS_WITH: + case MATCH_REGEX: + case CONTAINS: + case NOT_BEGINS_WITH: + case NOT_ENDS_WITH: + case NOT_CONTAINS: + case NOT_MATCH_REGEX: + case IN: + case NOT_IN: + case SOUNDEX: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(true); + andText.setVisible(false); + secondArgDate.setVisible(false); + comboThreshold.setVisible(false); + thresholdText.setVisible(false); + } else { + firstArgValue.setVisible(true); + andText.setVisible(false); + secondArgValue.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } + break; + case BETWEEN: + case NOT_BETWEEN: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArgValue.setVisible(true); + andText.setVisible(true); + secondArgValue.setVisible(true); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } + break; + case LEVENSHTEIN: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArgValue.setVisible(true); + andText.setVisible(false); + secondArgValue.setVisible(false); + thresholdText.setVisible(true); + storeThreshold.clear(); + storeThreshold + .addAll(ThresholdStore.thresholdsLevenshtein); + storeThreshold.commitChanges(); + comboThreshold.clear(); + comboThreshold.reset(); + comboThreshold.setVisible(true); + comboThreshold.setValue(ThresholdStore + .defaultThresholdLevenshtein()); + + } + break; + case SIMILARITY: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArgValue.setVisible(true); + andText.setVisible(false); + secondArgValue.setVisible(false); + thresholdText.setVisible(true); + storeThreshold.clear(); + storeThreshold + .addAll(ThresholdStore.thresholdsSimilarity); + storeThreshold.commitChanges(); + comboThreshold.clear(); + comboThreshold.reset(); + comboThreshold.setVisible(true); + comboThreshold.setValue(ThresholdStore + .defaultThresholdSimilarity()); + + } + break; + case IS_NULL: + case IS_NOT_NULL: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArgValue.setVisible(false); + andText.setVisible(false); + secondArgValue.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } + break; + default: + break; + } + + thisCont.forceLayout(); + + } + } + + }); + + comboOp.setEmptyText("Select a condition..."); + comboOp.setItemId(itemIdComboOperation); + comboOp.setWidth("230px"); + comboOp.setEditable(false); + comboOp.setTriggerAction(TriggerAction.ALL); + + // Button + final IconButton btnAdd = new IconButton(); + btnAdd.setItemId(itemIdBtnAdd); + btnAdd.setIcon(ExpressionResources.INSTANCE.add()); + btnAdd.addClickHandler(new ClickHandler() { + + public void onClick(ClickEvent event) { + Log.debug("Clicked btnAdd"); + addCondition(); + thisCont.forceLayout(); + vert.forceLayout(); + + } + }); + btnAdd.setVisible(false); + + final IconButton btnDel = new IconButton(); + btnDel.setItemId(itemIdBtnDel); + btnDel.setIcon(ExpressionResources.INSTANCE.delete()); + btnDel.addClickHandler(new ClickHandler() { + + public void onClick(ClickEvent event) { + Log.debug("Clicked btnDel"); + vert.remove(horiz); + if (vert.getWidgetCount() == 0) { + setup(); + } else { + if (vert.getWidgetCount() == 1) { + } + } + thisCont.forceLayout(); + vert.forceLayout(); + + } + }); + btnDel.setVisible(false); + + horiz.add(comboOp, new BoxLayoutData(new Margins(0))); + horiz.add(firstArgDate, new BoxLayoutData(new Margins(0))); + horiz.add(andText, new BoxLayoutData(new Margins(0))); + horiz.add(secondArgDate, new BoxLayoutData(new Margins(0))); + horiz.add(thresholdText, new BoxLayoutData(new Margins(0))); + horiz.add(comboThreshold, new BoxLayoutData(new Margins(0))); + + horiz.add(btnAdd, new BoxLayoutData(new Margins(2, 0, 2, 0))); + horiz.add(btnDel, new BoxLayoutData(new Margins(2, 0, 2, 0))); + + vert.add(horiz, new VerticalLayoutData(-1, -1, new Margins(1))); + + addBeforeShowHandler(new BeforeShowEvent.BeforeShowHandler() { + + @Override + public void onBeforeShow(BeforeShowEvent event) { + forceLayout(); + + } + }); + + } + + protected void addCondition() { + + final HBoxLayoutContainer horiz = new HBoxLayoutContainer(); + + // Combo Indent + ColumnDataPropertiesCombo propsIndent = GWT + .create(ColumnDataPropertiesCombo.class); + Log.debug("Props: " + propsIndent); + final ListStore storeIndent = new ListStore( + propsIndent.id()); + Log.debug("StoreIndent: " + storeIndent); + + Log.debug("StoreIndent created"); + final ComboBox comboIndent = new ComboBox( + storeIndent, propsIndent.label()); + + Log.debug("Combo Indent created"); + + comboIndent.setEmptyText("Select a type..."); + comboIndent.setItemId(itemIdComboIndent); + comboIndent.setWidth("100px"); + comboIndent.setEditable(false); + comboIndent.setTriggerAction(TriggerAction.ALL); + comboIndent.setVisible(false); + + // Combo FirstElementColumn + ColumnDataPropertiesCombo propsFirstElementColumn = GWT + .create(ColumnDataPropertiesCombo.class); + Log.debug("Props: " + propsFirstElementColumn); + final ListStore storeFirstElementColumn = new ListStore( + propsFirstElementColumn.id()); + Log.debug("StoreFirstElementColumn: " + storeFirstElementColumn); + + Log.debug("StoreFirstElementColumn created"); + final ComboBox comboFirstElementColumn = new ComboBox( + storeFirstElementColumn, propsFirstElementColumn.label()); + + Log.debug("Combo FirstElementColumn created"); + + comboFirstElementColumn.setEmptyText("Select a column..."); + comboFirstElementColumn.setItemId(itemIdFirstElementColumn); + comboFirstElementColumn.setWidth("100px"); + comboFirstElementColumn.setEditable(false); + comboFirstElementColumn.setTriggerAction(TriggerAction.ALL); + comboFirstElementColumn.setVisible(false); + + // Combo FirstArgColumn + ColumnDataPropertiesCombo propsFirstArgColumn = GWT + .create(ColumnDataPropertiesCombo.class); + Log.debug("Props: " + propsFirstArgColumn); + final ListStore storeFirstArgColumn = new ListStore( + propsFirstArgColumn.id()); + Log.debug("StoreFirstArgColumn: " + storeFirstArgColumn); + + Log.debug("StoreFirstArgColumn created"); + final ComboBox comboFirstArgColumn = new ComboBox( + storeFirstArgColumn, propsFirstArgColumn.label()); + + Log.debug("Combo FirstArgColumn created"); + + comboFirstArgColumn.setEmptyText("Select a column..."); + comboFirstArgColumn.setItemId(itemIdFirstArgColumn); + comboFirstArgColumn.setWidth("100px"); + comboFirstArgColumn.setEditable(false); + comboFirstArgColumn.setTriggerAction(TriggerAction.ALL); + comboFirstArgColumn.setVisible(false); + + final TextField firstArgValue = new TextField(); + firstArgValue.setItemId(itemIdFirstArgValue); + firstArgValue.setVisible(false); + + final DateField firstArgDate = new DateField(); + firstArgDate.setItemId(itemIdFirstArgDate); + firstArgDate.setVisible(false); + + // And + final HTML andText = new HTML( + "
and
"); + andText.setVisible(false); + + // Combo SecondArgColumn + ColumnDataPropertiesCombo propsSecondArgColumn = GWT + .create(ColumnDataPropertiesCombo.class); + Log.debug("Props: " + propsSecondArgColumn); + final ListStore storeSecondArgColumn = new ListStore( + propsSecondArgColumn.id()); + Log.debug("StoreSecondArgColumn: " + storeSecondArgColumn); + + Log.debug("StoreSecondArgColumn created"); + final ComboBox comboSecondArgColumn = new ComboBox( + storeSecondArgColumn, propsSecondArgColumn.label()); + + Log.debug("Combo SecondArgColumn created"); + + comboSecondArgColumn.setEmptyText("Select a column..."); + comboSecondArgColumn.setItemId(itemIdSecondArgColumn); + comboSecondArgColumn.setWidth("100px"); + comboSecondArgColumn.setEditable(false); + comboSecondArgColumn.setTriggerAction(TriggerAction.ALL); + comboSecondArgColumn.setVisible(false); + + final TextField secondArgValue = new TextField(); + secondArgValue.setItemId(itemIdSecondArgValue); + secondArgValue.setVisible(false); + + final DateField secondArgDate = new DateField(); + secondArgDate.setItemId(itemIdSecondArgDate); + secondArgDate.setVisible(false); + + // Combo Similarity and Levenshtein threshold + ThresholdProperties propsThreshold = GWT + .create(ThresholdProperties.class); + Log.debug("Props: " + propsThreshold); + final ListStore storeThreshold = new ListStore( + propsThreshold.id()); + Log.debug("StoreThreshold: " + storeThreshold); + storeThreshold.addAll(ThresholdStore.thresholdsLevenshtein); + + Log.debug("StoreThreshold created"); + final ComboBox comboThreshold = new ComboBox( + storeThreshold, propsThreshold.label()); + + Log.debug("Combo Threshold created"); + + comboThreshold.setEmptyText("Select a threshold..."); + comboThreshold.setItemId(itemIdComboThreshold); + comboThreshold.setWidth("100px"); + comboThreshold.setEditable(false); + comboThreshold.setTriggerAction(TriggerAction.ALL); + comboThreshold.setVisible(false); + + final HTML thresholdText = new HTML( + "
Threshold:
"); + thresholdText.setVisible(false); + + // Operation + OperationProperties props = GWT.create(OperationProperties.class); + Log.debug("Props: " + props); + ListStore storeOp = new ListStore(props.id()); + Log.debug("Store: " + storeOp); + + Log.debug("Store created"); + ComboBox comboOp = new ComboBox(storeOp, + props.label()); + + Log.debug("Combo created"); + + comboOp.addSelectionHandler(new SelectionHandler() { + + public void onSelection(SelectionEvent event) { + if (event.getSelectedItem() != null) { + ColumnData column = comboFirstElementColumn + .getCurrentValue(); + Operation op = event.getSelectedItem(); + Log.debug("Condition selected:" + op.toString()); + switch (op.getOperatorType()) { + case EQUALS: + case GREATER: + case GREATER_OR_EQUALS: + case LESSER: + case LESSER_OR_EQUALS: + case NOT_EQUALS: + case NOT_GREATER: + case NOT_LESSER: + case BEGINS_WITH: + case ENDS_WITH: + case MATCH_REGEX: + case CONTAINS: + case NOT_BEGINS_WITH: + case NOT_ENDS_WITH: + case NOT_CONTAINS: + case NOT_MATCH_REGEX: + case IN: + case NOT_IN: + case SOUNDEX: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(true); + andText.setVisible(false); + secondArgDate.setVisible(false); + comboThreshold.setVisible(false); + thresholdText.setVisible(false); + } else { + firstArgValue.setVisible(true); + andText.setVisible(false); + secondArgValue.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } + break; + case BETWEEN: + case NOT_BETWEEN: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArgValue.setVisible(true); + andText.setVisible(true); + secondArgValue.setVisible(true); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } + break; + case LEVENSHTEIN: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArgValue.setVisible(true); + andText.setVisible(false); + secondArgValue.setVisible(false); + thresholdText.setVisible(true); + storeThreshold.clear(); + storeThreshold + .addAll(ThresholdStore.thresholdsLevenshtein); + storeThreshold.commitChanges(); + comboThreshold.clear(); + comboThreshold.reset(); + comboThreshold.setVisible(true); + comboThreshold.setValue(ThresholdStore + .defaultThresholdLevenshtein()); + + } + break; + case SIMILARITY: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArgValue.setVisible(true); + andText.setVisible(false); + secondArgValue.setVisible(false); + thresholdText.setVisible(true); + storeThreshold.clear(); + storeThreshold + .addAll(ThresholdStore.thresholdsSimilarity); + storeThreshold.commitChanges(); + comboThreshold.clear(); + comboThreshold.reset(); + comboThreshold.setVisible(true); + comboThreshold.setValue(ThresholdStore + .defaultThresholdSimilarity()); + + } + break; + case IS_NULL: + case IS_NOT_NULL: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArgValue.setVisible(false); + andText.setVisible(false); + secondArgValue.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } + break; + default: + break; + } + + thisCont.forceLayout(); + + } + } + + }); + + comboOp.setEmptyText("Select a condition..."); + comboOp.setItemId(itemIdComboOperation); + comboOp.setWidth("230px"); + comboOp.setEditable(false); + comboOp.setTriggerAction(TriggerAction.ALL); + + // Button + final IconButton btnAdd = new IconButton(); + btnAdd.setItemId(itemIdBtnAdd); + btnAdd.setIcon(ExpressionResources.INSTANCE.add()); + btnAdd.addClickHandler(new ClickHandler() { + + public void onClick(ClickEvent event) { + Log.debug("Clicked btnAdd"); + addCondition(); + thisCont.forceLayout(); + vert.forceLayout(); + + } + }); + btnAdd.setVisible(false); + + final IconButton btnDel = new IconButton(); + btnDel.setItemId(itemIdBtnDel); + btnDel.setIcon(ExpressionResources.INSTANCE.delete()); + btnDel.addClickHandler(new ClickHandler() { + + public void onClick(ClickEvent event) { + Log.debug("Clicked btnDel"); + vert.remove(horiz); + if (vert.getWidgetCount() == 0) { + setup(); + } else { + if (vert.getWidgetCount() == 1) { + } + } + thisCont.forceLayout(); + vert.forceLayout(); + + } + }); + btnDel.setVisible(false); + + horiz.add(comboOp, new BoxLayoutData(new Margins(0))); + horiz.add(firstArgDate, new BoxLayoutData(new Margins(0))); + horiz.add(andText, new BoxLayoutData(new Margins(0))); + horiz.add(secondArgDate, new BoxLayoutData(new Margins(0))); + horiz.add(thresholdText, new BoxLayoutData(new Margins(0))); + horiz.add(comboThreshold, new BoxLayoutData(new Margins(0))); + + horiz.add(btnAdd, new BoxLayoutData(new Margins(2, 0, 2, 0))); + horiz.add(btnDel, new BoxLayoutData(new Margins(2, 0, 2, 0))); + + + vert.add(horiz, new VerticalLayoutData(-1, -1, new Margins(1))); + + } + + @SuppressWarnings("unchecked") + public C_Expression getExpression() throws ConditionTypeMapException { + C_Expression exp = null; + readableExpression = new String(); + List arguments = new ArrayList(); + List readableExpressionList = new ArrayList(); + TextField firstArg; + TextField secondArg; + DateField firstArgDate; + DateField secondArgDate; + ComboBox comboThreshold; + + C_Expression expression = null; + + + DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); + + ConditionTypeMap mapOp = new ConditionTypeMap(); + Iterator iteratorVert = vert.iterator(); + HBoxLayoutContainer horiz; + while (iteratorVert.hasNext()) { + horiz = (HBoxLayoutContainer) iteratorVert.next(); + + ComboBox comboFirstElementColumn = (ComboBox) horiz + .getItemByItemId(itemIdFirstElementColumn); + ColumnData column = comboFirstElementColumn + .getCurrentValue(); + + + ComboBox comboOp = (ComboBox) horiz + .getItemByItemId(itemIdComboOperation); + Log.debug("combo: " + comboOp.getCurrentValue()); + + if (comboOp.getCurrentValue() == null) { + throw new ConditionTypeMapException("Fill all conditions!"); + } + + if (column.getDataTypeName().compareTo( + ColumnDataType.Date.toString()) == 0) { + firstArgDate = (DateField) horiz + .getItemByItemId(itemIdFirstArgDate); + secondArgDate = (DateField) horiz + .getItemByItemId(itemIdSecondArgDate); + Log.debug("argLeft: " + firstArgDate + " argRight:" + + secondArgDate); + Date firstDate = firstArgDate.getCurrentValue(); + Date secondDate = secondArgDate.getCurrentValue(); + + expression = mapOp.map(column, comboOp.getCurrentValue() + .getOperatorType(), + firstDate == null ? null : sdf.format(firstDate), + secondDate == null ? null : sdf.format(secondDate), + null); + } else { + + firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArgValue); + secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArgValue); + comboThreshold = (ComboBox) horiz + .getItemByItemId(itemIdComboThreshold); + + Log.debug("argLeft: " + firstArg.getCurrentValue() + + " argRight: " + secondArg.getCurrentValue()); + + expression = mapOp.map(column, comboOp.getCurrentValue() + .getOperatorType(), + firstArg == null ? null : firstArg.getCurrentValue(), + secondArg == null ? null : secondArg.getCurrentValue(), + comboThreshold.getCurrentValue() == null ? null + : comboThreshold.getCurrentValue()); + } + readableExpressionList.add(mapOp.getReadableExpression()); + Log.debug(expression.toString()); + arguments.add(expression); + } + Log.debug("Expression Arguments Calculated: " + arguments.size()); + if (arguments.size() > 0) { + if (arguments.size() == 1) { + exp = arguments.get(0); + readableExpression = readableExpressionList.get(0); + } else { + /*Radio radio = (Radio) groupMatch.getValue(); + Log.debug("Match:" + radio); + if (radio.getName().compareTo("All") == 0) { + exp = mapOp.createC_And(arguments); + readableExpression = "And("; + boolean first = true; + for (String read : readableExpressionList) { + if (first) { + readableExpression += read; + } else { + readableExpression += ", " + read; + } + } + readableExpression += ")"; + + } else { + if (radio.getName().compareTo("Any") == 0) { + exp = mapOp.createC_Or(arguments); + readableExpression = "Or("; + boolean first = true; + for (String read : readableExpressionList) { + if (first) { + readableExpression += read; + } else { + readableExpression += ", " + read; + } + } + readableExpression += ")"; + } else { + Log.error("No All or Any set!"); + } + }*/ + } + + } + Log.debug("C_Expression:" + exp.toString()); + return exp; + } + + public String getReadableExpression() { + return readableExpression; + } +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/multicolumn/DepthOfExpressionType.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/multicolumn/DepthOfExpressionType.java new file mode 100644 index 0000000..8ffe98a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/multicolumn/DepthOfExpressionType.java @@ -0,0 +1,48 @@ +package org.gcube.portlets.user.td.expressionwidget.client.multicolumn; + + +/** + * + * @author giancarlo + * email: g.panichi@isti.cnr.it + * + */ +public enum DepthOfExpressionType { + BOTTOM("Botom"), + STARTOR("StartOr"), + ENDOR("EndOr"), + STARTAND("StartAnd"), + ENDAND("EndAnd"), + COMMA("Comma"); + + + + /** + * @param text + */ + private DepthOfExpressionType(final String id) { + this.id = id; + } + + private final String id; + + @Override + public String toString() { + return id; + } + + public String getTableTypeLabel() { + return id; + } + + + public static DepthOfExpressionType getColumnDataTypeFromId(String id) { + for (DepthOfExpressionType tableType : values()) { + if (tableType.id.compareToIgnoreCase(id) == 0) { + return tableType; + } + } + return null; + } + +}