Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/map/GetFeatureInfoWindow.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/map/GetFeatureInfoWindow.java@79717f1cf6eb |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui.map; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 | |
5 import com.smartgwt.client.widgets.HTMLPane; | |
6 import com.smartgwt.client.widgets.Label; | |
7 import com.smartgwt.client.widgets.Window; | |
8 import com.smartgwt.client.widgets.layout.VLayout; | |
9 import com.smartgwt.client.widgets.viewer.DetailViewer; | |
10 import com.smartgwt.client.widgets.viewer.DetailViewerField; | |
11 import com.smartgwt.client.widgets.viewer.DetailViewerRecord; | |
12 | |
13 import de.intevation.flys.client.client.FLYSConstants; | |
14 import de.intevation.flys.client.shared.model.FeatureInfo; | |
15 import de.intevation.flys.client.shared.model.FeatureInfoResponse; | |
16 | |
17 import java.util.ArrayList; | |
18 import java.util.List; | |
19 import java.util.Map; | |
20 import java.util.Set; | |
21 import java.util.MissingResourceException; | |
22 | |
23 import org.gwtopenmaps.openlayers.client.feature.VectorFeature; | |
24 import org.gwtopenmaps.openlayers.client.util.Attributes; | |
25 import org.gwtopenmaps.openlayers.client.util.JSObject; | |
26 | |
27 | |
28 public class GetFeatureInfoWindow extends Window { | |
29 | |
30 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
31 | |
32 protected List<FeatureInfo> features; | |
33 | |
34 protected String title; | |
35 | |
36 protected String featureInfoHTML; | |
37 | |
38 | |
39 public static final int ROW_HEIGHT = 25; | |
40 | |
41 | |
42 public GetFeatureInfoWindow(List<FeatureInfo> features, String title) { | |
43 super(); | |
44 this.features = features; | |
45 this.title = title; | |
46 | |
47 initLayout(); | |
48 } | |
49 | |
50 public GetFeatureInfoWindow(String featureInfoHTML, String title) { | |
51 super(); | |
52 features = null; | |
53 this.title = title; | |
54 this.featureInfoHTML = featureInfoHTML; | |
55 | |
56 initLayoutHTML(); | |
57 } | |
58 | |
59 protected void initLayoutHTML() { | |
60 HTMLPane pane = new HTMLPane(); | |
61 pane.setContents(featureInfoHTML); | |
62 addItem(pane); | |
63 setWidth(500); | |
64 setHeight(300); | |
65 | |
66 setTitle(MSG.getFeatureInfoWindowTitle() + " " + title); | |
67 | |
68 setIsModal(false); | |
69 // setShowModalMask(true); | |
70 | |
71 centerInPage(); | |
72 } | |
73 | |
74 protected void initLayout() { | |
75 VLayout root = new VLayout(); | |
76 | |
77 for (FeatureInfo feature: features) { | |
78 // Currently this should alway be only one | |
79 root.addMember(createFeatureViewer(feature)); | |
80 setTitle(MSG.getFeatureInfoWindowTitle() + " " + title); | |
81 } | |
82 | |
83 addItem(root); | |
84 | |
85 setWidth(500); | |
86 setHeight(300); | |
87 | |
88 setIsModal(false); | |
89 // setShowModalMask(true); | |
90 | |
91 centerInPage(); | |
92 } | |
93 | |
94 | |
95 protected DetailViewer createFeatureViewer(FeatureInfo feature) { | |
96 DetailViewer detailViewer = new DetailViewer(); | |
97 detailViewer.setWidth(487); | |
98 | |
99 Map<String, String> attrs = feature.getAttrs(); | |
100 Set<Map.Entry<String, String>> entries = attrs.entrySet(); | |
101 List <DetailViewerField> fields = new ArrayList<DetailViewerField>(); | |
102 DetailViewerRecord dr = new DetailViewerRecord(); | |
103 | |
104 DetailViewerField path_field = null; // Make sure path is always the last element | |
105 | |
106 for (Map.Entry<String, String> entry: entries) { | |
107 String localized; | |
108 try { | |
109 localized = MSG.getString(entry.getKey()); | |
110 } catch (MissingResourceException mre) { | |
111 localized = entry.getKey(); | |
112 // We filter unwanted information by localization | |
113 // Uncomment to filter out unlocalized elements | |
114 // continue; | |
115 } | |
116 if (entry.getKey().equals("PATH")) { | |
117 path_field = new DetailViewerField(entry.getKey(), localized); | |
118 } else { | |
119 fields.add(new DetailViewerField(entry.getKey(), localized)); | |
120 } | |
121 dr.setAttribute(entry.getKey(), entry.getValue()); | |
122 } | |
123 if (path_field != null) | |
124 fields.add(path_field); | |
125 | |
126 DetailViewerField[] fieldArray = new DetailViewerField[fields.size()]; | |
127 detailViewer.setFields(fields.toArray(fieldArray)); | |
128 detailViewer.setData(new DetailViewerRecord[]{dr}); | |
129 detailViewer.setCanSelectText(true); | |
130 | |
131 return detailViewer; | |
132 } | |
133 | |
134 | |
135 protected String[][] extractProperties(VectorFeature feature) { | |
136 Attributes tmp = feature.getAttributes(); | |
137 JSObject jsobj = tmp.getJSObject(); | |
138 | |
139 String tmpNames = jsobj.getPropertyNames(); | |
140 String[] allNames = tmpNames.split(","); | |
141 | |
142 String[][] attr = new String[allNames.length][]; | |
143 | |
144 for (int i = 0, n = attr.length; i < n; i++) { | |
145 attr[i] = new String[] { | |
146 allNames[i], | |
147 jsobj.getPropertyAsString(allNames[i]) }; | |
148 } | |
149 | |
150 return attr; | |
151 } | |
152 } | |
153 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |