diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geometry/GeometryCreatePointPanel.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geometry/GeometryCreatePointPanel.java index 4306c2f..4080c0f 100644 --- a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geometry/GeometryCreatePointPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geometry/GeometryCreatePointPanel.java @@ -177,12 +177,11 @@ public class GeometryCreatePointPanel extends FramedPanel implements vl.setScrollMode(ScrollMode.AUTO); vl.setAdjustForScroll(true); - vl.add(new FieldLabel(comboLatitude, "Latitude"), - new VerticalLayoutData(1, -1)); - vl.add(new FieldLabel(comboLongitude, "Longitude"), new VerticalLayoutData(1, -1)); - + vl.add(new FieldLabel(comboLatitude, "Latitude"), + new VerticalLayoutData(1, -1)); + vl.add(columnLab, new VerticalLayoutData(1, -1)); vl.add(createPointButton, new VerticalLayoutData(-1, -1, new Margins( @@ -248,10 +247,10 @@ public class GeometryCreatePointPanel extends FramedPanel implements } protected void onGeometryCreatePoint() { - ColumnData latitude = comboLatitude.getCurrentValue(); - if (latitude != null) { - ColumnData longitude = comboLongitude.getCurrentValue(); - if (longitude != null) { + ColumnData longitude = comboLongitude.getCurrentValue(); + if (longitude != null) { + ColumnData latitude = comboLatitude.getCurrentValue(); + if (latitude != null) { String columnLab = columnLabelField.getCurrentValue(); if (columnLab != null && !columnLab.isEmpty()) { GeometryCreatePointSession geoCreatePointSession = new GeometryCreatePointSession( @@ -261,10 +260,10 @@ public class GeometryCreatePointPanel extends FramedPanel implements UtilsGXT3.alert("Attention", "Select a column label!"); } } else { - UtilsGXT3.alert("Attention", "Select Longitude!"); + UtilsGXT3.alert("Attention", "Select Latitude!"); } } else { - UtilsGXT3.alert("Attention", "Select Latitude!"); + UtilsGXT3.alert("Attention", "Select Longitude!"); } } diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/GeospatialCreateCoordinatesPanel.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/GeospatialCreateCoordinatesPanel.java index a788a37..09c986b 100644 --- a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/GeospatialCreateCoordinatesPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/GeospatialCreateCoordinatesPanel.java @@ -53,7 +53,6 @@ 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.Radio; -import com.sencha.gxt.widget.core.client.form.TextField; import com.sencha.gxt.widget.core.client.info.Info; /** @@ -88,7 +87,9 @@ public class GeospatialCreateCoordinatesPanel extends FramedPanel implements private Radio hasQuadrantFalse; private FieldLabel comboQuadrantLabel; private FieldLabel hasQuadrantLabel; - private TextField resolutionField; + + private ComboBox comboResolution; + private ListStore storeComboResolution; public GeospatialCreateCoordinatesPanel(TRId trId, RequestProperties requestProperties, EventBus eventBus) { @@ -207,9 +208,28 @@ public class GeospatialCreateCoordinatesPanel extends FramedPanel implements comboGsCoordinatesType.setTriggerAction(TriggerAction.ALL); // Resolution - resolutionField = new TextField(); - resolutionField.setValue("0.1"); - FieldLabel resolutionLabel = new FieldLabel(resolutionField, + ResolutionPropertiesCombo propsResolution = GWT + .create(ResolutionPropertiesCombo.class); + + storeComboResolution = new ListStore(propsResolution.id()); + storeComboResolution + .addAll(ResolutionStore.getStoreCSquareResolution()); + + comboResolution = new ComboBox(storeComboResolution, + propsResolution.value()); + Log.trace("Combo Resolution created"); + + addHandlersForComboResolution(propsResolution.value()); + + comboResolution.setEmptyText("Select a resolution..."); + comboResolution.setValue(ResolutionStore + .getStoreCSquareResolutionDefault()); + comboResolution.setWidth(191); + comboResolution.setTypeAhead(false); + comboResolution.setEditable(false); + comboResolution.setTriggerAction(TriggerAction.ALL); + + FieldLabel resolutionLabel = new FieldLabel(comboResolution, "Resolution"); // Has Quadrant @@ -301,11 +321,10 @@ public class GeospatialCreateCoordinatesPanel extends FramedPanel implements vl.setScrollMode(ScrollMode.AUTO); vl.setAdjustForScroll(true); - vl.add(new FieldLabel(comboLatitude, "Latitude"), - new VerticalLayoutData(1, -1)); - vl.add(new FieldLabel(comboLongitude, "Longitude"), new VerticalLayoutData(1, -1)); + vl.add(new FieldLabel(comboLatitude, "Latitude"), + new VerticalLayoutData(1, -1)); vl.add(new FieldLabel(comboGsCoordinatesType, "Type"), new VerticalLayoutData(1, -1)); @@ -325,6 +344,32 @@ public class GeospatialCreateCoordinatesPanel extends FramedPanel implements } + private void addHandlersForComboResolution( + final LabelProvider value) { + comboResolution.addSelectionHandler(new SelectionHandler() { + + @Override + public void onSelection(SelectionEvent event) { + Info.display( + "Resolution Selected", + "You selected " + + (event.getSelectedItem() == null ? "nothing" + : value.getLabel(event + .getSelectedItem()) + "!")); + Log.debug("Reolution selected: " + event.getSelectedItem()); + Resolution resolution = event.getSelectedItem(); + updatedResolution(resolution); + + } + + }); + + } + + protected void updatedResolution(Resolution resolution) { + + } + private void addHandlersForComboColumnLatitude( final LabelProvider labelProvider) { comboLatitude.addSelectionHandler(new SelectionHandler() { @@ -417,7 +462,14 @@ public class GeospatialCreateCoordinatesPanel extends FramedPanel implements hasQuadrantLabel.setVisible(false); comboQuadrantLabel.setVisible(false); comboGsCoordinatesType.setValue(gsCoordinatesType); - resolutionField.setValue("10.0"); + storeComboResolution.clear(); + storeComboResolution.addAll(ResolutionStore + .getStoreCSquareResolution()); + storeComboResolution.commitChanges(); + comboResolution.clear(); + comboResolution.reset(); + comboResolution.setValue(ResolutionStore + .getStoreCSquareResolutionDefault()); createCoordinatesButton.setIcon(ResourceBundle.INSTANCE .geospatialCSquare()); @@ -433,14 +485,28 @@ public class GeospatialCreateCoordinatesPanel extends FramedPanel implements comboQuadrantLabel.setVisible(true); } - resolutionField.setValue("0.1"); + storeComboResolution.clear(); + storeComboResolution.addAll(ResolutionStore + .getStoreOceanAreaResolution()); + storeComboResolution.commitChanges(); + comboResolution.clear(); + comboResolution.reset(); + comboResolution.setValue(ResolutionStore + .getStoreOceanAreaResolutionDefault()); hasQuadrantLabel.setVisible(true); comboGsCoordinatesType.setValue(gsCoordinatesType); createCoordinatesButton.setIcon(ResourceBundle.INSTANCE .geospatialOceanArea()); break; default: - resolutionField.setValue("10.0"); + storeComboResolution.clear(); + storeComboResolution.addAll(ResolutionStore + .getStoreCSquareResolution()); + storeComboResolution.commitChanges(); + comboResolution.clear(); + comboResolution.reset(); + comboResolution.setValue(ResolutionStore + .getStoreCSquareResolutionDefault()); hasQuadrantLabel.setVisible(false); comboQuadrantLabel.setVisible(false); createCoordinatesButton.setIcon(ResourceBundle.INSTANCE @@ -488,70 +554,68 @@ public class GeospatialCreateCoordinatesPanel extends FramedPanel implements } protected void onGeospatialCreateCoordinates() { - ColumnData latitude = comboLatitude.getCurrentValue(); - if (latitude != null) { - ColumnData longitude = comboLongitude.getCurrentValue(); - if (longitude != null) { - String resol = resolutionField.getCurrentValue(); - Double resolution = null; - try { - resolution = new Double(resol); - } catch (NumberFormatException e) { - UtilsGXT3.alert("Attention", "Insert a valid resolution!"); - return; - } + ColumnData longitude = comboLongitude.getCurrentValue(); + if (longitude != null) { + ColumnData latitude = comboLatitude.getCurrentValue(); + if (latitude != null) { + Resolution resolution = comboResolution.getCurrentValue(); + if (resolution != null) { - GeospatialCoordinatesType type = comboGsCoordinatesType - .getCurrentValue(); - if (type != null) { - GeospatialCreateCoordinatesSession gsCreateCoordinatesSession; - switch (type) { - case C_SQUARE: - gsCreateCoordinatesSession = new GeospatialCreateCoordinatesSession( - trId, latitude, longitude, type, false, null, - resolution); - callGeospatialCreateCoordinates(gsCreateCoordinatesSession); - break; - case OCEAN_AREA: - if (hasQuadrant()) { - ColumnData quadrant = comboQuadrant - .getCurrentValue(); - if (quadrant != null) { - gsCreateCoordinatesSession = new GeospatialCreateCoordinatesSession( - trId, latitude, longitude, type, true, - quadrant, resolution); - callGeospatialCreateCoordinates(gsCreateCoordinatesSession); - } else { - UtilsGXT3.alert("Attention", - "Select Quadrant column!"); - break; - } - - } else { + GeospatialCoordinatesType type = comboGsCoordinatesType + .getCurrentValue(); + if (type != null) { + GeospatialCreateCoordinatesSession gsCreateCoordinatesSession; + switch (type) { + case C_SQUARE: gsCreateCoordinatesSession = new GeospatialCreateCoordinatesSession( trId, latitude, longitude, type, false, - null, resolution); + null, resolution.getValue()); callGeospatialCreateCoordinates(gsCreateCoordinatesSession); + break; + case OCEAN_AREA: + if (hasQuadrant()) { + ColumnData quadrant = comboQuadrant + .getCurrentValue(); + if (quadrant != null) { + gsCreateCoordinatesSession = new GeospatialCreateCoordinatesSession( + trId, latitude, longitude, type, + true, quadrant, resolution.getValue()); + callGeospatialCreateCoordinates(gsCreateCoordinatesSession); + } else { + UtilsGXT3.alert("Attention", + "Select Quadrant column!"); + break; + } + + } else { + gsCreateCoordinatesSession = new GeospatialCreateCoordinatesSession( + trId, latitude, longitude, type, false, + null, resolution.getValue()); + callGeospatialCreateCoordinates(gsCreateCoordinatesSession); + } + + break; + default: + UtilsGXT3 + .alert("Attention", + "Select valid geospatial coordinates type!"); + break; + } - break; - default: + } else { UtilsGXT3.alert("Attention", - "Select valid geospatial coordinates type!"); - break; - + "Invalid Geospatial Coordinates Type!"); } - } else { - UtilsGXT3.alert("Attention", - "Invalid Geospatial Coordinates Type!"); + UtilsGXT3.alert("Attention", "Select Resolution!"); } } else { - UtilsGXT3.alert("Attention", "Select Longitude!"); + UtilsGXT3.alert("Attention", "Select Latitude!"); } } else { - UtilsGXT3.alert("Attention", "Select Latitude!"); + UtilsGXT3.alert("Attention", "Select Longitude!"); } } diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/Resolution.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/Resolution.java new file mode 100644 index 0000000..f70a558 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/Resolution.java @@ -0,0 +1,43 @@ +package org.gcube.portlets.user.td.tablewidget.client.geospatial; + +/** + * + * @author giancarlo + * email: g.panichi@isti.cnr.it + * + */ +public class Resolution { + private int id; + private Double value; + + public Resolution() { + } + + public Resolution(int id, Double value) { + super(); + this.id = id; + this.value = value; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Double getValue() { + return value; + } + + public void setValue(Double value) { + this.value = value; + } + + @Override + public String toString() { + return "Resolution [id=" + id + ", value=" + value + "]"; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/ResolutionPropertiesCombo.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/ResolutionPropertiesCombo.java new file mode 100644 index 0000000..6a0fd7e --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/ResolutionPropertiesCombo.java @@ -0,0 +1,21 @@ +package org.gcube.portlets.user.td.tablewidget.client.geospatial; + +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 + * email: g.panichi@isti.cnr.it + * + */ +public interface ResolutionPropertiesCombo extends PropertyAccess { + + @Path("id") + ModelKeyProvider id(); + + LabelProvider value(); + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/ResolutionStore.java b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/ResolutionStore.java new file mode 100644 index 0000000..4d86a8b --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/tablewidget/client/geospatial/ResolutionStore.java @@ -0,0 +1,58 @@ +package org.gcube.portlets.user.td.tablewidget.client.geospatial; + +import java.io.Serializable; +import java.util.ArrayList; + +/** + * + * @author giancarlo + * email: g.panichi@isti.cnr.it + * + */ +public class ResolutionStore implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 6520001942214730827L; + + private static ArrayList storeCSquareResolution; + private static ArrayList storeOcenaAreaResolution; + + private static Resolution resolutionCSquare1=new Resolution(1, 0.1d); + private static Resolution resolutionCSquare2=new Resolution(2, 0.5d); + private static Resolution resolutionCSquare3=new Resolution(3, 1.0d); + private static Resolution resolutionCSquare4=new Resolution(4, 5.0d); + private static Resolution resolutionCSquare5=new Resolution(5, 10.0d); + + private static Resolution resolutionOceanArea1=new Resolution(1, 1.0d); + private static Resolution resolutionOceanArea2=new Resolution(2, 5.0d); + private static Resolution resolutionOceanArea3=new Resolution(3, 10.0d); + + public static ArrayList getStoreCSquareResolution() { + storeCSquareResolution=new ArrayList(); + storeCSquareResolution.add(resolutionCSquare1); + storeCSquareResolution.add(resolutionCSquare2); + storeCSquareResolution.add(resolutionCSquare3); + storeCSquareResolution.add(resolutionCSquare4); + storeCSquareResolution.add(resolutionCSquare5); + return storeCSquareResolution; + } + + public static Resolution getStoreCSquareResolutionDefault(){ + return resolutionCSquare2; + } + + public static ArrayList getStoreOceanAreaResolution() { + storeOcenaAreaResolution=new ArrayList(); + storeOcenaAreaResolution.add(resolutionOceanArea1); + storeOcenaAreaResolution.add(resolutionOceanArea2); + storeOcenaAreaResolution.add(resolutionOceanArea3); + return storeOcenaAreaResolution; + } + + public static Resolution getStoreOceanAreaResolutionDefault(){ + return resolutionOceanArea2; + } + +}