diff --git a/.classpath b/.classpath index 3468a2b..6991d1a 100644 --- a/.classpath +++ b/.classpath @@ -10,6 +10,7 @@ + @@ -25,6 +26,7 @@ + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index b90405e..e2ceea1 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -10,4 +10,5 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.7 diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/openlayerwidget/GeoJsonAreaSelectionDialog.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/openlayerwidget/GeoJsonAreaSelectionDialog.java index 5c91666..b1b486a 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/openlayerwidget/GeoJsonAreaSelectionDialog.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/openlayerwidget/GeoJsonAreaSelectionDialog.java @@ -31,6 +31,7 @@ public class GeoJsonAreaSelectionDialog extends AreaSelectionDialog{ * Instantiates a new geo json area selection dialog. */ public GeoJsonAreaSelectionDialog() { + super(); //THE HANDLER SelectAreaDialogEventHandler handler = new SelectAreaDialogEventHandler() { @@ -82,22 +83,22 @@ public class GeoJsonAreaSelectionDialog extends AreaSelectionDialog{ var ol = $wnd.ol; var geojson_options = {}; var wkt_format = new ol.format.WKT(); - var testFeature = wkt_format.readFeature(wktData); + var wktFeature = wkt_format.readFeature(wktData); + //console.log('WKT feature: '+wktFeature); var wkt_options = {}; var geojson_format = new ol.format.GeoJSON(wkt_options); - var out = geojson_format.writeFeature(testFeature); - //window.getELementById("my-id").innerhtml(out); - //alert(out); - console.log(out) - return out; + console.log('geojson_format: '+geojson_format); + var geoJsonFeature = geojson_format.writeFeature(wktFeature); + //console.log('GeoJSON Feature: '+geoJsonFeature); + return geoJsonFeature; }catch(err) { console.log(err.message); return null; } }-*/; - public static native String print(String data) /*-{ - console.log(out) + public static native String print(String txt) /*-{ + console.log(txt) }-*/; @@ -106,32 +107,39 @@ public class GeoJsonAreaSelectionDialog extends AreaSelectionDialog{ * * @param wktTxt the wkt txt * @return the string + * @throws Exception the exception */ - public String wktToGeoJSON(String wktTxt){ - String geoJSON = convertWKTToGeoJSON(wktTxt); - //Window.alert("geoJSON: "+geoJSON); - print("geoJSON: "+geoJSON); - - if(geoJSON==null) - return null; - - JavaScriptObject toJSON = JsonUtils.safeEval(geoJSON); - JSONObject objJson = new JSONObject(toJSON); - return objJson.get("geometry").toString(); + public String wktToGeoJSON(String wktTxt) throws Exception{ + try { + String geoJSON = convertWKTToGeoJSON(wktTxt); + //Window.alert("geoJSON: "+geoJSON); + print("geoJSON: "+geoJSON); + + if(geoJSON==null) + throw new Exception(); + + JavaScriptObject toJSON = JsonUtils.safeEval(geoJSON); + JSONObject objJson = new JSONObject(toJSON); + return objJson.get("geometry").toString(); + }catch(Exception e) { + //silent + throw new Exception("Sorry, an error occurred while getting GeoJSON format for the drawn Geometry"); + } } /** * Gets the WKT to geo json. * * @return the WKT to geo json + * @throws Exception the exception */ - public String getWKTToGeoJSON(){ + public String getWKTToGeoJSON() throws Exception{ if(wktArea==null){ print("wktArea is null"); - return null; + throw new Exception("Sorry, an error occurred while reading the drawn Geometry"); } - + //print("wktArea is: "+wktArea); return wktToGeoJSON(wktArea); } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java index 18c978c..f361666 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/metadata/MetaDataFieldSkeleton.java @@ -127,7 +127,6 @@ public class MetaDataFieldSkeleton extends Composite{ case GeoJSON: //MANAGED By FRANCESCO - // start and end range date final VerticalPanel containerGeoJSON = new VerticalPanel(); //containerGeoJSON.setWidth("100%"); @@ -150,12 +149,16 @@ public class MetaDataFieldSkeleton extends Composite{ Command fillGeoJSONArea = new Command() { public void execute() { - String geoJsonGeom = dialog.getWKTToGeoJSON(); - if(geoJsonGeom!=null) - textArea.setText(geoJsonGeom); - else{ - textArea.setText(""); - containerGeoJSON.add(new Alert("Error on drawing the Geometry", AlertType.WARNING, true)); + try { + String geoJsonGeom = dialog.getWKTToGeoJSON(); + if(geoJsonGeom!=null) + textArea.setText(geoJsonGeom); + else{ + textArea.setText(""); + containerGeoJSON.add(new Alert("Sorry, an error occurred by reading the Geometry", AlertType.ERROR, true)); + } + }catch (Exception e) { + containerGeoJSON.add(new Alert(e.getMessage(), AlertType.ERROR, true)); } } };