From 4dfe6711ffc98254d20ed51b905f3648d77815ca Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 19 Sep 2014 15:37:59 +0000 Subject: [PATCH] Updated Geometry Type Support git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-column-widget@100061 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/create/AddColumnPanel.java | 114 ++++++++++-------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/create/AddColumnPanel.java b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/create/AddColumnPanel.java index 7a88115..eaa98b5 100644 --- a/src/main/java/org/gcube/portlets/user/td/columnwidget/client/create/AddColumnPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/columnwidget/client/create/AddColumnPanel.java @@ -45,6 +45,8 @@ import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.event.logical.shared.SelectionEvent; import com.google.gwt.event.logical.shared.SelectionHandler; 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.rpc.AsyncCallback; import com.google.web.bindery.event.shared.EventBus; import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign; @@ -73,6 +75,9 @@ import com.sencha.gxt.widget.core.client.info.Info; */ public class AddColumnPanel extends FramedPanel implements CodelistSelectionListener, MonitorDialogListener { + 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 static final String WIDTH = "640px"; protected static final String HEIGHT = "520px"; @@ -106,17 +111,16 @@ public class AddColumnPanel extends FramedPanel implements protected ListStore storeComboLocaleType; protected AddColumnSession addColumnSession; - + protected TextButton btnAddColumn; protected TextField label; protected TextField defaultValueString; protected DateField defaultValueDate; - + protected FieldLabel defaultStringLabel; protected FieldLabel defaultDateLabel; - - + private DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); /** @@ -134,7 +138,7 @@ public class AddColumnPanel extends FramedPanel implements init(); create(); } - + /** * * @param parent @@ -149,7 +153,6 @@ public class AddColumnPanel extends FramedPanel implements init(); create(); } - protected void init() { setWidth(WIDTH); @@ -161,22 +164,22 @@ public class AddColumnPanel extends FramedPanel implements protected void create() { // Label label = new TextField(); - - //TODO + + // TODO // Default Value defaultValueString = new TextField(); - defaultStringLabel= new FieldLabel(defaultValueString, "Default"); - + defaultStringLabel = new FieldLabel(defaultValueString, "Default"); + defaultValueDate = new DateField(); defaultDateLabel = new FieldLabel(defaultValueDate, "Default"); - - + // comboColumnTypeCode ColumnTypeCodeProperties propsColumnTypeCode = GWT .create(ColumnTypeCodeProperties.class); ListStore storeComboTypeCode = new ListStore( propsColumnTypeCode.id()); - storeComboTypeCode.addAll(ColumnTypeCodeStore.getColumnTypeCodesForAddColumn(trId)); + storeComboTypeCode.addAll(ColumnTypeCodeStore + .getColumnTypeCodesForAddColumn(trId)); comboColumnTypeCode = new ComboBox( storeComboTypeCode, propsColumnTypeCode.label()); @@ -318,15 +321,13 @@ public class AddColumnPanel extends FramedPanel implements comboTimeDimensionTypeLabel = new FieldLabel(comboTimeDimensionType, "Time Type"); - - + // Save btnAddColumn = new TextButton("Add"); btnAddColumn.setIcon(ResourceBundle.INSTANCE.columnAdd()); btnAddColumn.setIconAlign(IconAlign.RIGHT); btnAddColumn.setTitle("Add Column"); - SelectHandler changeHandler = new SelectHandler() { public void onSelect(SelectEvent event) { @@ -353,13 +354,11 @@ public class AddColumnPanel extends FramedPanel implements new Margins(1))); v.add(comboTimeDimensionTypeLabel, new VerticalLayoutData(1, -1, new Margins(1))); - - v.add(defaultStringLabel, new VerticalLayoutData( - 1, -1, new Margins(1))); - v.add(defaultDateLabel, new VerticalLayoutData( - 1, -1, new Margins(1))); - v.add(btnAddColumn, - new VerticalLayoutData(-1, -1, new Margins(10, 0, 10, 0))); + + v.add(defaultStringLabel, new VerticalLayoutData(1, -1, new Margins(1))); + v.add(defaultDateLabel, new VerticalLayoutData(1, -1, new Margins(1))); + v.add(btnAddColumn, new VerticalLayoutData(-1, -1, new Margins(10, 0, + 10, 0))); add(v, new VerticalLayoutData(-1, -1, new Margins(0))); comboMeasureTypeLabel.setVisible(false); @@ -368,7 +367,7 @@ public class AddColumnPanel extends FramedPanel implements comboColumnReferenceTypeLabel.setVisible(false); comboTimeDimensionTypeLabel.setVisible(false); comboLocaleTypeLabel.setVisible(false); - + defaultDateLabel.setVisible(false); defaultStringLabel.setVisible(false); @@ -559,7 +558,7 @@ public class AddColumnPanel extends FramedPanel implements comboTimeDimensionTypeLabel.setVisible(false); defaultStringLabel.setVisible(false); defaultDateLabel.setVisible(false); - + break; case MEASURE: comboLocaleTypeLabel.setVisible(false); @@ -632,7 +631,7 @@ public class AddColumnPanel extends FramedPanel implements defaultDateLabel.setVisible(false); break; } - + forceLayout(); } @@ -692,28 +691,47 @@ public class AddColumnPanel extends FramedPanel implements ColumnDataType dataType = columnDataTypeElement .getType(); if (dataType != null) { - if(dataType==ColumnDataType.Date){ - Date d = defaultValueDate.getCurrentValue(); - if(d==null){ - UtilsGXT3.alert("Attention", - "Column data type not selected!"); - } else { - String dateS = sdf.format(d); - defNewColumn = new DefNewColumn(labelS, type, - dataType, dateS); - addColumnSession = new AddColumnSession(trId, - defNewColumn); + if (dataType == ColumnDataType.Geometry) { + // TODO + RegExp regExp = RegExp + .compile(GEOMETRY_REGEXPR); + MatchResult matcher = regExp.exec(defaultV); + boolean matchFound = matcher != null; + if (matchFound) { + defNewColumn = new DefNewColumn(labelS, + type, dataType, defaultV); + addColumnSession = new AddColumnSession( + trId, defNewColumn); callAddColumm(); + } else { + UtilsGXT3 + .alert("Attention", + "The default value is not a valid text representation for geometry type ( e.g. POINT(34 56) or LINESTRING(65 34, 56.43 78.65)!"); } } else { - defNewColumn = new DefNewColumn(labelS, type, - dataType, defaultV); - addColumnSession = new AddColumnSession(trId, - defNewColumn); - callAddColumm(); + if (dataType == ColumnDataType.Date) { + Date d = defaultValueDate.getCurrentValue(); + if (d == null) { + UtilsGXT3 + .alert("Attention", + "Column data type not selected!"); + } else { + String dateS = sdf.format(d); + defNewColumn = new DefNewColumn(labelS, + type, dataType, dateS); + addColumnSession = new AddColumnSession( + trId, defNewColumn); + callAddColumm(); + } + } else { + defNewColumn = new DefNewColumn(labelS, + type, dataType, defaultV); + addColumnSession = new AddColumnSession( + trId, defNewColumn); + callAddColumm(); + } + } - - } else { UtilsGXT3.alert("Attention", @@ -928,15 +946,13 @@ public class AddColumnPanel extends FramedPanel implements } } - - public void close() { if (parent != null) { parent.close(); } } - - /// + + // / protected void openMonitorDialog(String taskId) { MonitorDialog monitorDialog = new MonitorDialog(taskId, eventBus); monitorDialog.addProgressDialogListener(this); @@ -980,5 +996,5 @@ public class AddColumnPanel extends FramedPanel implements close(); } - + }