comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java @ 790:3fa8583434b2

Made stepping forward/backword much smoother in the parameter list. flys-client/trunk@2294 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 06 Jul 2011 15:34:38 +0000
parents e8be9a188e64
children 653ae84533e7
comparison
equal deleted inserted replaced
789:e8be9a188e64 790:3fa8583434b2
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.List; 4 import java.util.List;
5 import java.util.Map; 5 import java.util.Map;
6 import java.util.Set; 6 import java.util.Set;
7 import java.util.TreeMap;
7 8
8 import com.google.gwt.core.client.GWT; 9 import com.google.gwt.core.client.GWT;
9 import com.google.gwt.user.client.rpc.AsyncCallback; 10 import com.google.gwt.user.client.rpc.AsyncCallback;
10 11
11 import com.smartgwt.client.types.VerticalAlignment; 12 import com.smartgwt.client.types.VerticalAlignment;
93 protected CollectionView cView; 94 protected CollectionView cView;
94 95
95 protected Artifact artifact; 96 protected Artifact artifact;
96 97
97 protected List<DataList> old; 98 protected List<DataList> old;
99 protected Map<String, Canvas> oldStorage;
98 protected DataList current; 100 protected DataList current;
99 101
100 protected UIProvider uiProvider; 102 protected UIProvider uiProvider;
101 103
102 protected VLayout topLayout; 104 protected VLayout topLayout;
114 this.cView = cView; 116 this.cView = cView;
115 this.flys = flys; 117 this.flys = flys;
116 118
117 parameterHandlers = new ArrayList<ParameterChangeHandler>(); 119 parameterHandlers = new ArrayList<ParameterChangeHandler>();
118 old = new ArrayList<DataList>(); 120 old = new ArrayList<DataList>();
121 oldStorage = new TreeMap<String, Canvas>();
119 topLayout = new VLayout(); 122 topLayout = new VLayout();
120 oldItems = new VLayout(); 123 oldItems = new VLayout();
121 currentItems = new VLayout(); 124 currentItems = new VLayout();
122 exportModes = new VLayout(); 125 exportModes = new VLayout();
123 report = new VLayout(); 126 report = new VLayout();
140 this.flys = flys; 143 this.flys = flys;
141 this.artifact = artifact; 144 this.artifact = artifact;
142 145
143 parameterHandlers = new ArrayList<ParameterChangeHandler>(); 146 parameterHandlers = new ArrayList<ParameterChangeHandler>();
144 old = new ArrayList<DataList>(); 147 old = new ArrayList<DataList>();
148 oldStorage = new TreeMap<String, Canvas>();
145 topLayout = new VLayout(); 149 topLayout = new VLayout();
146 oldItems = new VLayout(); 150 oldItems = new VLayout();
147 currentItems = new VLayout(); 151 currentItems = new VLayout();
148 exportModes = new VLayout(); 152 exportModes = new VLayout();
149 report = new VLayout(); 153 report = new VLayout();
150 154
151 init(); 155 init();
152 156
153 addParameterChangeHandler(this); 157 addParameterChangeHandler(this);
154 158
155 setArtifact(artifact); 159 setArtifact(artifact, false);
156 } 160 }
157 161
158 162
159 protected void init() { 163 protected void init() {
160 HLayout rootLayout = new HLayout(); 164 HLayout rootLayout = new HLayout();
245 return stack; 249 return stack;
246 } 250 }
247 251
248 252
249 protected void setArtifact(Artifact artifact) { 253 protected void setArtifact(Artifact artifact) {
254 setArtifact(artifact, true);
255 }
256
257
258 protected void setArtifact(Artifact artifact, boolean forward) {
250 Artifact tmp = this.artifact; 259 Artifact tmp = this.artifact;
251 this.artifact = artifact; 260 this.artifact = artifact;
252 261
253 fireParameterChangeEvent(tmp, this.artifact); 262 if (forward) {
263 fireParameterChangeEvent(
264 tmp, this.artifact, ParameterChangeEvent.Type.FORWARD);
265 }
266 else {
267 fireParameterChangeEvent(
268 tmp, this.artifact, ParameterChangeEvent.Type.BACK);
269 }
254 } 270 }
255 271
256 272
257 /** 273 /**
258 * This method registers a new ParameterChangeHandler. 274 * This method registers a new ParameterChangeHandler.
268 284
269 /** 285 /**
270 * This method calls the <code>onParameterChange()</code> method of all 286 * This method calls the <code>onParameterChange()</code> method of all
271 * registered ParameterChangeHandler. 287 * registered ParameterChangeHandler.
272 */ 288 */
273 protected void fireParameterChangeEvent(Artifact old, Artifact newArt) { 289 protected void fireParameterChangeEvent(
290 Artifact old,
291 Artifact newArt,
292 ParameterChangeEvent.Type type)
293 {
294 ParameterChangeEvent e = new ParameterChangeEvent(old, newArt, type);
295
274 for (ParameterChangeHandler handler: parameterHandlers) { 296 for (ParameterChangeHandler handler: parameterHandlers) {
275 handler.onParameterChange(new ParameterChangeEvent(old, newArt)); 297 handler.onParameterChange(e);
276 } 298 }
277 } 299 }
278 300
279 301
280 /** 302 /**
346 SC.warn(caught.getMessage()); 368 SC.warn(caught.getMessage());
347 } 369 }
348 370
349 public void onSuccess(Artifact artifact) { 371 public void onSuccess(Artifact artifact) {
350 GWT.log("Successfully feed the artifact."); 372 GWT.log("Successfully feed the artifact.");
373 old.clear();
351 setArtifact(artifact); 374 setArtifact(artifact);
352 } 375 }
353 }); 376 });
354 } 377 }
355 }); 378 });
367 old.clear(); 390 old.clear();
368 } 391 }
369 392
370 393
371 public void addOldData(DataList old) { 394 public void addOldData(DataList old) {
395 addOldData(old, true);
396 }
397
398
399 public void addOldData(DataList old, boolean redraw) {
372 if (old != null) { 400 if (old != null) {
373 this.old.add(old); 401 this.old.add(old);
374 } 402 }
375 403
376 refreshOld(); 404 refreshOld(redraw);
377 } 405 }
378 406
379 407
380 public void addOldDatas(DataList[] old) { 408 public void addOldDatas(DataList[] old) {
409 addOldDatas(old, true);
410 }
411
412
413 public void addOldDatas(DataList[] old, boolean redraw) {
381 if (old != null && old.length > 0) { 414 if (old != null && old.length > 0) {
382 for (DataList o: old) { 415 for (DataList o: old) {
383 if (o == null) { 416 if (o == null) {
384 continue; 417 continue;
385 } 418 }
386 419
387 if (!exists(o)) { 420 if (!exists(o)) {
388 GWT.log("Data '" + o.getLabel() + "' is new."); 421 GWT.log("Data '" + o.getLabel() + "' is new.");
389 addOldData(o); 422 addOldData(o, false);
390 } 423 }
424 }
425
426 if (redraw) {
427 addOldData(null, true);
391 } 428 }
392 429
393 return; 430 return;
394 } 431 }
395 432
396 addOldData(null); 433 addOldData(null, true);
397 } 434 }
398 435
399 436
400 public boolean exists(DataList data) { 437 public boolean exists(DataList data) {
401 if (data == null) { 438 if (data == null) {
420 457
421 refreshCurrent(); 458 refreshCurrent();
422 } 459 }
423 460
424 461
425 public void refreshOld() { 462 public void refreshOld(boolean redrawAll) {
426 // XXX maybe we should not remove all items but just add the newest item 463 if (redrawAll) {
427 // to the list. 464 refreshAllOld();
428 oldItems.removeMembers(oldItems.getMembers()); 465 }
429 466 else {
430 for (DataList dataList: old) { 467 DataList dataList = old.get(old.size()-1);
431 HLayout h = new HLayout(); 468 String state = dataList.getState();
432 h.setAlign(VerticalAlignment.TOP); 469
433 h.setHeight(20); 470 if (oldStorage.get(state) == null) {
434 471 String provider = dataList.getUIProvider();
435 String provider = dataList.getUIProvider(); 472 UIProvider uiprovider = UIProviderFactory.getProvider(provider);
436 UIProvider uiprovider = UIProviderFactory.getProvider(provider); 473 ((HasStepBackHandlers) uiprovider).addStepBackHandler(this);
437 ((HasStepBackHandlers) uiprovider).addStepBackHandler(this); 474
438 475 Canvas c = uiprovider.createOld(dataList);
439 oldItems.addMember(uiprovider.createOld(dataList)); 476 if (c != null) {
440 } 477 oldStorage.put(dataList.getState(), c);
441 478 oldItems.addMember(c);
479 }
480 }
481 }
482
483 updateOldHeight();
484 }
485
486
487 protected void refreshAllOld() {
488 List<String> not = new ArrayList<String>();
489
490 for (DataList data: old) {
491 String state = data.getState();
492
493 Canvas c = oldStorage.get(state);
494
495 if (c != null) {
496 not.add(state);
497 }
498 }
499
500 Map<String, Canvas> newOld = new TreeMap<String, Canvas>();
501
502 Set<Map.Entry<String, Canvas>> entries = oldStorage.entrySet();
503 for (Map.Entry<String, Canvas> entry: entries) {
504 String state = entry.getKey();
505 Canvas value = entry.getValue();
506
507 if (not.indexOf(state) < 0) {
508 oldItems.removeMember(value);
509 }
510 else {
511 newOld.put(state, value);
512 }
513 }
514
515 oldStorage = newOld;
516 }
517
518
519 protected void updateOldHeight() {
442 int minHeight = oldItems.getMinHeight(); 520 int minHeight = oldItems.getMinHeight();
443 if (minHeight <= 20) { 521 if (minHeight <= 20) {
444 oldItems.setHeight(20); 522 oldItems.setHeight(20);
445 } 523 }
446 else { 524 else {
506 SC.warn(MSG.getString(caught.getMessage())); 584 SC.warn(MSG.getString(caught.getMessage()));
507 } 585 }
508 586
509 public void onSuccess(Artifact artifact) { 587 public void onSuccess(Artifact artifact) {
510 GWT.log("Successfully feed the artifact."); 588 GWT.log("Successfully feed the artifact.");
511 setArtifact(artifact); 589 old.clear();
590
591 setArtifact(artifact, true);
512 } 592 }
513 }); 593 });
514 } 594 }
515 595
516 596
536 616
537 public void onSuccess(Artifact artifact) { 617 public void onSuccess(Artifact artifact) {
538 GWT.log("Successfully step back to '" + target + "'"); 618 GWT.log("Successfully step back to '" + target + "'");
539 619
540 old.clear(); 620 old.clear();
541 oldItems.removeMembers(oldItems.getMembers()); 621
542 622 setArtifact(artifact, false);
543 setArtifact(artifact);
544 } 623 }
545 } 624 }
546 ); 625 );
547 } 626 }
548 627
561 640
562 public void onSuccess(Artifact artifact) { 641 public void onSuccess(Artifact artifact) {
563 GWT.log("Successfully advanced to '" + target + "'"); 642 GWT.log("Successfully advanced to '" + target + "'");
564 643
565 old.clear(); 644 old.clear();
566 oldItems.removeMembers(oldItems.getMembers()); 645
567 646 setArtifact(artifact, true);
568 setArtifact(artifact);
569 } 647 }
570 } 648 }
571 ); 649 );
572 } 650 }
573 651
620 // we have reached a final state with no more user input 698 // we have reached a final state with no more user input
621 setCurrentData(null, null); 699 setCurrentData(null, null);
622 } 700 }
623 } 701 }
624 702
625 addOldDatas(desc.getOldData()); 703 addOldDatas(
704 desc.getOldData(),
705 event.getType() == ParameterChangeEvent.Type.BACK);
626 } 706 }
627 707
628 708
629 public void onCollectionChange(CollectionChangeEvent event) { 709 public void onCollectionChange(CollectionChangeEvent event) {
630 Collection c = event.getNewValue(); 710 Collection c = event.getNewValue();

http://dive4elements.wald.intevation.org