diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java index 00a93d1..e025664 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnExpressionPanel.java @@ -178,7 +178,7 @@ public class ColumnExpressionPanel extends FramedPanel { public void onSelect(SelectEvent event) { Log.debug("Pressed Apply"); - applyRule(); + applySeleceted(); } }); @@ -305,7 +305,7 @@ public class ColumnExpressionPanel extends FramedPanel { public void onSelect(SelectEvent event) { Log.debug("Pressed Apply"); - applyRule(); + applySeleceted(); } }); @@ -391,10 +391,11 @@ public class ColumnExpressionPanel extends FramedPanel { if (event.getSelectedItem() != null) { ColumnData col = event.getSelectedItem(); Log.debug("Col selected:" + col.toString()); + column=col; btnApply.enable(); conditionWidget.update(col); - } else { + column=null; btnApply.disable(); conditionWidget.update(null); } @@ -453,7 +454,7 @@ public class ColumnExpressionPanel extends FramedPanel { public void onSelect(SelectEvent event) { Log.debug("Pressed Add Filter"); - applyRule(); + applySeleceted(); } }); @@ -470,7 +471,9 @@ public class ColumnExpressionPanel extends FramedPanel { } - protected void applyRule() { + protected void applySeleceted() { + Log.debug("Apply: "+column); + C_Expression exp; try { exp = conditionWidget.getExpression(); @@ -479,7 +482,7 @@ public class ColumnExpressionPanel extends FramedPanel { UtilsGXT3.alert("Attention", e.getLocalizedMessage()); return; } - + switch (type) { case Template: parentRuleDialog.setExpression(exp); @@ -499,7 +502,7 @@ public class ColumnExpressionPanel extends FramedPanel { eventBus.fireEvent(expressionEvent); break; case ColumnFilter: - parentFilterDialog.applyFilter(exp); + parentFilterDialog.applyFilter(column,exp); break; case MultiColumnFilter: parentMultiColumnFilterTabPanel.applyFilter(column, exp); diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnFilterDialog.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnFilterDialog.java index 2be3aec..b23c2fc 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnFilterDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ColumnFilterDialog.java @@ -91,8 +91,6 @@ public class ColumnFilterDialog extends Window implements MonitorDialogListener columnExpressionPanel = new ColumnExpressionPanel(this, column,columns, eventBus); add(columnExpressionPanel); - - } @@ -108,8 +106,9 @@ public class ColumnFilterDialog extends Window implements MonitorDialogListener this.exp = exp; } - protected void applyFilter(C_Expression exp) { + protected void applyFilter(ColumnData column,C_Expression exp) { this.exp = exp; + this.column= column; callApplyFilter(); } @@ -139,24 +138,29 @@ public class ColumnFilterDialog extends Window implements MonitorDialogListener public void onSuccess(ArrayList result) { Log.debug("Retrived column: " + result); columns = result; - removableColumn=new ArrayList(); - for(ColumnData c:columns){ - if(c.getTypeCode().compareTo(ColumnTypeCode.DIMENSION.toString())==0|| - c.getTypeCode().compareTo(ColumnTypeCode.TIMEDIMENSION.toString())==0 ){ - removableColumn.add(c); - } else { - if(columnLocalId!=null && c.getColumnId().compareTo(columnLocalId)==0){ - column=c; - } - } - } - columns.removeAll(removableColumn); + sanitizesColumns(); create(); } }); } + + protected void sanitizesColumns() { + removableColumn=new ArrayList(); + for(ColumnData c:columns){ + if(c.getTypeCode().compareTo(ColumnTypeCode.DIMENSION.toString())==0|| + c.getTypeCode().compareTo(ColumnTypeCode.TIMEDIMENSION.toString())==0 ){ + removableColumn.add(c); + } else { + if(columnLocalId!=null && c.getColumnId().compareTo(columnLocalId)==0){ + column=c; + } + } + } + columns.removeAll(removableColumn); + } + protected void callApplyFilter() { filterColumnSession = new FilterColumnSession(column, exp); @@ -252,4 +256,6 @@ public class ColumnFilterDialog extends Window implements MonitorDialogListener } + + } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java index 55f3dda..e567f65 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java @@ -72,6 +72,8 @@ public class ConditionWidget extends SimpleContainer { protected ColumnData column; protected String readableExpression; + private Radio radioAll; + private Radio radioAny; public ConditionWidget(ColumnData column) { super(); @@ -84,11 +86,12 @@ public class ConditionWidget extends SimpleContainer { } public void update(ColumnData newColumn){ - int count=vert.getWidgetCount(); - for(int i=0; i columns; - - //private String columnName = null; + private EventBus eventBus; private ReplaceColumnByExpressionType replaceColumnByExpressionType; - + private String columnLocalId; + private TRId trId; /** * @@ -81,12 +79,14 @@ public class ReplaceColumnByExpressionDialog extends Window implements * @param columnName * @param eventBus */ - public ReplaceColumnByExpressionDialog(TRId trId, String columnName, + public ReplaceColumnByExpressionDialog(TRId trId, String columnLocalId, EventBus eventBus) { this.eventBus = eventBus; + this.columnLocalId = columnLocalId; + this.trId = trId; replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace; initWindow(); - load(trId, columnName); + load(); } @@ -118,67 +118,13 @@ public class ReplaceColumnByExpressionDialog extends Window implements } + protected void create() { - if (column == null) { - UtilsGXT3.info("Attention ", - "You must select a column!"); - hide(); - return; - } - - if (column.isViewColumn()) { - UtilsGXT3.info("Attention is View Column", - "You can not make expressions on view column for now!"); - hide(); - return; - } - - if (column.getDataTypeName().compareTo(ColumnDataType.Text.toString()) == 0 - ||column.getDataTypeName().compareTo(ColumnDataType.Integer.toString()) == 0 - ||column.getDataTypeName().compareTo(ColumnDataType.Numeric.toString()) == 0 - ||column.getDataTypeName().compareTo(ColumnDataType.Geometry.toString()) == 0 - ) { - setHeight(HEIGHT); - } else { - setHeight(HEIGHT_REDUCE); - } - - if (column.getTypeCode() - .compareTo(ColumnTypeCode.ANNOTATION.toString()) == 0 - || column.getTypeCode().compareTo( - ColumnTypeCode.ATTRIBUTE.toString()) == 0 - || column.getTypeCode().compareTo( - ColumnTypeCode.CODE.toString()) == 0 - || column.getTypeCode().compareTo( - ColumnTypeCode.CODEDESCRIPTION.toString()) == 0 - || column.getTypeCode().compareTo( - ColumnTypeCode.CODENAME.toString()) == 0 - || column.getTypeCode().compareTo( - ColumnTypeCode.MEASURE.toString()) == 0) { - switch (replaceColumnByExpressionType) { - case Replace: - replaceColumnByExpressionPanel = new ReplaceColumnByExpressionPanel( - this, column, eventBus); - break; - case Template: - replaceColumnByExpressionPanel = new ReplaceColumnByExpressionPanel( - this, column, columns, eventBus); - - break; - default: - break; - } - - add(replaceColumnByExpressionPanel); - - } else { - HTML errorMessage = new HTML( - "This type of column is not supported for now!"); - add(errorMessage); - UtilsGXT3.alert("Error", - "This type of column is not supported for now!"); - } + replaceColumnByExpressionPanel = new ReplaceColumnByExpressionPanel( + this, column, columns, eventBus, replaceColumnByExpressionType); + add(replaceColumnByExpressionPanel); } + public C_Expression getExpression() { return cConditionExpression; @@ -189,29 +135,29 @@ public class ReplaceColumnByExpressionDialog extends Window implements this.cConditionExpression = exp; } - protected void applyReplaceColumnByExpression( - boolean allRows,C_Expression cConditionExpression, String replaceValue) { - + protected void applyReplaceColumnByExpression(ColumnData column,boolean allRows, + C_Expression cConditionExpression, String replaceValue) { + this.column=column; this.cConditionExpression = cConditionExpression; - ReplaceColumnByExpressionSession replaceColumnByExpressionSession = new ReplaceColumnByExpressionSession( - column, allRows,cConditionExpression, replaceValue); + column, allRows, cConditionExpression, replaceValue); callApplyReplaceByExpression(replaceColumnByExpressionSession); } - protected void applyReplaceColumnByExpression(boolean allRows, + protected void applyReplaceColumnByExpression(ColumnData column, boolean allRows, C_Expression cConditionExpression, C_Expression cReplaceExpression) { + this.column=column; this.cConditionExpression = cConditionExpression; - + ReplaceColumnByExpressionSession replaceColumnByExpressionSession = new ReplaceColumnByExpressionSession( - column, allRows, cConditionExpression, cReplaceExpression); + column, allRows, cConditionExpression, cReplaceExpression); callApplyReplaceByExpression(replaceColumnByExpressionSession); } - protected void load(TRId trId, String columnName) { - TDGWTServiceAsync.INSTANCE.getColumn(trId, columnName, - new AsyncCallback() { + protected void load() { + TDGWTServiceAsync.INSTANCE.getColumns(trId, + new AsyncCallback>() { public void onFailure(Throwable caught) { if (caught instanceof TDGWTSessionExpiredException) { @@ -231,9 +177,10 @@ public class ReplaceColumnByExpressionDialog extends Window implements } } - public void onSuccess(ColumnData result) { - Log.debug("Retrived column: " + result); - column = result; + public void onSuccess(ArrayList result) { + Log.debug("Retrived columns: " + result); + columns = result; + sanitizesColumns(); create(); } @@ -242,6 +189,28 @@ public class ReplaceColumnByExpressionDialog extends Window implements } + protected void sanitizesColumns() { + ArrayList removableColumn = new ArrayList(); + for (ColumnData c : columns) { + if (c.getTypeCode().compareTo( + ColumnTypeCode.DIMENSION.toString()) == 0 + || c.getTypeCode().compareTo( + ColumnTypeCode.TIMEDIMENSION + .toString()) == 0) { + removableColumn.add(c); + } else { + if (columnLocalId != null + && c.getColumnId().compareTo( + columnLocalId) == 0) { + column = c; + } + } + } + columns.removeAll(removableColumn); + } + + + protected void callApplyReplaceByExpression( ReplaceColumnByExpressionSession replaceColumnByExpressionSession) { Log.debug("Replace Column By Expression Session " @@ -303,7 +272,8 @@ public class ReplaceColumnByExpressionDialog extends Window implements public void operationComplete(OperationResult operationResult) { ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED; ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent( - ChangeTableRequestType.COLUMNFILTER, operationResult.getTrId(), why); + ChangeTableRequestType.COLUMNFILTER, operationResult.getTrId(), + why); eventBus.fireEvent(changeTableRequestEvent); close(); } @@ -316,10 +286,12 @@ public class ReplaceColumnByExpressionDialog extends Window implements } @Override - public void operationStopped(OperationResult operationResult, String reason, String details) { + public void operationStopped(OperationResult operationResult, + String reason, String details) { ChangeTableWhy why = ChangeTableWhy.TABLECURATION; ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent( - ChangeTableRequestType.COLUMNFILTER, operationResult.getTrId(), why); + ChangeTableRequestType.COLUMNFILTER, operationResult.getTrId(), + why); eventBus.fireEvent(changeTableRequestEvent); close(); @@ -337,4 +309,6 @@ public class ReplaceColumnByExpressionDialog extends Window implements } + + } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java index 8629b2a..6db2f80 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByExpressionPanel.java @@ -3,6 +3,7 @@ package org.gcube.portlets.user.td.expressionwidget.client; import java.util.ArrayList; import java.util.Date; +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.type.ReplaceColumnByExpressionType; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException; @@ -14,20 +15,27 @@ import org.gcube.portlets.user.td.widgetcommonevent.client.type.ExpressionType; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_Expression; import org.gcube.portlets.user.td.widgetcommonevent.shared.expression.C_ExpressionContainer; import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnDataType; +import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode; 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.i18n.client.DateTimeFormat; import com.google.gwt.regexp.shared.MatchResult; import com.google.gwt.regexp.shared.RegExp; +import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HasValue; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign; +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.ListStore; import com.sencha.gxt.widget.core.client.FramedPanel; import com.sencha.gxt.widget.core.client.button.TextButton; import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutData; @@ -38,6 +46,7 @@ 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.SelectEvent; import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; +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.FieldLabel; import com.sencha.gxt.widget.core.client.form.FieldSet; @@ -57,10 +66,12 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { private static final String WIDTH = "868px"; private static final String HEIGHT = "454px"; private static final String HEIGHT_REDUCE = "368px"; + private static final String PARENT_HEIGHT = "490px"; + private static final String PARENT_HEIGHT_REDUCE = "404px"; - private static final String CONDITIONWIDTH = "832px"; + private static final String CONDITIONWIDTH = "818px"; private static final String CONDITIONHEIGHT = "120px"; - private static final String CONDITION_LAYOUT_WIDTH = "832px"; + private static final String CONDITION_LAYOUT_WIDTH = "818px"; private static final String REPLACEWIDTH = "832px"; private static final String REPLACEHEIGHT = "120px"; private static final String ALL_ROWS_FIELD_WIDTH = "832px"; @@ -82,6 +93,8 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { private TextButton btnApply; private TextButton btnClose; + private ComboBox comboCols; + private FieldSet conditionsFieldSet; private ConditionWidget conditionWidget; @@ -93,28 +106,84 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { private FieldLabel allRowsField; private boolean allRows; - public ReplaceColumnByExpressionPanel( - ReplaceColumnByExpressionDialog parent, ColumnData column, - EventBus eventBus) { - super(); - this.parent = parent; - this.column = column; - this.eventBus = eventBus; - replaceColumnByExpressionType = ReplaceColumnByExpressionType.Replace; - Log.debug("Column: " + column); - init(); - create(); + private FieldSet replaceValueFieldSet; + + protected void createPArent() { + if (column == null) { + UtilsGXT3.info("Attention ", "You must select a column!"); + hide(); + return; + } + + if (column.isViewColumn()) { + UtilsGXT3.info("Attention is View Column", + "You can not make expressions on view column for now!"); + hide(); + return; + } + + if (column.getDataTypeName().compareTo(ColumnDataType.Text.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Integer.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Numeric.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Geometry.toString()) == 0) { + setHeight(HEIGHT); + } else { + setHeight(HEIGHT_REDUCE); + } + + if (column.getTypeCode() + .compareTo(ColumnTypeCode.ANNOTATION.toString()) == 0 + || column.getTypeCode().compareTo( + ColumnTypeCode.ATTRIBUTE.toString()) == 0 + || column.getTypeCode().compareTo( + ColumnTypeCode.CODE.toString()) == 0 + || column.getTypeCode().compareTo( + ColumnTypeCode.CODEDESCRIPTION.toString()) == 0 + || column.getTypeCode().compareTo( + ColumnTypeCode.CODENAME.toString()) == 0 + || column.getTypeCode().compareTo( + ColumnTypeCode.MEASURE.toString()) == 0) { + switch (replaceColumnByExpressionType) { + case Replace: + // replaceColumnByExpressionPanel = new + // ReplaceColumnByExpressionPanel( + // this, column, eventBus); + break; + case Template: + // replaceColumnByExpressionPanel = new + // ReplaceColumnByExpressionPanel( + // this, column, columns, eventBus, + // replaceColumnByExpressionType); + + break; + default: + break; + } + + // add(replaceColumnByExpressionPanel); + + } else { + HTML errorMessage = new HTML( + "This type of column is not supported for now!"); + add(errorMessage); + UtilsGXT3.alert("Error", + "This type of column is not supported for now!"); + } } public ReplaceColumnByExpressionPanel( ReplaceColumnByExpressionDialog parent, ColumnData column, - ArrayList columns, EventBus eventBus) { + ArrayList columns, EventBus eventBus, + ReplaceColumnByExpressionType replaceColumnByExpressionType) { super(); this.parent = parent; this.column = column; this.columns = columns; this.eventBus = eventBus; - replaceColumnByExpressionType = ReplaceColumnByExpressionType.Template; + this.replaceColumnByExpressionType = replaceColumnByExpressionType; Log.debug("Column: " + column); Log.debug("Columns: " + columns); init(); @@ -123,6 +192,16 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { protected void init() { setWidth(WIDTH); + calcHeight(); + + setBodyBorder(false); + setHeaderVisible(false); + // Important: fixed rendering of widgets + forceLayoutOnResize = true; + + } + + protected void calcHeight() { if (column != null && (column.getDataTypeName().compareTo( ColumnDataType.Text.toString()) == 0 @@ -132,15 +211,13 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { ColumnDataType.Numeric.toString()) == 0 || column .getDataTypeName().compareTo( ColumnDataType.Geometry.toString()) == 0)) { + parent.setHeight(PARENT_HEIGHT); setHeight(HEIGHT); + } else { + parent.setHeight(PARENT_HEIGHT_REDUCE); setHeight(HEIGHT_REDUCE); } - setBodyBorder(false); - setHeaderVisible(false); - // Important: fixed rendering of widgets - forceLayoutOnResize = true; - } protected void create() { @@ -160,11 +237,29 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { VerticalLayoutContainer propertiesLayout = new VerticalLayoutContainer(); properties.add(propertiesLayout); - TextField columnName = new TextField(); - columnName.setToolTip("Column"); - columnName.setReadOnly(true); - columnName.setValue(column.getLabel()); - propertiesLayout.add(new FieldLabel(columnName, "Column"), + // Combo Column + ColumnDataPropertiesCombo propsCols = GWT + .create(ColumnDataPropertiesCombo.class); + Log.debug("Props: " + propsCols); + final ListStore storeCols = new ListStore( + propsCols.id()); + Log.debug("Store Col: " + storeCols); + storeCols.addAll(columns); + + Log.debug("StoreCol created"); + comboCols = new ComboBox(storeCols, propsCols.label()); + + Log.debug("Combo Threshold created"); + + comboCols.addSelectionHandler(comboColsSelection()); + + comboCols.setEmptyText("Select a column..."); + comboCols.setEditable(false); + comboCols.setTriggerAction(TriggerAction.ALL); + + setSelectedColumn(); + + propertiesLayout.add(new FieldLabel(comboCols, "Column"), new VerticalLayoutData(1, -1)); // Conditions @@ -221,57 +316,11 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { conditionsFieldSet.add(conditionsVerticalLayout); // Value - FieldSet replaceValueFieldSet = new FieldSet(); + replaceValueFieldSet = new FieldSet(); replaceValueFieldSet.setHeadingText("Replace Value"); replaceValueFieldSet.setCollapsible(false); - VerticalLayoutContainer replaceValueFieldSetLayout = new VerticalLayoutContainer(); - replaceValueFieldSet.add(replaceValueFieldSetLayout); - - if (column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) { - replaceValueDate = new DateField(); - replaceValueDate.setToolTip("Replace Value"); - replaceValueFieldSetLayout.add(new FieldLabel(replaceValueDate, - "Replace Value"), new VerticalLayoutData(1, -1)); - - } else { - if (column.getDataTypeName().compareTo( - ColumnDataType.Text.toString()) == 0 - || column.getDataTypeName().compareTo( - ColumnDataType.Integer.toString()) == 0 - || column.getDataTypeName().compareTo( - ColumnDataType.Numeric.toString()) == 0 - || column.getDataTypeName().compareTo( - ColumnDataType.Geometry.toString()) == 0) { - switch (replaceColumnByExpressionType) { - case Replace: - replaceWidget = new ReplaceWidget(column, REPLACEWIDTH, - REPLACEHEIGHT, eventBus); - break; - case Template: - replaceWidget = new ReplaceWidget(column, columns, - REPLACEWIDTH, REPLACEHEIGHT, eventBus); - break; - default: - Log.debug("Attention Replace Widget have not a valid type"); - UtilsGXT3.alert("Attention", - "Attention Replace Widget have not a valid type"); - if (parent != null) { - parent.hide(); - } - return; - - } - replaceValueFieldSetLayout.add(replaceWidget, - new VerticalLayoutData(1, -1)); - } else { - replaceValue = new TextField(); - replaceValue.setToolTip("Replace Value"); - replaceValue.setValue(""); - replaceValueFieldSetLayout.add(new FieldLabel(replaceValue, - "Replace Value"), new VerticalLayoutData(1, -1)); - } - } + calcReplaceValue(); // btnApply = new TextButton("Apply"); @@ -287,6 +336,11 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { } }); + if(column==null){ + btnApply.disable(); + } + + btnClose = new TextButton("Close"); btnClose.setIcon(ExpressionResources.INSTANCE.close()); @@ -316,6 +370,135 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { } + protected void calcReplaceValue() { + replaceValueFieldSet.clear(); + VerticalLayoutContainer replaceValueFieldSetLayout = new VerticalLayoutContainer(); + replaceValueFieldSet.add(replaceValueFieldSetLayout); + + if (column == null) { + replaceValue = new TextField(); + replaceValue.setToolTip("Replace Value"); + replaceValue.setValue(""); + replaceValueFieldSetLayout.add(new FieldLabel(replaceValue, + "Replace Value"), new VerticalLayoutData(1, -1)); + } else { + if (column.getDataTypeName().compareTo( + ColumnDataType.Date.toString()) == 0) { + replaceValueDate = new DateField(); + replaceValueDate.setToolTip("Replace Value"); + replaceValueFieldSetLayout.add(new FieldLabel(replaceValueDate, + "Replace Value"), new VerticalLayoutData(1, -1)); + + } else { + if (column.getDataTypeName().compareTo( + ColumnDataType.Text.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Integer.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Numeric.toString()) == 0 + || column.getDataTypeName().compareTo( + ColumnDataType.Geometry.toString()) == 0) { + switch (replaceColumnByExpressionType) { + case Replace: + replaceWidget = new ReplaceWidget(column, REPLACEWIDTH, + REPLACEHEIGHT, eventBus); + break; + case Template: + replaceWidget = new ReplaceWidget(column, columns, + REPLACEWIDTH, REPLACEHEIGHT, eventBus); + break; + default: + Log.debug("Attention Replace Widget have not a valid type"); + UtilsGXT3 + .alert("Attention", + "Attention Replace Widget have not a valid type"); + return; + + } + replaceValueFieldSetLayout.add(replaceWidget, + new VerticalLayoutData(1, -1)); + } else { + replaceValue = new TextField(); + replaceValue.setToolTip("Replace Value"); + replaceValue.setValue(""); + replaceValueFieldSetLayout.add(new FieldLabel(replaceValue, + "Replace Value"), new VerticalLayoutData(1, -1)); + } + } + } + } + + protected void setSelectedColumn() { + if (column == null) { + + } else { + ColumnTypeCode typeCode = ColumnTypeCode + .getColumnTypeCodeFromId(column.getTypeCode()); + HTML errorMessage; + if (typeCode == null) { + errorMessage = new HTML( + "This column has column data type null!"); + UtilsGXT3.alert("Error", + "This column has column data type null!!"); + return; + } + + switch (typeCode) { + case ANNOTATION: + case ATTRIBUTE: + case CODE: + case CODEDESCRIPTION: + case CODENAME: + case MEASURE: + comboCols.setValue(column); + break; + case DIMENSION: + case TIMEDIMENSION: + errorMessage = new HTML( + "This type of column is not supported for now!"); + add(errorMessage); + UtilsGXT3.alert("Error", + "This type of column is not supported for now!"); + break; + default: + errorMessage = new HTML( + "This type of column is not supported for now!"); + add(errorMessage); + UtilsGXT3.alert("Error", + "This type of column is not supported for now!"); + break; + + } + } + } + + protected SelectionHandler comboColsSelection() { + SelectionHandler selectionHandler = new SelectionHandler() { + + @Override + public void onSelection(SelectionEvent event) { + if (event.getSelectedItem() != null) { + ColumnData col = event.getSelectedItem(); + Log.debug("Col selected:" + col.toString()); + column=col; + btnApply.enable(); + conditionWidget.update(col); + calcReplaceValue(); + + } else { + column=null; + btnApply.disable(); + conditionWidget.update(null); + calcReplaceValue(); + } + calcHeight(); + parent.forceLayout(); + } + }; + + return selectionHandler; + } + protected void callAllRowChange(ValueChangeEvent> event) { ToggleGroup group = (ToggleGroup) event.getSource(); Radio radio = (Radio) group.getValue(); @@ -402,6 +585,12 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { protected void callApplyReplaceColumnByExpression( C_Expression cConditionExpression, String replaceValue) { + if(column==null){ + UtilsGXT3.alert("Attention", "Select a valid column!"); + return; + } + + switch (replaceColumnByExpressionType) { case Template: ExpressionEvent expressionEvent = new ExpressionEvent( @@ -409,11 +598,10 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { C_ExpressionContainer container; if (allRows) { container = new C_ExpressionContainer( - C_ExpressionContainer.Contains.C_Expression, - true,null, - "AllRows()"); + C_ExpressionContainer.Contains.C_Expression, true, + null, "AllRows()"); } else { - container = new C_ExpressionContainer( + container = new C_ExpressionContainer( C_ExpressionContainer.Contains.C_Expression, cConditionExpression, conditionWidget.getReadableExpression()); @@ -429,8 +617,8 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { eventBus.fireEvent(expressionEvent); break; case Replace: - parent.applyReplaceColumnByExpression(allRows,cConditionExpression, - replaceValue); + parent.applyReplaceColumnByExpression(column,allRows, + cConditionExpression, replaceValue); break; default: break; @@ -440,6 +628,11 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { protected void callApplyReplaceColumnByExpression( C_Expression cConditionExpression, C_Expression cReplaceExpression) { + if(column==null){ + UtilsGXT3.alert("Attention", "Select a valid column!"); + return; + } + switch (replaceColumnByExpressionType) { case Template: ExpressionEvent expressionEvent = new ExpressionEvent( @@ -447,14 +640,13 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { C_ExpressionContainer conditionExpressionContainer; if (allRows) { conditionExpressionContainer = new C_ExpressionContainer( - C_ExpressionContainer.Contains.C_Expression, - true,null, - "AllRows()"); + C_ExpressionContainer.Contains.C_Expression, true, + null, "AllRows()"); } else { conditionExpressionContainer = new C_ExpressionContainer( - C_ExpressionContainer.Contains.C_Expression, - cConditionExpression, - conditionWidget.getReadableExpression()); + C_ExpressionContainer.Contains.C_Expression, + cConditionExpression, + conditionWidget.getReadableExpression()); } expressionEvent .setC_ConditionExpressionContainer(conditionExpressionContainer); @@ -473,8 +665,8 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { eventBus.fireEvent(expressionEvent); break; case Replace: - parent.applyReplaceColumnByExpression(allRows,cConditionExpression, - cReplaceExpression); + parent.applyReplaceColumnByExpression(column, allRows, + cConditionExpression, cReplaceExpression); break; default: break; diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java index 522c6a6..1ab7236 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceWidget.java @@ -986,11 +986,11 @@ public class ReplaceWidget extends SimpleContainer { ComboBox comboColumns = (ComboBox) horiz .getItemByItemId(itemIdComboColumns); Log.debug("combo columns: " + comboColumns.getCurrentValue()); - ColumnData column = comboColumns.getCurrentValue(); + ColumnData columnOfCombo = comboColumns.getCurrentValue(); firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArg); secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArg); - Log.debug("[column: " + column + ", firstArg: " + Log.debug("[combo column: " + columnOfCombo + ", firstArg: " + firstArg.getCurrentValue() + ", secondArg: " + secondArg.getCurrentValue() + "]"); @@ -1015,7 +1015,7 @@ public class ReplaceWidget extends SimpleContainer { switch (replaceColumnByExpressionType) { case Replace: expLeaf = mapReplace.map( - column, + columnOfCombo, ColumnDataType.Text, comboLeafReplaceType, firstArg == null ? null : firstArg @@ -1025,7 +1025,7 @@ public class ReplaceWidget extends SimpleContainer { break; case Template: expLeaf = mapReplace.map( - column, + columnOfCombo, ColumnDataType.Text, comboLeafReplaceType, firstArg == null ? null : firstArg @@ -1035,7 +1035,7 @@ public class ReplaceWidget extends SimpleContainer { break; default: expLeaf = mapReplace.map( - column, + columnOfCombo, ColumnDataType.Text, comboLeafReplaceType, firstArg == null ? null : firstArg @@ -1059,7 +1059,7 @@ public class ReplaceWidget extends SimpleContainer { switch (replaceColumnByExpressionType) { case Replace: exp = mapReplace.map( - column, + columnOfCombo, targetType, comboOperationsReplaceType, firstArg == null ? null : firstArg @@ -1072,7 +1072,7 @@ public class ReplaceWidget extends SimpleContainer { break; case Template: exp = mapReplace.map( - column, + columnOfCombo, targetType, comboOperationsReplaceType, firstArg == null ? null : firstArg @@ -1085,7 +1085,7 @@ public class ReplaceWidget extends SimpleContainer { break; default: exp = mapReplace.map( - column, + columnOfCombo, targetType, comboOperationsReplaceType, firstArg == null ? null : firstArg @@ -1123,13 +1123,17 @@ public class ReplaceWidget extends SimpleContainer { comboLeafReplaceType = comboLeaf.getCurrentValue() .getReplaceType(); - cType = ColumnDataType.getColumnDataTypeFromId(column + + if(columnOfCombo==null){ + throw new ReplaceTypeMapException("Selected a valid column!"); + } + cType = ColumnDataType.getColumnDataTypeFromId(columnOfCombo .getDataTypeName()); switch (replaceColumnByExpressionType) { case Replace: expLeaf = mapReplace.map( - column, + columnOfCombo, cType, comboLeafReplaceType, firstArg == null ? null : firstArg @@ -1139,7 +1143,7 @@ public class ReplaceWidget extends SimpleContainer { break; case Template: expLeaf = mapReplace.map( - column, + columnOfCombo, cType, comboLeafReplaceType, firstArg == null ? null : firstArg @@ -1149,7 +1153,7 @@ public class ReplaceWidget extends SimpleContainer { break; default: expLeaf = mapReplace.map( - column, + columnOfCombo, cType, comboLeafReplaceType, firstArg == null ? null : firstArg @@ -1172,7 +1176,7 @@ public class ReplaceWidget extends SimpleContainer { switch (replaceColumnByExpressionType) { case Replace: exp = mapReplace.map( - column, + columnOfCombo, targetType, comboOperationsReplaceType, firstArg == null ? null : firstArg @@ -1186,7 +1190,7 @@ public class ReplaceWidget extends SimpleContainer { break; case Template: exp = mapReplace.map( - column, + columnOfCombo, targetType, comboOperationsReplaceType, firstArg == null ? null : firstArg @@ -1200,7 +1204,7 @@ public class ReplaceWidget extends SimpleContainer { break; default: exp = mapReplace.map( - column, + columnOfCombo, targetType, comboOperationsReplaceType, firstArg == null ? null : firstArg @@ -1226,7 +1230,7 @@ public class ReplaceWidget extends SimpleContainer { switch (replaceColumnByExpressionType) { case Replace: exp = mapReplace.map( - column, + columnOfCombo, targetType, comboOperationsReplaceType, firstArg == null ? null : firstArg @@ -1236,7 +1240,7 @@ public class ReplaceWidget extends SimpleContainer { break; case Template: exp = mapReplace.map( - column, + columnOfCombo, targetType, comboOperationsReplaceType, firstArg == null ? null : firstArg @@ -1246,7 +1250,7 @@ public class ReplaceWidget extends SimpleContainer { break; default: exp = mapReplace.map( - column, + columnOfCombo, targetType, comboOperationsReplaceType, firstArg == null ? null : firstArg