From 3df7ab17877438a1dddf8d8d7e776fe54c63d2ad Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Mon, 27 Sep 2021 15:28:36 +0200 Subject: [PATCH] Fired event after Record Updated --- .../ConstantsGeoPortalDataEntryApp.java | 2 +- .../client/GeoPortalDataEntryApp.java | 33 +++++++++++---- .../client/events/ActionOnItemEvent.java | 7 +++- .../client/ui/GeonaMainTabPanel.java | 2 +- .../client/ui/edit/EditModeRecord.java | 21 +++++++--- .../ui/edit/jseditor/JSONEditorWrapper.java | 42 +++++++++++++++++++ 6 files changed, 90 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java index 538c8f9..dea88f1 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ConstantsGeoPortalDataEntryApp.java @@ -38,7 +38,7 @@ public class ConstantsGeoPortalDataEntryApp { * Aug 6, 2021 */ public enum ACTION_ON_ITEM { - SHOW_ON_MAP, SHOW_METADATA, SHOW_REPORT, DELETE_RECORD, EDIT_RECORD + SHOW_ON_MAP, SHOW_METADATA, SHOW_REPORT, SHOW_EDIT_MODE, DELETE_RECORD, UPDATED_RECORD } /** diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index a0c8c51..6a51d43 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -75,7 +75,8 @@ public class GeoPortalDataEntryApp implements EntryPoint { private static final String DIV_PORTLET_ID = "geoportal-data-entry"; - public static final GeoportalDataEntryServiceAsync geoportalDataEntryService = GWT.create(GeoportalDataEntryService.class); + public static final GeoportalDataEntryServiceAsync geoportalDataEntryService = GWT + .create(GeoportalDataEntryService.class); private final HandlerManager appManagerBus = new HandlerManager(null); @@ -151,7 +152,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { int topBorder = workspace.getAbsoluteTop(); int footer = 85; // footer is bottombar + sponsor int headerSize = 90; - //int headerSize = 30; + // int headerSize = 30; int rootHeight = Window.getClientHeight() - topBorder - headerSize - footer;// - ((footer == // null)?0:(footer.getOffsetHeight()-15)); @@ -428,8 +429,12 @@ public class GeoPortalDataEntryApp implements EntryPoint { @Override public void onGetList(GetListOfRecordsEvent getListOfRecordsEvent) { + SortFilter sortFilter = getListOfRecordsEvent.getSortFilter(); + if(sortFilter==null){ + sortFilter = mainTabPanel.getCurrentSortFilter(); + } grpw = new GeonaRecordsPaginatedView(appManagerBus, RECORD_TYPE.CONCESSIONE, null, - getListOfRecordsEvent.getSortFilter()); + sortFilter); mainTabPanel.showListOfConcessioniView(grpw); } }); @@ -505,7 +510,8 @@ public class GeoPortalDataEntryApp implements EntryPoint { case SHOW_REPORT: final Modal modal2 = new Modal(true, true); - modal2.setTitle("Report
"+concessione.getNome()+"
"); + modal2.setTitle("Report
" + concessione.getNome() + + "
"); modal2.setWidth(800); modal2.setCloseVisible(true); if (concessione.getValidationReport() == null) { @@ -518,18 +524,27 @@ public class GeoPortalDataEntryApp implements EntryPoint { modal2.show(); break; - - case EDIT_RECORD: + + case SHOW_EDIT_MODE: final Modal modal3 = new Modal(true, true); - modal3.setTitle("Edit
"+concessione.getNome()+"
"); + modal3.setTitle("Edit
" + concessione.getNome() + + "
"); modal3.setWidth(950); modal3.setHeight("700px"); modal3.setCloseVisible(true); - ((Element)modal3.getElement().getChildNodes().getItem(1)).addClassName("modal-body-custom"); - EditModeRecord emr = new EditModeRecord(concessione,RECORD_TYPE.CONCESSIONE); + ((Element) modal3.getElement().getChildNodes().getItem(1)) + .addClassName("modal-body-custom"); + EditModeRecord emr = new EditModeRecord(appManagerBus, concessione, + RECORD_TYPE.CONCESSIONE); modal3.add(emr); modal3.show(); break; + + case UPDATED_RECORD: + appManagerBus.fireEvent( + new GetListOfRecordsEvent(RECORD_TYPE.CONCESSIONE, + mainTabPanel.getCurrentSortFilter())); + break; case DELETE_RECORD: String htmlMsg = "Going to delete the project with:"; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java index b1d3594..11386db 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/events/ActionOnItemEvent.java @@ -21,7 +21,7 @@ public class ActionOnItemEvent extends GwtEvent extends GwtEvent(listConcessioni, ACTION_ON_ITEM.EDIT_RECORD)); + .fireEvent(new ActionOnItemEvent(listConcessioni, ACTION_ON_ITEM.SHOW_EDIT_MODE)); } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java index 001b801..afe6fcd 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java @@ -2,7 +2,9 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui.edit; import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; +import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; +import org.gcube.portlets.user.geoportaldataentry.client.events.ActionOnItemEvent; import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp; import org.gcube.portlets.user.geoportaldataentry.client.ui.edit.jseditor.JSONEditorWrapper; import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.LoaderIcon; @@ -12,6 +14,7 @@ import com.github.gwtbootstrap.client.ui.Tab; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; +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.user.client.Random; @@ -51,6 +54,8 @@ public class EditModeRecord extends Composite { private JSONEditorWrapper jsEditor; + private HandlerManager appManagerBus; + /** * The Interface EditModeRecordUiBinder. * @@ -64,26 +69,28 @@ public class EditModeRecord extends Composite { /** * Instantiates a new edits the mode record. * + * @param appManagerBus the app manager bus * @param selectedConcessione the selected concessione * @param type the type */ - public EditModeRecord(BaseConcessioneDV selectedConcessione, RECORD_TYPE type) { + public EditModeRecord(HandlerManager appManagerBus, BaseConcessioneDV selectedConcessione, RECORD_TYPE type) { initWidget(uiBinder.createAndBindUi(this)); this.selectedConcessione = selectedConcessione; this.recordType = type; + this.appManagerBus = appManagerBus; instanceJSONEditor(); bindEvents(); } private void instanceJSONEditor() { - + rawUpdatePanel.clear(); final FlowPanel fp = new FlowPanel(); fp.getElement().setId("jsoneditor" + Random.nextInt()); fp.setHeight("400px"); rawUpdatePanel.add(fp); - + GeoPortalDataEntryApp.geoportalDataEntryService.getJSONRecord(selectedConcessione.getItemId(), recordType, new AsyncCallback() { @@ -138,6 +145,9 @@ public class EditModeRecord extends Composite { // TODO: handle exception } + appManagerBus.fireEvent( + new ActionOnItemEvent(null, ACTION_ON_ITEM.UPDATED_RECORD)); + } @Override @@ -152,8 +162,9 @@ public class EditModeRecord extends Composite { selectedConcessione = result; instanceJSONEditor(); - Window.alert("Project '"+result.getNome()+"' updated correctly"); - + Window.alert("Project '" + result.getNome() + "' updated correctly"); + appManagerBus.fireEvent( + new ActionOnItemEvent(null, ACTION_ON_ITEM.UPDATED_RECORD)); } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/jseditor/JSONEditorWrapper.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/jseditor/JSONEditorWrapper.java index 6c85d5c..b8b43b1 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/jseditor/JSONEditorWrapper.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/jseditor/JSONEditorWrapper.java @@ -2,11 +2,30 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui.edit.jseditor; import com.google.gwt.core.client.JavaScriptObject; + +/** + * The Class JSONEditorWrapper. + * + * Wrapper for https://github.com/josdejong/jsoneditor + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Sep 27, 2021 + */ public class JSONEditorWrapper extends JavaScriptObject { + /** + * Instantiates a new JSON editor wrapper. + */ protected JSONEditorWrapper() { } + /** + * Inits the. + * + * @param divID the div ID + * @return the JSON editor wrapper + */ public static native JSONEditorWrapper init(String divID) /*-{ var container = $doc.getElementById(divID); var options = { @@ -20,6 +39,11 @@ public class JSONEditorWrapper extends JavaScriptObject { return new $wnd.JSONEditor(container, options); }-*/; + /** + * Sets the. + * + * @param json the json + */ public final native void set(String json) /*-{ var toJSONObject = JSON.parse(json); // set json @@ -28,19 +52,37 @@ public class JSONEditorWrapper extends JavaScriptObject { this.refresh(); }-*/; + /** + * Gets the text. + * + * @return the text + */ public final native String getText() /*-{ console.log("this.get(): " +this.getText()); return this.getText(); }-*/; + /** + * On error. + */ public final native void onError() /*-{ this.onError(error); }-*/; + /** + * Sets the mode. + * + * @param mode the new mode + */ public final native void setMode(String mode) /*-{ this.setMode(mode); }-*/; + /** + * Sets the name. + * + * @param rootName the new name + */ public final native void setName(String rootName) /*-{ this.setName(rootName); }-*/;