Updated Replace by Expression
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-expression-widget@99996 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3f8baf4909
commit
e6ba70d77b
|
@ -35,8 +35,10 @@ import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
|||
*/
|
||||
public class ReplaceColumnByExpressionDialog extends Window implements
|
||||
MonitorDialogListener {
|
||||
protected String WIDTH = "660px";
|
||||
protected String HEIGHT = "400px";
|
||||
protected static final String WIDTH = "660px";
|
||||
protected static final String HEIGHT = "490px";
|
||||
protected static final String HEIGHT_REDUCE = "404px";
|
||||
|
||||
protected ReplaceColumnByExpressionPanel replaceColumnByExpressionPanel;
|
||||
protected C_Expression cConditionExpression = null;
|
||||
protected C_Expression cReplaceExpression = null;
|
||||
|
@ -49,22 +51,22 @@ public class ReplaceColumnByExpressionDialog extends Window implements
|
|||
public ReplaceColumnByExpressionDialog(String columnId,
|
||||
ColumnTypeCode columnTypeCode, ColumnDataType dataTypeName,
|
||||
EventBus eventBus) {
|
||||
initWindow();
|
||||
this.eventBus = eventBus;
|
||||
column = new ColumnData();
|
||||
column.setColumnId(columnId);
|
||||
column.setDataTypeName(dataTypeName.toString());
|
||||
column.setTypeCode(columnTypeCode.toString());
|
||||
initWindow();
|
||||
create();
|
||||
|
||||
}
|
||||
|
||||
public ReplaceColumnByExpressionDialog(TRId trId, String columnName,
|
||||
EventBus eventBus) {
|
||||
initWindow();
|
||||
this.eventBus = eventBus;
|
||||
this.trId = trId;
|
||||
this.columnName = columnName;
|
||||
initWindow();
|
||||
load(trId, columnName);
|
||||
|
||||
}
|
||||
|
@ -98,6 +100,14 @@ public class ReplaceColumnByExpressionDialog extends Window implements
|
|||
}
|
||||
|
||||
protected void create() {
|
||||
if (column != null
|
||||
&& column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Text.toString())==0) {
|
||||
setHeight(HEIGHT);
|
||||
} else {
|
||||
setHeight(HEIGHT_REDUCE);
|
||||
}
|
||||
|
||||
if (column.getTypeCode()
|
||||
.compareTo(ColumnTypeCode.ANNOTATION.toString()) == 0
|
||||
|| column.getTypeCode().compareTo(
|
||||
|
@ -132,8 +142,8 @@ public class ReplaceColumnByExpressionDialog extends Window implements
|
|||
this.cConditionExpression = exp;
|
||||
}
|
||||
|
||||
protected void applyReplaceColumnByExpression(C_Expression cConditionExpression,
|
||||
String replaceValue) {
|
||||
protected void applyReplaceColumnByExpression(
|
||||
C_Expression cConditionExpression, String replaceValue) {
|
||||
this.cConditionExpression = cConditionExpression;
|
||||
this.replaceValue = replaceValue;
|
||||
|
||||
|
@ -142,8 +152,8 @@ public class ReplaceColumnByExpressionDialog extends Window implements
|
|||
callApplyReplaceByExpression(replaceColumnByExpressionSession);
|
||||
}
|
||||
|
||||
protected void applyReplaceColumnByExpression(C_Expression cConditionExpression,
|
||||
C_Expression cReplaceExpression) {
|
||||
protected void applyReplaceColumnByExpression(
|
||||
C_Expression cConditionExpression, C_Expression cReplaceExpression) {
|
||||
this.cConditionExpression = cConditionExpression;
|
||||
this.cReplaceExpression = cReplaceExpression;
|
||||
ReplaceColumnByExpressionSession replaceColumnByExpressionSession = new ReplaceColumnByExpressionSession(
|
||||
|
@ -181,7 +191,8 @@ public class ReplaceColumnByExpressionDialog extends Window implements
|
|||
|
||||
protected void callApplyReplaceByExpression(
|
||||
ReplaceColumnByExpressionSession replaceColumnByExpressionSession) {
|
||||
Log.debug("Replace Column By Expression Session "+replaceColumnByExpressionSession);
|
||||
Log.debug("Replace Column By Expression Session "
|
||||
+ replaceColumnByExpressionSession);
|
||||
|
||||
ExpressionServiceAsync.INSTANCE.startReplaceColumnByExpression(
|
||||
replaceColumnByExpressionSession, new AsyncCallback<String>() {
|
||||
|
|
|
@ -46,12 +46,14 @@ import com.sencha.gxt.widget.core.client.form.TextField;
|
|||
*/
|
||||
public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
||||
protected static final String WIDTH = "648px";
|
||||
protected static final String HEIGHT = "364px";
|
||||
protected static final String HEIGHT = "454px";
|
||||
protected static final String HEIGHT_REDUCE = "368px";
|
||||
|
||||
protected static final String CONDITIONWIDTH = "612px";
|
||||
protected static final String CONDITIONHEIGHT = "120px";
|
||||
protected static final String REPLACEWIDTH = "612px";
|
||||
protected static final String REPLACEHEIGHT = "120px";
|
||||
|
||||
|
||||
protected EventBus eventBus;
|
||||
|
||||
protected ReplaceColumnByExpressionDialog parent;
|
||||
|
@ -65,7 +67,7 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
|||
|
||||
private FieldSet conditionsFieldSet;
|
||||
private ConditionWidget conditionWidget;
|
||||
|
||||
|
||||
private ReplaceWidget replaceWidget;
|
||||
private TextField replaceValue;
|
||||
private DateField replaceValueDate;
|
||||
|
@ -73,7 +75,6 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
|||
private VerticalLayoutContainer conditionsVerticalLayout;
|
||||
private FieldLabel allRowsField;
|
||||
private boolean allRows;
|
||||
|
||||
|
||||
public ReplaceColumnByExpressionPanel(
|
||||
ReplaceColumnByExpressionDialog parent, ColumnData column,
|
||||
|
@ -89,7 +90,13 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
|||
|
||||
protected void init() {
|
||||
setWidth(WIDTH);
|
||||
setHeight(HEIGHT);
|
||||
if (column != null
|
||||
&& column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Text.toString())==0) {
|
||||
setHeight(HEIGHT);
|
||||
} else {
|
||||
setHeight(HEIGHT_REDUCE);
|
||||
}
|
||||
setBodyBorder(false);
|
||||
setHeaderVisible(false);
|
||||
// Important: fixed rendering of widgets
|
||||
|
@ -190,8 +197,10 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
|||
} else {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Text.toString()) == 0) {
|
||||
replaceWidget=new ReplaceWidget(column, REPLACEWIDTH, REPLACEHEIGHT);
|
||||
replaceValueFieldSetLayout.add(replaceWidget, new VerticalLayoutData(1, -1));
|
||||
replaceWidget = new ReplaceWidget(column, REPLACEWIDTH,
|
||||
REPLACEHEIGHT);
|
||||
replaceValueFieldSetLayout.add(replaceWidget,
|
||||
new VerticalLayoutData(1, -1));
|
||||
} else {
|
||||
replaceValue = new TextField();
|
||||
replaceValue.setToolTip("Replace Value");
|
||||
|
@ -279,27 +288,40 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel {
|
|||
"Select a valid date as replace value!");
|
||||
return;
|
||||
}
|
||||
parent.applyReplaceColumnByExpression(cConditionExpression, value);
|
||||
|
||||
parent.applyReplaceColumnByExpression(cConditionExpression,
|
||||
value);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
if (column.getDataTypeName().compareTo(
|
||||
ColumnDataType.Text.toString()) == 0) {
|
||||
C_Expression replaceExpression=replaceWidget.getExpression();
|
||||
parent.applyReplaceColumnByExpression(cConditionExpression, replaceExpression);
|
||||
C_Expression cReplaceExpression = null;
|
||||
try {
|
||||
cReplaceExpression = replaceWidget.getExpression();
|
||||
if(cReplaceExpression==null){
|
||||
UtilsGXT3.alert("Attention", "Replace expression is not valid!");
|
||||
return;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
UtilsGXT3.alert("Attention", "Replace expression is not valid!");
|
||||
return;
|
||||
}
|
||||
parent.applyReplaceColumnByExpression(cConditionExpression,
|
||||
cReplaceExpression);
|
||||
} else {
|
||||
value = replaceValue.getCurrentValue();
|
||||
if (checkValue(value)) {
|
||||
parent.applyReplaceColumnByExpression(cConditionExpression, value);
|
||||
parent.applyReplaceColumnByExpression(cConditionExpression,
|
||||
value);
|
||||
} else {
|
||||
UtilsGXT3.alert("Error replace value", "Insert a valid value!");
|
||||
UtilsGXT3.alert("Error replace value",
|
||||
"Insert a valid value!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private boolean checkValue(String value) {
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.gcube.portlets.user.td.expressionwidget.client;
|
|||
import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElement;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElementProperties;
|
||||
import org.gcube.portlets.user.td.expressionwidget.client.properties.ReplaceElementStore;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceType;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceTypeMap;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
|
||||
|
||||
|
@ -11,11 +13,13 @@ 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.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
|
||||
import com.sencha.gxt.core.client.dom.ScrollSupport.ScrollMode;
|
||||
import com.sencha.gxt.core.client.util.Margins;
|
||||
import com.sencha.gxt.core.client.util.ToggleGroup;
|
||||
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.MarginData;
|
||||
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;
|
||||
|
@ -32,18 +36,58 @@ import com.sencha.gxt.widget.core.client.form.TextField;
|
|||
*/
|
||||
public class ReplaceWidget extends SimpleContainer {
|
||||
|
||||
private static final String EMPTY_TEXT_TO_STRING = "to string...";
|
||||
private static final String EMPTY_TEXT_FROM_STRING = "from string...";
|
||||
private static final String EMPTY_TEXT_TO_INDEX = "to index...";
|
||||
private static final String EMPTY_TEXT_FROM_INDEX = "from index...";
|
||||
private static final String EMPTY_TEXT_REGEXP = "regexp...";
|
||||
private static final String EMPTY_TEXT_INSERT_A_STRING = "insert a string...";
|
||||
private ReplaceWidget thisCont;
|
||||
|
||||
protected static final String HEIGHT = "210px";
|
||||
protected static final String WIDTH = "612px";
|
||||
protected static final String COMBO_WIDTH = "150px";
|
||||
protected FieldLabel matchLabel;
|
||||
protected ToggleGroup groupMatch;
|
||||
|
||||
|
||||
protected VerticalLayoutContainer vert;
|
||||
protected ColumnData column;
|
||||
|
||||
protected String readableExpression;
|
||||
private TextField replaceValue;
|
||||
private String itemIdComboConcat;
|
||||
private String itemIdComboLeaf;
|
||||
private String itemIdFirstArg;
|
||||
private String itemIdSecondArg;
|
||||
private String itemIdHoriz;
|
||||
|
||||
public class ExpressionContainer {
|
||||
private C_Expression expression;
|
||||
private String readableExpression;
|
||||
|
||||
public ExpressionContainer(C_Expression expression,
|
||||
String readableExpression) {
|
||||
super();
|
||||
this.expression = expression;
|
||||
this.readableExpression = readableExpression;
|
||||
}
|
||||
|
||||
public C_Expression getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
public void setExpression(C_Expression expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
public String getReadableExpression() {
|
||||
return readableExpression;
|
||||
}
|
||||
|
||||
public void setReadableExpression(String readableExpression) {
|
||||
this.readableExpression = readableExpression;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ReplaceWidget(ColumnData column) {
|
||||
super();
|
||||
|
@ -62,7 +106,7 @@ public class ReplaceWidget extends SimpleContainer {
|
|||
setHeight(height);
|
||||
forceLayoutOnResize = true;
|
||||
thisCont = this;
|
||||
|
||||
|
||||
setup();
|
||||
addBeforeShowHandler(new BeforeShowEvent.BeforeShowHandler() {
|
||||
|
||||
|
@ -76,29 +120,44 @@ public class ReplaceWidget extends SimpleContainer {
|
|||
}
|
||||
|
||||
protected void setup() {
|
||||
itemIdComboConcat = "ComboConcat" + column.getName();
|
||||
itemIdComboLeaf = "ComboLeaf" + column.getName();
|
||||
itemIdFirstArg = "FirstArg" + column.getName();
|
||||
itemIdSecondArg = "SecondArg" + column.getName();
|
||||
itemIdHoriz = "Horiz" + column.getName();
|
||||
|
||||
vert = new VerticalLayoutContainer();
|
||||
|
||||
|
||||
vert.setScrollMode(ScrollMode.AUTO);
|
||||
|
||||
final HBoxLayoutContainer horiz = new HBoxLayoutContainer();
|
||||
|
||||
//
|
||||
final TextField firstArg = new TextField();
|
||||
firstArg.setEmptyText("Insert a string");
|
||||
firstArg.setItemId(itemIdFirstArg);
|
||||
|
||||
final TextField secondArg = new TextField();
|
||||
secondArg.setEmptyText("");
|
||||
secondArg.setItemId(itemIdSecondArg);
|
||||
|
||||
ReplaceElementStore factory = new ReplaceElementStore();
|
||||
|
||||
ReplaceElementProperties props = GWT
|
||||
.create(ReplaceElementProperties.class);
|
||||
Log.debug("Props: " + props);
|
||||
ListStore<ReplaceElement> storeReplaceElement = new ListStore<ReplaceElement>(
|
||||
|
||||
// Combo Leaf
|
||||
ListStore<ReplaceElement> storeReplaceElementsLeaf = new ListStore<ReplaceElement>(
|
||||
props.id());
|
||||
Log.debug("Store: " + storeReplaceElement);
|
||||
ReplaceElementStore factory = new ReplaceElementStore();
|
||||
storeReplaceElement.addAll(factory.replaceElements);
|
||||
|
||||
|
||||
Log.debug("Store Leaf: " + storeReplaceElementsLeaf);
|
||||
storeReplaceElementsLeaf.addAll(factory.replaceElements);
|
||||
|
||||
Log.debug("Store created");
|
||||
ComboBox<ReplaceElement> comboReplaceElement = new ComboBox<ReplaceElement>(
|
||||
storeReplaceElement, props.label());
|
||||
final ComboBox<ReplaceElement> comboReplaceElementsLeaf = new ComboBox<ReplaceElement>(
|
||||
storeReplaceElementsLeaf, props.label());
|
||||
|
||||
Log.debug("Combo created");
|
||||
|
||||
comboReplaceElement
|
||||
comboReplaceElementsLeaf
|
||||
.addSelectionHandler(new SelectionHandler<ReplaceElement>() {
|
||||
|
||||
public void onSelection(SelectionEvent<ReplaceElement> event) {
|
||||
|
@ -106,14 +165,43 @@ public class ReplaceWidget extends SimpleContainer {
|
|||
ReplaceElement re = event.getSelectedItem();
|
||||
Log.debug("Condition selected:" + re.toString());
|
||||
switch (re.getReplaceType()) {
|
||||
case Value:
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING);
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
break;
|
||||
case ColumnValue:
|
||||
firstArg.setVisible(false);
|
||||
firstArg.setEmptyText("");
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
break;
|
||||
case Concat:
|
||||
break;
|
||||
case Equals:
|
||||
case SubstringByRegex:
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_REGEXP);
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
break;
|
||||
case SubstringByIndex:
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX);
|
||||
secondArg.setVisible(true);
|
||||
secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX);
|
||||
break;
|
||||
case SubstringByCharSeq:
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING);
|
||||
secondArg.setVisible(true);
|
||||
secondArg.setEmptyText(EMPTY_TEXT_TO_STRING);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
vert.forceLayout();
|
||||
thisCont.forceLayout();
|
||||
|
||||
}
|
||||
|
@ -121,35 +209,470 @@ public class ReplaceWidget extends SimpleContainer {
|
|||
|
||||
});
|
||||
|
||||
comboReplaceElement.setEmptyText("Select...");
|
||||
comboReplaceElement.setWidth("230px");
|
||||
comboReplaceElement.setEditable(false);
|
||||
comboReplaceElement.setTriggerAction(TriggerAction.ALL);
|
||||
|
||||
comboReplaceElement.setValue(storeReplaceElement.get(0), true);
|
||||
comboReplaceElementsLeaf.setEmptyText("Select...");
|
||||
comboReplaceElementsLeaf.setItemId(itemIdComboLeaf);
|
||||
comboReplaceElementsLeaf.setWidth(COMBO_WIDTH);
|
||||
comboReplaceElementsLeaf.setEditable(false);
|
||||
|
||||
comboReplaceElementsLeaf.setTriggerAction(TriggerAction.ALL);
|
||||
|
||||
// ComboConcat
|
||||
ListStore<ReplaceElement> storeReplaceElementsConcat = new ListStore<ReplaceElement>(
|
||||
props.id());
|
||||
Log.debug("Store Concat: " + storeReplaceElementsConcat);
|
||||
storeReplaceElementsConcat.addAll(factory.replaceElementsConcat);
|
||||
|
||||
Log.debug("Store created");
|
||||
final ComboBox<ReplaceElement> comboReplaceElementsConcat = new ComboBox<ReplaceElement>(
|
||||
storeReplaceElementsConcat, props.label());
|
||||
|
||||
Log.debug("Combo created");
|
||||
|
||||
comboReplaceElementsConcat
|
||||
.addSelectionHandler(new SelectionHandler<ReplaceElement>() {
|
||||
|
||||
public void onSelection(SelectionEvent<ReplaceElement> event) {
|
||||
if (event.getSelectedItem() != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ComboBox<ReplaceElement> source = (ComboBox<ReplaceElement>) event
|
||||
.getSource();
|
||||
ReplaceElement re = event.getSelectedItem();
|
||||
Log.debug("Condition selected:" + re.toString());
|
||||
switch (re.getReplaceType()) {
|
||||
case Value:
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING);
|
||||
firstArg.setVisible(true);
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
removeConcat(source);
|
||||
break;
|
||||
case ColumnValue:
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
firstArg.setVisible(false);
|
||||
firstArg.setEmptyText("");
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
break;
|
||||
case Concat:
|
||||
if (!existConcat(source)) {
|
||||
comboReplaceElementsLeaf.setVisible(true);
|
||||
firstArg.setVisible(false);
|
||||
firstArg.setEmptyText("");
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
addConcat();
|
||||
}
|
||||
break;
|
||||
case SubstringByRegex:
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_REGEXP);
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
removeConcat(source);
|
||||
break;
|
||||
case SubstringByIndex:
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX);
|
||||
secondArg.setVisible(true);
|
||||
secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX);
|
||||
removeConcat(source);
|
||||
break;
|
||||
case SubstringByCharSeq:
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING);
|
||||
secondArg.setVisible(true);
|
||||
secondArg.setEmptyText(EMPTY_TEXT_TO_STRING);
|
||||
removeConcat(source);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
vert.forceLayout();
|
||||
thisCont.forceLayout();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
comboReplaceElementsConcat.setEmptyText("Select...");
|
||||
comboReplaceElementsConcat.setItemId(itemIdComboConcat);
|
||||
comboReplaceElementsConcat.setWidth(COMBO_WIDTH);
|
||||
comboReplaceElementsConcat.setEditable(false);
|
||||
comboReplaceElementsConcat.setTriggerAction(TriggerAction.ALL);
|
||||
|
||||
comboReplaceElementsConcat.setValue(storeReplaceElementsConcat.get(0),
|
||||
true);
|
||||
|
||||
//
|
||||
replaceValue = new TextField();
|
||||
replaceValue.setToolTip("Replace Value");
|
||||
replaceValue.setValue("");
|
||||
|
||||
horiz.add(comboReplaceElement, new BoxLayoutData(new Margins(1)));
|
||||
horiz.add(replaceValue, new BoxLayoutData(new Margins(1)));
|
||||
|
||||
horiz.add(comboReplaceElementsConcat, new BoxLayoutData(new Margins(0)));
|
||||
horiz.add(comboReplaceElementsLeaf, new BoxLayoutData(new Margins(0)));
|
||||
horiz.add(firstArg, new BoxLayoutData(new Margins(0)));
|
||||
horiz.add(secondArg, new BoxLayoutData(new Margins(0)));
|
||||
horiz.setItemId(itemIdHoriz);
|
||||
vert.add(horiz, new VerticalLayoutData(-1, -1, new Margins(1)));
|
||||
|
||||
add(vert);
|
||||
add(vert, new MarginData(0));
|
||||
|
||||
|
||||
firstArg.setVisible(true);
|
||||
secondArg.setVisible(false);
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
comboReplaceElementsConcat.setVisible(true);
|
||||
forceLayout();
|
||||
}
|
||||
|
||||
protected void addConcat() {
|
||||
final HBoxLayoutContainer horiz = new HBoxLayoutContainer();
|
||||
|
||||
final TextField firstArg = new TextField();
|
||||
firstArg.setItemId(itemIdFirstArg);
|
||||
|
||||
final TextField secondArg = new TextField();
|
||||
secondArg.setItemId(itemIdSecondArg);
|
||||
|
||||
ReplaceElementStore factory = new ReplaceElementStore();
|
||||
|
||||
ReplaceElementProperties props = GWT
|
||||
.create(ReplaceElementProperties.class);
|
||||
Log.debug("Props: " + props);
|
||||
|
||||
// Combo Leaf
|
||||
ListStore<ReplaceElement> storeReplaceElementsLeaf = new ListStore<ReplaceElement>(
|
||||
props.id());
|
||||
Log.debug("Store Leaf: " + storeReplaceElementsLeaf);
|
||||
storeReplaceElementsLeaf.addAll(factory.replaceElements);
|
||||
|
||||
Log.debug("Store created");
|
||||
final ComboBox<ReplaceElement> comboReplaceElementsLeaf = new ComboBox<ReplaceElement>(
|
||||
storeReplaceElementsLeaf, props.label());
|
||||
|
||||
Log.debug("Combo created");
|
||||
|
||||
comboReplaceElementsLeaf
|
||||
.addSelectionHandler(new SelectionHandler<ReplaceElement>() {
|
||||
|
||||
public void onSelection(SelectionEvent<ReplaceElement> event) {
|
||||
if (event.getSelectedItem() != null) {
|
||||
ReplaceElement re = event.getSelectedItem();
|
||||
Log.debug("Condition selected:" + re.toString());
|
||||
switch (re.getReplaceType()) {
|
||||
case Value:
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING);
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
break;
|
||||
case ColumnValue:
|
||||
firstArg.setVisible(false);
|
||||
firstArg.setEmptyText("");
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
break;
|
||||
case Concat:
|
||||
break;
|
||||
case SubstringByRegex:
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_REGEXP);
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
break;
|
||||
case SubstringByIndex:
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX);
|
||||
secondArg.setVisible(true);
|
||||
secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX);
|
||||
break;
|
||||
case SubstringByCharSeq:
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING);
|
||||
secondArg.setVisible(true);
|
||||
secondArg.setEmptyText(EMPTY_TEXT_TO_STRING);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
vert.forceLayout();
|
||||
thisCont.forceLayout();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
comboReplaceElementsLeaf.setEmptyText("Select...");
|
||||
comboReplaceElementsLeaf.setItemId(itemIdComboLeaf);
|
||||
comboReplaceElementsLeaf.setWidth(COMBO_WIDTH);
|
||||
comboReplaceElementsLeaf.setEditable(false);
|
||||
|
||||
comboReplaceElementsLeaf.setTriggerAction(TriggerAction.ALL);
|
||||
|
||||
// ComboConcat
|
||||
ListStore<ReplaceElement> storeReplaceElementsConcat = new ListStore<ReplaceElement>(
|
||||
props.id());
|
||||
Log.debug("Store Concat: " + storeReplaceElementsConcat);
|
||||
storeReplaceElementsConcat.addAll(factory.replaceElementsConcat);
|
||||
|
||||
Log.debug("Store created");
|
||||
final ComboBox<ReplaceElement> comboReplaceElementsConcat = new ComboBox<ReplaceElement>(
|
||||
storeReplaceElementsConcat, props.label());
|
||||
|
||||
Log.debug("Combo created");
|
||||
|
||||
comboReplaceElementsConcat
|
||||
.addSelectionHandler(new SelectionHandler<ReplaceElement>() {
|
||||
|
||||
public void onSelection(SelectionEvent<ReplaceElement> event) {
|
||||
|
||||
if (event.getSelectedItem() != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ComboBox<ReplaceElement> source = (ComboBox<ReplaceElement>) event
|
||||
.getSource();
|
||||
ReplaceElement re = event.getSelectedItem();
|
||||
Log.debug("Condition selected:" + re.toString());
|
||||
switch (re.getReplaceType()) {
|
||||
case Value:
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_INSERT_A_STRING);
|
||||
firstArg.setVisible(true);
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
removeConcat(source);
|
||||
break;
|
||||
case ColumnValue:
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
firstArg.setVisible(false);
|
||||
firstArg.setEmptyText("");
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
break;
|
||||
case Concat:
|
||||
if (!existConcat(source)) {
|
||||
comboReplaceElementsLeaf.setVisible(true);
|
||||
firstArg.setVisible(false);
|
||||
firstArg.setEmptyText("");
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
addConcat();
|
||||
}
|
||||
break;
|
||||
case SubstringByRegex:
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_REGEXP);
|
||||
secondArg.setVisible(false);
|
||||
secondArg.setEmptyText("");
|
||||
removeConcat(source);
|
||||
break;
|
||||
case SubstringByIndex:
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_FROM_INDEX);
|
||||
secondArg.setVisible(true);
|
||||
secondArg.setEmptyText(EMPTY_TEXT_TO_INDEX);
|
||||
removeConcat(source);
|
||||
break;
|
||||
case SubstringByCharSeq:
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
firstArg.setVisible(true);
|
||||
firstArg.setEmptyText(EMPTY_TEXT_FROM_STRING);
|
||||
secondArg.setVisible(true);
|
||||
secondArg.setEmptyText(EMPTY_TEXT_TO_STRING);
|
||||
removeConcat(source);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
vert.forceLayout();
|
||||
thisCont.forceLayout();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
comboReplaceElementsConcat.setEmptyText("Select...");
|
||||
comboReplaceElementsConcat.setItemId(itemIdComboConcat);
|
||||
comboReplaceElementsConcat.setWidth(COMBO_WIDTH);
|
||||
comboReplaceElementsConcat.setEditable(false);
|
||||
comboReplaceElementsConcat.setTriggerAction(TriggerAction.ALL);
|
||||
|
||||
comboReplaceElementsConcat.setValue(storeReplaceElementsConcat.get(0),
|
||||
true);
|
||||
|
||||
//
|
||||
horiz.add(comboReplaceElementsConcat, new BoxLayoutData(new Margins(0)));
|
||||
horiz.add(comboReplaceElementsLeaf, new BoxLayoutData(new Margins(0)));
|
||||
horiz.add(firstArg, new BoxLayoutData(new Margins(0)));
|
||||
horiz.add(secondArg, new BoxLayoutData(new Margins(0)));
|
||||
horiz.setItemId(itemIdHoriz);
|
||||
vert.add(horiz, new VerticalLayoutData(-1, -1, new Margins(1)));
|
||||
|
||||
firstArg.setVisible(true);
|
||||
secondArg.setVisible(false);
|
||||
comboReplaceElementsLeaf.setVisible(false);
|
||||
comboReplaceElementsConcat.setVisible(true);
|
||||
forceLayout();
|
||||
}
|
||||
|
||||
private void removeConcat(ComboBox<ReplaceElement> source) {
|
||||
HBoxLayoutContainer horiz = (HBoxLayoutContainer) source.getParent();
|
||||
int index = vert.getWidgetIndex(horiz);
|
||||
Log.debug("No concat for index: " + index);
|
||||
index++;
|
||||
for (int i = index; i < vert.getWidgetCount();) {
|
||||
Log.debug("Remove horiz index: " + i);
|
||||
vert.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean existConcat(ComboBox<ReplaceElement> source) {
|
||||
boolean exist = false;
|
||||
HBoxLayoutContainer horiz = (HBoxLayoutContainer) source.getParent();
|
||||
int index = vert.getWidgetIndex(horiz);
|
||||
Log.debug("No concat for index: " + index);
|
||||
index++;
|
||||
if (index < vert.getWidgetCount()) {
|
||||
exist = true;
|
||||
} else {
|
||||
exist = false;
|
||||
}
|
||||
return exist;
|
||||
}
|
||||
|
||||
public C_Expression getExpression() {
|
||||
C_Expression exp = null;
|
||||
ExpressionContainer expressionContainer = null;
|
||||
readableExpression = new String();
|
||||
C_Expression expression = null;
|
||||
|
||||
Log.debug("C_Expression:" + exp);
|
||||
return exp;
|
||||
if (vert.getWidgetCount() > 0) {
|
||||
int index = 0;
|
||||
expressionContainer = calcCExpression(index);
|
||||
if (expressionContainer != null) {
|
||||
readableExpression = expressionContainer
|
||||
.getReadableExpression();
|
||||
expression = expressionContainer.getExpression();
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Log.debug("ReadableExpression: " + readableExpression);
|
||||
Log.debug("C_Expression:" + expression);
|
||||
return expression;
|
||||
}
|
||||
|
||||
public String getReadableExpression() {
|
||||
return readableExpression;
|
||||
}
|
||||
|
||||
protected ExpressionContainer calcCExpression(int index) {
|
||||
ExpressionContainer expressionContainer = null;
|
||||
ExpressionContainer expContainerConcat = null;
|
||||
C_Expression exp = null;
|
||||
C_Expression expLeaf = null;
|
||||
String readableExp = "";
|
||||
String readableExpLeaf = "";
|
||||
TextField firstArg;
|
||||
TextField secondArg;
|
||||
HBoxLayoutContainer horiz;
|
||||
ReplaceTypeMap mapReplace = new ReplaceTypeMap();
|
||||
|
||||
horiz = (HBoxLayoutContainer) vert.getWidget(index);
|
||||
@SuppressWarnings("unchecked")
|
||||
ComboBox<ReplaceElement> comboConcat = (ComboBox<ReplaceElement>) horiz
|
||||
.getItemByItemId(itemIdComboConcat);
|
||||
Log.debug("combo: " + comboConcat.getCurrentValue().toString());
|
||||
@SuppressWarnings("unchecked")
|
||||
ComboBox<ReplaceElement> comboLeaf = (ComboBox<ReplaceElement>) horiz
|
||||
.getItemByItemId(itemIdComboLeaf);
|
||||
Log.debug("combo: " + comboConcat.getCurrentValue().toString());
|
||||
|
||||
firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArg);
|
||||
secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArg);
|
||||
Log.debug("firstArg: " + firstArg.getCurrentValue() + " secondArg: "
|
||||
+ secondArg.getCurrentValue());
|
||||
|
||||
ReplaceType comboConcatReplaceType = null;
|
||||
ReplaceType comboLeafReplaceType = null;
|
||||
|
||||
if (comboConcat.getCurrentValue() == null) {
|
||||
if (index == vert.getWidgetCount() - 1) {
|
||||
exp = mapReplace.map(column, ReplaceType.Null,
|
||||
firstArg == null ? null : firstArg.getCurrentValue(),
|
||||
secondArg == null ? null : secondArg.getCurrentValue());
|
||||
readableExp = mapReplace.getReadableExpression();
|
||||
expressionContainer = new ExpressionContainer(exp, readableExp);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
comboConcatReplaceType = comboConcat.getCurrentValue()
|
||||
.getReplaceType();
|
||||
if (comboConcatReplaceType.compareTo(ReplaceType.Concat) == 0) {
|
||||
|
||||
if (comboLeaf.getCurrentValue() == null) {
|
||||
expLeaf = mapReplace.map(
|
||||
column,
|
||||
ReplaceType.Null,
|
||||
firstArg == null ? null : firstArg
|
||||
.getCurrentValue(),
|
||||
secondArg == null ? null : secondArg
|
||||
.getCurrentValue());
|
||||
readableExpLeaf = mapReplace.getReadableExpression();
|
||||
|
||||
} else {
|
||||
comboLeafReplaceType = comboLeaf.getCurrentValue()
|
||||
.getReplaceType();
|
||||
expLeaf = mapReplace.map(
|
||||
column,
|
||||
comboLeafReplaceType,
|
||||
firstArg == null ? null : firstArg
|
||||
.getCurrentValue(),
|
||||
secondArg == null ? null : secondArg
|
||||
.getCurrentValue());
|
||||
readableExpLeaf = mapReplace.getReadableExpression();
|
||||
}
|
||||
|
||||
index++;
|
||||
if (index < vert.getWidgetCount()) {
|
||||
expContainerConcat = calcCExpression(index);
|
||||
if (expContainerConcat == null) {
|
||||
return null;
|
||||
} else {
|
||||
exp = mapReplace.map(
|
||||
column,
|
||||
comboConcatReplaceType,
|
||||
firstArg == null ? null : firstArg
|
||||
.getCurrentValue(),
|
||||
secondArg == null ? null : secondArg
|
||||
.getCurrentValue(), expLeaf,
|
||||
expContainerConcat.getExpression(),
|
||||
readableExpLeaf, expContainerConcat
|
||||
.getReadableExpression());
|
||||
readableExp = mapReplace.getReadableExpression();
|
||||
expressionContainer = new ExpressionContainer(exp,
|
||||
readableExp);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
} else {
|
||||
exp = mapReplace.map(column, comboConcatReplaceType,
|
||||
firstArg == null ? null : firstArg.getCurrentValue(),
|
||||
secondArg == null ? null : secondArg.getCurrentValue());
|
||||
readableExp = mapReplace.getReadableExpression();
|
||||
expressionContainer = new ExpressionContainer(exp,
|
||||
readableExp);
|
||||
|
||||
}
|
||||
}
|
||||
return expressionContainer;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.gcube.portlets.user.td.expressionwidget.client.properties;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo email: <a
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.gcube.portlets.user.td.expressionwidget.client.properties;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.replace.ReplaceType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
|
@ -10,14 +12,33 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class ReplaceElementStore {
|
||||
|
||||
public ArrayList<ReplaceElement> replaceElementsConcat = new ArrayList<ReplaceElement>() {
|
||||
|
||||
private static final long serialVersionUID = 1690916203781730778L;
|
||||
|
||||
{
|
||||
add(new ReplaceElement(1, ReplaceType.Value));
|
||||
add(new ReplaceElement(2, ReplaceType.ColumnValue));
|
||||
add(new ReplaceElement(3, ReplaceType.SubstringByRegex));
|
||||
add(new ReplaceElement(4, ReplaceType.SubstringByIndex));
|
||||
add(new ReplaceElement(5, ReplaceType.SubstringByCharSeq));
|
||||
add(new ReplaceElement(6, ReplaceType.Concat));
|
||||
}
|
||||
};
|
||||
|
||||
public ArrayList<ReplaceElement> replaceElements = new ArrayList<ReplaceElement>() {
|
||||
|
||||
private static final long serialVersionUID = 1690916203781730778L;
|
||||
|
||||
{
|
||||
add(new ReplaceElement(1, ReplaceType.Equals));
|
||||
add(new ReplaceElement(2, ReplaceType.Concat));
|
||||
add(new ReplaceElement(1, ReplaceType.Value));
|
||||
add(new ReplaceElement(2, ReplaceType.ColumnValue));
|
||||
add(new ReplaceElement(3, ReplaceType.SubstringByRegex));
|
||||
add(new ReplaceElement(4, ReplaceType.SubstringByIndex));
|
||||
add(new ReplaceElement(5, ReplaceType.SubstringByCharSeq));
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.client.properties;
|
||||
|
||||
public enum ReplaceType {
|
||||
Equals("Equals"),
|
||||
Concat("Concat");
|
||||
|
||||
/**
|
||||
* @param text
|
||||
*/
|
||||
private ReplaceType(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private final String id;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
|
@ -91,7 +91,9 @@ public class C_ExpressionParser {
|
|||
protected SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
public Expression parse(C_Expression exp) {
|
||||
logger.debug("Parse: "+exp);
|
||||
Expression ex = null;
|
||||
|
||||
switch (exp.getId()) {
|
||||
case "ColumnReferencePlaceholder":
|
||||
ex = getColumnReferencePlaceholder(exp);
|
||||
|
|
|
@ -39,8 +39,6 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
|
|||
protected static SimpleDateFormat sdf = new SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm");
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
|
@ -52,66 +50,81 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
|
|||
try {
|
||||
logger.debug("ExpressionService submitColumnFilter");
|
||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||
logger.debug("Session: "+session);
|
||||
|
||||
if(filterColumnSession==null){
|
||||
logger.debug("Session: " + session);
|
||||
|
||||
if (filterColumnSession == null) {
|
||||
logger.error("FilterColumnSession is null");
|
||||
new ExpressionServiceException("FilterColumnSession is null");
|
||||
}
|
||||
ExpressionSession.setColumnFilterSession(session, filterColumnSession);
|
||||
|
||||
C_ExpressionParser parser=new C_ExpressionParser();
|
||||
Expression expression=parser.parse(filterColumnSession.getCexpression());
|
||||
logger.debug("Service Expression:"+expression);
|
||||
|
||||
|
||||
ExpressionSession.setColumnFilterSession(session,
|
||||
filterColumnSession);
|
||||
|
||||
C_ExpressionParser parser = new C_ExpressionParser();
|
||||
Expression expression = parser.parse(filterColumnSession
|
||||
.getCexpression());
|
||||
logger.debug("Service Expression:" + expression);
|
||||
|
||||
TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
|
||||
|
||||
String taskId= gwtService.startFilterColumn(filterColumnSession, expression, session);
|
||||
|
||||
|
||||
String taskId = gwtService.startFilterColumn(filterColumnSession,
|
||||
expression, session);
|
||||
|
||||
return taskId;
|
||||
|
||||
} catch (TDGWTSessionExpiredException e){
|
||||
|
||||
} catch (TDGWTSessionExpiredException e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new TDGWTServiceException(
|
||||
"Error in Client Library Request: "
|
||||
+ e.getLocalizedMessage());
|
||||
throw new TDGWTServiceException("Error in Client Library Request: "
|
||||
+ e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String startReplaceColumnByExpression(ReplaceColumnByExpressionSession replaceColumnByExpressionSession)
|
||||
public String startReplaceColumnByExpression(
|
||||
ReplaceColumnByExpressionSession replaceColumnByExpressionSession)
|
||||
throws TDGWTServiceException {
|
||||
|
||||
try {
|
||||
logger.debug("ExpressionService submitReplaceColumnByExpression");
|
||||
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||
logger.debug("Session: "+session);
|
||||
|
||||
if(replaceColumnByExpressionSession==null){
|
||||
logger.debug("Session: " + session);
|
||||
|
||||
if (replaceColumnByExpressionSession == null) {
|
||||
logger.error("ReplaceColumnByExpressionSession is null");
|
||||
new ExpressionServiceException("ReplaceColumnByExpressionSession is null");
|
||||
new ExpressionServiceException(
|
||||
"ReplaceColumnByExpressionSession is null");
|
||||
}
|
||||
ExpressionSession.setReplaceColumnByExpressionSession(session, replaceColumnByExpressionSession);
|
||||
|
||||
C_ExpressionParser parser=new C_ExpressionParser();
|
||||
Expression expression=parser.parse(replaceColumnByExpressionSession.getcConditionExpression());
|
||||
logger.debug("Service Expression:"+expression);
|
||||
|
||||
|
||||
ExpressionSession.setReplaceColumnByExpressionSession(session,
|
||||
replaceColumnByExpressionSession);
|
||||
|
||||
C_ExpressionParser parser = new C_ExpressionParser();
|
||||
Expression conditionExpression = parser
|
||||
.parse(replaceColumnByExpressionSession
|
||||
.getcConditionExpression());
|
||||
logger.debug("Service Condition Expression:" + conditionExpression);
|
||||
|
||||
Expression replaceExpression = null;
|
||||
if (!replaceColumnByExpressionSession.isReplaceByValue()) {
|
||||
replaceExpression = parser
|
||||
.parse(replaceColumnByExpressionSession
|
||||
.getcReplaceExpression());
|
||||
logger.debug("Service Replace Expression:"
|
||||
+ conditionExpression);
|
||||
}
|
||||
|
||||
TDGWTServiceImpl gwtService = new TDGWTServiceImpl();
|
||||
|
||||
String taskId= gwtService.startReplaceColumnByExpression(replaceColumnByExpressionSession, expression, session);
|
||||
|
||||
|
||||
String taskId = gwtService.startReplaceColumnByExpression(
|
||||
replaceColumnByExpressionSession, conditionExpression,
|
||||
replaceExpression, session);
|
||||
return taskId;
|
||||
|
||||
} catch (TDGWTSessionExpiredException e){
|
||||
|
||||
} catch (TDGWTSessionExpiredException e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
|
@ -120,11 +133,7 @@ public class ExpressionServiceImpl extends RemoteServiceServlet implements
|
|||
+ e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve and set Tabular Resource Type
|
||||
*
|
||||
|
|
|
@ -21,10 +21,9 @@ public class C_SubstringByRegex extends C_Expression {
|
|||
super();
|
||||
}
|
||||
|
||||
public C_SubstringByRegex(String id, C_Expression sourceString,
|
||||
public C_SubstringByRegex(C_Expression sourceString,
|
||||
C_Expression regex) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.sourceString = sourceString;
|
||||
this.regex = regex;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.shared.replace;
|
||||
|
||||
public enum ReplaceType {
|
||||
Null("Null"),
|
||||
Value("Value"),
|
||||
ColumnValue("Column Value"),
|
||||
SubstringByRegex("Substring by Regex"),
|
||||
SubstringByIndex("Substring by Index"),
|
||||
SubstringByCharSeq("Substring by Char Seq."),
|
||||
Concat("Concat");
|
||||
|
||||
/**
|
||||
* @param text
|
||||
*/
|
||||
private ReplaceType(final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
private final String id;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
package org.gcube.portlets.user.td.expressionwidget.shared.replace;
|
||||
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Concat;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByIndex;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByRegex;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringPosition;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_ColumnReferencePlaceholder;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.C_TypedColumnReference;
|
||||
import org.gcube.portlets.user.td.expressionwidget.shared.model.leaf.TD_Value;
|
||||
import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType;
|
||||
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeMap;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
|
||||
/**
|
||||
* OperatorTypeMap creates a C_Expression usable client-side
|
||||
*
|
||||
* @author "Giancarlo Panichi" <a
|
||||
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||
*
|
||||
*/
|
||||
public class ReplaceTypeMap {
|
||||
private String readableExpression;
|
||||
|
||||
public ReplaceTypeMap() {
|
||||
|
||||
}
|
||||
|
||||
public C_Expression map(ColumnData column, ReplaceType replaceType,
|
||||
String firstArg, String secondArg) {
|
||||
return map(column, replaceType,firstArg, secondArg, null, null, null, null);
|
||||
}
|
||||
|
||||
public C_Expression map(ColumnData column, ReplaceType replaceType,
|
||||
String firstArg, String secondArg, C_Expression firstE,
|
||||
C_Expression secondE, String readableFirstE, String readableSecondE) {
|
||||
Log.debug("ReplaceTypeMap Map");
|
||||
C_Expression exp = null;
|
||||
readableExpression = new String();
|
||||
if (column.getTrId() == null) {
|
||||
exp = mapPlaceHolder(column, replaceType, firstArg, secondArg,
|
||||
firstE, secondE, readableFirstE,readableSecondE);
|
||||
} else {
|
||||
exp = mapTypedColumnReference(column, replaceType, firstArg,
|
||||
secondArg, firstE, secondE,readableFirstE,readableSecondE);
|
||||
}
|
||||
return exp;
|
||||
}
|
||||
|
||||
public C_Expression mapPlaceHolder(ColumnData column,
|
||||
ReplaceType replaceType, String firstArg, String secondArg,
|
||||
C_Expression firstE, C_Expression secondE,String readableFirstE, String readableSecondE) {
|
||||
Log.debug("OperatorTypeMap Map Place Holder");
|
||||
C_Expression exp = null;
|
||||
Log.debug("Column Data Type Name:" + column.getDataTypeName());
|
||||
ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column
|
||||
.getDataTypeName());
|
||||
Log.debug("Data Type:" + dataType);
|
||||
C_ColumnReferencePlaceholder placeHolder = new C_ColumnReferencePlaceholder(
|
||||
dataType, column.getColumnId());
|
||||
Log.debug("placeHolder:" + placeHolder);
|
||||
String readablePlaceHolder = column.getColumnId();
|
||||
TD_Value fArg, sArg;
|
||||
C_Expression posFrom, posTo;
|
||||
|
||||
switch (replaceType) {
|
||||
case Null:
|
||||
exp = new TD_Value(ColumnDataType.Text, "");
|
||||
readableExpression = "Null()";
|
||||
break;
|
||||
case Value:
|
||||
exp = new TD_Value(dataType, firstArg);
|
||||
readableExpression = "Value(" + firstArg + ")";
|
||||
break;
|
||||
case ColumnValue:
|
||||
exp = placeHolder;
|
||||
readableExpression = "ColumnValue(" + readablePlaceHolder + ")";
|
||||
break;
|
||||
case Concat:
|
||||
exp = new C_Concat(firstE, secondE);
|
||||
readableExpression = "Concat(" + readableFirstE
|
||||
+ ", " + readableSecondE + ")";
|
||||
break;
|
||||
case SubstringByRegex:
|
||||
fArg = new TD_Value(ColumnDataType.Text, firstArg);
|
||||
exp = new C_SubstringByRegex(placeHolder, fArg);
|
||||
readableExpression = "SubStringByRegex(" + readablePlaceHolder
|
||||
+ ", " + firstArg + ")";
|
||||
break;
|
||||
case SubstringByIndex:
|
||||
fArg = new TD_Value(ColumnDataType.Integer, firstArg);
|
||||
sArg = new TD_Value(ColumnDataType.Integer, secondArg);
|
||||
exp = new C_SubstringByIndex(placeHolder, fArg, sArg);
|
||||
readableExpression = "SubstringByIndex(" + readablePlaceHolder
|
||||
+ ", " + firstArg + ", " + secondArg + ")";
|
||||
break;
|
||||
case SubstringByCharSeq:
|
||||
fArg = new TD_Value(ColumnDataType.Text, firstArg);
|
||||
posFrom = new C_SubstringPosition(placeHolder, fArg);
|
||||
sArg = new TD_Value(ColumnDataType.Text, secondArg);
|
||||
posTo = new C_SubstringPosition(placeHolder, fArg);
|
||||
exp = new C_SubstringByIndex(placeHolder, posFrom, posTo);
|
||||
readableExpression = "SubstringByCharSeq(" + readablePlaceHolder
|
||||
+ ", " + firstArg + ", " + secondArg + ")";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return exp;
|
||||
}
|
||||
|
||||
public C_Expression mapTypedColumnReference(ColumnData column,
|
||||
ReplaceType replaceType, String firstArg, String secondArg,
|
||||
C_Expression firstE, C_Expression secondE, String readableFirstE, String readableSecondE) {
|
||||
Log.debug("OperatorTypeMap Map Typed Column Reference");
|
||||
C_Expression exp = null;
|
||||
|
||||
Log.debug("Column Data Type Name:" + column.getDataTypeName());
|
||||
ColumnDataType dataType = ColumnTypeMap.getColumnDataType(column
|
||||
.getDataTypeName());
|
||||
Log.debug("Data Type:" + dataType);
|
||||
C_TypedColumnReference columnReference = new C_TypedColumnReference(
|
||||
column.getTrId(), dataType, column.getColumnId());
|
||||
Log.debug("Typed Column Reference:" + columnReference);
|
||||
String readableColumnReference = column.getLabel();
|
||||
|
||||
TD_Value fArg, sArg;
|
||||
C_Expression posFrom, posTo;
|
||||
|
||||
switch (replaceType) {
|
||||
case Null:
|
||||
exp = new TD_Value(ColumnDataType.Text, "");
|
||||
readableExpression = "Null()";
|
||||
break;
|
||||
case Value:
|
||||
exp = new TD_Value(dataType, firstArg);
|
||||
readableExpression = "Value(" + firstArg + ")";
|
||||
break;
|
||||
case ColumnValue:
|
||||
exp = columnReference;
|
||||
readableExpression = "ColumnValue(" + readableColumnReference + ")";
|
||||
break;
|
||||
case Concat:
|
||||
exp = new C_Concat(firstE, secondE);
|
||||
readableExpression = "Concat(" + readableFirstE
|
||||
+ ", " + readableSecondE + ")";
|
||||
break;
|
||||
case SubstringByRegex:
|
||||
fArg = new TD_Value(ColumnDataType.Text, firstArg);
|
||||
exp = new C_SubstringByRegex(columnReference, fArg);
|
||||
readableExpression = "SubStringByRegex(" + readableColumnReference
|
||||
+ ", " + firstArg + ")";
|
||||
break;
|
||||
case SubstringByIndex:
|
||||
fArg = new TD_Value(ColumnDataType.Integer, firstArg);
|
||||
sArg = new TD_Value(ColumnDataType.Integer, secondArg);
|
||||
exp = new C_SubstringByIndex(columnReference, fArg, sArg);
|
||||
readableExpression = "SubstringByIndex(" + readableColumnReference
|
||||
+ ", " + firstArg + ", " + secondArg + ")";
|
||||
break;
|
||||
case SubstringByCharSeq:
|
||||
fArg = new TD_Value(ColumnDataType.Text, firstArg);
|
||||
posFrom = new C_SubstringPosition(columnReference, fArg);
|
||||
sArg = new TD_Value(ColumnDataType.Text, secondArg);
|
||||
posTo = new C_SubstringPosition(columnReference, fArg);
|
||||
exp = new C_SubstringByIndex(columnReference, posFrom, posTo);
|
||||
readableExpression = "SubstringByCharSeq("
|
||||
+ readableColumnReference + ", " + firstArg + ", "
|
||||
+ secondArg + ")";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return exp;
|
||||
}
|
||||
|
||||
public String getReadableExpression() {
|
||||
return readableExpression;
|
||||
}
|
||||
|
||||
}
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
<!-- Specify the app entry point class. -->
|
||||
<!-- <entry-point class='org.gcube.portlets.user.td.expressionwidget.client.ExpressionWidgetEntry' /> -->
|
||||
<!-- <entry-point class='org.gcube.portlets.user.td.expressionwidget.client.ExpressionWidgetEntry' /> -->
|
||||
|
||||
<!-- Specify the paths for translatable code -->
|
||||
<source path='client' />
|
||||
|
|
Loading…
Reference in New Issue