From 597a1095a41c8c33cbb7650f2ab6e0f9259b89df Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Tue, 6 Feb 2018 11:36:58 +0000 Subject: [PATCH] added handler for enabling confirmation button on changes git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/grsf-manage-widget@162960 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../events/EnableConfirmButtonEvent.java | 21 +++++++ .../EnableConfirmButtonEventHandler.java | 9 +++ .../client/view/ManageProductWidget.java | 62 ++++++++++++++++++- .../client/view/ManageProductWidget.ui.xml | 2 +- .../view/subwidgets/ConnectToWidget.java | 20 ++++-- .../subwidgets/SimilarGRSFRecordWidget.java | 11 +++- .../client/view/subwidgets/SuggestMerges.java | 20 ++++-- .../server/manage/Utils.java | 2 +- 8 files changed, 127 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/events/EnableConfirmButtonEvent.java create mode 100644 src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/events/EnableConfirmButtonEventHandler.java diff --git a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/events/EnableConfirmButtonEvent.java b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/events/EnableConfirmButtonEvent.java new file mode 100644 index 0000000..5595d8c --- /dev/null +++ b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/events/EnableConfirmButtonEvent.java @@ -0,0 +1,21 @@ +package org.gcube.datacatalogue.grsf_manage_widget.client.events; + +import com.google.gwt.event.shared.GwtEvent; + +public class EnableConfirmButtonEvent extends GwtEvent { + public static Type TYPE = new Type(); + + public EnableConfirmButtonEvent() { + } + + @Override + public Type getAssociatedType() { + return TYPE; + } + + @Override + protected void dispatch(EnableConfirmButtonEventHandler handler) { + handler.onEvent(this); + } + +} diff --git a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/events/EnableConfirmButtonEventHandler.java b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/events/EnableConfirmButtonEventHandler.java new file mode 100644 index 0000000..f1ad6dd --- /dev/null +++ b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/events/EnableConfirmButtonEventHandler.java @@ -0,0 +1,9 @@ +package org.gcube.datacatalogue.grsf_manage_widget.client.events; + +import com.google.gwt.event.shared.EventHandler; + +public interface EnableConfirmButtonEventHandler extends EventHandler { + + void onEvent(EnableConfirmButtonEvent event); + +} diff --git a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/ManageProductWidget.java b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/ManageProductWidget.java index d35089f..8152617 100644 --- a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/ManageProductWidget.java +++ b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/ManageProductWidget.java @@ -9,6 +9,8 @@ import java.util.Set; import org.gcube.datacatalogue.common.enums.Status; import org.gcube.datacatalogue.grsf_manage_widget.client.GRSFManageWidgetService; import org.gcube.datacatalogue.grsf_manage_widget.client.GRSFManageWidgetServiceAsync; +import org.gcube.datacatalogue.grsf_manage_widget.client.events.EnableConfirmButtonEvent; +import org.gcube.datacatalogue.grsf_manage_widget.client.events.EnableConfirmButtonEventHandler; import org.gcube.datacatalogue.grsf_manage_widget.client.events.HideManagementPanelEvent; import org.gcube.datacatalogue.grsf_manage_widget.client.view.subwidgets.ConnectToWidget; import org.gcube.datacatalogue.grsf_manage_widget.client.view.subwidgets.SimilarGRSFRecordWidget; @@ -35,7 +37,10 @@ import com.github.gwtbootstrap.client.ui.TextBox; import com.github.gwtbootstrap.client.ui.constants.AlertType; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.SelectElement; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; 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; @@ -181,6 +186,19 @@ public class ManageProductWidget extends Composite{ // async request to fetch the product retrieveProductBean(productIdentifier); + + listenEvents(this.eventBus); + } + + + private void listenEvents(HandlerManager eventBus) { + eventBus.addHandler(EnableConfirmButtonEvent.TYPE, new EnableConfirmButtonEventHandler() { + + @Override + public void onEvent(EnableConfirmButtonEvent event) { + confirmButton.setEnabled(true); + } + }); } @@ -227,12 +245,30 @@ public class ManageProductWidget extends Composite{ // top: more or less fixed information GRSFNameTexBox.setText(bean.getTitle()); shortNameTextBox.setText(bean.getShortName()); + shortNameTextBox.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + eventBus.fireEvent(new EnableConfirmButtonEvent()); + } + }); + semanticIdentifierTextBox.setText(bean.getSemanticIdentifier()); productGrsfType.setText(bean.getGrsfType()); currentStatus.setText(bean.getCurrentStatus().toString()); traceabilityFlag.setValue(bean.isTraceabilityFlag()); traceabilityFlag.setText("Traceability"); traceabilityFlag.setTitle("Current value for this flag in the Knowledge Base is " + bean.isTraceabilityFlag()); + + traceabilityFlag.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + eventBus.fireEvent(new EnableConfirmButtonEvent()); + + } + }); // manage sources List availableSources = bean.getSources(); @@ -241,17 +277,17 @@ public class ManageProductWidget extends Composite{ // manage similar GRSF records, if any if(bean.getSimilarGrsfRecords() != null && !bean.getSimilarGrsfRecords().isEmpty()){ List availableGRSFSimilarRecords = bean.getSimilarGrsfRecords(); - similarRecordPanel = new SimilarGRSFRecordWidget(availableGRSFSimilarRecords); + similarRecordPanel = new SimilarGRSFRecordWidget(availableGRSFSimilarRecords, eventBus); panelForSimilarGRSFRecords.add(similarRecordPanel); }else similarGRSFRecordGroup.setVisible(false); // further suggested merges - suggestedMergesPanel = new SuggestMerges(service, bean.getDomain()); + suggestedMergesPanel = new SuggestMerges(service, bean.getDomain(), eventBus); panelForFurtherMerges.add(suggestedMergesPanel); // prepare "connect" panel - connectWidget = new ConnectToWidget(bean, service); + connectWidget = new ConnectToWidget(bean, service, eventBus); panelForConnectOtherRecords.add(connectWidget); // check for new status box @@ -270,6 +306,26 @@ public class ManageProductWidget extends Composite{ } listBoxStatus.setSelectedIndex(0); + listBoxStatus.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + + eventBus.fireEvent(new EnableConfirmButtonEvent()); + + } + }); + + annotationArea.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + + eventBus.fireEvent(new EnableConfirmButtonEvent()); + + } + }); + formUpdate.setVisible(true); } diff --git a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/ManageProductWidget.ui.xml b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/ManageProductWidget.ui.xml index d1ac80c..9ba1cf0 100644 --- a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/ManageProductWidget.ui.xml +++ b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/ManageProductWidget.ui.xml @@ -164,7 +164,7 @@ Cancel - Confirm + Confirm diff --git a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/ConnectToWidget.java b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/ConnectToWidget.java index 34c2cf7..0ccf035 100644 --- a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/ConnectToWidget.java +++ b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/ConnectToWidget.java @@ -6,6 +6,7 @@ import java.util.List; import org.gcube.datacatalogue.common.enums.Product_Type; import org.gcube.datacatalogue.grsf_manage_widget.client.GRSFManageWidgetServiceAsync; +import org.gcube.datacatalogue.grsf_manage_widget.client.events.EnableConfirmButtonEvent; import org.gcube.datacatalogue.grsf_manage_widget.shared.ConnectedBean; import org.gcube.datacatalogue.grsf_manage_widget.shared.ManageProductBean; @@ -21,6 +22,7 @@ import com.google.gwt.dom.client.Style.FontWeight; import com.google.gwt.dom.client.Style.Unit; 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.rpc.AsyncCallback; @@ -54,10 +56,13 @@ public class ConnectToWidget extends Composite{ private List suggestedByKnowledgeBase; // they can be "connected" private GRSFManageWidgetServiceAsync service; - public ConnectToWidget(final ManageProductBean bean, GRSFManageWidgetServiceAsync service) { + private HandlerManager eventBus; + + public ConnectToWidget(final ManageProductBean bean, GRSFManageWidgetServiceAsync service, final HandlerManager eventBus) { initWidget(uiBinder.createAndBindUi(this)); this.service = service; + this.eventBus = eventBus; // get already connected beans, and suggested ones currentlyConnected = bean.getCurrentConnections(); @@ -65,7 +70,7 @@ public class ConnectToWidget extends Composite{ if(currentlyConnected != null){ connectPanel.add(new HTML("
")); for (ConnectedBean connected : currentlyConnected) { - Widget widget = buildWidgetForConnected(connected, false); + Widget widget = buildWidgetForConnected(connected, false, eventBus); connectPanel.add(widget); connectPanel.add(new HTML("
")); } @@ -76,7 +81,7 @@ public class ConnectToWidget extends Composite{ if(suggestedByKnowledgeBase != null){ for (ConnectedBean connected : suggestedByKnowledgeBase) { - Widget widget = buildWidgetForConnected(connected, true); + Widget widget = buildWidgetForConnected(connected, true, eventBus); connectPanel.add(widget); connectPanel.add(new HTML("
")); } @@ -98,7 +103,7 @@ public class ConnectToWidget extends Composite{ public void onClick(ClickEvent arg0) { ConnectedBean cb = new ConnectedBean(); - Tuple t = buildWidgetConnect(cb, acceptedDomain); + Tuple t = buildWidgetConnect(cb, acceptedDomain, eventBus); connectList.add(t); connectPanel.add(t.getW()); @@ -112,7 +117,7 @@ public class ConnectToWidget extends Composite{ * @param similarGRSFRecord * @return */ - public static Widget buildWidgetForConnected(final ConnectedBean connected, boolean suggestedByKb){ + public static Widget buildWidgetForConnected(final ConnectedBean connected, boolean suggestedByKb, final HandlerManager eventBus){ HorizontalPanel hp = new HorizontalPanel(); hp.setWidth("95%"); VerticalPanel leftPanel = new VerticalPanel(); @@ -149,6 +154,7 @@ public class ConnectToWidget extends Composite{ @Override public void onClick(ClickEvent arg0) { connected.setRemove(removeExtra.getValue()); + eventBus.fireEvent(new EnableConfirmButtonEvent()); } }); rightPanel.add(removeExtra); @@ -162,6 +168,7 @@ public class ConnectToWidget extends Composite{ @Override public void onClick(ClickEvent arg0) { connected.setConnect(connect.getValue()); + eventBus.fireEvent(new EnableConfirmButtonEvent()); } }); rightPanel.add(connect); @@ -178,7 +185,7 @@ public class ConnectToWidget extends Composite{ * @param cb the connectBean. * @param acceptedDomain */ - private Tuple buildWidgetConnect(final ConnectedBean cb, final String acceptedDomain){ + private Tuple buildWidgetConnect(final ConnectedBean cb, final String acceptedDomain, HandlerManager eventBus){ VerticalPanel main = new VerticalPanel(); HorizontalPanel hp = new HorizontalPanel(); @@ -281,6 +288,7 @@ public class ConnectToWidget extends Composite{ validateUUIDButton.setText("Accepted"); validateUUIDButton.setType(ButtonType.SUCCESS); validateUUIDButton.setEnabled(false); + eventBus.fireEvent(new EnableConfirmButtonEvent()); } else{ view.setVisible(false); diff --git a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/SimilarGRSFRecordWidget.java b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/SimilarGRSFRecordWidget.java index 764da26..8adc3e3 100644 --- a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/SimilarGRSFRecordWidget.java +++ b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/SimilarGRSFRecordWidget.java @@ -3,6 +3,7 @@ package org.gcube.datacatalogue.grsf_manage_widget.client.view.subwidgets; import java.util.ArrayList; import java.util.List; +import org.gcube.datacatalogue.grsf_manage_widget.client.events.EnableConfirmButtonEvent; import org.gcube.datacatalogue.grsf_manage_widget.shared.SimilarGRSFRecord; import com.github.gwtbootstrap.client.ui.Button; @@ -15,6 +16,7 @@ import com.google.gwt.dom.client.Style.FontWeight; import com.google.gwt.dom.client.Style.Unit; 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.ui.Anchor; @@ -48,9 +50,10 @@ public class SimilarGRSFRecordWidget extends Composite { /** * Get widget for available similar grsf records * @param availableGRSFSimilarRecords + * @param eventBus * @param service */ - public SimilarGRSFRecordWidget(List availableGRSFSimilarRecords) { + public SimilarGRSFRecordWidget(List availableGRSFSimilarRecords, HandlerManager eventBus) { initWidget(uiBinder.createAndBindUi(this)); //this.service = service; @@ -93,7 +96,7 @@ public class SimilarGRSFRecordWidget extends Composite { int index = 0; for (final SimilarGRSFRecord similarGRSFRecord : availableGRSFSimilarRecords) { - Widget widget = buildWidgetForSimilarRecord(similarGRSFRecord); + Widget widget = buildWidgetForSimilarRecord(similarGRSFRecord, eventBus); similarGrsfRecordsPanel.add(widget); HTML separator = new HTML("
"); similarGrsfRecordsPanel.add(separator); @@ -113,11 +116,12 @@ public class SimilarGRSFRecordWidget extends Composite { /** * Builds widget for already present similar GRSF records * @param similarGRSFRecord + * @param eventBus * @param hideMore * @param index * @return a Widget (actually a VerticalPanel) */ - public static Widget buildWidgetForSimilarRecord(final SimilarGRSFRecord similarGRSFRecord){ + public static Widget buildWidgetForSimilarRecord(final SimilarGRSFRecord similarGRSFRecord, final HandlerManager eventBus){ HorizontalPanel hp = new HorizontalPanel(); hp.setWidth("95%"); @@ -160,6 +164,7 @@ public class SimilarGRSFRecordWidget extends Composite { @Override public void onClick(ClickEvent arg0) { similarGRSFRecord.setSuggestedMerge(mergeSuggested.getValue()); + eventBus.fireEvent(new EnableConfirmButtonEvent()); } }); diff --git a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/SuggestMerges.java b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/SuggestMerges.java index 24d607c..638b85b 100644 --- a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/SuggestMerges.java +++ b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/client/view/subwidgets/SuggestMerges.java @@ -5,6 +5,7 @@ import java.util.Iterator; import java.util.List; import org.gcube.datacatalogue.grsf_manage_widget.client.GRSFManageWidgetServiceAsync; +import org.gcube.datacatalogue.grsf_manage_widget.client.events.EnableConfirmButtonEvent; import org.gcube.datacatalogue.grsf_manage_widget.shared.SimilarGRSFRecord; import com.github.gwtbootstrap.client.ui.AppendButton; @@ -18,6 +19,7 @@ import com.google.gwt.dom.client.Style.FontWeight; import com.google.gwt.dom.client.Style.Unit; 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.rpc.AsyncCallback; @@ -46,9 +48,12 @@ public class SuggestMerges extends Composite { private GRSFManageWidgetServiceAsync service; - public SuggestMerges(GRSFManageWidgetServiceAsync service, final String acceptedDomain) { + private HandlerManager eventBus; + + public SuggestMerges(GRSFManageWidgetServiceAsync service, final String acceptedDomain, final HandlerManager eventBus) { initWidget(uiBinder.createAndBindUi(this)); this.service = service; + this.eventBus = eventBus; // manage the "suggest button" addSimilarRecord.setText("Add Merge"); @@ -62,10 +67,10 @@ public class SuggestMerges extends Composite { @Override public void onClick(ClickEvent arg0) { SimilarGRSFRecord s = new SimilarGRSFRecord(); - Widget w = buildWidgetForExtraSimilarRecord(s, acceptedDomain); + Widget w = buildWidgetForExtraSimilarRecord(s, acceptedDomain, eventBus); extraSimilarRecordsList.add(new Tuple(s, w, null)); similarGrsfRecordsSuggestedPanel.add(w); - } + } }); } @@ -73,8 +78,9 @@ public class SuggestMerges extends Composite { * Builds up a widget for suggested similar grsf records. Changes are performed in place with respect to w and s. * @param w the widget * @param s the similar record. + * @param eventBus */ - private Widget buildWidgetForExtraSimilarRecord(final SimilarGRSFRecord s, final String acceptedDomain){ + private Widget buildWidgetForExtraSimilarRecord(final SimilarGRSFRecord s, final String acceptedDomain, final HandlerManager eventBus){ VerticalPanel main = new VerticalPanel(); main.getElement().getStyle().setMarginTop(10, Unit.PX); @@ -110,7 +116,7 @@ public class SuggestMerges extends Composite { @Override public void onClick(ClickEvent event) { - validateUUID(box, s, view, validateUUIDButton, acceptedDomain); + validateUUID(box, s, view, validateUUIDButton, acceptedDomain, eventBus); } }); @@ -166,8 +172,9 @@ public class SuggestMerges extends Composite { * @param s * @param icon * @param view + * @param eventBus2 */ - protected void validateUUID(final TextBox box, final SimilarGRSFRecord s, final Anchor view, final Button validateUUIDButton, final String acceptedDomain) { + protected void validateUUID(final TextBox box, final SimilarGRSFRecord s, final Anchor view, final Button validateUUIDButton, final String acceptedDomain, HandlerManager eventBus2) { validateUUIDButton.setText("Validating..."); validateUUIDButton.setEnabled(false); @@ -193,6 +200,7 @@ public class SuggestMerges extends Composite { validateUUIDButton.setText("Accepted"); validateUUIDButton.setType(ButtonType.SUCCESS); validateUUIDButton.setEnabled(false); + eventBus.fireEvent(new EnableConfirmButtonEvent()); } else{ view.setVisible(false); diff --git a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/server/manage/Utils.java b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/server/manage/Utils.java index db119dd..00f8252 100644 --- a/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/server/manage/Utils.java +++ b/src/main/java/org/gcube/datacatalogue/grsf_manage_widget/server/manage/Utils.java @@ -468,7 +468,7 @@ public class Utils { uuid, (String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_DESCRIPTION), (String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_NAME), - dataset.getTitle(), // no title + dataset.getTitle(), (String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_URL), (String)object.get(Constants.SIMILAR_RECORDS_BEAN_FIELD_IDENTIFIER), dataset.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY)