comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/minfo/DifferenceSelect.java @ 3614:68beaa827751

MINFO: Implemented UI and facet/artifact stack for bed height differences. flys-artifacts/trunk@5276 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 28 Aug 2012 11:45:23 +0000
parents
children 8e66293c5369
comparison
equal deleted inserted replaced
3613:dd6e25980c91 3614:68beaa827751
1 package de.intevation.flys.artifacts.states.minfo;
2
3 import java.util.List;
4
5 import org.apache.log4j.Logger;
6 import org.w3c.dom.Element;
7
8 import de.intevation.artifactdatabase.state.Facet;
9 import de.intevation.artifacts.Artifact;
10 import de.intevation.artifacts.CallContext;
11 import de.intevation.artifacts.common.utils.XMLUtils;
12 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
13 import de.intevation.flys.artifacts.FLYSArtifact;
14 import de.intevation.flys.artifacts.access.BedHeightAccess;
15 import de.intevation.flys.artifacts.states.DefaultState;
16 import de.intevation.flys.utils.StringUtil;
17
18 /**
19 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
20 */
21 public class DifferenceSelect extends DefaultState {
22
23 /** The logger used in this class. */
24 private static Logger logger = Logger.getLogger(DifferenceSelect.class);
25
26 /**
27 * The default constructor that initializes an empty State object.
28 */
29 public DifferenceSelect() {
30 }
31 /**
32 * Specify to display nothing (this is kind of a "final" state).
33 */
34 @Override
35 protected String getUIProvider() {
36 return "bedheights_twin_panel";
37 }
38
39 /**
40 * Overridden to do nothing.
41 */
42 @Override
43 public Object computeAdvance(
44 FLYSArtifact artifact,
45 String hash,
46 CallContext context,
47 List<Facet> facets,
48 Object old
49 ) {
50 //Get data and do stuff, do not calculate
51 return "";
52 }
53
54 @Override
55 protected Element[] createItems(
56 XMLUtils.ElementCreator ec,
57 Artifact artifact,
58 String name,
59 CallContext context)
60 {
61 Element[] elements = new Element[1];
62 BedHeightAccess bha = new BedHeightAccess((FLYSArtifact)artifact);
63 String time = bha.getYearEpoch();
64 elements[0] = createItem(
65 ec,
66 new String[] {"year-epoch", time});
67
68 return elements;
69 }
70
71 /**
72 * Creates the data element used for the static part of DESCRIBE document.
73 */
74 @Override
75 protected Element createStaticData(
76 FLYSArtifact flys,
77 ElementCreator creator,
78 CallContext cc,
79 String name,
80 String value,
81 String type
82 ) {
83 Element dataElement = creator.create("data");
84 creator.addAttr(dataElement, "name", name, true);
85 creator.addAttr(dataElement, "type", type, true);
86
87 Element itemElement = creator.create("item");
88 creator.addAttr(itemElement, "value", value, true);
89
90 String[] labels = getLabels(cc, value);
91
92 creator.addAttr(
93 itemElement,
94 "label",
95 labels[0],
96 true);
97 dataElement.appendChild(itemElement);
98
99 return dataElement;
100 }
101
102
103 /**
104 * Get name to display for selected watelerlevels (for example "Q=123")
105 * from the CalculationResult.
106 */
107 public static String[] getLabels(CallContext cc, String value) {
108 String[] recommendations = value.split("#");
109 String displayString = "";
110
111 // Walk over all selected recommendations and create label
112 for (int i = 0; i < recommendations.length; i+=2) {
113 String[] minuendParts = StringUtil
114 .unbracket(recommendations[i+0])
115 .split(";");
116 if(minuendParts.length >= 4) {
117 displayString += "(" + minuendParts[3];
118 }
119 else {
120 displayString += "([error]";
121 }
122
123 displayString += " - ";
124
125 String[] subtrahendParts = StringUtil
126 .unbracket(recommendations[i+1])
127 .split(";");
128 if(subtrahendParts.length >= 4) {
129 displayString += subtrahendParts[3] + ") ";
130 }
131 else {
132 displayString += "[error])";
133 }
134 }
135
136 return new String[] { displayString };
137 }
138 }
139 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org