refactored
This commit is contained in:
parent
0477713424
commit
f274760dfb
|
@ -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
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<!-- Other module inherits -->
|
||||
|
||||
<!-- Specify the app entry point class. -->
|
||||
|
||||
<entry-point class='org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilder' />
|
||||
|
||||
<!-- Specify the paths for translatable code -->
|
||||
|
|
|
@ -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<java.lang.String> 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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -1,22 +1,9 @@
|
|||
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 <code>onModuleLoad()</code>.
|
||||
|
@ -27,124 +14,28 @@ public class MetadataProfileFormBuilder implements EntryPoint {
|
|||
* 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.";
|
||||
+ "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);
|
||||
|
||||
private final Messages messages = GWT.create(Messages.class);
|
||||
private final MetadataProfileFormBuilderAsync greetingService = GWT.create(MetadataProfileFormBuilderService.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("<b>Sending name to the server:</b>"));
|
||||
dialogVPanel.add(textToServerLabel);
|
||||
dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
|
||||
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<String>() {
|
||||
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);
|
||||
}
|
||||
greetingService.greetServer("Hello World", new AsyncCallback<String>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(String result) {
|
||||
dialogBox.setText("Remote Procedure Call");
|
||||
serverResponseLabel.removeStyleName("serverResponseLabelError");
|
||||
serverResponseLabel.setHTML(result);
|
||||
dialogBox.center();
|
||||
closeButton.setFocus(true);
|
||||
Window.alert(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add a handler to send the name to the server
|
||||
MyHandler handler = new MyHandler();
|
||||
sendButton.addClickHandler(handler);
|
||||
nameField.addKeyUpHandler(handler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<java.lang.String> 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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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.
|
|
@ -13,7 +13,7 @@
|
|||
<!-- Other module inherits -->
|
||||
|
||||
<!-- Specify the app entry point class. -->
|
||||
<entry-point class='org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilder' />
|
||||
<!--<entry-point class='org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilder' />-->
|
||||
|
||||
<!-- Specify the paths for translatable code -->
|
||||
<source path='client' />
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<!-- Servlets -->
|
||||
<servlet>
|
||||
<servlet-name>greetServlet</servlet-name>
|
||||
<servlet-class>org.gcube.portlets.widgets.mpformbuilder.server.GreetingServiceImpl</servlet-class>
|
||||
<servlet-class>org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
|
|
Loading…
Reference in New Issue