Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/SwitchModeState.java @ 1038:9981452c7e75
First step: Added a new state handling the selection between vector or scalar and a new transition in timeseries to provide vector values (issue27).
gnv-artifacts/trunk@1110 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 18 May 2010 16:28:05 +0000 |
parents | |
children | f953c9a559d8 |
comparison
equal
deleted
inserted
replaced
1037:da4306683186 | 1038:9981452c7e75 |
---|---|
1 package de.intevation.gnv.state; | |
2 | |
3 import de.intevation.artifactdatabase.XMLUtils; | |
4 | |
5 import de.intevation.artifacts.CallContext; | |
6 import de.intevation.artifacts.CallMeta; | |
7 import de.intevation.artifacts.PreferredLocale; | |
8 | |
9 import de.intevation.gnv.artifacts.ressource.RessourceFactory; | |
10 | |
11 import org.apache.log4j.Logger; | |
12 | |
13 import org.w3c.dom.Document; | |
14 import org.w3c.dom.Element; | |
15 import org.w3c.dom.Node; | |
16 | |
17 | |
18 /** | |
19 * This task of this <code>State</code> implementation is to switch between | |
20 * working with vector or scalar data. | |
21 * | |
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
23 */ | |
24 public class SwitchModeState extends StateBase { | |
25 | |
26 public static final String VECTOR_VALUE = "vector"; | |
27 public static final String SCALAR_VALUE = "scalar"; | |
28 | |
29 public static final String RESSOURCE_VECTOR = "vectorvalues"; | |
30 public static final String RESSOURCE_SCALAR = "scalarvalues"; | |
31 | |
32 private static Logger logger = Logger.getLogger(SwitchModeState.class); | |
33 | |
34 public SwitchModeState() { | |
35 } | |
36 | |
37 | |
38 @Override | |
39 protected void describeDynamic( | |
40 XMLUtils.ElementCreator artCreator, | |
41 XMLUtils.ElementCreator creator, | |
42 Document document, | |
43 Node dynamic, | |
44 CallContext context, | |
45 String uuid) | |
46 { | |
47 RessourceFactory ressource = RessourceFactory.getInstance(); | |
48 CallMeta callMeta = context.getMeta(); | |
49 PreferredLocale[] locales = callMeta.getLanguages(); | |
50 | |
51 Element selectNode = creator.create("select1"); | |
52 creator.addAttr(selectNode, "ref", dataName); | |
53 | |
54 Element labelNode = creator.create("label"); | |
55 labelNode.setTextContent(ressource.getRessource( | |
56 locales, dataName, dataName)); | |
57 selectNode.appendChild(labelNode); | |
58 | |
59 selectNode.appendChild(createChoices(creator, context)); | |
60 dynamic.appendChild(selectNode); | |
61 logger.debug("creating dynamic ui elements finished"); | |
62 } | |
63 | |
64 | |
65 protected Node createChoices( | |
66 XMLUtils.ElementCreator creator, | |
67 CallContext context) | |
68 { | |
69 RessourceFactory ressource = RessourceFactory.getInstance(); | |
70 CallMeta callMeta = context.getMeta(); | |
71 PreferredLocale[] locales = callMeta.getLanguages(); | |
72 | |
73 Element choiceNodes = creator.create("choices"); | |
74 | |
75 // add choice for scalar values | |
76 logger.debug("create choice for scalar values"); | |
77 Element scalar = creator.create("item"); | |
78 Element label = creator.create("label"); | |
79 label.setTextContent(ressource.getRessource( | |
80 locales, RESSOURCE_SCALAR, RESSOURCE_SCALAR)); | |
81 scalar.appendChild(label); | |
82 | |
83 Element value = creator.create("value"); | |
84 value.setTextContent(SCALAR_VALUE); | |
85 scalar.appendChild(value); | |
86 | |
87 // add choice for vector values | |
88 logger.debug("create choice for vector values"); | |
89 Element vector = creator.create("item"); | |
90 label = creator.create("label"); | |
91 label.setTextContent(ressource.getRessource( | |
92 locales, RESSOURCE_VECTOR, RESSOURCE_VECTOR)); | |
93 vector.appendChild(label); | |
94 | |
95 value = creator.create("value"); | |
96 value.setTextContent(VECTOR_VALUE); | |
97 vector.appendChild(value); | |
98 | |
99 choiceNodes.appendChild(scalar); | |
100 choiceNodes.appendChild(vector); | |
101 | |
102 return choiceNodes; | |
103 } | |
104 | |
105 | |
106 @Override | |
107 protected String[] getDescriptionForInputData( | |
108 InputData data, CallContext context, String uuid) | |
109 { | |
110 RessourceFactory ressource = RessourceFactory.getInstance(); | |
111 CallMeta callMeta = context.getMeta(); | |
112 PreferredLocale[] locales = callMeta.getLanguages(); | |
113 | |
114 String value = data.getValue(); | |
115 | |
116 if (value != null && value.equals(SCALAR_VALUE)) { | |
117 return new String[] { ressource.getRessource( | |
118 locales, RESSOURCE_SCALAR, RESSOURCE_SCALAR) }; | |
119 } | |
120 else if (value != null && value.equals(VECTOR_VALUE)) { | |
121 return new String[] { ressource.getRessource( | |
122 locales, RESSOURCE_VECTOR, RESSOURCE_VECTOR) }; | |
123 } | |
124 | |
125 return null; | |
126 } | |
127 } | |
128 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |