diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/EditRowDialog.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/EditRowDialog.java index ac8b229..2b5acd0 100644 --- a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/EditRowDialog.java +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/EditRowDialog.java @@ -1,5 +1,7 @@ package org.gcube.portlets.user.td.tablewidget.client.rows; +import java.util.ArrayList; + import org.gcube.portlets.user.td.gwtservice.shared.tr.rows.DeleteRowsSession; import org.gcube.portlets.user.td.tablewidget.client.resources.ResourceBundle; import org.gcube.portlets.user.td.tablewidget.client.util.UtilsGXT3; @@ -22,29 +24,29 @@ public class EditRowDialog extends Window { protected String HEIGHT = "456px"; protected TRId trId; protected EventBus eventBus; - protected RowRaw row; + protected ArrayList rows; protected DeleteRowsSession deleteRowsSession; private boolean addRow; /** - * Edit selected row + * Edit selected rows * * @param trId - * @param row + * @param rows * @param eventBus */ - public EditRowDialog(TRId trId, RowRaw row, EventBus eventBus) { + public EditRowDialog(TRId trId, ArrayList rows, EventBus eventBus) { this.trId = trId; - this.row = row; + //this.rows = rows; this.eventBus = eventBus; addRow = false; - if (row == null) { + if (rows == null) { UtilsGXT3.alert("Attentions", "No row selected"); } else { initWindow(); - EditRowPanel editRowPanel = new EditRowPanel(this, trId, row, + EditRowPanel editRowPanel = new EditRowPanel(this, trId, rows, eventBus); add(editRowPanel); } diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/EditRowPanel.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/EditRowPanel.java index d42220b..12e580f 100644 --- a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/EditRowPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/rows/EditRowPanel.java @@ -61,6 +61,7 @@ import com.sencha.gxt.widget.core.client.event.TriggerClickEvent.TriggerClickHan 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; import com.sencha.gxt.widget.core.client.form.validator.RegExValidator; @@ -71,22 +72,27 @@ import com.sencha.gxt.widget.core.client.form.validator.RegExValidator; * */ public class EditRowPanel extends FramedPanel implements MonitorDialogListener { + private static final String ITEM_CREATE_ROW = "NewRow"; + 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*$)"; - protected String WIDTH = "510px"; - protected String HEIGHT = "370px"; - protected String FIELDSHEIGHT = "370px"; - protected int LABELSIZE = 120; + private static final String WIDTH = "510px"; + private static final String HEIGHT = "370px"; + private static final String FIELDSHEIGHT = "370px"; + private static final int LABELSIZE = 120; - protected EditRowDialog parent; - protected TRId trId; - protected EventBus eventBus; - protected ArrayList columns; - protected RowRaw rowRaw; - protected boolean editRow; + private EditRowDialog parent; + private TRId trId; + private EventBus eventBus; + private ArrayList columns; + private ArrayList rowsRaw; + private boolean editRow; - protected VerticalLayoutContainer v; + private VerticalLayoutContainer v; + + private ArrayList rowsId; + private TextButton btnSave; private TextButton btnClose; @@ -97,20 +103,20 @@ public class EditRowPanel extends FramedPanel implements MonitorDialogListener { * * @param parent * @param trId - * @param rowRaw + * @param rowsRaw * @param eventBus */ - public EditRowPanel(EditRowDialog parent, TRId trId, RowRaw rowRaw, - EventBus eventBus) { + public EditRowPanel(EditRowDialog parent, TRId trId, + ArrayList rowsRaw, EventBus eventBus) { super(); this.parent = parent; this.trId = trId; - this.rowRaw = rowRaw; + this.rowsRaw = rowsRaw; this.eventBus = eventBus; this.editRow = true; - Log.debug("Create EditRowPanel(): [" + trId.toString() + " , RowRaw:" - + rowRaw + "]"); - if (rowRaw == null) { + Log.debug("Create EditRowPanel(): [" + trId.toString() + " , RowsRaw:" + + rowsRaw + "]"); + if (rowsRaw == null || rowsRaw.isEmpty()) { UtilsGXT3.alert("Attentions", "No row selected"); } else { init(); @@ -166,8 +172,8 @@ public class EditRowPanel extends FramedPanel implements MonitorDialogListener { } }); - - if(columns.size()<1){ + + if (columns.size() < 1) { btnSave.disable(); } @@ -190,10 +196,45 @@ public class EditRowPanel extends FramedPanel implements MonitorDialogListener { flowButton.add(btnSave, new BoxLayoutData(new Margins(2, 4, 2, 4))); flowButton.add(btnClose, new BoxLayoutData(new Margins(2, 4, 2, 4))); - ArrayList fields = generateFields(); - for (FieldLabel fl : fields) { - v.add(fl, new VerticalLayoutData(1, -1, new Margins(1))); + rowsId=new ArrayList(); + if (editRow) { + for (RowRaw rowRaw : rowsRaw) { + FieldSet fieldSet = new FieldSet(); + fieldSet.setCollapsible(false); + fieldSet.setItemId(rowRaw.getRowId()); + rowsId.add(rowRaw.getRowId()); + + VerticalLayoutContainer fieldSetLayout = new VerticalLayoutContainer(); + fieldSetLayout.setScrollMode(ScrollMode.AUTO); + fieldSet.add(fieldSetLayout); + ArrayList fields = generateFields(rowRaw); + for (FieldLabel fl : fields) { + fieldSetLayout.add(fl, new VerticalLayoutData(1, -1, + new Margins(1))); + } + + v.add(fieldSet, new VerticalLayoutData(1, -1, new Margins(1))); + + } + + } else { + FieldSet fieldSet = new FieldSet(); + fieldSet.setCollapsible(false); + fieldSet.setItemId(ITEM_CREATE_ROW); + rowsId.add(ITEM_CREATE_ROW); + + VerticalLayoutContainer fieldSetLayout = new VerticalLayoutContainer(); + fieldSetLayout.setScrollMode(ScrollMode.AUTO); + fieldSet.add(fieldSetLayout); + + ArrayList fields = generateFields(null); + for (FieldLabel fl : fields) { + fieldSetLayout.add(fl, new VerticalLayoutData(1, -1, + new Margins(1))); + } + + v.add(fieldSet, new VerticalLayoutData(1, -1, new Margins(1))); } container.forceLayout(); @@ -236,7 +277,7 @@ public class EditRowPanel extends FramedPanel implements MonitorDialogListener { } - protected ArrayList generateFields() { + protected ArrayList generateFields(RowRaw rowRaw) { ArrayList fields = new ArrayList(); for (ColumnData col : columns) { @@ -254,8 +295,8 @@ public class EditRowPanel extends FramedPanel implements MonitorDialogListener { || col.getTypeCode().compareTo( ColumnTypeCode.TIMEDIMENSION.toString()) == 0) { - FieldLabel dimensionLabel = retrieveDimensionLabel(col, - label); + FieldLabel dimensionLabel = retrieveDimensionLabel(rowRaw, + col, label); dimensionLabel.setLabelWidth(LABELSIZE); fields.add(dimensionLabel); } else { @@ -424,8 +465,8 @@ public class EditRowPanel extends FramedPanel implements MonitorDialogListener { } - protected FieldLabel retrieveDimensionLabel(final ColumnData col, - String label) { + protected FieldLabel retrieveDimensionLabel(RowRaw rowRaw, + final ColumnData col, String label) { Log.debug("retriveDimensionLabel on:" + col); // comboDimension DimensionRowsProperties propsDimension = GWT @@ -503,146 +544,164 @@ public class EditRowPanel extends FramedPanel implements MonitorDialogListener { protected void save() { int i = 0; int lenght = v.getWidgetCount(); - HashMap maps = new HashMap(); + HashMap> rowsMaps = new HashMap>(); + for (; i < lenght; i++) { - FieldLabel fieldLabel = (FieldLabel) v.getWidget(i); - String columnId = fieldLabel.getId(); - ColumnData colCurrent = null; - for (ColumnData col : columns) { - if (col.getColumnId().compareTo(columnId) == 0) { - colCurrent = col; - break; + FieldSet fieldSet = (FieldSet) v.getWidget(i); + VerticalLayoutContainer fieldSetLayout = (VerticalLayoutContainer) fieldSet + .getWidget(); + int j = 0; + int fieldSetLayoutLenght = fieldSetLayout.getWidgetCount(); + HashMap maps = new HashMap(); + for (; j < fieldSetLayoutLenght; j++) { + FieldLabel fieldLabel = (FieldLabel) fieldSetLayout + .getWidget(j); + String columnId = fieldLabel.getId(); + ColumnData colCurrent = null; + for (ColumnData col : columns) { + if (col.getColumnId().compareTo(columnId) == 0) { + colCurrent = col; + break; + } } - } - if (colCurrent == null) { - Log.debug("Current col is null"); - btnSave.enable(); - return; - } - if (colCurrent.getTypeCode().compareTo( - ColumnTypeCode.DIMENSION.toString()) == 0 - || colCurrent.getTypeCode().compareTo( - ColumnTypeCode.TIMEDIMENSION.toString()) == 0) { - @SuppressWarnings("unchecked") - ComboBox comboDimension = (ComboBox) fieldLabel - .getWidget(); - DimensionRow dimRow = comboDimension.getValue(); - if (dimRow == null - || (dimRow != null && (dimRow.getRowId() == null || dimRow - .getRowId().isEmpty()))) { - UtilsGXT3.alert("Attentions", "Select a valid value for " - + colCurrent.getLabel()); + if (colCurrent == null) { + Log.debug("Current col is null"); btnSave.enable(); return; } - maps.put(columnId, dimRow.getRowId()); - } else { - if (colCurrent.getDataTypeName().compareTo( - ColumnDataType.Boolean.toString()) == 0) { - HorizontalPanel hpanel = (HorizontalPanel) fieldLabel + if (colCurrent.getTypeCode().compareTo( + ColumnTypeCode.DIMENSION.toString()) == 0 + || colCurrent.getTypeCode().compareTo( + ColumnTypeCode.TIMEDIMENSION.toString()) == 0) { + @SuppressWarnings("unchecked") + ComboBox comboDimension = (ComboBox) fieldLabel .getWidget(); - Radio radioTrue = (Radio) hpanel.getWidget(0); - maps.put(columnId, radioTrue.getValue().toString()); + DimensionRow dimRow = comboDimension.getValue(); + if (dimRow == null + || (dimRow != null && (dimRow.getRowId() == null || dimRow + .getRowId().isEmpty()))) { + UtilsGXT3.alert( + "Attentions", + "Select a valid value for " + + colCurrent.getLabel()); + btnSave.enable(); + return; + } + maps.put(columnId, dimRow.getRowId()); } else { if (colCurrent.getDataTypeName().compareTo( - ColumnDataType.Date.toString()) == 0) { - DateField date = (DateField) fieldLabel.getWidget(); - if (date == null || date.getCurrentValue() == null) { - maps.put(columnId, null); - } else { - Date d = date.getCurrentValue(); - String dateS = sdf.format(d); - maps.put(columnId, dateS); - } + ColumnDataType.Boolean.toString()) == 0) { + HorizontalPanel hpanel = (HorizontalPanel) fieldLabel + .getWidget(); + Radio radioTrue = (Radio) hpanel.getWidget(0); + maps.put(columnId, radioTrue.getValue().toString()); } else { if (colCurrent.getDataTypeName().compareTo( - ColumnDataType.Text.toString()) == 0) { - TextField text = (TextField) fieldLabel.getWidget(); - String val = text.getCurrentValue(); - if (val == null) { - val = ""; + ColumnDataType.Date.toString()) == 0) { + DateField date = (DateField) fieldLabel.getWidget(); + if (date == null || date.getCurrentValue() == null) { + maps.put(columnId, null); + } else { + Date d = date.getCurrentValue(); + String dateS = sdf.format(d); + maps.put(columnId, dateS); } - maps.put(columnId, val); } else { if (colCurrent.getDataTypeName().compareTo( - ColumnDataType.Geometry.toString()) == 0) { - TextField geometry = (TextField) fieldLabel + ColumnDataType.Text.toString()) == 0) { + TextField text = (TextField) fieldLabel .getWidget(); - if (geometry.isValid()) { - String val = geometry.getCurrentValue(); - if (val == null) { - val = ""; - } - maps.put(columnId, val); - } else { - UtilsGXT3 - .alert("Attentions", - "The value of " - + colCurrent - .getLabel() - + " is not a valid text representation for geometry type ( e.g. POINT(34 56) or LINESTRING(65 34, 56.43 78.65)!"); - btnSave.enable(); - return; + String val = text.getCurrentValue(); + if (val == null) { + val = ""; } + maps.put(columnId, val); } else { if (colCurrent.getDataTypeName().compareTo( - ColumnDataType.Integer.toString()) == 0) { - TextField integ = (TextField) fieldLabel + ColumnDataType.Geometry.toString()) == 0) { + TextField geometry = (TextField) fieldLabel .getWidget(); - @SuppressWarnings("unused") - Integer intege; - try { - intege = new Integer( - integ.getCurrentValue()); - } catch (NumberFormatException e) { + if (geometry.isValid()) { + String val = geometry.getCurrentValue(); + if (val == null) { + val = ""; + } + maps.put(columnId, val); + } else { UtilsGXT3 .alert("Attentions", - colCurrent.getLabel() - + " is no a valid Integer type"); + "The value of " + + colCurrent + .getLabel() + + " is not a valid text representation for geometry type ( e.g. POINT(34 56) or LINESTRING(65 34, 56.43 78.65)!"); btnSave.enable(); return; } - - maps.put(columnId, integ.getCurrentValue()); } else { if (colCurrent.getDataTypeName().compareTo( - ColumnDataType.Numeric.toString()) == 0) { - TextField numeric = (TextField) fieldLabel + ColumnDataType.Integer.toString()) == 0) { + TextField integ = (TextField) fieldLabel .getWidget(); @SuppressWarnings("unused") - Double d; - String val = numeric.getCurrentValue(); - if (val == null) { - Log.debug("Attentions" - + colCurrent.getLabel() - + " is no a valid Numeric type"); - UtilsGXT3 - .alert("Attentions", - colCurrent - .getLabel() - + " is no a valid Numeric type"); - btnSave.enable(); - return; - } + Integer intege; try { - d = new Double(val); + intege = new Integer( + integ.getCurrentValue()); } catch (NumberFormatException e) { - Log.debug("Attentions" - + colCurrent.getLabel() - + " is no a valid Numeric type"); UtilsGXT3 .alert("Attentions", colCurrent .getLabel() - + " is no a valid Numeric type"); + + " is no a valid Integer type"); btnSave.enable(); return; } - maps.put(columnId, - numeric.getCurrentValue()); - } else { + maps.put(columnId, + integ.getCurrentValue()); + } else { + if (colCurrent.getDataTypeName() + .compareTo( + ColumnDataType.Numeric + .toString()) == 0) { + TextField numeric = (TextField) fieldLabel + .getWidget(); + @SuppressWarnings("unused") + Double d; + String val = numeric + .getCurrentValue(); + if (val == null) { + Log.debug("Attentions" + + colCurrent.getLabel() + + " is no a valid Numeric type"); + UtilsGXT3 + .alert("Attentions", + colCurrent + .getLabel() + + " is no a valid Numeric type"); + btnSave.enable(); + return; + } + try { + d = new Double(val); + } catch (NumberFormatException e) { + Log.debug("Attentions" + + colCurrent.getLabel() + + " is no a valid Numeric type"); + UtilsGXT3 + .alert("Attentions", + colCurrent + .getLabel() + + " is no a valid Numeric type"); + btnSave.enable(); + return; + } + maps.put(columnId, + numeric.getCurrentValue()); + } else { + + } } } } @@ -650,14 +709,17 @@ public class EditRowPanel extends FramedPanel implements MonitorDialogListener { } } } + + rowsMaps.put(fieldSet.getItemId(), maps); + } EditRowSession editRowSession; if (editRow) { - editRowSession = new EditRowSession(trId, columns, maps, - rowRaw.getRowId()); + editRowSession = new EditRowSession(trId, columns, rowsMaps, + rowsId); } else { - editRowSession = new EditRowSession(trId, columns, maps); + editRowSession = new EditRowSession(trId, columns, rowsMaps); } callEditRow(editRowSession);