diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/MultiColumnExpressionPanel.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/MultiColumnExpressionPanel.java index 6ae6c13..15ac304 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/MultiColumnExpressionPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/MultiColumnExpressionPanel.java @@ -58,6 +58,9 @@ import com.sencha.gxt.widget.core.client.info.Info; * */ public class MultiColumnExpressionPanel extends FramedPanel { + private static final String WIDTH = "929px"; + private static final String HEIGHT = "352px"; + private static final String ROW_DELETE_BY_EXPRESSION_HEIGHT = "388px"; private static final String RULE_DESCRIPTION_HEIGHT = "44px"; private static final String RULE_PLACE_HOLDER_ID = "Column"; @@ -65,15 +68,13 @@ public class MultiColumnExpressionPanel extends FramedPanel { ColumnFilter, RowDeleteByExpression, Template, Rule; } - private static final String WIDTH = "920px"; - private static final String HEIGHT = "352px"; - private static final String RULE_HEIGHT = "388px"; + private MultiColumnExpressionPanelType type; - private TemplateColumnExpressionDialog parentTemplateDialog; + private TemplateMultiColumnExpressionDialog parentTemplateDialog; private MultiColumnFilterDialog parentMultiFilterDialog; - private RowsDeleteByExpressionDialog parentRowsDeleteByExpressionDialog; + private RowsDeleteByMultiColumnExpressionDialog parentRowsDeleteByExpressionDialog; private ColumnData column; private ArrayList columns; @@ -100,80 +101,71 @@ public class MultiColumnExpressionPanel extends FramedPanel { /** * - * @param parentMultiColumnFilterDialog + * @param parent * @param column * @param columns * @param eventBus */ - public MultiColumnExpressionPanel(MultiColumnFilterDialog parentMultiColumnFilterDialog, + public MultiColumnExpressionPanel(MultiColumnFilterDialog parent, ArrayList columns, EventBus eventBus) { super(); setWidth(WIDTH); setHeight(HEIGHT); type = MultiColumnExpressionPanelType.ColumnFilter; - this.parentMultiFilterDialog = parentMultiColumnFilterDialog; + this.parentMultiFilterDialog = parent; this.columns = columns; - Log.debug("Column:" + column); createOnFilter(); } /** * - * @param parentRowsDeleteByExpressionDialog + * @param parent * @param column * @param columns * @param eventBus */ public MultiColumnExpressionPanel( - RowsDeleteByExpressionDialog parentRowsDeleteByExpressionDialog, - ColumnData column, ArrayList columns, EventBus eventBus) { + RowsDeleteByMultiColumnExpressionDialog parent, + ArrayList columns, EventBus eventBus) { super(); setWidth(WIDTH); - setHeight(RULE_HEIGHT); + setHeight(ROW_DELETE_BY_EXPRESSION_HEIGHT); type = MultiColumnExpressionPanelType.RowDeleteByExpression; - this.parentRowsDeleteByExpressionDialog = parentRowsDeleteByExpressionDialog; - this.column = column; + this.parentRowsDeleteByExpressionDialog = parent; this.columns = columns; - Log.debug("Column:" + column); createOnRowsDeleteByExpression(); } /** * - * @param parentColumnExpressionDialog + * @param parent * @param column * @param eventBus */ public MultiColumnExpressionPanel( - TemplateColumnExpressionDialog parentColumnExpressionDialog, - ColumnData column, EventBus eventBus) { + TemplateMultiColumnExpressionDialog parent, + ArrayList columns, EventBus eventBus) { super(); setWidth(WIDTH); setHeight(HEIGHT); type = MultiColumnExpressionPanelType.Template; - this.parentTemplateDialog = parentColumnExpressionDialog; - this.column = column; - this.columns = null; - Log.debug("Column:" + column); - + this.parentTemplateDialog = parent; + this.columns = columns; createOnTemplate(); } /** * - * @param parentRuleDialog + * @param parent * @param eventBus */ - public MultiColumnExpressionPanel(RuleDialog parentRuleDialog, EventBus eventBus) { + public MultiColumnExpressionPanel(RuleDialog parent, EventBus eventBus) { super(); setWidth(WIDTH); setHeight(HEIGHT); type = MultiColumnExpressionPanelType.Rule; - this.parentRuleDialog = parentRuleDialog; - this.column = null; + this.parentRuleDialog = parent; this.columns = null; - Log.debug("Column:" + column); - createOnRule(); } @@ -205,14 +197,11 @@ public class MultiColumnExpressionPanel extends FramedPanel { flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); flowButton.setPack(BoxLayoutPack.CENTER); - - conditionsField = new FieldSet(); conditionsField.setHeadingText("Conditions"); conditionsField.setCollapsible(false); conditionWidget = new ConditionOnMultiColumnWidget(columns); - Log.debug("ConditionWidget" + conditionWidget); conditionsField.add(conditionWidget); btnApply = new TextButton("Save"); @@ -543,7 +532,7 @@ public class MultiColumnExpressionPanel extends FramedPanel { setHeaderVisible(false); VerticalLayoutContainer basicLayout = new VerticalLayoutContainer(); - basicLayout.setAdjustForScroll(false); + basicLayout.setAdjustForScroll(true); HBoxLayoutContainer flowButton = new HBoxLayoutContainer(); flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); @@ -554,7 +543,6 @@ public class MultiColumnExpressionPanel extends FramedPanel { conditionsField.setCollapsible(false); conditionWidget = new ConditionOnMultiColumnWidget(columns); - Log.debug("ConditionWidget" + conditionWidget); conditionsField.add(conditionWidget); btnApply = new TextButton("Apply"); @@ -585,7 +573,7 @@ public class MultiColumnExpressionPanel extends FramedPanel { flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4))); - basicLayout.add(conditionsField, new VerticalLayoutData(1, -1, + basicLayout.add(conditionsField, new VerticalLayoutData(-1, -1, new Margins(1))); basicLayout.add(flowButton, new VerticalLayoutData(1, 36, new Margins( 5, 2, 5, 2))); @@ -603,16 +591,10 @@ public class MultiColumnExpressionPanel extends FramedPanel { VerticalLayoutContainer basicLayout = new VerticalLayoutContainer(); basicLayout.setAdjustForScroll(true); - HBoxLayoutContainer flowButton = new HBoxLayoutContainer(); flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); flowButton.setPack(BoxLayoutPack.CENTER); - - - - - - // + conditionsField = new FieldSet(); conditionsField.setHeadingText("Conditions"); conditionsField.setCollapsible(false); @@ -621,6 +603,7 @@ public class MultiColumnExpressionPanel extends FramedPanel { Log.debug("ConditionWidget" + conditionWidget); conditionsField.add(conditionWidget); + btnApply = new TextButton("Delete"); btnApply.setIcon(ExpressionResources.INSTANCE .tableRowDeleteByExpression()); @@ -634,14 +617,12 @@ public class MultiColumnExpressionPanel extends FramedPanel { } }); - if (column == null) { - btnApply.disable(); - } + btnClose = new TextButton("Close"); btnClose.setIcon(ExpressionResources.INSTANCE.close()); btnClose.setIconAlign(IconAlign.RIGHT); - btnClose.setToolTip("Cancel filter"); + btnClose.setToolTip("Cancel"); btnClose.addSelectHandler(new SelectHandler() { public void onSelect(SelectEvent event) { @@ -652,12 +633,15 @@ public class MultiColumnExpressionPanel extends FramedPanel { flowButton.add(btnApply, new BoxLayoutData(new Margins(2, 4, 2, 4))); flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4))); + basicLayout.add(conditionsField, new VerticalLayoutData(1, -1, new Margins(1))); basicLayout.add(flowButton, new VerticalLayoutData(1, 36, new Margins( 5, 2, 5, 2))); add(basicLayout); + + } @@ -792,7 +776,7 @@ public class MultiColumnExpressionPanel extends FramedPanel { return; } C_Expression notExp = new C_Not(exp); - parentRowsDeleteByExpressionDialog.deleteRowsByExpression(column, + parentRowsDeleteByExpressionDialog.deleteRowsByExpression( notExp); break; diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/MultiColumnFilterDialog.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/MultiColumnFilterDialog.java index 5f3266e..500b7f4 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/MultiColumnFilterDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/MultiColumnFilterDialog.java @@ -37,13 +37,11 @@ import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; * */ public class MultiColumnFilterDialog extends Window implements MonitorDialogListener { - private static final String WIDTH = "932px"; + private static final String WIDTH = "940px"; private static final String HEIGHT = "388px"; private MultiColumnExpressionPanel multiColumnExpressionPanel; private C_Expression exp = null; private TRId trId; - private ColumnData column = null; - private String columnLocalId = null; private ArrayList columns=null; private ArrayList removableColumn=null; private EventBus eventBus; @@ -151,9 +149,7 @@ public class MultiColumnFilterDialog extends Window implements MonitorDialogList c.getTypeCode().compareTo(ColumnTypeCode.TIMEDIMENSION.toString())==0 ){ removableColumn.add(c); } else { - if(columnLocalId!=null && c.getColumnId().compareTo(columnLocalId)==0){ - column=c; - } + } } columns.removeAll(removableColumn); 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 74bbb54..ec7382c 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 @@ -242,7 +242,6 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { conditionWidget = new ConditionWidget(column, CONDITIONWIDTH, CONDITIONHEIGHT); conditionWidget.setEnabled(false); - Log.debug("ConditionWidget" + conditionWidget); conditionsVerticalLayout.add(allRowsField, new VerticalLayoutData(100, -1, new Margins(0))); @@ -371,10 +370,8 @@ public class ReplaceColumnByExpressionPanel extends FramedPanel { .getColumnTypeCodeFromId(column.getTypeCode()); HTML errorMessage; if (typeCode == null) { - errorMessage = new HTML( - "This column has column type code null!"); - UtilsGXT3.alert("Error", - "This column has column type code null!!"); + Log.debug( + "This column has column type code null, Dimension and TimeDimesion not supported for now!"); return; } diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByMultiColumnExpressionDialog.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByMultiColumnExpressionDialog.java new file mode 100644 index 0000000..7abb03d --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByMultiColumnExpressionDialog.java @@ -0,0 +1,330 @@ +package org.gcube.portlets.user.td.expressionwidget.client; + +import java.util.ArrayList; + +import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; +import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync; +import org.gcube.portlets.user.td.expressionwidget.client.type.ReplaceExpressionType; +import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3; +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; +import org.gcube.portlets.user.td.gwtservice.shared.tr.column.ReplaceColumnByExpressionSession; +import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialog; +import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialogListener; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.ChangeTableRequestEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableWhy; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; +import org.gcube.portlets.user.td.widgetcommonevent.shared.OperationResult; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; +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.ColumnMockUp; +import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.web.bindery.event.shared.EventBus; +import com.sencha.gxt.widget.core.client.Window; +import com.sencha.gxt.widget.core.client.event.SelectEvent; +import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class ReplaceColumnByMultiColumnExpressionDialog extends Window implements + MonitorDialogListener { + private static final String WIDTH = "950px"; + private static final String HEIGHT = "490px"; + // private static final String HEIGHT_REDUCE = "404px"; + + private ReplaceColumnByMultiColumnExpressionPanel replaceColumnByMultiColumnExpressionPanel; + private C_Expression cConditionExpression = null; + private ColumnData column = null; + private ArrayList columns; + + private EventBus eventBus; + private ReplaceExpressionType replaceExpressionType; + // private String columnLocalId; + private TRId trId; + + /** + * + * Columns must have set columnId, label, columnTypeCode and ColumnDataType + * + * @param column + * The column selected + * @param columns + * @param eventBus + */ + public ReplaceColumnByMultiColumnExpressionDialog(ColumnMockUp columnMockUp, + ArrayList columnMockUpList, EventBus eventBus) { + this.eventBus = eventBus; + column = new ColumnData(); + column.setColumnId(columnMockUp.getColumnId()); + column.setLabel(columnMockUp.getLabel()); + column.setDataTypeName(columnMockUp.getColumnDataType().toString()); + column.setTypeCode(columnMockUp.getColumnType().toString()); + + columns = new ArrayList(); + for (ColumnMockUp colMock : columnMockUpList) { + ColumnData col = new ColumnData(); + col.setColumnId(colMock.getColumnId()); + col.setLabel(colMock.getLabel()); + col.setDataTypeName(colMock.getColumnDataType().toString()); + col.setTypeCode(colMock.getColumnType().toString()); + columns.add(col); + } + + replaceExpressionType = ReplaceExpressionType.Template; + initWindow(); + sanitizesColumns(); + create(); + + } + + /** + * + * @param trId + * @param columnName + * @param eventBus + */ + public ReplaceColumnByMultiColumnExpressionDialog(TRId trId, String columnId, + EventBus eventBus) { + this.eventBus = eventBus; + this.trId = trId; + if (columnId == null) { + column=null; + } else { + column = new ColumnData(); + column.setColumnId(columnId); + } + replaceExpressionType = ReplaceExpressionType.Replace; + initWindow(); + load(); + + } + + protected void initWindow() { + setWidth(WIDTH); + setHeight(HEIGHT); + setBodyBorder(false); + setResizable(false); + setHeadingText("Replace Column By Expression"); + setClosable(true); + getHeader().setIcon( + ExpressionResources.INSTANCE.columnReplaceByExpression()); + + } + + /** + * {@inheritDoc} + */ + @Override + protected void initTools() { + super.initTools(); + + closeBtn.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + close(); + } + }); + + } + + protected void create() { + replaceColumnByMultiColumnExpressionPanel = new ReplaceColumnByMultiColumnExpressionPanel( + this, column, columns, eventBus, replaceExpressionType); + add(replaceColumnByMultiColumnExpressionPanel); + } + + public C_Expression getExpression() { + return cConditionExpression; + } + + protected void setExpression(C_Expression exp) { + Log.debug("New Expression set:" + exp.toString()); + this.cConditionExpression = exp; + } + + 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); + callApplyReplaceByExpression(replaceColumnByExpressionSession); + } + + 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); + callApplyReplaceByExpression(replaceColumnByExpressionSession); + } + + protected void load() { + TDGWTServiceAsync.INSTANCE.getColumns(trId, + new AsyncCallback>() { + + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + if (caught instanceof TDGWTIsLockedException) { + Log.error(caught.getLocalizedMessage()); + UtilsGXT3.alert("Error Locked", + caught.getLocalizedMessage()); + } else { + Log.error("Error retrieving column: " + + caught.getMessage()); + UtilsGXT3.alert("Error retrieving column", + caught.getMessage()); + } + } + } + + public void onSuccess(ArrayList result) { + Log.debug("Retrived columns: " + result); + columns = result; + sanitizesColumns(); + create(); + + } + + }); + + } + + 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 (c.getColumnId() != null && column != null + && column.getColumnId() != null + && !column.getColumnId().isEmpty() + && c.getColumnId().compareTo(column.getColumnId()) == 0) { + column = c; + } + } + } + columns.removeAll(removableColumn); + } + + protected void callApplyReplaceByExpression( + ReplaceColumnByExpressionSession replaceColumnByExpressionSession) { + Log.debug("Replace Column By Expression Session " + + replaceColumnByExpressionSession); + + ExpressionServiceAsync.INSTANCE.startReplaceColumnByExpression( + replaceColumnByExpressionSession, new AsyncCallback() { + + @Override + public void onSuccess(String taskId) { + Log.debug("Submitted replace column by expression"); + openMonitorDialog(taskId); + + } + + @Override + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + if (caught instanceof TDGWTIsLockedException) { + Log.error(caught.getLocalizedMessage()); + UtilsGXT3.alert("Error Locked", + caught.getLocalizedMessage()); + } else { + if (caught instanceof TDGWTIsFinalException) { + Log.error(caught.getLocalizedMessage()); + UtilsGXT3.alert("Error Final", + caught.getLocalizedMessage()); + } else { + Log.error("Error submitting replace column by expression: " + + caught.getLocalizedMessage()); + caught.printStackTrace(); + UtilsGXT3 + .alert("Error submitting replace column by expression", + caught.getLocalizedMessage()); + } + } + } + + } + }); + + } + + protected void close() { + hide(); + } + + // / + protected void openMonitorDialog(String taskId) { + MonitorDialog monitorDialog = new MonitorDialog(taskId, eventBus); + monitorDialog.addProgressDialogListener(this); + monitorDialog.show(); + } + + @Override + public void operationComplete(OperationResult operationResult) { + ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED; + ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent( + ChangeTableRequestType.COLUMNFILTER, operationResult.getTrId(), + why); + eventBus.fireEvent(changeTableRequestEvent); + close(); + } + + @Override + public void operationFailed(Throwable caught, String reason, String details) { + UtilsGXT3.alert(reason, details); + close(); + + } + + @Override + public void operationStopped(OperationResult operationResult, + String reason, String details) { + ChangeTableWhy why = ChangeTableWhy.TABLECURATION; + ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent( + ChangeTableRequestType.COLUMNFILTER, operationResult.getTrId(), + why); + eventBus.fireEvent(changeTableRequestEvent); + close(); + + } + + @Override + public void operationAborted() { + close(); + + } + + @Override + public void operationPutInBackground() { + close(); + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByMultiColumnExpressionPanel.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByMultiColumnExpressionPanel.java new file mode 100644 index 0000000..23e42a1 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ReplaceColumnByMultiColumnExpressionPanel.java @@ -0,0 +1,699 @@ +package org.gcube.portlets.user.td.expressionwidget.client; + +import java.util.ArrayList; +import java.util.Date; + +import org.gcube.portlets.user.td.expressionwidget.client.expression.ConditionOnMultiColumnWidget; +import org.gcube.portlets.user.td.expressionwidget.client.expression.ReplaceWidget; +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.ReplaceExpressionType; +import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException; +import org.gcube.portlets.user.td.expressionwidget.shared.exception.ReplaceTypeMapException; +import org.gcube.portlets.user.td.monitorwidget.client.utils.UtilsGXT3; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.ExpressionWrapperEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.expression.C_ExpressionContainer; +import org.gcube.portlets.user.td.widgetcommonevent.client.expression.ExpressionWrapper; +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 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; +import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutPack; +import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer; +import com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.HBoxLayoutAlign; +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; +import com.sencha.gxt.widget.core.client.form.Radio; +import com.sencha.gxt.widget.core.client.form.TextField; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class ReplaceColumnByMultiColumnExpressionPanel extends FramedPanel { + private static final String GEOMETRY_REGEXPR = "(\\s*POINT\\s*\\(\\s*(-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*\\)\\s*$)" + + "|(\\s*LINESTRING\\s*\\((\\s*(-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*,)+\\s*((-)?\\d+(\\.\\d+)?\\s+(-)?\\d+(\\.\\d+)?\\s*)\\)\\s*$)"; + + private static final String WIDTH = "938px"; + 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 = "890px"; + private static final String CONDITIONHEIGHT = "120px"; + private static final String CONDITION_LAYOUT_WIDTH = "890px"; + private static final String REPLACEWIDTH = "894px"; + private static final String REPLACEHEIGHT = "120px"; + private static final String ALL_ROWS_FIELD_WIDTH = "884px"; + + private static final String RADIO_LABEL_BY_CONDITION = "By Condition"; + private static final String RADIO_LABEL_ALL_ROWS = "All Rows"; + + private EventBus eventBus; + + private ReplaceColumnByMultiColumnExpressionDialog parent; + + private ColumnData column; + private ArrayList columns; + + private ReplaceExpressionType replaceExpressionType; + + private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); + + private TextButton btnApply; + private TextButton btnClose; + + private ComboBox comboCols; + + private FieldSet conditionsFieldSet; + private ConditionOnMultiColumnWidget conditionWidget; + + private ReplaceWidget replaceWidget; + private TextField replaceValue; + private DateField replaceValueDate; + + private FieldSet replaceValueFieldSet; + + private VerticalLayoutContainer conditionsVerticalLayout; + + private boolean allRows; + + private FieldLabel allRowsField; + + public ReplaceColumnByMultiColumnExpressionPanel( + ReplaceColumnByMultiColumnExpressionDialog parent, + ColumnData column, ArrayList columns, + EventBus eventBus, ReplaceExpressionType replaceExpressionType) { + super(); + this.parent = parent; + this.column = column; + this.columns = columns; + this.eventBus = eventBus; + this.replaceExpressionType = replaceExpressionType; + Log.debug("Column: " + column); + Log.debug("Columns: " + columns); + init(); + create(); + } + + 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() != null + && !column.getDataTypeName().isEmpty() + && (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)) { + parent.setHeight(PARENT_HEIGHT); + setHeight(HEIGHT); + + } else { + parent.setHeight(PARENT_HEIGHT_REDUCE); + setHeight(HEIGHT_REDUCE); + } + } + + protected void create() { + VerticalLayoutContainer basicLayout = new VerticalLayoutContainer(); + basicLayout.setAdjustForScroll(true); + // basicLayout.setScrollMode(ScrollMode.AUTO); + + HBoxLayoutContainer flowButton = new HBoxLayoutContainer(); + flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); + flowButton.setPack(BoxLayoutPack.CENTER); + + // Properties + FieldSet properties = new FieldSet(); + properties.setHeadingText("Properties"); + properties.setCollapsible(false); + + VerticalLayoutContainer propertiesLayout = new VerticalLayoutContainer(); + properties.add(propertiesLayout); + + // 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 + conditionsFieldSet = new FieldSet(); + conditionsFieldSet.setHeadingText("Conditions"); + conditionsFieldSet.setCollapsible(false); + + conditionsVerticalLayout = new VerticalLayoutContainer(); + conditionsVerticalLayout.setWidth(CONDITION_LAYOUT_WIDTH); + conditionsVerticalLayout.setAdjustForScroll(false); + + Radio radioAllRowsTrue = new Radio(); + radioAllRowsTrue.setBoxLabel(RADIO_LABEL_ALL_ROWS); + + Radio radioAllRowsFalse = new Radio(); + radioAllRowsFalse.setBoxLabel(RADIO_LABEL_BY_CONDITION); + + radioAllRowsTrue.setValue(true); + allRows = true; + + ToggleGroup toggleGroup = new ToggleGroup(); + toggleGroup.add(radioAllRowsTrue); + toggleGroup.add(radioAllRowsFalse); + + toggleGroup + .addValueChangeHandler(new ValueChangeHandler>() { + + @Override + public void onValueChange( + ValueChangeEvent> event) { + callAllRowChange(event); + + } + }); + + HorizontalPanel hp = new HorizontalPanel(); + hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); + hp.add(radioAllRowsTrue); + hp.add(radioAllRowsFalse); + hp.setWidth("140px"); + + allRowsField = new FieldLabel(hp, "Select"); + allRowsField.setWidth(ALL_ROWS_FIELD_WIDTH); + + conditionWidget = new ConditionOnMultiColumnWidget(columns,CONDITIONWIDTH, + CONDITIONHEIGHT); + + conditionWidget.setEnabled(false); + + conditionsVerticalLayout.add(allRowsField, new VerticalLayoutData(100, + -1, new Margins(0))); + conditionsVerticalLayout.add(conditionWidget, new VerticalLayoutData( + -1, -1, new Margins(0))); + + conditionsFieldSet.add(conditionsVerticalLayout); + + // Value + replaceValueFieldSet = new FieldSet(); + replaceValueFieldSet.setHeadingText("Replace Value"); + replaceValueFieldSet.setCollapsible(false); + + calcReplaceValue(); + + // + btnApply = new TextButton("Apply"); + btnApply.setIcon(ExpressionResources.INSTANCE + .columnReplaceByExpression()); + btnApply.setIconAlign(IconAlign.RIGHT); + btnApply.setToolTip("Apply replace by expression"); + btnApply.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + Log.debug("Pressed Apply"); + applyReplaceColumnByExpression(); + + } + }); + if (column == null) { + btnApply.disable(); + } + + btnClose = new TextButton("Close"); + btnClose.setIcon(ExpressionResources.INSTANCE.close()); + btnClose.setIconAlign(IconAlign.RIGHT); + btnClose.setToolTip("Close"); + btnClose.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + Log.debug("Pressed Close"); + close(); + } + }); + flowButton.add(btnApply, new BoxLayoutData(new Margins(2, 4, 2, 4))); + flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4))); + + // Add to basic layout + basicLayout.add(properties, new VerticalLayoutData(1, -1, + new Margins(1))); + basicLayout.add(conditionsFieldSet, new VerticalLayoutData(1, -1, + new Margins(1))); + basicLayout.add(replaceValueFieldSet, new VerticalLayoutData(1, -1, + new Margins(1))); + + basicLayout.add(flowButton, new VerticalLayoutData(1, 36, new Margins( + 5, 2, 5, 2))); + add(basicLayout); + + } + + protected void calcReplaceValue() { + replaceValueFieldSet.clear(); + VerticalLayoutContainer replaceValueFieldSetLayout = new VerticalLayoutContainer(); + replaceValueFieldSet.add(replaceValueFieldSetLayout); + + if (column == null || column.getDataTypeName() == null + || column.getDataTypeName().isEmpty()) { + 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 (replaceExpressionType) { + 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) { + Log.debug("This column has column type code null, Dimension and TimeDimesion not supported for now!"); + 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.resetCondition(); + calcReplaceValue(); + + } else { + column = null; + btnApply.disable(); + conditionWidget.resetCondition(); + calcReplaceValue(); + } + calcHeight(); + parent.forceLayout(); + } + }; + + return selectionHandler; + } + + protected void callAllRowChange(ValueChangeEvent> event) { + ToggleGroup group = (ToggleGroup) event.getSource(); + Radio radio = (Radio) group.getValue(); + if (radio.getBoxLabel().compareTo(RADIO_LABEL_ALL_ROWS) == 0) { + conditionWidget.setEnabled(false); + allRows = true; + } else { + conditionWidget.setEnabled(true); + allRows = false; + } + + } + + protected void applyReplaceColumnByExpression() { + C_Expression cConditionExpression = null; + if (allRows) { + + } else { + + try { + cConditionExpression = conditionWidget.getExpression(); + } catch (ConditionTypeMapException e) { + Log.debug(e.getLocalizedMessage()); + UtilsGXT3.alert("Attention", e.getLocalizedMessage()); + return; + } + + } + String value = null; + if (column.getDataTypeName().compareTo(ColumnDataType.Date.toString()) == 0) { + + Date valueDate = replaceValueDate.getCurrentValue(); + if (valueDate == null) { + UtilsGXT3.alert("Error replace value", + "Select a valid date as replace value!"); + return; + } else { + try { + value = sdf.format(valueDate); + } catch (Throwable e) { + UtilsGXT3.alert("Error replace value", + "Select a valid date as replace value!"); + return; + } + callApplyReplaceColumnByExpression(cConditionExpression, value); + + } + + } 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) { + C_Expression cReplaceExpression = null; + try { + cReplaceExpression = replaceWidget.getExpression(); + if (cReplaceExpression == null) { + UtilsGXT3.alert("Attention", + "Replace expression is not valid!"); + return; + } + } catch (ReplaceTypeMapException e) { + UtilsGXT3.alert("Attention", e.getLocalizedMessage()); + return; + } + callApplyReplaceColumnByExpression(cConditionExpression, + cReplaceExpression); + } else { + value = replaceValue.getCurrentValue(); + if (checkValue(value)) { + callApplyReplaceColumnByExpression(cConditionExpression, + value); + } else { + return; + } + } + } + + } + + protected void callApplyReplaceColumnByExpression( + C_Expression cConditionExpression, String replaceValue) { + if (column == null) { + UtilsGXT3.alert("Attention", "Select a valid column!"); + return; + } + + switch (replaceExpressionType) { + case Template: + C_ExpressionContainer conditionExpressionContainer; + if (allRows) { + conditionExpressionContainer = new C_ExpressionContainer( + C_ExpressionContainer.Contains.C_Expression, true, + null, "AllRows()"); + } else { + conditionExpressionContainer = new C_ExpressionContainer( + C_ExpressionContainer.Contains.C_Expression, + cConditionExpression, + cConditionExpression.getReadableExpression()); + } + + ExpressionWrapper exWrapper = new ExpressionWrapper( + column.getTrId(), column, conditionExpressionContainer, + replaceValue); + ExpressionWrapperEvent expressionEvent = new ExpressionWrapperEvent( + exWrapper); + Log.debug(expressionEvent.toString()); + parent.hide(); + eventBus.fireEvent(expressionEvent); + break; + case Replace: + parent.applyReplaceColumnByExpression(column, allRows, + cConditionExpression, replaceValue); + break; + default: + break; + } + + } + + protected void callApplyReplaceColumnByExpression( + C_Expression cConditionExpression, C_Expression cReplaceExpression) { + if (column == null) { + UtilsGXT3.alert("Attention", "Select a valid column!"); + return; + } + + switch (replaceExpressionType) { + case Template: + C_ExpressionContainer conditionExpressionContainer; + if (allRows) { + conditionExpressionContainer = new C_ExpressionContainer( + C_ExpressionContainer.Contains.C_Expression, true, + null, "AllRows()"); + } else { + conditionExpressionContainer = new C_ExpressionContainer( + C_ExpressionContainer.Contains.C_Expression, + cConditionExpression, + cConditionExpression.getReadableExpression()); + } + C_ExpressionContainer replaceExpressionContainer = new C_ExpressionContainer( + C_ExpressionContainer.Contains.C_Expression, + cReplaceExpression, replaceWidget.getReadableExpression()); + + ExpressionWrapper exWrapper = new ExpressionWrapper( + column.getTrId(), column, conditionExpressionContainer, + replaceExpressionContainer); + ExpressionWrapperEvent expressionEvent = new ExpressionWrapperEvent( + exWrapper); + + Log.debug(expressionEvent.toString()); + parent.hide(); + eventBus.fireEvent(expressionEvent); + break; + case Replace: + parent.applyReplaceColumnByExpression(column, allRows, + cConditionExpression, cReplaceExpression); + break; + default: + break; + } + } + + private boolean checkValue(String value) { + try { + boolean ok = false; + ColumnDataType columnDataType = ColumnDataType + .getColumnDataTypeFromId(column.getDataTypeName()); + switch (columnDataType) { + case Boolean: + Boolean.valueOf(value); + ok = true; + break; + case Date: + ok = true; + break; + case Geometry: + try { + RegExp regExp = RegExp.compile(GEOMETRY_REGEXPR); + MatchResult matcher = regExp.exec(value); + boolean matchFound = matcher != null; + if (matchFound) { + ok = true; + } else { + ok = false; + } + + } catch (Throwable e) { + UtilsGXT3.alert("Error replace value", + "Insert a valid replace value for Geometry type! "); + e.printStackTrace(); + return false; + } + break; + case Integer: + try { + Integer.parseInt(value); + } catch (Throwable e) { + e.printStackTrace(); + UtilsGXT3.alert("Error replace value", + "Insert a valid replace value for Integer type! "); + return false; + } + ok = true; + break; + case Numeric: + try { + Double.parseDouble(value); + } catch (Throwable e) { + e.printStackTrace(); + UtilsGXT3.alert("Error replace value", + "Insert a valid replace value for Numeric type! "); + return false; + } + ok = true; + break; + case Text: + ok = true; + break; + default: + break; + } + return ok; + + } catch (Throwable e) { + e.printStackTrace(); + UtilsGXT3.alert("Error replace value", + "Insert a valid replace value! " + e.getLocalizedMessage()); + + return false; + } + } + + protected void close() { + switch (replaceExpressionType) { + case Template: + ExpressionWrapper exWrapper = new ExpressionWrapper(); + ExpressionWrapperEvent expressionEvent = new ExpressionWrapperEvent( + exWrapper); + Log.debug(expressionEvent.toString()); + parent.close(); + eventBus.fireEvent(expressionEvent); + break; + case Replace: + if (parent != null) { + parent.close(); + } + break; + default: + break; + + } + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/RowsDeleteByMultiColumnExpressionDialog.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/RowsDeleteByMultiColumnExpressionDialog.java new file mode 100644 index 0000000..9f6c042 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/RowsDeleteByMultiColumnExpressionDialog.java @@ -0,0 +1,255 @@ +package org.gcube.portlets.user.td.expressionwidget.client; + +import java.util.ArrayList; + +import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; +import org.gcube.portlets.user.td.expressionwidget.client.rpc.ExpressionServiceAsync; +import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3; +import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsFinalException; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTIsLockedException; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; +import org.gcube.portlets.user.td.gwtservice.shared.tr.column.FilterColumnSession; +import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialog; +import org.gcube.portlets.user.td.monitorwidget.client.MonitorDialogListener; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.ChangeTableRequestEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableRequestType; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.ChangeTableWhy; +import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType; +import org.gcube.portlets.user.td.widgetcommonevent.shared.OperationResult; +import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; +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.ColumnTypeCode; + +import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.web.bindery.event.shared.EventBus; +import com.sencha.gxt.widget.core.client.Window; +import com.sencha.gxt.widget.core.client.event.SelectEvent; +import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class RowsDeleteByMultiColumnExpressionDialog extends Window implements MonitorDialogListener { + private static final String WIDTH = "940px"; + private static final String HEIGHT = "388px"; + private MultiColumnExpressionPanel multiColumnExpressionPanel; + private C_Expression exp = null; + private TRId trId; + private ArrayList columns=null; + private ArrayList removableColumn=null; + private EventBus eventBus; + private FilterColumnSession filterColumnSession; + + + + public RowsDeleteByMultiColumnExpressionDialog(TRId trId, EventBus eventBus) { + initWindow(); + this.eventBus = eventBus; + this.trId = trId; + loadColumns(); + + } + + protected void initWindow() { + setWidth(WIDTH); + setHeight(HEIGHT); + setBodyBorder(false); + setResizable(false); + setHeadingText("Delete Rows By Expression"); + setClosable(true); + getHeader().setIcon(ExpressionResources.INSTANCE.tableRowDeleteByExpression()); + + } + + /** + * {@inheritDoc} + */ + @Override + protected void initTools() { + super.initTools(); + + closeBtn.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + close(); + } + }); + + } + + protected void create() { + multiColumnExpressionPanel = new MultiColumnExpressionPanel(this, columns, + eventBus); + add(multiColumnExpressionPanel); + + } + + + + + public C_Expression getExpression() { + return exp; + } + + protected void setExpression(C_Expression exp) { + Log.debug("New Expression set:" + exp.toString()); + this.exp = exp; + } + + protected void deleteRowsByExpression(C_Expression exp) { + this.exp = exp; + callDeleteRows(); + } + + protected void loadColumns() { + TDGWTServiceAsync.INSTANCE.getColumns(trId, + new AsyncCallback>() { + + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + if (caught instanceof TDGWTIsLockedException) { + Log.error(caught.getLocalizedMessage()); + UtilsGXT3.alert("Error Locked", + caught.getLocalizedMessage()); + + } else { + Log.error("Error retrieving column: " + + caught.getMessage()); + UtilsGXT3.alert("Error retrieving column", + caught.getMessage()); + } + } + } + + public void onSuccess(ArrayList result) { + Log.debug("Retrived column: " + result); + columns = result; + 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 { + + } + } + columns.removeAll(removableColumn); + } + + + protected void callDeleteRows() { + filterColumnSession = new FilterColumnSession(trId, exp); + Log.debug(filterColumnSession.toString()); + + ExpressionServiceAsync.INSTANCE.startFilterColumn(filterColumnSession, + new AsyncCallback() { + + @Override + public void onSuccess(String taskId) { + Log.debug("Submitted column filter"); + openMonitorDialog(taskId); + + } + + @Override + public void onFailure(Throwable caught) { + if (caught instanceof TDGWTSessionExpiredException) { + eventBus.fireEvent(new SessionExpiredEvent( + SessionExpiredType.EXPIREDONSERVER)); + } else { + if (caught instanceof TDGWTIsLockedException) { + Log.error(caught.getLocalizedMessage()); + UtilsGXT3.alert("Error Locked", + caught.getLocalizedMessage()); + } else { + if (caught instanceof TDGWTIsFinalException) { + Log.error(caught.getLocalizedMessage()); + UtilsGXT3.alert("Error Final", + caught.getLocalizedMessage()); + } else { + Log.error("Error submitting the column filter: " + + caught.getLocalizedMessage()); + caught.printStackTrace(); + UtilsGXT3 + .alert("Error submitting the column filter", + caught.getLocalizedMessage()); + } + } + } + + } + }); + + } + + protected void close() { + hide(); + } + + // / + protected void openMonitorDialog(String taskId) { + MonitorDialog monitorDialog = new MonitorDialog(taskId, eventBus); + monitorDialog.addProgressDialogListener(this); + monitorDialog.show(); + } + + @Override + public void operationComplete(OperationResult operationResult) { + ChangeTableWhy why = ChangeTableWhy.TABLEUPDATED; + ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent( + ChangeTableRequestType.COLUMNFILTER, operationResult.getTrId(), why); + eventBus.fireEvent(changeTableRequestEvent); + close(); + } + + @Override + public void operationFailed(Throwable caught, String reason, String details) { + UtilsGXT3.alert(reason, details); + close(); + + } + + @Override + public void operationStopped(OperationResult operationResult, String reason, String details) { + ChangeTableWhy why = ChangeTableWhy.TABLECURATION; + ChangeTableRequestEvent changeTableRequestEvent = new ChangeTableRequestEvent( + ChangeTableRequestType.COLUMNFILTER, operationResult.getTrId(), why); + eventBus.fireEvent(changeTableRequestEvent); + close(); + + } + + @Override + public void operationAborted() { + close(); + + } + + @Override + public void operationPutInBackground() { + close(); + + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/TemplateMultiColumnExpressionDialog.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/TemplateMultiColumnExpressionDialog.java new file mode 100644 index 0000000..f0cc1cc --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/TemplateMultiColumnExpressionDialog.java @@ -0,0 +1,168 @@ +package org.gcube.portlets.user.td.expressionwidget.client; + +import java.util.ArrayList; + +import org.gcube.portlets.user.td.expressionwidget.client.notification.ExpressionWrapperNotification; +import org.gcube.portlets.user.td.expressionwidget.client.notification.ExpressionWrapperNotification.ExpressionWrapperNotificationListener; +import org.gcube.portlets.user.td.expressionwidget.client.notification.ExpressionWrapperNotification.HasExpressionWrapperNotificationListener; +import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; +import org.gcube.portlets.user.td.expressionwidget.client.utils.UtilsGXT3; +import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnData; +import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnMockUp; +import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ColumnTypeCode; + +import com.google.gwt.user.client.ui.HTML; +import com.google.web.bindery.event.shared.EventBus; +import com.sencha.gxt.widget.core.client.Window; +import com.sencha.gxt.widget.core.client.event.SelectEvent; +import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class TemplateMultiColumnExpressionDialog extends Window implements + HasExpressionWrapperNotificationListener { + private static final String WIDTH = "940px"; + private static final String HEIGHT = "388px"; + private ArrayList listeners; + private MultiColumnExpressionPanel multiColumnExpressionPanel; + private ArrayList columns; + private EventBus eventBus; + + /** + * + * @param columnsMockUp + * @param eventBus + */ + public TemplateMultiColumnExpressionDialog( + ArrayList columnsMockUp, EventBus eventBus) { + listeners = new ArrayList(); + this.eventBus = eventBus; + columns = new ArrayList(); + for (ColumnMockUp columnMockUp : columnsMockUp) { + ColumnData column = new ColumnData(); + column.setColumnId(columnMockUp.getColumnId()); + column.setLabel(columnMockUp.getLabel()); + column.setDataTypeName(columnMockUp.getColumnDataType().toString()); + column.setTypeCode(columnMockUp.getColumnType().toString()); + columns.add(column); + } + sanitizesColumns(); + initWindow(); + create(); + + } + + 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 { + + } + } + columns.removeAll(removableColumn); + } + + protected void initWindow() { + setWidth(WIDTH); + setHeight(HEIGHT); + setBodyBorder(false); + setResizable(false); + setHeadingText("New Rule"); + setClosable(true); + setModal(true); + forceLayoutOnResize = true; + getHeader().setIcon(ExpressionResources.INSTANCE.ruleAdd()); + + } + + /** + * {@inheritDoc} + */ + @Override + protected void initTools() { + super.initTools(); + + closeBtn.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + close(); + } + }); + + } + + protected void close() { + fireAborted(); + } + + protected void create() { + if(columns.size()>0){ + multiColumnExpressionPanel = new MultiColumnExpressionPanel(this,columns, + eventBus); + add(multiColumnExpressionPanel); + } else { + HTML errorMessage = new HTML( + "Attention no columns with a type supported(Dimension and TimeDimension is not supported)!"); + add(errorMessage); + UtilsGXT3.alert("Attention","Attention no columns with a type supported(Dimension and TimeDimension is not supported)!"); + + } + } + + protected void onExpression( + ExpressionWrapperNotification expressionWrapperNotification) { + fireNotification(expressionWrapperNotification); + } + + + @Override + public void addExpressionWrapperNotificationListener( + ExpressionWrapperNotificationListener handler) { + listeners.add(handler); + + } + + @Override + public void removeExpressionWrapperNotificationListener( + ExpressionWrapperNotificationListener handler) { + listeners.remove(handler); + + } + + private void fireNotification( + ExpressionWrapperNotification expressionWrapperNotification) { + if (listeners != null) { + for (ExpressionWrapperNotificationListener listener : listeners) { + listener.onExpression(expressionWrapperNotification); + } + } + hide(); + } + + private void fireAborted() { + if (listeners != null) { + for (ExpressionWrapperNotificationListener listener : listeners) { + listener.aborted(); + } + } + hide(); + } + + private void fireFailed(Throwable caught) { + if (listeners != null) { + for (ExpressionWrapperNotificationListener listener : listeners) { + listener.failed(caught); + } + } + hide(); + + } + +} 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 index 5aa1bc8..50e90d9 100644 --- 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 @@ -61,7 +61,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { private static final String SIGN = "ConditionOnMultiColumns"; private static final String HEIGHT = "268px"; - private static final String WIDTH = "664px"; + private static final String WIDTH = "890px"; private static final String COMBO_DEPTH_WIDTH = "64px"; private static final String COMBO_FIRST_ELEMENT_COLUMN_WIDTH = "150px"; private static final String COMBO_OPERATOR_WIDTH = "130px"; @@ -115,6 +115,11 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { this.columns = newColumns; setup(); } + + public void resetCondition(){ + vert.clear(); + setup(); + } protected void init(String width, String height) { setWidth(width); @@ -466,7 +471,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(true); + btnAdd.setVisible(false); btnDel.setVisible(false); removeCondition(source); break; @@ -516,7 +521,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { thresholdText.setVisible(false); comboThreshold.setVisible(false); btnAdd.setVisible(true); - btnDel.setVisible(true); + btnDel.setVisible(false); removeCondition(source); break; default: @@ -559,8 +564,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(false); - btnDel.setVisible(false); + } else { Log.debug("ComboFirstElement selected: " @@ -586,8 +590,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(false); - btnDel.setVisible(false); + } else { OperationsStore operationStore = new OperationsStore(); storeOperator.clear(); @@ -609,8 +612,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(true); - btnDel.setVisible(false); + } @@ -638,8 +640,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(false); - btnDel.setVisible(false); + } else { Log.debug("Operator selected:" + op.toString()); switch (op.getOperatorType()) { @@ -674,8 +675,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(true); - btnDel.setVisible(false); + break; case BETWEEN: case NOT_BETWEEN: @@ -693,8 +693,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(true); - btnDel.setVisible(false); + break; case SOUNDEX: comboFirstArgType.reset(); @@ -711,8 +710,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(true); - btnDel.setVisible(false); + break; case LEVENSHTEIN: comboFirstArgType.reset(); @@ -735,8 +733,6 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(true); comboThreshold.setVisible(true); - btnAdd.setVisible(true); - btnDel.setVisible(false); comboThreshold.setValue(ThresholdStore .defaultThresholdLevenshtein()); @@ -763,12 +759,9 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(true); comboThreshold.setVisible(true); - btnAdd.setVisible(true); - btnDel.setVisible(false); comboThreshold.setValue(ThresholdStore .defaultThresholdSimilarity()); - break; case IS_NULL: case IS_NOT_NULL: @@ -783,8 +776,6 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(true); - btnDel.setVisible(false); break; default: comboFirstArgType.setVisible(false); @@ -798,8 +789,6 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(false); - btnDel.setVisible(false); break; } } @@ -852,9 +841,11 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { comboFirstArgColumn.setVisible(false); if (columnDataType .compareTo(ColumnDataType.Date) == 0) { + firstArgDate.reset(); firstArgValue.setVisible(false); - firstArgDate.setVisible(true); + firstArgDate.setVisible(true); } else { + firstArgValue.reset(); firstArgValue.setVisible(true); firstArgDate.setVisible(false); } @@ -917,9 +908,11 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { comboSecondArgColumn.setVisible(false); if (columnDataType .compareTo(ColumnDataType.Date) == 0) { + secondArgDate.reset(); secondArgValue.setVisible(false); secondArgDate.setVisible(true); } else { + secondArgValue.reset(); secondArgValue.setVisible(true); secondArgDate.setVisible(false); } @@ -963,7 +956,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { secondArgDate.setVisible(false); thresholdText.setVisible(false); comboThreshold.setVisible(false); - btnAdd.setVisible(true); + btnAdd.setVisible(false); btnDel.setVisible(false); horiz.add(comboDepth, new BoxLayoutData(new Margins(0))); @@ -1647,9 +1640,11 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { comboFirstArgColumn.setVisible(false); if (columnDataType .compareTo(ColumnDataType.Date) == 0) { + firstArgDate.reset(); firstArgValue.setVisible(false); firstArgDate.setVisible(true); } else { + firstArgValue.reset(); firstArgValue.setVisible(true); firstArgDate.setVisible(false); } @@ -1712,9 +1707,11 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { comboSecondArgColumn.setVisible(false); if (columnDataType .compareTo(ColumnDataType.Date) == 0) { + secondArgDate.reset(); secondArgValue.setVisible(false); secondArgDate.setVisible(true); } else { + secondArgValue.reset(); secondArgValue.setVisible(true); secondArgDate.setVisible(false); } @@ -1824,23 +1821,23 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { .getCurrentValue(); if (depthOfExpressionElement == null) { - return null; + throw new ConditionTypeMapException("Fill all field and creates a valid expression!"); } DepthOfExpressionType depth = depthOfExpressionElement.getType(); if (depth == null) { - return null; + throw new ConditionTypeMapException("Fill all field and creates a valid expression!"); } if (expSet) { - return null; + throw new ConditionTypeMapException("Expression is invalid!"); } switch (depth) { case BOTTOM: if (vert.getWidgetCount() != 1) { - return null; + throw new ConditionTypeMapException("Expression is invalid!"); } C_Expression singleCondition = calcExpression(horiz); exp = singleCondition; @@ -1862,7 +1859,7 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { break; case ENDAND: if (depthStack.isEmpty()) { - return null; + throw new ConditionTypeMapException("Expression is invalid!"); } else { LogicalDepth endAndPopped = depthStack.pop(); if (endAndPopped.getType().compareTo( @@ -1879,17 +1876,17 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { .getArguments(); args.add(cAnd); } else { - return null; + throw new ConditionTypeMapException("Expression is invalid!"); } } } else { - return null; + throw new ConditionTypeMapException("Expression is invalid, brackets do not match!"); } } break; case ENDOR: if (depthStack.isEmpty()) { - return null; + throw new ConditionTypeMapException("Expression is invalid!"); } else { LogicalDepth endOrPopped = depthStack.pop(); if (endOrPopped.getType().compareTo( @@ -1906,11 +1903,11 @@ public class ConditionOnMultiColumnWidget extends SimpleContainer { .getArguments(); args.add(cOr); } else { - return null; + throw new ConditionTypeMapException("Expression is invalid!"); } } } else { - return null; + throw new ConditionTypeMapException("Expression is invalid, brackets do not match!"); } } break;