From f707692a4003394e1afb321ccfbf43e378d4348c Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Tue, 24 Mar 2015 18:13:41 +0000 Subject: [PATCH] Updated ReplaceBatch git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-column-widget@113709 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/batch/ReplaceBatchDialog.java | 2 +- .../client/batch/ReplaceBatchPanel.java | 349 +++++++++++++----- 2 files changed, 266 insertions(+), 85 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/batch/ReplaceBatchDialog.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/batch/ReplaceBatchDialog.java index 0c8f1a6..a51e514 100644 --- a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/batch/ReplaceBatchDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/batch/ReplaceBatchDialog.java @@ -48,7 +48,7 @@ public class ReplaceBatchDialog extends Window implements MonitorDialogListener } private static final String WIDTH = "650px"; - private static final String HEIGHT = "530px"; + private static final String HEIGHT = "560px"; private TRId trId; private EventBus eventBus; diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/batch/ReplaceBatchPanel.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/batch/ReplaceBatchPanel.java index 812ceb9..dc5f1d7 100644 --- a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/batch/ReplaceBatchPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/batch/ReplaceBatchPanel.java @@ -8,6 +8,7 @@ import org.gcube.portlets.user.td.columnwidget.client.dimension.ConnectCodelistD import org.gcube.portlets.user.td.columnwidget.client.dimension.ConnectCodelistListener; import org.gcube.portlets.user.td.columnwidget.client.dimension.DimensionRowSelectionDialog; import org.gcube.portlets.user.td.columnwidget.client.dimension.DimensionRowSelectionListener; +import org.gcube.portlets.user.td.columnwidget.client.properties.ColumnDataPropertiesCombo; import org.gcube.portlets.user.td.columnwidget.client.properties.ShowOccurrencesTypeProperties; import org.gcube.portlets.user.td.columnwidget.client.resources.ResourceBundle; import org.gcube.portlets.user.td.columnwidget.client.store.ShowOccurrencesTypeElement; @@ -41,18 +42,22 @@ import com.google.gwt.cell.client.Cell.Context; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; import com.google.gwt.safecss.shared.SafeStylesBuilder; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.HTML; 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.IdentityValueProvider; import com.sencha.gxt.core.client.Style.SelectionMode; +import com.sencha.gxt.core.client.dom.XElement; import com.sencha.gxt.core.client.resources.ThemeStyles; import com.sencha.gxt.core.client.util.Format; import com.sencha.gxt.core.client.util.Margins; @@ -72,11 +77,14 @@ import com.sencha.gxt.widget.core.client.container.BoxLayoutContainer.BoxLayoutD 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.HorizontalLayoutContainer; +import com.sencha.gxt.widget.core.client.container.HorizontalLayoutContainer.HorizontalLayoutData; 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.FieldLabel; import com.sencha.gxt.widget.core.client.form.TextField; import com.sencha.gxt.widget.core.client.grid.CheckBoxSelectionModel; import com.sencha.gxt.widget.core.client.grid.ColumnConfig; @@ -84,7 +92,6 @@ import com.sencha.gxt.widget.core.client.grid.ColumnModel; import com.sencha.gxt.widget.core.client.grid.Grid; import com.sencha.gxt.widget.core.client.grid.RowNumberer; import com.sencha.gxt.widget.core.client.info.Info; -import com.sencha.gxt.widget.core.client.toolbar.LabelToolItem; import com.sencha.gxt.widget.core.client.toolbar.ToolBar; /** @@ -98,16 +105,22 @@ public class ReplaceBatchPanel extends FramedPanel implements ConnectCodelistListener { private static final String DON_T_REPLACE = "Don't replace"; private static final String WIDTH = "560px"; - private static final String HEIGHT = "520px"; - + private static final String HEIGHT = "550px"; + private static final String GRID_HEIGHT = "344px"; + private static final String TOOLBAR_HEAD_HEIGHT = "102px"; + private static final String CONNECTION_FIELD_WIDTH = "470px"; + private static final int SHOW_OCCURENCE_TYPE_WIDTH = 100; + private static final String COMBOCOLS_WIDTH = "510px"; + private EventBus eventBus; private TRId trId; - + private ArrayList columns; + private RefColumn refColumn; private String columnLocalId; private ConditionCode conditionCode; // For Curation private String validationColumnColumnId; // For Curation - + private boolean curation; private ColumnData column; private boolean hasValidationColumns; @@ -138,6 +151,8 @@ public class ReplaceBatchPanel extends FramedPanel implements private boolean simpleReplace; + private ComboBox comboCols; + public ReplaceBatchPanel(ReplaceBatchDialog parent, TRId trId, RequestProperties requestProperties, EventBus eventBus) { this.curation = true; @@ -149,7 +164,7 @@ public class ReplaceBatchPanel extends FramedPanel implements RequestPropertiesParameterType.InvocationS); columnLocalId = invocationS.getColumnId(); - + refColumn = invocationS.getRefColumn(); conditionCode = (ConditionCode) requestProperties.getMap().get( @@ -181,7 +196,7 @@ public class ReplaceBatchPanel extends FramedPanel implements Log.debug("Create BatchReplacePanel(): [" + trId.toString() + " , columnLocalId:" + columnLocalId + "]"); init(); - retrieveColumnByColumnId(); + retrieveColumnsWithViewColumnIncluded(); } @@ -195,8 +210,33 @@ public class ReplaceBatchPanel extends FramedPanel implements protected void create() { showOccurencesType = ShowOccurrencesType.ONLYERRORS; - toolBarHead = new ToolBar(); - toolBarHead.add(new LabelToolItem("Show: ")); + FlexTable flexTable = new FlexTable(); + flexTable.setCellSpacing(1); + + // 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); + comboCols.setWidth(COMBOCOLS_WIDTH); + + FieldLabel columnField = new FieldLabel(comboCols, "Column"); + + flexTable.setWidget(0, 0, columnField); // Create Combo Show ShowOccurrencesTypeProperties propsShowOccurrencesType = GWT @@ -211,18 +251,21 @@ public class ReplaceBatchPanel extends FramedPanel implements addHandlersForShowOccurrencesType(propsShowOccurrencesType.label()); comboShowOccurrencesType.setEmptyText("Select a show type..."); - comboShowOccurrencesType.setWidth(100); + comboShowOccurrencesType.setWidth(SHOW_OCCURENCE_TYPE_WIDTH); comboShowOccurrencesType.setTypeAhead(true); comboShowOccurrencesType.setEditable(false); comboShowOccurrencesType.setTriggerAction(TriggerAction.ALL); - - + comboShowOccurrencesType .setValue(ShowOccurrencesTypeStore.onlyErrorsElement); - - toolBarHead.add(comboShowOccurrencesType); - if (!column.isViewColumn()) { + FieldLabel comboShowOccurrencesTypeField = new FieldLabel( + comboShowOccurrencesType, "Show"); + flexTable.setWidget(1, 0, comboShowOccurrencesTypeField); + + HorizontalLayoutContainer connectionLayout = new HorizontalLayoutContainer(); + if (column == null || !column.isViewColumn()) { + // Connect Codelist btnConnect = new TextButton(); btnConnect.setIcon(ResourceBundle.INSTANCE.codelistLink24()); @@ -239,7 +282,8 @@ public class ReplaceBatchPanel extends FramedPanel implements }); - toolBarHead.add(btnConnect); + connectionLayout.add(btnConnect, new HorizontalLayoutData(-1, 1, + new Margins(1))); // Disconnect Codelist btnDisconnect = new TextButton(); @@ -257,16 +301,33 @@ public class ReplaceBatchPanel extends FramedPanel implements } }); - toolBarHead.add(btnDisconnect); + connectionLayout.add(btnDisconnect, new HorizontalLayoutData(-1, 1, + new Margins(1))); connectionField = new TextField(); - toolBarHead.add(connectionField); + connectionField.setWidth(CONNECTION_FIELD_WIDTH); + connectionLayout.add(connectionField, new HorizontalLayoutData(-1, + 1, new Margins(1))); } else { connectionField = new TextField(); - toolBarHead.add(connectionField); + connectionField.setWidth(CONNECTION_FIELD_WIDTH); + + connectionLayout.add(connectionField, new HorizontalLayoutData(-1, + 1, new Margins(1))); + } + FieldLabel conField = new FieldLabel(connectionLayout, "Connection"); + flexTable.setWidget(2, 0, conField); + + cleanCells(flexTable.getElement()); + + toolBarHead = new ToolBar(); + toolBarHead.setHeight(TOOLBAR_HEAD_HEIGHT); + // toolBarHead.setHeight(""); + toolBarHead.add(flexTable, new BoxLayoutData(new Margins(0))); + // Create Grid IdentityValueProvider identity = new IdentityValueProvider(); CheckBoxSelectionModel sm = new CheckBoxSelectionModel( @@ -274,17 +335,10 @@ public class ReplaceBatchPanel extends FramedPanel implements RowNumberer number = new RowNumberer( identity); - // number.setFixed(false); - // number.setResizable(false); number.setWidth(50); - - //From gxt 3.1.1 + number.setCellClassName(""); number.setCellPadding(true); - - //GXT 3.0.1 - //number.setColumnClassSuffix(""); - number.setHeader("N."); SafeStylesBuilder styleBuilder = new SafeStylesBuilder(); styleBuilder.width(50, Unit.PX); @@ -308,10 +362,13 @@ public class ReplaceBatchPanel extends FramedPanel implements sb.appendHtmlConstant("" + DON_T_REPLACE + ""); } else { - + String style = "style='color: green;font-weight:normal'"; - sb.appendHtmlConstant("" + new SafeHtmlBuilder().appendEscaped(value).toSafeHtml().asString() - + ""); + sb.appendHtmlConstant("" + + new SafeHtmlBuilder().appendEscaped(value) + .toSafeHtml().asString() + ""); } } @@ -388,7 +445,7 @@ public class ReplaceBatchPanel extends FramedPanel implements grid.setLoader(loader); grid.setSelectionModel(sm); number.initPlugin(grid); - grid.setHeight("376px"); + grid.setHeight(GRID_HEIGHT); grid.getView().setStripeRows(true); grid.getView().setColumnLines(true); grid.getView().setAutoFill(true); @@ -434,8 +491,8 @@ public class ReplaceBatchPanel extends FramedPanel implements HBoxLayoutContainer flowButton = new HBoxLayoutContainer(); flowButton.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE); flowButton.setPack(BoxLayoutPack.CENTER); - - BoxLayoutData boxLayoutData=new BoxLayoutData(new Margins(2, 4, 2, 4)); + + BoxLayoutData boxLayoutData = new BoxLayoutData(new Margins(2, 4, 2, 4)); flowButton.add(btnSave, boxLayoutData); flowButton.add(btnClose, boxLayoutData); @@ -443,59 +500,157 @@ public class ReplaceBatchPanel extends FramedPanel implements v.add(toolBarHead, new VerticalLayoutData(1, -1, new Margins(0))); v.add(grid, new VerticalLayoutData(1, -1, new Margins(0))); v.add(toolBar, new VerticalLayoutData(1, 25, new Margins(0))); - v.add(flowButton, new VerticalLayoutData(1, 36, - new Margins(5, 2, 5, 2))); + v.add(flowButton, + new VerticalLayoutData(1, 36, new Margins(5, 2, 5, 2))); add(v); - if (curation) { - storeShowOccurrencesType.addAll(ShowOccurrencesTypeStore - .getShowOccurrencesType()); - if (connection != null) { - Log.debug("Selected connection: " + connection); - connectionField.setValue(connection.getLabel()); - connectionField.setVisible(true); - btnDisconnect.setVisible(true); - btnConnect.setVisible(false); - btnConnect.enable(); - - } else { - - } - toolBarHead.forceLayout(); - } else { - if (column.isViewColumn()) { - Log.debug("Is View Column"); - //storeShowOccurrencesType - // .add(ShowOccurrencesTypeStore.onlyErrorsElement); - storeShowOccurrencesType - .addAll(ShowOccurrencesTypeStore.getShowOccurrencesType()); - - - ColumnViewData cViewData = column.getColumnViewData(); - RefColumn refCol = new RefColumn(String.valueOf(cViewData - .getTargetTableId()), - cViewData.getTargetTableColumnId()); - retrieveConnectionForViewColumn(refCol); - } else { - storeShowOccurrencesType.addAll(ShowOccurrencesTypeStore - .getShowOccurrencesType()); - Log.debug("Not Is View Column"); - connectionField.setVisible(false); - btnDisconnect.setVisible(false); - toolBarHead.forceLayout(); - } - - } + setSelectedColumn(); } + protected void update(ColumnData column) { + this.column = column; + if (column == null) { + setSelectedColumn(); + } else { + columnLocalId = column.getColumnId(); + connection=null; + conditionCode=null; + refColumn = null; + validationColumnColumnId = null; + hasValidationColumns = false; + clear(); + retrieveValidationColumn(); + } + + } - protected void retrieveColumnByColumnId() { + protected void setSelectedColumn() { + if (column == null) { + columnLocalId=null; + connection = null; + conditionCode=null; + refColumn = null; + validationColumnColumnId = null; + hasValidationColumns = false; + comboCols.reset(); + storeShowOccurrencesType.addAll(ShowOccurrencesTypeStore + .getShowOccurrencesType()); + Log.debug("Not Is View Column"); + connectionField.setVisible(false); + btnDisconnect.setVisible(false); + btnConnect.setVisible(false); + if(curation){ + comboCols.setReadOnly(true); + } + toolBarHead.forceLayout(); + } else { + comboCols.setValue(column); + if (curation) { + comboCols.setReadOnly(true); + storeShowOccurrencesType.addAll(ShowOccurrencesTypeStore + .getShowOccurrencesType()); + if (connection != null) { + Log.debug("Selected connection: " + connection); + connectionField.setValue(connection.getLabel()); + connectionField.setVisible(true); + btnDisconnect.setVisible(true); + btnConnect.setVisible(false); + btnConnect.disable(); + toolBarHead.forceLayout(); + } else { + if (column.isViewColumn()) { + Log.debug("Is View Column"); + // storeShowOccurrencesType + // .add(ShowOccurrencesTypeStore.onlyErrorsElement); + storeShowOccurrencesType.addAll(ShowOccurrencesTypeStore + .getShowOccurrencesType()); + + ColumnViewData cViewData = column.getColumnViewData(); + RefColumn refCol = new RefColumn(String.valueOf(cViewData + .getTargetTableId()), + cViewData.getTargetTableColumnId()); + retrieveConnectionForViewColumn(refCol); + } else { + storeShowOccurrencesType.addAll(ShowOccurrencesTypeStore + .getShowOccurrencesType()); + Log.debug("Not Is View Column"); + connectionField.setVisible(false); + btnDisconnect.setVisible(false); + btnConnect.setVisible(true); + btnConnect.setEnabled(true); + toolBarHead.forceLayout(); + } + } + + } else { + + if (column.isViewColumn()) { + Log.debug("Is View Column"); + // storeShowOccurrencesType + // .add(ShowOccurrencesTypeStore.onlyErrorsElement); + storeShowOccurrencesType.addAll(ShowOccurrencesTypeStore + .getShowOccurrencesType()); + + ColumnViewData cViewData = column.getColumnViewData(); + RefColumn refCol = new RefColumn(String.valueOf(cViewData + .getTargetTableId()), + cViewData.getTargetTableColumnId()); + retrieveConnectionForViewColumn(refCol); + } else { + storeShowOccurrencesType.addAll(ShowOccurrencesTypeStore + .getShowOccurrencesType()); + Log.debug("Not Is View Column"); + connectionField.setVisible(false); + btnDisconnect.setVisible(false); + btnConnect.setVisible(true); + btnConnect.setEnabled(true); + toolBarHead.forceLayout(); + } + + } + } + } + + 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; + btnSave.enable(); + update(col); + } else { + column = null; + btnSave.disable(); + update(null); + } + } + }; + + return selectionHandler; + } + + private void cleanCells(Element elem) { + NodeList tds = elem. cast().select("td"); + for (int i = 0; i < tds.getLength(); i++) { + Element td = tds.getItem(i); + + if (!td.hasChildNodes() && td.getClassName().equals("")) { + td.removeFromParent(); + } + } + } + + protected void retrieveColumnsWithViewColumnIncluded() { Log.debug("Retrieve Column by ColumnId: columnLocalId:" + columnLocalId + ", trId:" + trId); - TDGWTServiceAsync.INSTANCE.getColumn(columnLocalId, trId, - new AsyncCallback() { + TDGWTServiceAsync.INSTANCE.getColumnWithViewColumnIncluded(trId, + new AsyncCallback>() { public void onFailure(Throwable caught) { if (caught instanceof TDGWTSessionExpiredException) { @@ -521,17 +676,35 @@ public class ReplaceBatchPanel extends FramedPanel implements } } - public void onSuccess(ColumnData result) { + public void onSuccess(ArrayList result) { Log.debug("Column: " + result); - column = result; - retriveValidationColumn(); + columns = result; + retrieveColumn(); + if (column == null) { + hasValidationColumns = false; + create(); + } else { + retrieveValidationColumn(); + } } }); } - protected void retriveValidationColumn() { - TDGWTServiceAsync.INSTANCE.getValidationColumns(columnLocalId,trId, + protected void retrieveColumn() { + for (ColumnData c : columns) { + if (columnLocalId != null + && c.getColumnId().compareTo(columnLocalId) == 0) { + column = c; + return; + } + + } + + } + + protected void retrieveValidationColumn() { + TDGWTServiceAsync.INSTANCE.getValidationColumns(columnLocalId, trId, new AsyncCallback>() { public void onFailure(Throwable caught) { @@ -616,7 +789,15 @@ public class ReplaceBatchPanel extends FramedPanel implements */ protected void loadData(ListLoadConfig loadConfig, final AsyncCallback> callback) { - + + if(column==null){ + ListLoadResultBean loadedResult = new ListLoadResultBean( + getRecord(new ArrayList())); + Log.debug("created " + loadedResult.toString()); + callback.onSuccess(loadedResult); + return; + } + OccurrencesForReplaceBatchColumnSession occurrencesSession = new OccurrencesForReplaceBatchColumnSession( column, showOccurencesType, hasValidationColumns, conditionCode, validationColumnColumnId); @@ -1064,7 +1245,7 @@ public class ReplaceBatchPanel extends FramedPanel implements public void onSuccess(ColumnData result) { Log.debug("Column: " + result); connection = result; - retrieveColumnByColumnId(); + retrieveColumnsWithViewColumnIncluded(); } });