From 4a4ed2cd8da0609703acfec75906ee815f476a7a Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Thu, 27 Mar 2014 16:56:46 +0000 Subject: [PATCH] Added replace all value on view column git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-column-widget@93655 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 8 + .../user/td/columnwidget/ColumnWidget.gwt.xml | 3 +- .../DialogDimensionRowSelection.java | 197 ++++++++++++++++++ .../client/dimension/DimensionRow.java | 51 +++++ .../DimensionRowSelectionListener.java | 31 +++ .../replace/DimensionRowsProperties.java | 27 +++ .../client/replace/ReplaceDialog.java | 31 +-- .../client/replace/ReplacePanel.java | 165 ++++++++++++++- .../columnwidget/client/utils/Constants.java | 7 + .../user/td/columnwidget/ColumnWidget.gwt.xml | 3 +- 10 files changed, 482 insertions(+), 41 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DialogDimensionRowSelection.java create mode 100644 src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DimensionRow.java create mode 100644 src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DimensionRowSelectionListener.java create mode 100644 src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/DimensionRowsProperties.java create mode 100644 src/main/java/org/gcube/portlets/user/td/columnwidget/client/utils/Constants.java diff --git a/pom.xml b/pom.xml index 0344292..8880604 100644 --- a/pom.xml +++ b/pom.xml @@ -123,6 +123,14 @@ [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) provided + + + + org.gcube.portlets.user + tabular-data-widgetx-tdx-source + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + provided + diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/ColumnWidget.gwt.xml b/src/main/java/org/gcube/portlets/user/td/columnwidget/ColumnWidget.gwt.xml index b5d3d53..282f68f 100644 --- a/src/main/java/org/gcube/portlets/user/td/columnwidget/ColumnWidget.gwt.xml +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/ColumnWidget.gwt.xml @@ -19,7 +19,8 @@ - + + diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DialogDimensionRowSelection.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DialogDimensionRowSelection.java new file mode 100644 index 0000000..74c0fa9 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DialogDimensionRowSelection.java @@ -0,0 +1,197 @@ +package org.gcube.portlets.user.td.columnwidget.client.dimension; + +import java.util.ArrayList; + +import org.gcube.portlets.user.td.columnwidget.client.utils.Constants; +import org.gcube.portlets.user.td.columnwidget.client.utils.UtilsGXT3; +import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; +import org.gcube.portlets.user.td.widgetcommonevent.shared.CellData; +import org.gcube.portlets.user.tdwx.client.TabularDataX; +import org.gcube.portlets.user.tdwx.client.TabularDataXGridPanel; +import org.gcube.portlets.user.tdwx.client.event.FailureEvent; +import org.gcube.portlets.user.tdwx.client.event.FailureEventHandler; +import org.gcube.portlets.user.tdwx.shared.model.TableId; + + +import com.allen_sauer.gwt.log.client.Log; +import com.google.web.bindery.event.shared.EventBus; +import com.sencha.gxt.core.client.Style.SelectionMode; +import com.sencha.gxt.widget.core.client.FramedPanel; +import com.sencha.gxt.widget.core.client.Window; +import com.sencha.gxt.widget.core.client.button.TextButton; +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.FieldLabel; +import com.sencha.gxt.widget.core.client.form.TextField; +import com.sencha.gxt.widget.core.client.info.Info; + +public class DialogDimensionRowSelection extends Window { + protected static final int WIDTH = 550; + protected static final int HEIGHT = 520; + + protected ColumnData column; + protected EventBus eventBus; + protected DimensionRow dimRow; + protected CellData cellData; + + protected ArrayList listeners; + + private static TabularDataX tabularData; + private TabularDataXGridPanel gridPanel; + private TextField value; + private TextButton select; + + + public DialogDimensionRowSelection(ColumnData column, CellData cellData, EventBus eventBus) { + this.column=column; + this.eventBus=eventBus; + this.cellData=cellData; + listeners=new ArrayList(); + initWindow(); + create(); + open(); + } + + + protected void create(){ + final FramedPanel panel = new FramedPanel(); + panel.setHeaderVisible(false); + panel.setBodyBorder(false); + + VerticalLayoutContainer v = new VerticalLayoutContainer(); + + value = new TextField(); + value.setValue(cellData.getValue()); + value.setReadOnly(true); + + //Grid + tabularData = new TabularDataX(Constants.TDX_DATASOURCE_FACTORY_ID); + tabularData.addFailureHandler(new FailureEventHandler() { + + public void onFailure(FailureEvent event) { + Info.display("Error: " + event.getMessage(), event.getCaught() + .getMessage()); + + } + }); + + gridPanel = tabularData.getGridPanel(); + gridPanel.setHeaderVisible(false); + gridPanel.setSelectionModel(SelectionMode.SINGLE); + + v.add(new FieldLabel(value, "Value"), new VerticalLayoutData(1, -1)); + v.add(gridPanel, new VerticalLayoutData(1, 1)); + + panel.add(v); + + select = new TextButton("Select"); + select.addSelectHandler(new SelectHandler() { + + @Override + public void onSelect(SelectEvent event) { + startSelect(); + } + }); + + panel.addButton(select); + + add(panel); + forceLayout(); + } + + protected void startSelect(){ + ArrayList rowsId=gridPanel.getSelectedRowsId(); + if(rowsId==null||rowsId.size()==0){ + Log.debug("No row selected"); + UtilsGXT3.alert("Attention", + "Select a row"); + } else { + String rowId=rowsId.get(0); + Log.debug("Row selected: "+rowId); + ArrayList cellValues=gridPanel.getCellValue(column.getColumnId()); + if(cellValues==null|| cellValues.size()==0){ + Log.debug("No value retrieved"); + UtilsGXT3.alert("Attention", + "Select a row"); + } else { + String cellValue=cellValues.get(0); + Log.debug("Retrived: "+ rowId+" "+cellValue); + dimRow=new DimensionRow(rowId,cellValue); + fireCompleted(dimRow); + } + } + + } + + + + protected void open(){ + long tableId=column.getColumnViewData().getTargetTableId(); + + TableId tableOpening = new TableId(Constants.TDX_DATASOURCE_FACTORY_ID, + String.valueOf(tableId)); + tabularData.openTable(tableOpening); + } + + protected void initWindow() { + setWidth(WIDTH); + setHeight(HEIGHT); + setBodyBorder(false); + setResizable(false); + setHeadingText("Dimension"); + setClosable(true); + //getHeader().setIcon(ResourceBundle.INSTANCE.replace()); + + } + + /** + * {@inheritDoc} + */ + @Override + protected void initTools() { + super.initTools(); + + closeBtn.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + fireAborted(); + hide(); + } + }); + + } + + + + + public void addListener(DimensionRowSelectionListener listener) { + listeners.add(listener); + } + + public void removeListener(DimensionRowSelectionListener listener) { + listeners.remove(listener); + } + + public void fireCompleted(DimensionRow dimensionRow) { + for (DimensionRowSelectionListener listener : listeners) + listener.selected(dimensionRow); + hide(); + } + + public void fireAborted() { + for (DimensionRowSelectionListener listener : listeners) + listener.aborted(); + hide(); + } + + public void fireFailed(String reason, String details) { + for (DimensionRowSelectionListener listener : listeners) + listener.failed(reason, details); + hide(); + } + + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DimensionRow.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DimensionRow.java new file mode 100644 index 0000000..4bad874 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DimensionRow.java @@ -0,0 +1,51 @@ +package org.gcube.portlets.user.td.columnwidget.client.dimension; + +import java.io.Serializable; + +/** + * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * + */ +public class DimensionRow implements Serializable { + + private static final long serialVersionUID = -4220185160420435932L; + + + protected String rowId; + protected String value; + + public DimensionRow(){ + + } + + public DimensionRow(String rowId, String value){ + this.rowId=rowId; + this.value=value; + } + + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getRowId() { + return rowId; + } + + public void setRowId(String rowId) { + this.rowId = rowId; + } + + @Override + public String toString() { + return "DimensionRow [rowId=" + rowId + ", value=" + value + "]"; + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DimensionRowSelectionListener.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DimensionRowSelectionListener.java new file mode 100644 index 0000000..89fb9cc --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/dimension/DimensionRowSelectionListener.java @@ -0,0 +1,31 @@ +package org.gcube.portlets.user.td.columnwidget.client.dimension; + + + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public interface DimensionRowSelectionListener { + + /** + * Called when selected one row of dimension or time dimension without errors + */ + public void selected(DimensionRow dimensionRow); + + /** + * Called when the select operation is aborted by the user. + */ + public void aborted(); + + /** + * Called when the something in the wizard is failed. + * + * @param reason + * @param detail + */ + public void failed(String reason, String detail); + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/DimensionRowsProperties.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/DimensionRowsProperties.java new file mode 100644 index 0000000..62367b6 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/DimensionRowsProperties.java @@ -0,0 +1,27 @@ +/** + * + */ +package org.gcube.portlets.user.td.columnwidget.client.replace; + +import org.gcube.portlets.user.td.columnwidget.client.dimension.DimensionRow; + +import com.google.gwt.editor.client.Editor.Path; +import com.sencha.gxt.data.shared.LabelProvider; +import com.sencha.gxt.data.shared.ModelKeyProvider; +import com.sencha.gxt.data.shared.PropertyAccess; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public interface DimensionRowsProperties extends PropertyAccess { + + @Path("rowId") + ModelKeyProvider rowId(); + + LabelProvider value(); + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/ReplaceDialog.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/ReplaceDialog.java index aab7f90..27cddd8 100644 --- a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/ReplaceDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/ReplaceDialog.java @@ -17,9 +17,7 @@ public class ReplaceDialog extends Window { protected TRId trId; protected EventBus eventBus; - // private ReplaceSession columnFilterSession; - // private ReplaceProgressDialog dialog; - + public ReplaceDialog(CellData cellData, TRId trId, EventBus eventBus) { initWindow(); this.cellData = cellData; @@ -34,7 +32,7 @@ public class ReplaceDialog extends Window { setHeight(HEIGHT); setBodyBorder(false); setResizable(false); - setHeadingText("Replace"); + setHeadingText("Replace All"); setClosable(true); getHeader().setIcon(ResourceBundle.INSTANCE.replace()); @@ -66,29 +64,6 @@ public class ReplaceDialog extends Window { hide(); } - /* - * protected void callApplyFilter() { columnFilterSession = new - * ColumnFilterSession(column, exp); - * Log.debug(columnFilterSession.toString()); - * - * ExpressionServiceAsync.INSTANCE.submitColumnFilter(columnFilterSession, - * new AsyncCallback() { - * - * @Override public void onSuccess(Void result) { - * Log.debug("Submitted column filter"); callColumnFilterProgressDialog(); } - * - * @Override public void onFailure(Throwable caught) { - * Log.error("Error submitting the column filter: " + caught.getMessage() + - * " " + caught.getCause()); caught.printStackTrace(); - * UtilsGXT3.alert("Error submitting the column filter", - * caught.getMessage()); - * - * } }); - * - * } - * - * protected void callColumnFilterProgressDialog() { dialog = new - * ColumnFilterProgressDialog(this, eventBus); dialog.show(); } - */ + } diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/ReplacePanel.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/ReplacePanel.java index 83f23d4..83bc67e 100644 --- a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/ReplacePanel.java +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/replace/ReplacePanel.java @@ -2,6 +2,9 @@ package org.gcube.portlets.user.td.columnwidget.client.replace; import java.sql.Date; +import org.gcube.portlets.user.td.columnwidget.client.dimension.DialogDimensionRowSelection; +import org.gcube.portlets.user.td.columnwidget.client.dimension.DimensionRow; +import org.gcube.portlets.user.td.columnwidget.client.dimension.DimensionRowSelectionListener; import org.gcube.portlets.user.td.columnwidget.client.progress.ReplaceColumnProgressDialog; import org.gcube.portlets.user.td.columnwidget.client.resources.ResourceBundle; import org.gcube.portlets.user.td.columnwidget.client.utils.UtilsGXT3; @@ -12,10 +15,14 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.CellData; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import com.allen_sauer.gwt.log.client.Log; +import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; 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.data.shared.LabelProvider; +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; @@ -26,6 +33,9 @@ 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.event.TriggerClickEvent; +import com.sencha.gxt.widget.core.client.event.TriggerClickEvent.TriggerClickHandler; +import com.sencha.gxt.widget.core.client.form.ComboBox; import com.sencha.gxt.widget.core.client.form.FieldLabel; import com.sencha.gxt.widget.core.client.form.TextField; @@ -35,7 +45,8 @@ import com.sencha.gxt.widget.core.client.form.TextField; * href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it * */ -public class ReplacePanel extends FramedPanel { +public class ReplacePanel extends FramedPanel implements + DimensionRowSelectionListener { protected String WIDTH = "500px"; protected String HEIGHT = "150px"; protected EventBus eventBus; @@ -45,11 +56,14 @@ public class ReplacePanel extends FramedPanel { protected ColumnData column; protected ReplaceColumnSession replaceColumnSession; + private ComboBox comboDimensionType; + private FieldLabel comboDimensionTypeLabel; private TextField value; private TextField replaceValue; private TextButton btnApply; private TextButton btnClose; + private boolean isDimension; public ReplacePanel(ReplaceDialog parent, TRId trId, CellData cellData, EventBus eventBus) { @@ -57,7 +71,6 @@ public class ReplacePanel extends FramedPanel { this.cellData = cellData; this.trId = trId; this.eventBus = eventBus; - Log.debug("ReplacePanel:[" + trId + ", CellData:" + cellData + "]"); initPanel(); retrieveColumn(); @@ -84,13 +97,17 @@ public class ReplacePanel extends FramedPanel { public void onSuccess(ColumnData result) { Log.debug("Retrived column: " + result); + column = result; if (result.isViewColumn()) { - UtilsGXT3 - .info("View Column", - "You can not replace value on view column for now"); - close(); + /* + * UtilsGXT3 .info("View Column", + * "You can not replace value on view column for now" + * ); + */ + isDimension=true; + createForDimension(); } else { - column = result; + isDimension=false; create(); } } @@ -149,6 +166,74 @@ public class ReplacePanel extends FramedPanel { } + protected void createForDimension() { + value = new TextField(); + value.setValue(cellData.getValue()); + value.setReadOnly(true); + + // comboDimensionType + DimensionRowsProperties propsDimensionType = GWT + .create(DimensionRowsProperties.class); + ListStore storeComboDimensionType = new ListStore( + propsDimensionType.rowId()); + + comboDimensionType = new ComboBox( + storeComboDimensionType, propsDimensionType.value()); + + Log.trace("ComboDimensionType created"); + + addHandlersForComboDimensionType(propsDimensionType.value()); + + comboDimensionType.setEmptyText("Select a Value..."); + comboDimensionType.setWidth(300); + comboDimensionType.setEditable(false); + comboDimensionType.setTriggerAction(TriggerAction.ALL); + + comboDimensionTypeLabel = new FieldLabel(comboDimensionType, "Replace"); + + // + btnApply = new TextButton("Replace"); + btnApply.setIcon(ResourceBundle.INSTANCE.replace()); + btnApply.setIconAlign(IconAlign.RIGHT); + btnApply.setTitle("Replace Value"); + btnApply.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + Log.debug("Pressed Apply"); + replaceValueForDimension(); + + } + }); + + btnClose = new TextButton("Close"); + btnClose.setIcon(ResourceBundle.INSTANCE.close()); + btnClose.setIconAlign(IconAlign.RIGHT); + btnClose.setTitle("Close"); + btnClose.addSelectHandler(new SelectHandler() { + + public void onSelect(SelectEvent event) { + Log.debug("Pressed Close"); + close(); + + } + }); + + HBoxLayoutContainer flowButton = new HBoxLayoutContainer(); + flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); + flowButton.setPack(BoxLayoutPack.CENTER); + + flowButton.add(btnApply, new BoxLayoutData(new Margins(2, 4, 2, 4))); + flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4))); + + VerticalLayoutContainer v = new VerticalLayoutContainer(); + v.add(new FieldLabel(value, "Value"), new VerticalLayoutData(1, -1)); + v.add(comboDimensionTypeLabel, new VerticalLayoutData(1, -1)); + v.add(flowButton, new VerticalLayoutData(-1, 36, + new Margins(5, 2, 5, 2))); + add(v); + + } + protected void replaceValue() { String rValue = replaceValue.getCurrentValue(); if (rValue == null || rValue.isEmpty()) { @@ -165,6 +250,16 @@ public class ReplacePanel extends FramedPanel { } + protected void replaceValueForDimension() { + DimensionRow dimRow = comboDimensionType.getCurrentValue(); + if (dimRow == null) { + UtilsGXT3.alert("Attention", "Select a valid value"); + } else { + callReplaceValue(dimRow.getRowId()); + } + + } + protected String checkTypeData(String rValue) { String checked = null; try { @@ -211,11 +306,18 @@ public class ReplacePanel extends FramedPanel { } protected void callReplaceValue(String rValue) { - replaceColumnSession = new ReplaceColumnSession( - value.getCurrentValue(), rValue, trId, column, - cellData.getRowId()); - Log.debug(replaceColumnSession.toString()); + if (isDimension) { + replaceColumnSession = new ReplaceColumnSession( + value.getCurrentValue(), rValue, trId, column, + cellData.getRowId(), true); + Log.debug(replaceColumnSession.toString()); + } else { + replaceColumnSession = new ReplaceColumnSession( + value.getCurrentValue(), rValue, trId, column, + cellData.getRowId()); + Log.debug(replaceColumnSession.toString()); + } TDGWTServiceAsync.INSTANCE.startReplaceColumn(replaceColumnSession, new AsyncCallback() { @@ -250,4 +352,45 @@ public class ReplacePanel extends FramedPanel { parent.close(); } + protected void addHandlersForComboDimensionType( + final LabelProvider labelProvider) { + + comboDimensionType.addTriggerClickHandler(new TriggerClickHandler() { + + @Override + public void onTriggerClick(TriggerClickEvent event) { + Log.debug("ComboDimensionRows TriggerClickEvent"); + callDialogDimensionRowSelection(); + comboDimensionType.collapse(); + + } + + }); + + } + + protected void callDialogDimensionRowSelection() { + DialogDimensionRowSelection dialogDimensionRowSelection = new DialogDimensionRowSelection( + column, cellData, eventBus); + dialogDimensionRowSelection.addListener(this); + dialogDimensionRowSelection.show(); + } + + @Override + public void selected(DimensionRow dimRow) { + Log.debug("Selected dimension row: " + dimRow); + comboDimensionType.setValue(dimRow); + } + + @Override + public void aborted() { + comboDimensionType.setValue(null); + + } + + @Override + public void failed(String reason, String detail) { + comboDimensionType.setValue(null); + + } } diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/utils/Constants.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/utils/Constants.java new file mode 100644 index 0000000..5cf1d94 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/utils/Constants.java @@ -0,0 +1,7 @@ +package org.gcube.portlets.user.td.columnwidget.client.utils; + +public class Constants { + + public static final String TDX_DATASOURCE_FACTORY_ID = "TDXDataSourceFactory"; + +} diff --git a/src/main/resources/org/gcube/portlets/user/td/columnwidget/ColumnWidget.gwt.xml b/src/main/resources/org/gcube/portlets/user/td/columnwidget/ColumnWidget.gwt.xml index 6816114..5766e80 100644 --- a/src/main/resources/org/gcube/portlets/user/td/columnwidget/ColumnWidget.gwt.xml +++ b/src/main/resources/org/gcube/portlets/user/td/columnwidget/ColumnWidget.gwt.xml @@ -19,7 +19,8 @@ - + +