comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/SwitchModeState.java @ 1119:7c4f81f74c47

merged gnv-artifacts
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:00 +0200
parents dec4257ad570
children
comparison
equal deleted inserted replaced
1027:fca4b5eb8d2f 1119:7c4f81f74c47
1 /*
2 * Copyright (c) 2010 by Intevation GmbH
3 *
4 * This program is free software under the LGPL (>=v2.1)
5 * Read the file LGPL.txt coming with the software for details
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
7 */
8
9 package de.intevation.gnv.state;
10
11 import de.intevation.artifacts.common.utils.XMLUtils;
12
13 import de.intevation.artifacts.CallContext;
14 import de.intevation.artifacts.CallMeta;
15 import de.intevation.artifacts.PreferredLocale;
16
17 import de.intevation.gnv.artifacts.ressource.RessourceFactory;
18
19 import org.apache.log4j.Logger;
20
21 import org.w3c.dom.Document;
22 import org.w3c.dom.Element;
23 import org.w3c.dom.Node;
24
25
26 /**
27 * This task of this <code>State</code> implementation is to switch between
28 * working with vector or scalar data.
29 *
30 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
31 */
32 public class SwitchModeState extends StateBase {
33
34 public static final String VECTOR_VALUE = "vector";
35 public static final String SCALAR_VALUE = "scalar";
36
37 public static final String RESSOURCE_VECTOR = "vectorvalues";
38 public static final String RESSOURCE_SCALAR = "scalarvalues";
39
40 private static Logger logger = Logger.getLogger(SwitchModeState.class);
41
42 public SwitchModeState() {
43 }
44
45
46 @Override
47 protected void describeDynamic(
48 XMLUtils.ElementCreator artCreator,
49 XMLUtils.ElementCreator creator,
50 Document document,
51 Node dynamic,
52 CallContext context,
53 String uuid)
54 {
55 RessourceFactory ressource = RessourceFactory.getInstance();
56 CallMeta callMeta = context.getMeta();
57 PreferredLocale[] locales = callMeta.getLanguages();
58
59 Element selectNode = creator.create("select1");
60 creator.addAttr(selectNode, "ref", dataName);
61
62 Element labelNode = creator.create("label");
63 labelNode.setTextContent(ressource.getRessource(
64 locales, dataName, dataName));
65 selectNode.appendChild(labelNode);
66
67 selectNode.appendChild(createChoices(creator, context));
68 dynamic.appendChild(selectNode);
69 logger.debug("creating dynamic ui elements finished");
70 }
71
72
73 protected Node createChoices(
74 XMLUtils.ElementCreator creator,
75 CallContext context)
76 {
77 RessourceFactory ressource = RessourceFactory.getInstance();
78 CallMeta callMeta = context.getMeta();
79 PreferredLocale[] locales = callMeta.getLanguages();
80
81 Element choiceNodes = creator.create("choices");
82
83 // add choice for scalar values
84 logger.debug("create choice for scalar values");
85 Element scalar = creator.create("item");
86 Element label = creator.create("label");
87 label.setTextContent(ressource.getRessource(
88 locales, RESSOURCE_SCALAR, RESSOURCE_SCALAR));
89 scalar.appendChild(label);
90
91 Element value = creator.create("value");
92 value.setTextContent(SCALAR_VALUE);
93 scalar.appendChild(value);
94
95 // add choice for vector values
96 logger.debug("create choice for vector values");
97 Element vector = creator.create("item");
98 label = creator.create("label");
99 label.setTextContent(ressource.getRessource(
100 locales, RESSOURCE_VECTOR, RESSOURCE_VECTOR));
101 vector.appendChild(label);
102
103 value = creator.create("value");
104 value.setTextContent(VECTOR_VALUE);
105 vector.appendChild(value);
106
107 choiceNodes.appendChild(scalar);
108 choiceNodes.appendChild(vector);
109
110 return choiceNodes;
111 }
112
113
114 @Override
115 protected String[] getDescriptionForInputData(
116 InputData data, CallContext context, String uuid)
117 {
118 RessourceFactory ressource = RessourceFactory.getInstance();
119 CallMeta callMeta = context.getMeta();
120 PreferredLocale[] locales = callMeta.getLanguages();
121
122 String value = data.getValue();
123
124 if (value != null && value.equals(SCALAR_VALUE)) {
125 return new String[] { ressource.getRessource(
126 locales, RESSOURCE_SCALAR, RESSOURCE_SCALAR) };
127 }
128 else if (value != null && value.equals(VECTOR_VALUE)) {
129 return new String[] { ressource.getRessource(
130 locales, RESSOURCE_VECTOR, RESSOURCE_VECTOR) };
131 }
132
133 return null;
134 }
135 }
136 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org