diff --git a/${webappDirectory}/CKanMetadataPublisher.html b/${webappDirectory}/CKanMetadataPublisher.html new file mode 100644 index 0000000..f0b17e1 --- /dev/null +++ b/${webappDirectory}/CKanMetadataPublisher.html @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + +
+ + diff --git a/${webappDirectory}/TestCkanMetadataPublisher.html b/${webappDirectory}/TestCkanMetadataPublisher.html new file mode 100644 index 0000000..aff4f8e --- /dev/null +++ b/${webappDirectory}/TestCkanMetadataPublisher.html @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/${webappDirectory}/WEB-INF/web.xml b/${webappDirectory}/WEB-INF/web.xml new file mode 100644 index 0000000..1f5a954 --- /dev/null +++ b/${webappDirectory}/WEB-INF/web.xml @@ -0,0 +1,25 @@ + + + + + + + + ckanpublisherservices + org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl + + + + ckanpublisherservices + /CKanMetadataPublisher/ckanservices + + + + + + CKanMetadataPublisher.html + + + diff --git a/.classpath b/.classpath index 5b3b122..3468a2b 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + @@ -17,7 +17,7 @@ - + @@ -32,5 +32,5 @@ - + diff --git a/.settings/com.google.gdt.eclipse.core.prefs b/.settings/com.google.gdt.eclipse.core.prefs index f629078..1106945 100644 --- a/.settings/com.google.gdt.eclipse.core.prefs +++ b/.settings/com.google.gdt.eclipse.core.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 jarsExcludedFromWebInfLib= -lastWarOutDir=/home/costantino/workspace/ckan-metadata-publisher-widget/target/ckan-metadata-publisher-widget-1.0.0-SNAPSHOT +lastWarOutDir=/home/francesco-mangiacrapa/wseclipseluna/ckan-metadata-publisher-widget-TRUNK/${webappDirectory} +launchConfigExternalUrlPrefix= warSrcDir=src/main/webapp warSrcDirIsOutput=false diff --git a/distro/changelog.xml b/distro/changelog.xml index e316dd5..99a3cc5 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,9 @@ + + [Feature #13074] Integrated with 'openlayer-basic-widgets' + diff --git a/log.txt b/log.txt deleted file mode 100644 index e69de29..0000000 diff --git a/pom.xml b/pom.xml index bf3a99c..a9864a4 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.widgets ckan-metadata-publisher-widget - 1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT gCube Ckan metadata publisher widget @@ -27,6 +27,7 @@ 2.7.0 + ${project.build.directory}/${project.build.finalName} distro UTF-8 UTF-8 @@ -82,6 +83,11 @@ gwt-bootstrap 2.3.2.0 + + org.gcube.portlets.widgets + openlayer-basic-widgets + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + org.slf4j slf4j-log4j12 diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml new file mode 100644 index 0000000..b2174ff --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java index bf628be..d881656 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java @@ -3,16 +3,20 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client; import java.util.ArrayList; import java.util.List; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.openlayerwidget.GeoJsonAreaSelectionDialog; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection.TwinColumnSelectionMainPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.form.CreateDatasetForm; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.MetaDataFieldSkeleton; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.DataTypeWrapper; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.MetadataFieldWrapper; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.ListBox; import com.github.gwtbootstrap.client.ui.Modal; import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.SelectElement; import com.google.gwt.dom.client.Style.Unit; @@ -40,15 +44,34 @@ public class CKanMetadataPublisher implements EntryPoint { // remove comment to the below line for testing the widget // startExample(); - // testMetadata(); + testMetadata(); // testSelectionPanel(); // testHideOption(); // startTwinColumn(); + + //testSpatialWidget(); + + } + + private void testSpatialWidget(){ + //Use AreaSelectionDialog(GeometryType.Point) + //for specific Geometry + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + GeoJsonAreaSelectionDialog dialog=new GeoJsonAreaSelectionDialog(); + dialog.show(); + } + }); + + + //RootPanel.get("ckan-metadata-publisher-div").add(listBox); } @SuppressWarnings("unused") private void testHideOption() { - + ListBox listBox = new ListBox(true); listBox.addItem("A"); listBox.addItem("B"); @@ -56,14 +79,14 @@ public class CKanMetadataPublisher implements EntryPoint { listBox.addItem("D"); listBox.addItem("E"); listBox.addItem("F"); - + List toHide = new ArrayList(); toHide.add("A"); toHide.add("D"); - + RootPanel.get("ckan-metadata-publisher-div").add(listBox); SelectElement se = listBox.getElement().cast(); - + // hide for (int i = 0; i < listBox.getItemCount(); i++) { if(toHide.contains(listBox.getItemText(i))){ @@ -71,7 +94,7 @@ public class CKanMetadataPublisher implements EntryPoint { se.getOptions().getItem(i).getStyle().setProperty("display", "none"); } } - + } @SuppressWarnings("unused") @@ -89,9 +112,9 @@ public class CKanMetadataPublisher implements EntryPoint { // listLeft.add(new ResourceElementBean(null, "File I", false, null, "File I")); // // // test with folder and childs - // ArrayList childrenOfA = new ArrayList(); + // ArrayList childrenOfA = new ArrayList(); // ArrayList childrenOfW = new ArrayList(); - // + // // ResourceElementBean elementA = new ResourceElementBean(null, "Folder A", true, childrenOfA, "Folder A"); // childrenOfA.add(new ResourceElementBean(elementA, "File X", false, null, "Folder A:File X")); // childrenOfA.add(new ResourceElementBean(elementA, "File Y", false, null, "Folder A:File Y")); @@ -101,7 +124,7 @@ public class CKanMetadataPublisher implements EntryPoint { // childrenOfA.add(elementW); // childrenOfW.add(new ResourceElementBean(elementW, "File J", false, null, "Folder A:File W: File J")); // listLeft.add(elementA); - // + // // String folderId = "e87bfc7d-4fb0-4795-9c79-0c495500ca9c"; @@ -137,8 +160,12 @@ public class CKanMetadataPublisher implements EntryPoint { // checkbox //fields.add(new MetadataFieldWrapper("CheckBox", true, DataType.Boolean, "false", "Checkbox example", null, null)); + + // spatial + fields.add(new MetadataFieldWrapper("GeoJson", true, DataTypeWrapper.GeoJSON, "", "", null, null, null)); + // number - //fields.add(new MetadataFieldWrapper("Number", true, DataType.Number, "52", "Number example", null, null)); + fields.add(new MetadataFieldWrapper("Number", true, DataTypeWrapper.Number, "52", "Number example", null, null, null)); // other number //fields.add(new MetadataFieldWrapper("Number2", true, DataType.Number, null, "Number example 2", null, "[0-9]+")); @@ -194,7 +221,7 @@ public class CKanMetadataPublisher implements EntryPoint { public void onClick(ClickEvent event) { for (MetaDataFieldSkeleton field : widgetsList) { - String error = field.isFieldValueValid(); + String error = field.isFieldValueValid(); if(error != null) Window.alert(field.getFieldNameOriginal() + " is not valid. Suggestion: " + error); else @@ -213,7 +240,7 @@ public class CKanMetadataPublisher implements EntryPoint { public void onClick(ClickEvent event) { for (MetaDataFieldSkeleton field : widgetsList) field.freeze(); - } + } }); } @@ -225,13 +252,13 @@ public class CKanMetadataPublisher implements EntryPoint { RootPanel.get("ckan-metadata-publisher-div").add(new CreateDatasetForm(eventBus)); } - + // test resources @SuppressWarnings("unused") private void startTwinColumn() { - + TwinColumnSelectionMainPanel resourcesTwinPanel; - + Modal m = new Modal(); m.setTitle("Title ......"); m.setWidth("1200px"); @@ -241,10 +268,10 @@ public class CKanMetadataPublisher implements EntryPoint { r.setName("Root"); r.setParent(null); List children = new ArrayList(); - + // random strings for (int i = 0; i < 10; i++) { - + ResourceElementBean child = new ResourceElementBean(); child.setFolder(false); child.setName("BLUE_ECONOMY_WP6_TECHNO_ECONOMIC_ANALYSIS_MODEL.CITE.PPTX" + i); @@ -252,15 +279,15 @@ public class CKanMetadataPublisher implements EntryPoint { child.setParent(r); child.setFullPath("/" + "BLUE_ECONOMY_WP6_TECHNO_ECONOMIC_ANALYSIS_MODEL.CITE.PPTX" + + i); children.add(child); - + } - + r.setChildren(children); - + // create random childs resourcesTwinPanel = new TwinColumnSelectionMainPanel(r); m.add(resourcesTwinPanel); m.show(); - + } } 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 new file mode 100644 index 0000000..6196a33 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/openlayerwidget/GeoJsonAreaSelectionDialog.java @@ -0,0 +1,116 @@ +/** + * + */ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.openlayerwidget; + +import org.gcube.portlets.widgets.openlayerbasicwidgets.client.event.SelectAreaDialogEvent; +import org.gcube.portlets.widgets.openlayerbasicwidgets.client.event.SelectAreaDialogEvent.SelectAreaDialogEventHandler; +import org.gcube.portlets.widgets.openlayerbasicwidgets.client.widgets.AreaSelectionDialog; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.core.client.JsonUtils; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.user.client.Command; + + + +/** + * The Class GeoJsonAreaSelectionDialog. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Feb 20, 2019 + */ +public class GeoJsonAreaSelectionDialog extends AreaSelectionDialog{ + + + private String wktArea; + private Command onResponseCommand; + + /** + * Instantiates a new geo json area selection dialog. + */ + public GeoJsonAreaSelectionDialog() { + + //THE HANDLER + SelectAreaDialogEventHandler handler = new SelectAreaDialogEventHandler() { + + @Override + public void onResponse(SelectAreaDialogEvent event) { + GWT.log("SelectAreaDialog Response: "+event); + wktArea = event.getArea(); + onResponseCommand.execute(); + } + }; + + addSelectAreaDialogEventHandler(handler); + } + + + /** + * Fire command on response. + * + * @param command the command + */ + public void fireCommandOnResponse(Command command){ + this.onResponseCommand = command; + } + + + /** + * Convert wkt to geo json. + * + * @param wktData the wkt data + * @return the string + */ + private static native String convertWKTToGeoJSON(String wktData) /*-{ + var ol = $wnd.ol; + var geojson_options = {}; + var wkt_format = new ol.format.WKT(); + var testFeature = wkt_format.readFeature(wktData); + 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; + }-*/; + + + /** + * Wkt to geo json. + * + * @param wktTxt the wkt txt + * @return the string + */ + public String wktToGeoJSON(String wktTxt){ + String geoJSON = convertWKTToGeoJSON(wktTxt); + //Window.alert("geoJSON: "+geoJSON); + GWT.log("geoJSON: "+geoJSON); + JavaScriptObject toJSON = JsonUtils.safeEval(geoJSON); + JSONObject objJson = new JSONObject(toJSON); + return objJson.get("geometry").toString(); + } + + /** + * Gets the WKT to geo json. + * + * @return the WKT to geo json + */ + public String getWKTToGeoJSON(){ + + return wktToGeoJSON(wktArea); + } + + + /** + * Gets the wkt area. + * + * @return the wktArea + */ + public String getWktArea() { + + return 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 f25c20c..ebbca70 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 @@ -5,6 +5,7 @@ import java.util.List; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEvent; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEventHandler; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.openlayerwidget.GeoJsonAreaSelectionDialog; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.metadata.timeandreanges.DataTimeBox; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.GcubeDialogExtended; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.metadata.FieldAsGroup; @@ -18,6 +19,7 @@ import com.github.gwtbootstrap.client.ui.ControlGroup; import com.github.gwtbootstrap.client.ui.ControlLabel; import com.github.gwtbootstrap.client.ui.Controls; import com.github.gwtbootstrap.client.ui.Icon; +import com.github.gwtbootstrap.client.ui.InputAddOn; import com.github.gwtbootstrap.client.ui.ListBox; import com.github.gwtbootstrap.client.ui.Popover; import com.github.gwtbootstrap.client.ui.TextArea; @@ -37,6 +39,7 @@ import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.FlowPanel; @@ -111,7 +114,7 @@ public class MetaDataFieldSkeleton extends Composite{ switch(field.getType()){ - case Boolean : + case Boolean : // its a checkbox holder = new CheckBox(); @@ -120,7 +123,44 @@ public class MetaDataFieldSkeleton extends Composite{ break; case GeoJSON: - case Text: + //MANAGED By FRANCESCO + InputAddOn addOn = new InputAddOn(); + final TextArea textArea = new TextArea(); + + if(field.getDefaultValue() != null) + textArea.setText(field.getDefaultValue()); + + addOn.add(textArea); + Button butt = new Button(); + butt.setIcon(IconType.MAP_MARKER); + butt.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + final GeoJsonAreaSelectionDialog dialog=new GeoJsonAreaSelectionDialog(); + + Command fillGeoJSONArea = new Command() { + public void execute() { + textArea.setText(dialog.getWKTToGeoJSON()); + } + }; + + dialog.fireCommandOnResponse(fillGeoJSONArea); + + + dialog.show(); + + } + }); + + + addOn.add(butt); + holder = addOn; + + break; + + case Text: holder = new TextArea(); @@ -150,7 +190,7 @@ public class MetaDataFieldSkeleton extends Composite{ rangesList.add(rangeBox); break; - case Times_ListOf: + case Times_ListOf: holder = new FlowPanel(); @@ -161,7 +201,7 @@ public class MetaDataFieldSkeleton extends Composite{ SimplePanel panelFirstRange = new SimplePanel(); DataTimeBox rangeBoxFirst = new DataTimeBox(true); setRangeTimeInTimeBox(field.getDefaultValue(), rangeBoxFirst); - ((SimplePanel)panelFirstRange).add(rangeBoxFirst); + panelFirstRange.add(rangeBoxFirst); rangesList.add(rangeBoxFirst); // Add more button @@ -350,12 +390,12 @@ public class MetaDataFieldSkeleton extends Composite{ switch(field.getType()){ - case Boolean : + case Boolean : // nothing to validate return null; - case Text: + case Text: case GeoJSON: // validation for geojson will be performed at server side as well TODO String textAreaValue = getFieldCurrentValue().get(0); @@ -368,7 +408,7 @@ public class MetaDataFieldSkeleton extends Composite{ else return checkValidator(textAreaValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE; else return MANDATORY_ATTRIBUTE_MISSING; - }else{ + }else{ if(textAreaValue.trim().isEmpty()) return null; @@ -403,7 +443,7 @@ public class MetaDataFieldSkeleton extends Composite{ return null; - case Times_ListOf: + case Times_ListOf: for(DataTimeBox el: rangesList){ @@ -447,7 +487,7 @@ public class MetaDataFieldSkeleton extends Composite{ case String: - // just handle the case of textbox + // just handle the case of textbox if(holder.getClass().equals(TextBox.class)){ String textBoxValue = getFieldCurrentValue().get(0); @@ -458,7 +498,7 @@ public class MetaDataFieldSkeleton extends Composite{ else return checkValidator(textBoxValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE; else return MANDATORY_ATTRIBUTE_MISSING; - }else{ + }else{ if(textBoxValue.trim().isEmpty()) return null; else return checkValidator(textBoxValue, field.getValidator()) ? null : MALFORMED_ATTRIBUTE; @@ -467,7 +507,7 @@ public class MetaDataFieldSkeleton extends Composite{ else{ List listboxValues = getFieldCurrentValue(); - + if(listboxValues.isEmpty() && field.getMandatory()) return MANDATORY_ATTRIBUTE_MISSING; @@ -476,7 +516,7 @@ public class MetaDataFieldSkeleton extends Composite{ if(field.getValidator() == null || field.getValidator().isEmpty()) continue; - else + else if(checkValidator(value, field.getValidator())) continue; else return MALFORMED_ATTRIBUTE; @@ -533,12 +573,12 @@ public class MetaDataFieldSkeleton extends Composite{ switch(field.getType()){ - case Boolean : + case Boolean : - toReturn.add(((CheckBox)holder).getValue().toString()); + toReturn.add(((CheckBox)holder).getValue().toString()); break; - case Text: + case Text: case GeoJSON: toReturn.add(((TextArea)holder).getText()); @@ -563,7 +603,7 @@ public class MetaDataFieldSkeleton extends Composite{ toReturn.add(manipulatedTemp); break; - case Times_ListOf: + case Times_ListOf: manipulatedTemp = ""; for (DataTimeBox elem : rangesList) { @@ -574,9 +614,9 @@ public class MetaDataFieldSkeleton extends Composite{ String[] splitted = currentRange.split(DataTimeBox.RANGE_SEPARATOR_START_END); if(splitted[0].equals(splitted[1])) - manipulatedTemp += (manipulatedTemp.isEmpty()) ? splitted[0] : RANGE_SEPARATOR + splitted[0]; + manipulatedTemp += manipulatedTemp.isEmpty() ? splitted[0] : RANGE_SEPARATOR + splitted[0]; else - manipulatedTemp += (manipulatedTemp.isEmpty()) ? splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1] : + manipulatedTemp += manipulatedTemp.isEmpty() ? splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1] : RANGE_SEPARATOR + splitted[0] + DataTimeBox.RANGE_SEPARATOR_START_END + splitted[1]; } @@ -607,7 +647,7 @@ public class MetaDataFieldSkeleton extends Composite{ toReturn.clear(); toReturn.add(""); } - } + } break; @@ -647,13 +687,13 @@ public class MetaDataFieldSkeleton extends Composite{ switch(field.getType()){ - case Boolean : + case Boolean : ((CheckBox)holder).setEnabled(false); break; case GeoJSON: - case Text: + case Text: ((TextArea)holder).setEnabled(false); break; @@ -668,7 +708,7 @@ public class MetaDataFieldSkeleton extends Composite{ rangesList.get(0).freeze(); break; - case Times_ListOf: + case Times_ListOf: for(DataTimeBox el : rangesList) el.freeze(); @@ -684,7 +724,7 @@ public class MetaDataFieldSkeleton extends Composite{ if(holder.getClass().equals(ListBox.class)) ((ListBox)holder).setEnabled(false); - else + else ((TextBox)holder).setEnabled(false); break; @@ -782,7 +822,7 @@ public class MetaDataFieldSkeleton extends Composite{ } return false; } - + /** * Check if the propagateUp is set * @return diff --git a/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml b/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml index 8536846..b2174ff 100644 --- a/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml +++ b/src/main/resources/org/gcube/portlets/widgets/ckandatapublisherwidget/CKanMetadataPublisher.gwt.xml @@ -5,13 +5,17 @@ - + + + + + + + + + + + + + + + + + + + + + + + + +
+ +