comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java @ 1475:fb2fefe0325f

Improvements in CrossSectionChartThemePanel. flys-client/trunk@3520 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 22 Dec 2011 09:02:28 +0000
parents a2b0b2af529f
children edf18a9dfd8b
comparison
equal deleted inserted replaced
1474:0ba23e6fef0c 1475:fb2fefe0325f
68 protected String currentCSMasterUUID; 68 protected String currentCSMasterUUID;
69 69
70 /** The layout (used for visual active/inactive feedback). */ 70 /** The layout (used for visual active/inactive feedback). */
71 protected VLayout layout; 71 protected VLayout layout;
72 72
73 /** Data item name for CrossSections selected km. */
74 protected static String CROSS_KM = "cross_section.km";
75
76
73 /** 77 /**
74 * Trivial constructor. 78 * Trivial constructor.
75 */ 79 */
76 public CrossSectionChartThemePanel( 80 public CrossSectionChartThemePanel(
77 Collection collection, 81 Collection collection,
78 OutputMode mode) 82 OutputMode mode,
83 CollectionView view)
79 { 84 {
80 super(collection, mode); 85 super(collection, mode, view);
86 }
87
88
89 /** Create DefaultArtifact. */
90 public static DefaultArtifact artifactReference(String uuid) {
91 return new DefaultArtifact(uuid, "TODO:hash");
92 }
93
94
95 /** Access data of collection item of theme. */
96 public static String dataOf(Theme theme, String dataItemName) {
97 return theme.getCollectionItem().getData().get(dataItemName);
81 } 98 }
82 99
83 100
84 /** 101 /**
85 * Feed an artifact to let it know that it is master wrt cross-sections. 102 * Feed an artifact to let it know that it is master wrt cross-sections.
89 Data[] feedData = DefaultData.createSimpleStringDataArray( 106 Data[] feedData = DefaultData.createSimpleStringDataArray(
90 "cross_section.master?", "1"); 107 "cross_section.master?", "1");
91 108
92 feedService.feed( 109 feedService.feed(
93 Config.getInstance().getLocale(), 110 Config.getInstance().getLocale(),
94 new DefaultArtifact(artifact, "TODO:hash"), 111 artifactReference(artifact),
95 feedData, 112 feedData,
96 new AsyncCallback<Artifact>() { 113 new AsyncCallback<Artifact>() {
97 public void onFailure(Throwable caught) { 114 public void onFailure(Throwable caught) {
98 GWT.log("Could not feed artifact (" + artifact 115 GWT.log("Could not feed artifact (" + artifact
99 + ") with master marker: " + caught.getMessage()); 116 + ") with master marker: " + caught.getMessage());
116 */ 133 */
117 public String findCurrentCSMaster() { 134 public String findCurrentCSMaster() {
118 ThemeList themeList = getThemeList(); 135 ThemeList themeList = getThemeList();
119 int count = getThemeList().getThemeCount(); 136 int count = getThemeList().getThemeCount();
120 String firstCSUuid = null; 137 String firstCSUuid = null;
138 Theme firstCS = null;
121 for (int i = 1; i <= count; i++) { 139 for (int i = 1; i <= count; i++) {
122 Theme theme = themeList.getThemeAt(i); 140 Theme theme = themeList.getThemeAt(i);
123 String value = theme.getCollectionItem().getData().get("cross_section.master?"); 141 String value = dataOf(theme, "cross_section.master?");
124 142
125 if (value != null) { 143 if (value != null) {
126 if (firstCSUuid == null) { 144 if (firstCSUuid == null) {
127 firstCSUuid = theme.getArtifact(); 145 firstCSUuid = theme.getArtifact();
146 firstCS = theme;
128 } 147 }
129 if (!value.equals("0")) { 148 if (!value.equals("0")) {
130 setCurrentCSMaster(theme.getArtifact()); 149 setCurrentCSMaster(theme.getArtifact());
131 GWT.log("found a master: " + currentCSMasterUUID 150 GWT.log("found a master: " + currentCSMasterUUID
132 + "/" + theme.getDescription()); 151 + "/" + theme.getDescription());
152 Theme collectionMaster = getThemeList().getTheme(
153 view.getArtifact().getUuid());
154 if (!dataOf(theme, CROSS_KM)
155 .equals(dataOf(collectionMaster, CROSS_KM))
156 ) {
157 // Tell Collection Master which kilometer the Cross-
158 // Section Master is at, to have consistent subtitle
159 // in diagram.
160 //sendFeed(view.getArtifact().getUuid(),
161 // Double.valueOf(dataOf(theme, CROSS_KM)));
162 }
163
133 return theme.getDescription(); 164 return theme.getDescription();
134 } 165 }
135 } 166 }
136 } 167 }
137 // There is none selected. Take the first one. 168 // There is none selected. Take the first one.
138 if (firstCSUuid != null) { 169 if (firstCSUuid != null) {
139 setCurrentCSMaster(firstCSUuid); 170 setCurrentCSMaster(firstCSUuid);
140 feedTellMaster(firstCSUuid); 171 feedTellMaster(firstCSUuid);
172 // Tell Collection Master which kilometer the Cross-
173 // Section Master is at, to have consistent subtitle
174 // in diagram.
175 sendFeed(view.getArtifact().getUuid(),
176 Double.valueOf(dataOf(firstCS, CROSS_KM)));
141 } 177 }
142 return null; 178 return null;
143 } 179 }
144 180
145 181
182 if (getCurrentCSMaster() != null) { 218 if (getCurrentCSMaster() != null) {
183 Data[] feedData = DefaultData.createSimpleStringDataArray( 219 Data[] feedData = DefaultData.createSimpleStringDataArray(
184 "cross_section.master?", "0"); 220 "cross_section.master?", "0");
185 feedService.feed( 221 feedService.feed(
186 locale, 222 locale,
187 new DefaultArtifact(getCurrentCSMaster(), "TODO:hash"), 223 artifactReference(getCurrentCSMaster()),
188 feedData, 224 feedData,
189 new AsyncCallback<Artifact>() { 225 new AsyncCallback<Artifact>() {
190 public void onFailure(Throwable caught) { 226 public void onFailure(Throwable caught) {
191 GWT.log("Could not un-master artifact ("+getCurrentCSMaster()+"): " + 227 GWT.log("Could not un-master artifact ("+getCurrentCSMaster()+"): " +
192 caught.getMessage()); 228 caught.getMessage());
250 } 286 }
251 return bestMatch; 287 return bestMatch;
252 } 288 }
253 289
254 290
255 /** Feed a single artifact with the km of the crosssection to display. */ 291 /** Feed a single artifact with the km of the crosssection to display.
292 * If its the selected master, also feed the collectionmaster. */
256 public void sendFeed(final String artUUID, final double kmD) { 293 public void sendFeed(final String artUUID, final double kmD) {
257 Config config = Config.getInstance(); 294 Config config = Config.getInstance();
258 final String locale = config.getLocale(); 295 final String locale = config.getLocale();
259 296
260 Data[] feedData = 297 Data[] feedData =
261 DefaultData.createSimpleStringDataArray("cross_section.km", 298 DefaultData.createSimpleStringDataArray(CROSS_KM,
262 Double.valueOf(kmD).toString()); 299 Double.valueOf(kmD).toString());
263 300
264 disable(); 301 disable();
265 feedService.feed( 302 feedService.feed(
266 locale, 303 locale,
267 new DefaultArtifact( 304 artifactReference(artUUID),
268 artUUID,
269 "TODO:hash"),
270 feedData, 305 feedData,
271 new AsyncCallback<Artifact>() { 306 new AsyncCallback<Artifact>() {
272 @Override 307 @Override
273 public void onFailure(Throwable caught) { 308 public void onFailure(Throwable caught) {
274 GWT.log("Could not feed artifact " + caught.getMessage()); 309 GWT.log("Could not feed artifact " + caught.getMessage());
376 spinnerItem.setShowTitle(false); 411 spinnerItem.setShowTitle(false);
377 spinnerItem.setTitle("Waterlevel-Spinner"); 412 spinnerItem.setTitle("Waterlevel-Spinner");
378 spinnerItem.setWidth(45); 413 spinnerItem.setWidth(45);
379 spinnerItem.setDefaultValue(facetRecord.getTheme() 414 spinnerItem.setDefaultValue(facetRecord.getTheme()
380 .getCollectionItem() 415 .getCollectionItem()
381 .getData().get("cross_section.km")); 416 .getData().get(CROSS_KM));
382 417
383 // TODO actually use crosssectionkmservice with
384 // min/max-extension
385 spinnerItem.setMin(0); 418 spinnerItem.setMin(0);
386 spinnerItem.setMax(1000); 419 spinnerItem.setMax(2000);
387 spinnerItem.setStep(0.5f); 420 spinnerItem.setStep(0.5f);
388 spinnerItem.setChangeOnKeypress(true); 421 spinnerItem.setChangeOnKeypress(true);
389 return spinnerItem; 422 return spinnerItem;
390 } 423 }
391 424
414 447
415 if (fieldName.equals(GRID_FIELD_ACTIONS)) { 448 if (fieldName.equals(GRID_FIELD_ACTIONS)) {
416 HLayout recordCanvas = new HLayout(3); 449 HLayout recordCanvas = new HLayout(3);
417 recordCanvas.setHeight(22); 450 recordCanvas.setHeight(22);
418 recordCanvas.setAlign(Alignment.CENTER); 451 recordCanvas.setAlign(Alignment.CENTER);
419 // TODO Refactor in createSpinner(data, artifact)
420 SpinnerItem spinnerItem = createSpinnerItem(facetRecord); 452 SpinnerItem spinnerItem = createSpinnerItem(facetRecord);
421 spinnerItem.addChangedHandler( 453 spinnerItem.addChangedHandler(
422 createSpinnerHandler(feedService, facetRecord)); 454 createSpinnerHandler(feedService, facetRecord));
423 455
424 DynamicForm formWrap = new DynamicForm(); 456 DynamicForm formWrap = new DynamicForm();

http://dive4elements.wald.intevation.org