comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixationPanel.java @ 2505:87ac5c532523

First part of the UI for fixing analysis parameter. flys-client/trunk@4350 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 07 May 2012 13:22:43 +0000
parents
children 8f528f5ae137
comparison
equal deleted inserted replaced
2504:425bc486a40f 2505:87ac5c532523
1 package de.intevation.flys.client.client.ui.fixation;
2
3 import java.util.HashMap;
4
5 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.user.client.rpc.AsyncCallback;
7
8 import com.smartgwt.client.util.SC;
9
10 import com.smartgwt.client.widgets.Canvas;
11 import com.smartgwt.client.widgets.form.DynamicForm;
12 import com.smartgwt.client.widgets.HTMLPane;
13 import com.smartgwt.client.widgets.layout.VLayout;
14
15 import de.intevation.flys.client.client.FLYSConstants;
16 import de.intevation.flys.client.client.ui.AbstractUIProvider;
17
18 import de.intevation.flys.client.client.Config;
19
20 import de.intevation.flys.client.shared.model.Data;
21 import de.intevation.flys.client.shared.model.DataList;
22 import de.intevation.flys.client.shared.model.FixingsOverviewInfo;
23
24 import de.intevation.flys.client.client.services.FixingsOverviewService;
25 import de.intevation.flys.client.client.services.FixingsOverviewServiceAsync;
26
27
28 /**
29 * This UIProvider creates helper panel for fixation analysis without input
30 * elements.
31 *
32 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
33 */
34 public abstract class FixationPanel
35 extends AbstractUIProvider
36 {
37 protected static HashMap<String, FixationPanel> instances = new HashMap<String, FixationPanel>();
38
39 /** The message class that provides i18n strings. */
40 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
41
42 protected FixingsOverviewServiceAsync overviewService =
43 GWT.create(FixingsOverviewService.class);
44
45 protected String htmlOverview;
46 protected FixingsOverviewInfo fixInfo;
47
48 public FixationPanel() {
49 htmlOverview = "";
50 }
51
52 protected String getArtifactUuid() {
53 return this.artifact.getUuid();
54 }
55
56 protected void init() {
57
58 }
59
60 public Data[] getData() {
61 return null;
62 }
63
64 public Canvas create(DataList list) {
65 VLayout layout = new VLayout();
66
67 Canvas helper = createHelper();
68 this.helperContainer.addMember(helper);
69
70 Canvas submit = getNextButton();
71 Canvas widget = createWidget(list);
72
73 layout.addMember(widget);
74 layout.addMember(submit);
75 return layout;
76 }
77
78 public Canvas createOld(DataList list) {
79 return new DynamicForm();
80 }
81
82 protected Canvas createHelper() {
83 Config config = Config.getInstance();
84 String locale = config.getLocale ();
85
86 final HTMLPane helper = new HTMLPane();
87
88 String river = artifact.getArtifactDescription().getRiver();
89
90 createCallback();
91 /*
92 Filter example.
93 {"fixings": { "river": { "name": "Elbe"}, "range": {"from": 1, "to": 200}, "filter": {"and": { "column": {"cid": 1}, "column": {"cid": 2} } }}
94 */
95 String callBack = "fixationCallback(this.checked, this.name)";
96
97 overviewService.generateOverview(
98 locale,
99 artifact.getUuid(),
100 "{\"fixings\": {\"river\": {\"name\": \"" + river + "\"}}}",
101 renderCheckboxes(),
102 callBack,
103 new AsyncCallback<FixingsOverviewInfo>() {
104 public void onFailure(Throwable caught) {
105 GWT.log("Could not receive overview.");
106 SC.warn(caught.getMessage());
107 }
108 public void onSuccess(FixingsOverviewInfo info) {
109 GWT.log("Successfully loaded overview.");
110 fixInfo = info;
111 htmlOverview = info.getHTML();
112 GWT.log("html: " + info.getHTML());
113 helper.setContents(htmlOverview);
114
115 }
116 });
117
118 this.helperContainer.addMember(helper);
119
120 return helper;
121 }
122
123 private native void createCallback() /*-{
124 $wnd.fixationCallback = @de.intevation.flys.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;);
125 }-*/;
126
127 private static void helperCallback(boolean checked, String name) {
128 String[] parts = name.split(":");
129 String uuid = parts[0];
130 String cid = parts[1];
131 FixationPanel p = FixationPanel.getInstance(uuid);
132 if (p != null) {
133 p.setValues(cid, checked);
134 }
135 }
136
137 private static FixationPanel getInstance(String uuid) {
138 for (int i = 0; i < instances.size(); i++) {
139 if (instances.get(uuid) != null) {
140 return instances.get(uuid);
141 }
142 }
143 return null;
144 }
145
146 public abstract Canvas createWidget(DataList data);
147 public abstract void setValues(String cid, boolean checked);
148 public abstract boolean renderCheckboxes();
149 }

http://dive4elements.wald.intevation.org