comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelPairSelectState.java @ 9580:839b2aa84dd0

minuend/subtrahend-UI-switch
author gernotbelger
date Tue, 08 Jan 2019 17:01:09 +0100
parents 28df64078f27
children
comparison
equal deleted inserted replaced
9579:67a42c9c46a7 9580:839b2aa84dd0
9 package org.dive4elements.river.artifacts.states; 9 package org.dive4elements.river.artifacts.states;
10 10
11 import java.util.List; 11 import java.util.List;
12 12
13 import org.apache.log4j.Logger; 13 import org.apache.log4j.Logger;
14 14 import org.dive4elements.artifactdatabase.ProtocolUtils;
15 import org.w3c.dom.Element; 15 import org.dive4elements.artifactdatabase.state.Facet;
16
17 import org.dive4elements.artifacts.Artifact; 16 import org.dive4elements.artifacts.Artifact;
18 import org.dive4elements.artifacts.CallContext; 17 import org.dive4elements.artifacts.CallContext;
19
20 import org.dive4elements.artifactdatabase.ProtocolUtils;
21 import org.dive4elements.artifactdatabase.state.Facet;
22
23 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; 18 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
24
25 import org.dive4elements.river.artifacts.D4EArtifact; 19 import org.dive4elements.river.artifacts.D4EArtifact;
26 import org.dive4elements.river.artifacts.model.FacetTypes; 20 import org.dive4elements.river.artifacts.model.FacetTypes;
27 import org.dive4elements.river.artifacts.resources.Resources; 21 import org.dive4elements.river.artifacts.resources.Resources;
28
29 import org.dive4elements.river.backend.utils.StringUtil; 22 import org.dive4elements.river.backend.utils.StringUtil;
23 import org.w3c.dom.Element;
30 24
31 /** 25 /**
32 * State in which the user selects 1 to n pairs of Waterlevels and alikes. 26 * State in which the user selects 1 to n pairs of Waterlevels and alikes.
33 */ 27 */
34 public class WaterlevelPairSelectState 28 public class WaterlevelPairSelectState extends DefaultState implements FacetTypes {
35 extends DefaultState
36 implements FacetTypes
37 {
38 /** The log that is used in this state. */ 29 /** The log that is used in this state. */
39 private static Logger log = Logger.getLogger( 30 private static Logger log = Logger.getLogger(WaterlevelPairSelectState.class);
40 WaterlevelPairSelectState.class);
41
42 31
43 /** Trivial constructor. */ 32 /** Trivial constructor. */
44 public WaterlevelPairSelectState() { 33 public WaterlevelPairSelectState() {
45 } 34 }
46
47 35
48 /** Specify to display a datacage_twin_panel. */ 36 /** Specify to display a datacage_twin_panel. */
49 @Override 37 @Override
50 protected String getUIProvider() { 38 protected String getUIProvider() {
51 return "waterlevel_twin_panel"; 39 return "waterlevel_twin_panel";
52 } 40 }
53 41
54
55 /** 42 /**
56 * Overridden to do nothing. 43 * Overridden to do nothing.
57 */ 44 */
58 @Override 45 @Override
59 public Object computeAdvance( 46 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) {
60 D4EArtifact artifact, 47 // Get data and do stuff, do not calculate
61 String hash,
62 CallContext context,
63 List<Facet> facets,
64 Object old
65 ) {
66 //Get data and do stuff, do not calculate
67 return ""; 48 return "";
68 } 49 }
69 50
70
71 /** 51 /**
72 * Create elements for document (prepopulated with data, if any). 52 * Create elements for document (prepopulated with data, if any).
73 * @param artifact D4EArtifact to get data from. 53 *
74 * @param name DataName, expceted to be "diffids". 54 * @param artifact
55 * D4EArtifact to get data from.
56 * @param name
57 * DataName, expceted to be "diffids".
75 */ 58 */
76 @Override 59 @Override
77 protected Element[] createItems( 60 protected Element[] createItems(final ElementCreator cr, final Artifact artifact, final String name, final CallContext context) {
78 ElementCreator cr,
79 Artifact artifact,
80 String name,
81 CallContext context)
82 {
83 log.debug("createItems: " + name); 61 log.debug("createItems: " + name);
84 if (name.equals("diffids")) { 62 if (name.equals("diffids")) {
85 Element item = ProtocolUtils.createArtNode( 63 final Element item = ProtocolUtils.createArtNode(cr, "item", null, null);
86 cr, "item", null, null); 64 final Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
87 Element label = ProtocolUtils.createArtNode( 65 final Element value = ProtocolUtils.createArtNode(cr, "value", null, null);
88 cr, "label", null, null); 66 final D4EArtifact flys = (D4EArtifact) artifact;
89 Element value = ProtocolUtils.createArtNode( 67 final String s = flys.getDataAsString("diffids");
90 cr, "value", null, null);
91 D4EArtifact flys = (D4EArtifact) artifact;
92 String s = flys.getDataAsString("diffids");
93 value.setTextContent(s); 68 value.setTextContent(s);
94 item.appendChild(label); 69 item.appendChild(label);
95 item.appendChild(value); 70 item.appendChild(value);
96 return new Element[] { item }; 71 return new Element[] { item };
97 } 72 }
98 return new Element[] {}; 73 return new Element[] {};
99 } 74 }
100 75
101
102 /** 76 /**
103 * Creats the data element used for the static part of DESCRIBE document. 77 * Creats the data element used for the static part of DESCRIBE document.
104 */ 78 */
105 @Override 79 @Override
106 protected Element createStaticData( 80 protected Element createStaticData(final D4EArtifact flys, final ElementCreator creator, final CallContext cc, final String name, final String value,
107 D4EArtifact flys, 81 final String type) {
108 ElementCreator creator, 82 final Element dataElement = creator.create("data");
109 CallContext cc,
110 String name,
111 String value,
112 String type
113 ) {
114 Element dataElement = creator.create("data");
115 creator.addAttr(dataElement, "name", name, true); 83 creator.addAttr(dataElement, "name", name, true);
116 creator.addAttr(dataElement, "type", type, true); 84 creator.addAttr(dataElement, "type", type, true);
117 85
118 Element itemElement = creator.create("item"); 86 final Element itemElement = creator.create("item");
119 creator.addAttr(itemElement, "value", value, true); 87 creator.addAttr(itemElement, "value", value, true);
120 88
121 String[] labels = getLabels(cc, value); 89 final String[] labels = getLabels(cc, value, false);
122 Object[] obj = new Object[] { labels[0] }; 90 final Object[] obj = new Object[] { labels[0] };
123 91
124 // TODO own i18n 92 // TODO own i18n
125 String attrValue = Resources.getMsg( 93 final String attrValue = Resources.getMsg(cc.getMeta(), "wsp.selected.string", "wsp.selected.string", obj);
126 cc.getMeta(), "wsp.selected.string", "wsp.selected.string", obj); 94 // I18N_STATIC_KEY, I18N_STATIC_KEY, obj);
127 //I18N_STATIC_KEY, I18N_STATIC_KEY, obj);
128 95
129 creator.addAttr(itemElement, "label", attrValue, true); 96 creator.addAttr(itemElement, "label", attrValue, true);
130 dataElement.appendChild(itemElement); 97 dataElement.appendChild(itemElement);
131 98
132 return dataElement; 99 return dataElement;
133 } 100 }
134 101
135
136 /** 102 /**
137 * Get name to display for selected watelerlevels (for example "Q=123") 103 * Get name to display for selected watelerlevels (for example "Q=123")
138 * from the CalculationResult. 104 * from the CalculationResult.
139 */ 105 */
140 public static String[] getLabels(CallContext cc, String value) { 106 public static String[] getLabels(final CallContext cc, final String value, final boolean minuendSubtrahendUiReversed) {
141 String[] recommendations = value.split("#"); 107 final String[] recommendations = value.split("#");
142 String displayString = ""; 108 String displayString = "";
143 109
144 // Walk over all selected recommendations and create label 110 // Walk over all selected recommendations and create label
145 // like "W (Q=1) - W (Q=2)". 111 // like "W (Q=1) - W (Q=2)".
146 for (int i = 0; i < recommendations.length; i+=2) { 112 final int minuendIndex = minuendSubtrahendUiReversed ? 1 : 0;
147 String[] minuendParts = StringUtil 113 final int subtrahendIndex = minuendSubtrahendUiReversed ? 0 : 1;
148 .unbracket(recommendations[i+0]) 114
149 .split(";"); 115 for (int i = 0; i < recommendations.length; i += 2) {
150 if(minuendParts.length >= 4) { 116 final String[] minuendParts = StringUtil.unbracket(recommendations[i + minuendIndex]).split(";");
117 if (minuendParts.length >= 4) {
151 displayString += "(" + minuendParts[3]; 118 displayString += "(" + minuendParts[3];
152 } 119 } else {
153 else {
154 displayString += "([error]"; 120 displayString += "([error]";
155 } 121 }
156 122
157 displayString += " - "; 123 displayString += " - ";
158 124
159 String[] subtrahendParts = StringUtil 125 final String[] subtrahendParts = StringUtil.unbracket(recommendations[i + subtrahendIndex]).split(";");
160 .unbracket(recommendations[i+1]) 126 if (subtrahendParts.length >= 4) {
161 .split(";");
162 if(subtrahendParts.length >= 4) {
163 displayString += subtrahendParts[3] + ") "; 127 displayString += subtrahendParts[3] + ") ";
164 } 128 } else {
165 else {
166 displayString += "[error])"; 129 displayString += "[error])";
167 } 130 }
168 } 131 }
169 132
170 return new String[] { displayString }; 133 return new String[] { displayString };
171 } 134 }
135
172 } 136 }
173 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 137 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org