diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractUIProvider.java @ 9066:b5d7a9d79837

uinfo.inundation_duration ui
author gernotbelger
date Fri, 11 May 2018 17:04:35 +0200
parents 28df64078f27
children 766890addcb2
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractUIProvider.java	Wed May 09 16:36:55 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractUIProvider.java	Fri May 11 17:04:35 2018 +0200
@@ -8,18 +8,11 @@
 
 package org.dive4elements.river.client.client.ui;
 
-import com.google.gwt.core.client.GWT;
+import java.util.ArrayList;
+import java.util.List;
 
-import com.smartgwt.client.util.SC;
-import com.smartgwt.client.widgets.Button;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.Img;
-import com.smartgwt.client.widgets.events.ClickEvent;
-import com.smartgwt.client.widgets.events.ClickHandler;
-import com.smartgwt.client.widgets.layout.VLayout;
-
+import org.dive4elements.river.client.client.FLYS;
 import org.dive4elements.river.client.client.FLYSConstants;
-import org.dive4elements.river.client.client.FLYS;
 import org.dive4elements.river.client.client.event.HasStepBackHandlers;
 import org.dive4elements.river.client.client.event.HasStepForwardHandlers;
 import org.dive4elements.river.client.client.event.StepBackEvent;
@@ -35,19 +28,21 @@
 import org.dive4elements.river.client.shared.model.DefaultData;
 import org.dive4elements.river.client.shared.model.DefaultDataItem;
 
-import java.util.ArrayList;
-import java.util.List;
-
+import com.google.gwt.core.client.GWT;
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.Button;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Img;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.layout.VLayout;
 
 /**
  * An abstract UIProvider that provides some basic methods.
  *
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public abstract class AbstractUIProvider
-implements   UIProvider, HasStepForwardHandlers, ClickHandler,
-             HasStepBackHandlers
-{
+public abstract class AbstractUIProvider implements UIProvider, HasStepForwardHandlers, ClickHandler, HasStepBackHandlers {
     private static final long serialVersionUID = -1610874613377494184L;
 
     /** The message class that provides i18n strings. */
@@ -75,90 +70,87 @@
      * Creates a new UIProvider instance of this class.
      */
     public AbstractUIProvider() {
-        forwardHandlers = new ArrayList<StepForwardHandler>();
-        backHandlers    = new ArrayList<StepBackHandler>();
+        this.forwardHandlers = new ArrayList<StepForwardHandler>();
+        this.backHandlers = new ArrayList<StepBackHandler>();
     }
 
-
     /**
      * Appends a StepBackHandler that wants to listen to StepBackEvents.
      *
-     * @param handler A new StepBackHandler.
+     * @param handler
+     *            A new StepBackHandler.
      */
     @Override
-    public void addStepBackHandler(StepBackHandler handler) {
+    public void addStepBackHandler(final StepBackHandler handler) {
         if (handler != null) {
-            backHandlers.add(handler);
+            this.backHandlers.add(handler);
         }
     }
 
-
     /**
      * Appends a StepForwardHandler that wants to listen to StepForwardEvents.
      *
-     * @param handler A new StepForwardHandler.
+     * @param handler
+     *            A new StepForwardHandler.
      */
     @Override
-    public void addStepForwardHandler(StepForwardHandler handler) {
+    public void addStepForwardHandler(final StepForwardHandler handler) {
         if (handler != null) {
-            forwardHandlers.add(handler);
+            this.forwardHandlers.add(handler);
         }
     }
 
-
     /**
      * This method is called after the user has clicked one of the buttons to
      * step back to a previous state.
      *
-     * @param e The StepBackEvent.
+     * @param e
+     *            The StepBackEvent.
      */
-    protected void fireStepBackEvent(StepBackEvent e) {
-        GWT.log("AbstractUIProvider - fireStepBackEvent() handlers: "
-            + backHandlers.size());
-        for (StepBackHandler handler: backHandlers) {
+    protected void fireStepBackEvent(final StepBackEvent e) {
+        GWT.log("AbstractUIProvider - fireStepBackEvent() handlers: " + this.backHandlers.size());
+        for (final StepBackHandler handler : this.backHandlers) {
             handler.onStepBack(e);
         }
     }
 
-
     /**
      * This method is called after the user has clicked on the 'next' button to
      * step to the next state.
      *
-     * @param e The StepForwardEvent.
+     * @param e
+     *            The StepForwardEvent.
      */
-    protected void fireStepForwardEvent(StepForwardEvent e) {
-        GWT.log("AbstractUIProvider - fireStepForwardEvent() handlers: "
-            + forwardHandlers.size());
-        for (StepForwardHandler handler: forwardHandlers) {
+    protected void fireStepForwardEvent(final StepForwardEvent e) {
+        GWT.log("AbstractUIProvider - fireStepForwardEvent() handlers: " + this.forwardHandlers.size());
+        for (final StepForwardHandler handler : this.forwardHandlers) {
             handler.onStepForward(e);
         }
     }
 
-
     /**
      * This method is used to listen to click events on the 'next' button. The
      * fireStepForwardEvent() method is called here.
      *
-     * @param e The click event.
+     * @param e
+     *            The click event.
      */
     @Override
-    public void onClick(ClickEvent e) {
-        List<String> errors = validate();
-        if (errors == null || errors.isEmpty()) {
-            Data[] data = getData();
-            fireStepForwardEvent(new StepForwardEvent(data));
-        }
-        else {
-            showErrors(errors);
-        }
+    public void onClick(final ClickEvent e) {
+        final List<String> errors = validate();
+        // if (errors == null || errors.isEmpty()) {
+        final Data[] data = getData();
+        fireStepForwardEvent(new StepForwardEvent(data));
+        // }
+        // else {
+        // showErrors(errors);
+        // }
     }
 
+    protected void showErrors(final List<String> errors) {
+        final StringBuilder sb = new StringBuilder();
 
-    protected void showErrors(List<String> errors) {
-        StringBuilder sb = new StringBuilder();
-
-        for (String error: errors) {
+        for (final String error : errors) {
             sb.append(error);
             sb.append("<br>");
         }
@@ -166,43 +158,41 @@
         SC.warn(sb.toString());
     }
 
-
     /**
      * Creates the 'next' button to step forward to the next state.
      *
      * @return the 'next' button.
      */
     protected Canvas getNextButton() {
-        Button next = new Button(MSG.buttonNext());
+        final Button next = new Button(this.MSG.buttonNext());
         next.addClickHandler(this);
 
         return next;
     }
 
-
     @Override
-    public Canvas createHelpLink(DataList dataList, Data data, FLYS instance) {
-        String iUrl    = GWT.getHostPageBaseURL() + MSG.getFeatureInfo();
-        String helpUrl = dataList.getHelpText();
+    public Canvas createHelpLink(final DataList dataList, final Data data, final FLYS instance) {
+        final String iUrl = GWT.getHostPageBaseURL() + this.MSG.getFeatureInfo();
+        final String helpUrl = dataList.getHelpText();
 
         return new WikiImgLink(iUrl, helpUrl, 30, 30, instance);
     }
 
-
     /**
      * Creates the 'back' button to step back to a previous state.
      *
-     * @param targetState The identifier of the target state.
+     * @param targetState
+     *            The identifier of the target state.
      *
      * @return the 'back' button.
      */
     protected Canvas getBackButton(final String targetState) {
-        String url = GWT.getHostPageBaseURL() + MSG.imageBack();
-        Img back   = new Img(url, 16, 16);
+        final String url = GWT.getHostPageBaseURL() + this.MSG.imageBack();
+        final Img back = new Img(url, 16, 16);
 
         back.addClickHandler(new ClickHandler() {
             @Override
-            public void onClick(ClickEvent event) {
+            public void onClick(final ClickEvent event) {
                 fireStepBackEvent(new StepBackEvent(targetState));
             }
         });
@@ -210,58 +200,56 @@
         return back;
     }
 
-
     /**
      * This method injects a container that is used to position helper widgets.
      *
-     * @param helperContainer A container that is used to position helper
-     * widgets.
+     * @param helperContainer
+     *            A container that is used to position helper
+     *            widgets.
      */
     @Override
-    public void setContainer(VLayout helperContainer) {
+    public void setContainer(final VLayout helperContainer) {
         this.helperContainer = helperContainer;
     }
 
-
     /**
      * This method injects an artifact that contains the status information.
      *
-     * @param art An artifact containing status information.
+     * @param art
+     *            An artifact containing status information.
      */
     @Override
-    public void setArtifact(Artifact art) {
+    public void setArtifact(final Artifact art) {
         this.artifact = art;
     }
 
-
     @Override
-    public void setCollection(Collection collection) {
+    public void setCollection(final Collection collection) {
         this.collection = collection;
     }
 
-
     @Override
-    public void setParameterList(ParameterList list) {
+    public void setParameterList(final ParameterList list) {
         this.parameterList = list;
     }
 
-
     public Collection getCollection() {
-        return collection;
+        return this.collection;
     }
 
-
     /**
      * This method greps the Data with name <i>name</i> from the list and
      * returns it.
      *
-     * @param items A list of Data.
-     * @param name The name of the Data that we are searching for.
+     * @param items
+     *            A list of Data.
+     * @param name
+     *            The name of the Data that we are searching for.
      *
      * @return the Data with the name <i>name</i>.
      */
-    protected Data getData(List<Data> data, String name) {
-        for (Data d: data) {
+    protected Data getData(final List<Data> data, final String name) {
+        for (final Data d : data) {
             if (name.equals(d.getLabel())) {
                 return d;
             }
@@ -270,17 +258,16 @@
         return null;
     }
 
+    protected String getDataValue(final String state, final String name) {
+        final ArtifactDescription desc = this.artifact.getArtifactDescription();
 
-    protected String getDataValue(String state, String name) {
-        ArtifactDescription desc = artifact.getArtifactDescription();
+        final DataList[] old = desc.getOldData();
 
-        DataList[] old = desc.getOldData();
-
-        for (DataList list: old) {
+        for (final DataList list : old) {
             if (list == null) {
                 continue;
             }
-            Data d = getData(list.getAll(), name);
+            final Data d = getData(list.getAll(), name);
 
             if (d != null) {
                 return d.getItems()[0].getStringValue();
@@ -294,13 +281,15 @@
      * This method greps the DataItem with name <i>name</i> from the list and
      * returns it.
      *
-     * @param items A list of DataItems.
-     * @param name The name of the DataItem that we are searching for.
+     * @param items
+     *            A list of DataItems.
+     * @param name
+     *            The name of the DataItem that we are searching for.
      *
      * @return the DataItem with the name <i>name</i>.
      */
-    protected DataItem getDataItem(DataItem[] items, String name) {
-        for (DataItem item: items) {
+    protected DataItem getDataItem(final DataItem[] items, final String name) {
+        for (final DataItem item : items) {
             if (name.equals(item.getLabel())) {
                 return item;
             }
@@ -311,6 +300,7 @@
 
     /**
      * Validates the selection.
+     * 
      * @return List of internationalized errror messages (if any).
      */
     public List<String> validate() {
@@ -318,31 +308,24 @@
     }
 
     /** Create simple DefaultData with single DataItem inside. */
-    public static DefaultData createDataArray(String name, String value) {
-        DataItem item = new DefaultDataItem(
-            name,
-            name,
-            value);
+    public static DefaultData createDataArray(final String name, final String value) {
+        final DataItem item = new DefaultDataItem(name, name, value);
 
-        return new DefaultData(name,
-            null,
-            null,
-            new DataItem[] {item});
+        return new DefaultData(name, null, null, new DataItem[] { item });
     }
 
-
     /**
      * This method needs to be implemented by concrete subclasses. It should
      * create a new Canvas object with a representation of <i>data</i>.
      *
-     * @param data The data that should be displayed.
+     * @param data
+     *            The data that should be displayed.
      *
      * @return a Canvas object that displays <i>data</i>.
      */
     @Override
     public abstract Canvas create(DataList data);
 
-
     /**
      * This method needs to be implemented by concrete subclasses. It should
      * return the selected data.

http://dive4elements.wald.intevation.org