diff flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java @ 2494:88b51e6e0334

Issue 657. Added UI and service for shapefile upload. flys-client/trunk@4294 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 25 Apr 2012 07:58:58 +0000
parents bc06a671ef60
children 145980c21700
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java	Fri Apr 20 15:23:27 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DigitizePanel.java	Wed Apr 25 07:58:58 2012 +0000
@@ -1,18 +1,30 @@
 package de.intevation.flys.client.client.ui;
 
 import java.util.List;
+import java.util.LinkedHashMap;
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Button;
+import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.events.ResizedEvent;
 import com.smartgwt.client.widgets.events.ResizedHandler;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler;
 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent;
 import com.smartgwt.client.widgets.events.VisibilityChangedHandler;
 import com.smartgwt.client.widgets.events.VisibilityChangedEvent;
+import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.UploadItem;
+import com.smartgwt.client.widgets.form.fields.SelectItem;
+import com.smartgwt.client.types.VerticalAlignment;
+import com.smartgwt.client.widgets.HTMLPane;
+import com.smartgwt.client.types.Encoding;
 
 import org.gwtopenmaps.openlayers.client.Map;
 import org.gwtopenmaps.openlayers.client.feature.VectorFeature;
@@ -104,6 +116,101 @@
     }
 
 
+    /**
+     * This method creates the content of the widget.
+     *
+     * @param data The {@link DataList} object.
+     *
+     * @return a combobox.
+     */
+    protected Canvas createWidget(DataList data) {
+        GWT.log("DigitizePanel - createWidget()");
+
+        VLayout layout   = new VLayout();
+        layout.setAlign(VerticalAlignment.TOP);
+        layout.setHeight(25);
+
+        LinkedHashMap initial = new LinkedHashMap();
+
+        form = new DynamicForm();
+
+        int size = data.size();
+
+        for (int i = 0; i < size; i++) {
+            Data d = data.get(i);
+
+            Label label = new Label(d.getDescription());
+            label.setValign(VerticalAlignment.TOP);
+            label.setHeight(20);
+            label.setWidth(400);
+
+            SelectItem combobox = new SelectItem(d.getLabel());
+            combobox.setWidth(250);
+
+            LinkedHashMap<String, String> it = new LinkedHashMap<String, String>();
+
+            boolean  defaultSet = false;
+            boolean  first      = true;
+
+            DataItem def      = d.getDefault();
+            String   defValue = def != null ? def.getStringValue() : null;
+
+            if (defValue != null && defValue.length() > 0) {
+                initial.put(d.getLabel(), def.getStringValue());
+                defaultSet = true;
+            }
+
+            // I was here.
+            for (DataItem item: d.getItems()) {
+                if (!defaultSet && first) {
+                    initial.put(d.getLabel(), item.getStringValue());
+                    first = false;
+                }
+
+                it.put(item.getStringValue(), item.getLabel());
+            }
+
+            label.setWidth(50);
+            combobox.setValueMap(it);
+            combobox.setShowTitle(false);
+            form.setItems(combobox);
+
+            HTMLPane frame = new HTMLPane();
+            frame.setWidth("1px");
+            frame.setHeight("1px");
+            frame.setContents("<iframe id='uploadTarget' name='uploadTarget'></iframe>");
+
+            final DynamicForm uploadForm = new DynamicForm();
+            uploadForm.setAction("flys/fileupload?uuid=" + artifact.getUuid());
+            uploadForm.setTarget("uploadTarget");
+            uploadForm.setEncoding(Encoding.MULTIPART);
+            Label uploadLabel = new Label(MSG.shape_file_upload());
+            uploadLabel.setHeight(20);
+            UploadItem uploadItem = new UploadItem();
+            uploadItem.setShowTitle(false);
+            uploadForm.setFields(uploadItem);
+            Button submit = new Button(MSG.upload_file());
+            submit.addClickHandler(new ClickHandler() {
+                public void onClick(ClickEvent e) {
+                    uploadForm.submitForm();
+                }
+            });
+            layout.addMember(frame);
+            layout.addMember(label);
+            layout.addMember(form);
+            layout.addMember(uploadLabel);
+            layout.addMember(uploadForm);
+            layout.addMember(submit);
+        }
+
+        form.setValues(initial);
+
+        layout.setAlign(VerticalAlignment.TOP);
+
+        return layout;
+    }
+
+
     @Override
     protected Data[] getData() {
         Data[] data  = super.getData();

http://dive4elements.wald.intevation.org