From f274760dfbe1fb2b8025b78150b81a45034dde2b Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 30 Sep 2020 15:42:09 +0200 Subject: [PATCH] refactored --- README.md | 2 +- .../MetadataProfileFormBuilder.gwt.xml | 1 + .../client/GreetingServiceAsync.java | 37 ---- .../mpformbuilder/client/Messages.java | 13 -- .../client/MetadataProfileFormBuilder.java | 165 +++--------------- .../MetadataProfileFormBuilderAsync.java | 32 ++++ ...=> MetadataProfileFormBuilderService.java} | 2 +- ...etadataProfileFormBuilderServiceImpl.java} | 6 +- .../MetadataProfileFormBuilder.gwt.xml | 2 +- src/main/webapp/WEB-INF/web.xml | 2 +- 10 files changed, 68 insertions(+), 194 deletions(-) delete mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/GreetingServiceAsync.java delete mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/Messages.java create mode 100644 src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderAsync.java rename src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/{GreetingService.java => MetadataProfileFormBuilderService.java} (81%) rename src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/{GreetingServiceImpl.java => MetadataProfileFormBuilderServiceImpl.java} (87%) diff --git a/README.md b/README.md index 10540f5..8931d0e 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ You can find the D4Science Catalogue documentation at [GCat Background Wiki Page ## Change log -See the [Releases](https://code-repo.d4science.org/gCubeSystem/gcube-ckan-datacatalog/releases) +See the [Releases](https://code-repo.d4science.org/gCubeSystem/metadata-profile-form-builder-widget/releases) ## Authors diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml index a470622..e601e63 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml @@ -13,6 +13,7 @@ + diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/GreetingServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/GreetingServiceAsync.java deleted file mode 100644 index c558f79..0000000 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/GreetingServiceAsync.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.gcube.portlets.widgets.mpformbuilder.client; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.user.client.rpc.AsyncCallback; - -public interface GreetingServiceAsync -{ - - /** - * GWT-RPC service asynchronous (client-side) interface - * @see org.gcube.portlets.widgets.mpformbuilder.client.GreetingService - */ - void greetServer( java.lang.String name, AsyncCallback callback ); - - - /** - * Utility class to get the RPC Async interface from client-side code - */ - public static final class Util - { - private static GreetingServiceAsync instance; - - public static final GreetingServiceAsync getInstance() - { - if ( instance == null ) - { - instance = (GreetingServiceAsync) GWT.create( GreetingService.class ); - } - return instance; - } - - private Util() - { - // Utility class should not be instantiated - } - } -} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/Messages.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/Messages.java deleted file mode 100644 index e81f252..0000000 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/Messages.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.gcube.portlets.widgets.mpformbuilder.client; - -import com.google.gwt.i18n.client.LocalizableResource.Generate; - -@Generate(format = "com.google.gwt.i18n.server.PropertyCatalogFactory") -public interface Messages extends com.google.gwt.i18n.client.Messages { - - @DefaultMessage("Enter your name") - String nameField(); - - @DefaultMessage("Send") - String sendButton(); -} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilder.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilder.java index aebfadb..dc9725c 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilder.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilder.java @@ -1,150 +1,41 @@ package org.gcube.portlets.widgets.mpformbuilder.client; -import org.gcube.portlets.widgets.mpformbuilder.shared.FieldVerifier; - import com.google.gwt.core.client.EntryPoint; 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.dom.client.KeyCodes; -import com.google.gwt.event.dom.client.KeyUpEvent; -import com.google.gwt.event.dom.client.KeyUpHandler; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.DialogBox; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.RootPanel; -import com.google.gwt.user.client.ui.TextBox; -import com.google.gwt.user.client.ui.VerticalPanel; /** * Entry point classes define onModuleLoad(). */ public class MetadataProfileFormBuilder implements EntryPoint { - /** - * The message displayed to the user when the server cannot be reached or - * returns an error. - */ - private static final String SERVER_ERROR = "An error occurred while " - + "attempting to contact the server. Please check your network " - + "connection and try again."; + /** + * The message displayed to the user when the server cannot be reached or + * returns an error. + */ + private static final String SERVER_ERROR = "An error occurred while " + + "attempting to contact the server. Please check your network " + "connection and try again."; - /** - * Create a remote service proxy to talk to the server-side Greeting service. - */ - private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class); + /** + * Create a remote service proxy to talk to the server-side Greeting service. + */ + private final MetadataProfileFormBuilderAsync greetingService = GWT.create(MetadataProfileFormBuilderService.class); - private final Messages messages = GWT.create(Messages.class); - - /** - * This is the entry point method. - */ - public void onModuleLoad() { - final Button sendButton = new Button( messages.sendButton() ); - final TextBox nameField = new TextBox(); - nameField.setText( messages.nameField() ); - final Label errorLabel = new Label(); - - // We can add style names to widgets - sendButton.addStyleName("sendButton"); - - // Add the nameField and sendButton to the RootPanel - // Use RootPanel.get() to get the entire body element - RootPanel.get("nameFieldContainer").add(nameField); - RootPanel.get("sendButtonContainer").add(sendButton); - RootPanel.get("errorLabelContainer").add(errorLabel); - - // Focus the cursor on the name field when the app loads - nameField.setFocus(true); - nameField.selectAll(); - - // Create the popup dialog box - final DialogBox dialogBox = new DialogBox(); - dialogBox.setText("Remote Procedure Call"); - dialogBox.setAnimationEnabled(true); - final Button closeButton = new Button("Close"); - // We can set the id of a widget by accessing its Element - closeButton.getElement().setId("closeButton"); - final Label textToServerLabel = new Label(); - final HTML serverResponseLabel = new HTML(); - VerticalPanel dialogVPanel = new VerticalPanel(); - dialogVPanel.addStyleName("dialogVPanel"); - dialogVPanel.add(new HTML("Sending name to the server:")); - dialogVPanel.add(textToServerLabel); - dialogVPanel.add(new HTML("
Server replies:")); - dialogVPanel.add(serverResponseLabel); - dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); - dialogVPanel.add(closeButton); - dialogBox.setWidget(dialogVPanel); - - // Add a handler to close the DialogBox - closeButton.addClickHandler(new ClickHandler() { - public void onClick(ClickEvent event) { - dialogBox.hide(); - sendButton.setEnabled(true); - sendButton.setFocus(true); - } - }); - - // Create a handler for the sendButton and nameField - class MyHandler implements ClickHandler, KeyUpHandler { - /** - * Fired when the user clicks on the sendButton. - */ - public void onClick(ClickEvent event) { - sendNameToServer(); - } - - /** - * Fired when the user types in the nameField. - */ - public void onKeyUp(KeyUpEvent event) { - if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { - sendNameToServer(); - } - } - - /** - * Send the name from the nameField to the server and wait for a response. - */ - private void sendNameToServer() { - // First, we validate the input. - errorLabel.setText(""); - String textToServer = nameField.getText(); - if (!FieldVerifier.isValidName(textToServer)) { - errorLabel.setText("Please enter at least four characters"); - return; - } - - // Then, we send the input to the server. - sendButton.setEnabled(false); - textToServerLabel.setText(textToServer); - serverResponseLabel.setText(""); - greetingService.greetServer(textToServer, new AsyncCallback() { - public void onFailure(Throwable caught) { - // Show the RPC error message to the user - dialogBox.setText("Remote Procedure Call - Failure"); - serverResponseLabel.addStyleName("serverResponseLabelError"); - serverResponseLabel.setHTML(SERVER_ERROR); - dialogBox.center(); - closeButton.setFocus(true); - } - - public void onSuccess(String result) { - dialogBox.setText("Remote Procedure Call"); - serverResponseLabel.removeStyleName("serverResponseLabelError"); - serverResponseLabel.setHTML(result); - dialogBox.center(); - closeButton.setFocus(true); - } - }); - } - } - - // Add a handler to send the name to the server - MyHandler handler = new MyHandler(); - sendButton.addClickHandler(handler); - nameField.addKeyUpHandler(handler); - } + /** + * This is the entry point method. + */ + public void onModuleLoad() { + + greetingService.greetServer("Hello World", new AsyncCallback() { + + @Override + public void onSuccess(String result) { + Window.alert(result); + } + + @Override + public void onFailure(Throwable caught) { + } + }); + } } diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderAsync.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderAsync.java new file mode 100644 index 0000000..1439f7c --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderAsync.java @@ -0,0 +1,32 @@ +package org.gcube.portlets.widgets.mpformbuilder.client; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.rpc.AsyncCallback; + +public interface MetadataProfileFormBuilderAsync { + + /** + * GWT-RPC service asynchronous (client-side) interface + * + * @see org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderService + */ + void greetServer(java.lang.String name, AsyncCallback callback); + + /** + * Utility class to get the RPC Async interface from client-side code + */ + public static final class Util { + private static MetadataProfileFormBuilderAsync instance; + + public static final MetadataProfileFormBuilderAsync getInstance() { + if (instance == null) { + instance = (MetadataProfileFormBuilderAsync) GWT.create(MetadataProfileFormBuilderService.class); + } + return instance; + } + + private Util() { + // Utility class should not be instantiated + } + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/GreetingService.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderService.java similarity index 81% rename from src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/GreetingService.java rename to src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderService.java index bf60da2..9504e82 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/GreetingService.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/client/MetadataProfileFormBuilderService.java @@ -7,6 +7,6 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; * The client side stub for the RPC service. */ @RemoteServiceRelativePath("greet") -public interface GreetingService extends RemoteService { +public interface MetadataProfileFormBuilderService extends RemoteService { String greetServer(String name) throws IllegalArgumentException; } diff --git a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/GreetingServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataProfileFormBuilderServiceImpl.java similarity index 87% rename from src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/GreetingServiceImpl.java rename to src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataProfileFormBuilderServiceImpl.java index 1ee8230..4cc29ed 100644 --- a/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/GreetingServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/mpformbuilder/server/MetadataProfileFormBuilderServiceImpl.java @@ -1,6 +1,6 @@ package org.gcube.portlets.widgets.mpformbuilder.server; -import org.gcube.portlets.widgets.mpformbuilder.client.GreetingService; +import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderService; import org.gcube.portlets.widgets.mpformbuilder.shared.FieldVerifier; import com.google.gwt.user.server.rpc.RemoteServiceServlet; @@ -9,8 +9,8 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet; * The server side implementation of the RPC service. */ @SuppressWarnings("serial") -public class GreetingServiceImpl extends RemoteServiceServlet implements - GreetingService { +public class MetadataProfileFormBuilderServiceImpl extends RemoteServiceServlet implements + MetadataProfileFormBuilderService { public String greetServer(String input) throws IllegalArgumentException { // Verify that the input is valid. diff --git a/src/main/resources/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml b/src/main/resources/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml index a470622..4dc9af3 100644 --- a/src/main/resources/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml +++ b/src/main/resources/org/gcube/portlets/widgets/mpformbuilder/MetadataProfileFormBuilder.gwt.xml @@ -13,7 +13,7 @@ - + diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 8f7272c..fa381a7 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -8,7 +8,7 @@ greetServlet - org.gcube.portlets.widgets.mpformbuilder.server.GreetingServiceImpl + org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl