Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ScenarioSelect.java @ 3812:f788d2d901d6
merged flys-artifacts/pre2.6-2011-12-05
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:53 +0200 |
parents | 1aba1a75beb2 |
children | a78dafdd8590 |
comparison
equal
deleted
inserted
replaced
3808:5fab0fe3c445 | 3812:f788d2d901d6 |
---|---|
1 package de.intevation.flys.artifacts.states; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 | |
5 import org.w3c.dom.Element; | |
6 | |
7 import de.intevation.artifacts.Artifact; | |
8 import de.intevation.artifacts.CallContext; | |
9 import de.intevation.artifacts.CallMeta; | |
10 | |
11 import de.intevation.artifacts.common.utils.XMLUtils; | |
12 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
13 | |
14 import de.intevation.artifactdatabase.ProtocolUtils; | |
15 | |
16 import de.intevation.flys.artifacts.FLYSArtifact; | |
17 import de.intevation.flys.artifacts.resources.Resources; | |
18 | |
19 /** | |
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
21 */ | |
22 public class ScenarioSelect extends DefaultState { | |
23 | |
24 /** The logger that is used in this class.*/ | |
25 private static Logger logger = Logger.getLogger(ScenarioSelect.class); | |
26 | |
27 | |
28 public static final String FIELD_MODE = "scenario"; | |
29 public static final String FIELD_BARRIERS = "uesk.barriers"; | |
30 | |
31 public static final String SCENARIO_CURRENT = "scenario.current"; | |
32 public static final String SCENARIO_POTENTIEL = "scenario.potentiel"; | |
33 public static final String SCENARIO_SCENRAIO = "scenario.scenario"; | |
34 | |
35 public static final String[] SCENARIOS = { | |
36 SCENARIO_CURRENT, | |
37 SCENARIO_POTENTIEL, | |
38 SCENARIO_SCENRAIO }; | |
39 | |
40 | |
41 | |
42 @Override | |
43 protected String getUIProvider() { | |
44 return "map_digitize"; | |
45 } | |
46 | |
47 | |
48 @Override | |
49 protected void appendStaticData( | |
50 FLYSArtifact flys, | |
51 CallContext cc, | |
52 ElementCreator creator, | |
53 Element ui, | |
54 String name | |
55 ) { | |
56 if (name != null && name.equals(FIELD_BARRIERS)) { | |
57 return; | |
58 } | |
59 else { | |
60 super.appendStaticData(flys, cc, creator, ui, name); | |
61 } | |
62 } | |
63 | |
64 | |
65 @Override | |
66 protected Element[] createItems( | |
67 XMLUtils.ElementCreator cr, | |
68 Artifact artifact, | |
69 String name, | |
70 CallContext context) | |
71 { | |
72 CallMeta meta = context.getMeta(); | |
73 | |
74 if (name.equals(FIELD_MODE)) { | |
75 Element[] scenarios = new Element[SCENARIOS.length]; | |
76 | |
77 int i = 0; | |
78 | |
79 for (String scenario: SCENARIOS) { | |
80 scenarios[i++] = createItem( | |
81 cr, new String[] { | |
82 Resources.getMsg(meta, scenario, scenario), | |
83 scenario | |
84 }); | |
85 } | |
86 | |
87 return scenarios; | |
88 } | |
89 else { | |
90 FLYSArtifact flys = (FLYSArtifact) artifact; | |
91 String data = flys.getDataAsString(name); | |
92 | |
93 return new Element[] { createItem( | |
94 cr, | |
95 new String[] { | |
96 Resources.getMsg(meta, name, name), | |
97 data | |
98 } | |
99 )}; | |
100 } | |
101 } | |
102 | |
103 | |
104 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { | |
105 Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
106 Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
107 Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
108 | |
109 String[] arr = (String[]) obj; | |
110 | |
111 label.setTextContent(arr[0]); | |
112 value.setTextContent(arr[1]); | |
113 | |
114 item.appendChild(label); | |
115 item.appendChild(value); | |
116 | |
117 return item; | |
118 } | |
119 } | |
120 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |