Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/CrossSectionChartThemePanel.java @ 1457:3d9f81c3f00d
Refactored to use existing code.
flys-client/trunk@3487 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 20 Dec 2011 11:14:47 +0000 |
parents | fa63366ba115 |
children | 61521bc0ced3 |
comparison
equal
deleted
inserted
replaced
1456:1c2cd46d526d | 1457:3d9f81c3f00d |
---|---|
52 | 52 |
53 | 53 |
54 | 54 |
55 /** | 55 /** |
56 * ThemePanel much like ChartThemePanel, but shows an "Actions" column, | 56 * ThemePanel much like ChartThemePanel, but shows an "Actions" column, |
57 * needed for interaction in the CrossSection Charts and a selctor to | 57 * needed for interaction in the CrossSection Charts and a selector to |
58 * declare which cross section profile is "master". | 58 * declare which cross section profile is "master". |
59 * Also can show 'area creation' context menus. | |
59 */ | 60 */ |
60 public class CrossSectionChartThemePanel | 61 public class CrossSectionChartThemePanel |
61 extends ChartThemePanel { | 62 extends ChartThemePanel { |
62 /** Artifact Clone/Creation service. */ | 63 /** Artifact Clone/Creation service. */ |
63 protected LoadArtifactServiceAsync loadService = | 64 protected LoadArtifactServiceAsync loadService = |
111 } | 112 } |
112 }); | 113 }); |
113 } | 114 } |
114 | 115 |
115 | 116 |
116 /** | 117 |
117 * Tell an area artifact where to get the upper and lower curve from. | 118 /** |
118 * @param over if null, something | 119 * Sets currentMasterUUID. |
119 */ | |
120 public void feedTellArea(final String artifact, Theme under, Theme over) { | |
121 | |
122 Data[] feedData; | |
123 | |
124 if (over != null && under != null) { | |
125 feedData = new Data[] { | |
126 DefaultData.createSimpleStringData("area.curve_under", | |
127 under.getArtifact() + under.getIndex()), | |
128 DefaultData.createSimpleStringData("area.curve_over", | |
129 over.getArtifact() + over.getIndex()), | |
130 DefaultData.createSimpleStringData("area.name", | |
131 over.getDescription() + " / " + under.getDescription()), | |
132 DefaultData.createSimpleStringData("area.facet", | |
133 "cross_section.area") | |
134 }; | |
135 GWT.log("Have over and under"); | |
136 } | |
137 else if (over == null && under != null) { | |
138 feedData = new Data[] { | |
139 DefaultData.createSimpleStringData("area.curve_under", | |
140 under.getArtifact() + under.getIndex()), | |
141 DefaultData.createSimpleStringData("area.name", | |
142 under.getDescription() + " / " + MSG.getString("x_axis")), | |
143 DefaultData.createSimpleStringData("area.facet", | |
144 "cross_section.area") | |
145 }; | |
146 GWT.log("Have under only"); | |
147 } | |
148 else if (over != null && under == null) { | |
149 feedData = new Data[] { | |
150 DefaultData.createSimpleStringData("area.curve_over", | |
151 over.getArtifact() + over.getIndex()), | |
152 DefaultData.createSimpleStringData("area.name", | |
153 MSG.getString("x_axis") + " / " + over.getDescription()), | |
154 DefaultData.createSimpleStringData("area.facet", | |
155 "cross_section.area") | |
156 }; | |
157 GWT.log("Have over only"); | |
158 } | |
159 else { | |
160 GWT.log("Missing Data for area painting."); | |
161 return; | |
162 } | |
163 | |
164 | |
165 feedService.feed( | |
166 Config.getInstance().getLocale(), | |
167 new DefaultArtifact(artifact, "TODO:hash"), | |
168 feedData, | |
169 new AsyncCallback<Artifact>() { | |
170 public void onFailure(Throwable caught) { | |
171 GWT.log("Could not feed artifact (" + artifact | |
172 + ") with area info: " + caught.getMessage()); | |
173 SC.warn(MSG.getString(caught.getMessage())); | |
174 enable(); | |
175 } | |
176 public void onSuccess(Artifact artifact) { | |
177 GWT.log("Successfully set area params to " + artifact); | |
178 requestRedraw(); | |
179 updateCollection(); | |
180 updateGrid(); | |
181 enable(); | |
182 } | |
183 }); | |
184 } | |
185 | |
186 /** | |
187 * sets currentMasterUUID. | |
188 */ | 120 */ |
189 public String findCurrentMaster() { | 121 public String findCurrentMaster() { |
190 ThemeList themeList = getThemeList(); | 122 ThemeList themeList = getThemeList(); |
191 int count = getThemeList().getThemeCount(); | 123 int count = getThemeList().getThemeCount(); |
192 String firstCSUuid = null; | 124 String firstCSUuid = null; |
429 return handler; | 361 return handler; |
430 } | 362 } |
431 | 363 |
432 | 364 |
433 /** | 365 /** |
434 * Get the chosen km for given cross-section. | |
435 */ | |
436 final public double getKmForCrossSectionIdx(final int index) { | |
437 double km = 0d; | |
438 int collIdx = 0; | |
439 while (km == 0d) { | |
440 CollectionItem item = collection.getItem(collIdx++); | |
441 if (item == null) { | |
442 break; | |
443 } | |
444 if (item.getData() == null) continue; | |
445 String d = item.getData().get("cross_section" + index + ".km"); | |
446 if (d == null) { | |
447 continue; | |
448 } | |
449 km = Double.valueOf(d); | |
450 } | |
451 return km; | |
452 } | |
453 | |
454 | |
455 /** | |
456 * Create a "kilometer spinner" for CrossSection Facets. | 366 * Create a "kilometer spinner" for CrossSection Facets. |
457 * @param facetRecord The respective Facet/Theme. | 367 * @param facetRecord The respective Facet/Theme. |
458 * @return label, intialized SpinnerItem. | 368 * @return label, intialized SpinnerItem. |
459 */ | 369 */ |
460 public SpinnerItem createSpinnerItem(FacetRecord facetRecord) { | 370 public SpinnerItem createSpinnerItem(FacetRecord facetRecord) { |
567 public void setCurrentMaster(String currentMasterUuid) { | 477 public void setCurrentMaster(String currentMasterUuid) { |
568 this.currentMasterUUID = currentMasterUuid; | 478 this.currentMasterUUID = currentMasterUuid; |
569 } | 479 } |
570 | 480 |
571 | 481 |
572 /** | 482 /** Returns name of cross section area facets. */ |
573 * Create and parameterize a new area artifact. | 483 protected String getAreaFacetName() { |
574 * @param under | 484 return "cross_section.area"; |
575 * @param over if null, something. | 485 } |
576 */ | 486 |
577 public void createAreaArtifact( | 487 |
578 final Theme under, | 488 /** |
579 final Theme over, | 489 * Return true if two themes are canditates for an area being |
580 boolean between | 490 * rendered between them. |
581 ) { | 491 * TODO join with canArea, generalize to allow easier modification |
582 Config config = Config.getInstance(); | 492 * in subclasses. |
583 String locale = config.getLocale(); | 493 */ |
584 | 494 protected boolean areAreaCompatible(Theme a, Theme b) { |
585 Recommendation area = new Recommendation( | 495 if (a.equals(b)) { |
586 "area", | 496 return false; |
587 "", | |
588 "", | |
589 null); | |
590 Recommendation[] recommendations = new Recommendation[] {area}; | |
591 | |
592 loadService.loadMany( | |
593 this.collection, | |
594 recommendations, | |
595 null, //use individual factories. | |
596 locale, | |
597 new AsyncCallback<Artifact[]>() { | |
598 public void onFailure(Throwable caught) { | |
599 GWT.log("Failed, no area artifact: " + caught.getMessage()); | |
600 enable(); | |
601 // TODO SC.warn | |
602 } | |
603 public void onSuccess(Artifact[] artifacts) { | |
604 GWT.log("Success, created area artifact: " | |
605 + artifacts[0].getUuid()); | |
606 // Now, feed the artifact with the relevant data. | |
607 feedTellArea(artifacts[0].getUuid(), under, over); | |
608 } | |
609 } | |
610 ); | |
611 } | |
612 | |
613 /** | |
614 * Include area specific menu items. | |
615 */ | |
616 protected Menu getSingleContextMenu(final ListGridRecord[] records) { | |
617 Menu menu = super.getSingleContextMenu(records); | |
618 | |
619 final Theme facetTheme = ((FacetRecord)records[0]).getTheme(); | |
620 String thisItem = facetTheme.getDescription(); | |
621 if (facetTheme.getFacet().equals("area") || | |
622 facetTheme.getFacet().equals("cross_section.area") | |
623 ) { | |
624 return menu; | |
625 } | 497 } |
626 | 498 return (a.getFacet().equals("cross_section") |
627 menu.addItem(createSeparator()); | 499 || a.getFacet().equals("cross_section_water_line")) |
628 | 500 && (b.getFacet().equals("cross_section") |
629 // TODO i18n | 501 || b.getFacet().equals("cross_section_water_line")); |
630 //MenuItem properties = new MenuItem(MSG.properties()); | 502 } |
631 MenuItem areaMenuItem = new MenuItem("New Area..."); | 503 |
632 Menu areaMenu = new Menu(); | 504 |
633 | 505 /** |
634 ThemeList themes = getThemeList(); | 506 * True if context menu should contain 'create area' submenu on |
635 int nThemes = themes.getThemeCount(); | 507 * this theme. |
636 | 508 */ |
637 MenuItem underMenuItem = new MenuItem("Under ..."); | 509 protected boolean canArea(Theme a) { |
638 Menu underMenu = new Menu(); | 510 return a.getFacet().equals("cross_section") |
639 for (int i = 0; i < nThemes; i++) { | 511 || a.getFacet().equals("cross_section_water_line"); |
640 final Theme theme = themes.getThemeAt(i+1); | |
641 if (theme.getDescription().equals(thisItem) | |
642 || theme.getFacet().equals("area") | |
643 || theme.getFacet().equals("cross_section.area") | |
644 ) { | |
645 continue; | |
646 } | |
647 MenuItem againster = new MenuItem(theme.getDescription()); | |
648 underMenu.addItem(againster); | |
649 | |
650 againster.addClickHandler(new ClickHandler() { | |
651 public void onClick(MenuItemClickEvent evt) { | |
652 disable(); | |
653 createAreaArtifact(theme, facetTheme, false); | |
654 } | |
655 }); | |
656 } | |
657 | |
658 MenuItem overMenuItem = new MenuItem("Over ..."); | |
659 Menu overMenu = new Menu(); | |
660 for (int i = 0; i < nThemes; i++) { | |
661 final Theme theme = themes.getThemeAt(i+1); | |
662 if (theme.getDescription().equals(thisItem) | |
663 || theme.getFacet().equals("area") | |
664 || theme.getFacet().equals("cross_section.area") | |
665 ) { | |
666 continue; | |
667 } | |
668 MenuItem againster = new MenuItem(theme.getDescription()); | |
669 overMenu.addItem(againster); | |
670 | |
671 againster.addClickHandler(new ClickHandler() { | |
672 public void onClick(MenuItemClickEvent evt) { | |
673 disable(); | |
674 createAreaArtifact(facetTheme, theme, false); | |
675 } | |
676 }); | |
677 } | |
678 overMenu.addItem(createSeparator()); | |
679 MenuItem againstAxis = new MenuItem(MSG.getString("x_axis")); | |
680 againstAxis.addClickHandler(new ClickHandler() { | |
681 public void onClick(MenuItemClickEvent evt) { | |
682 disable(); | |
683 createAreaArtifact(facetTheme, null, false); | |
684 } | |
685 }); | |
686 overMenu.addItem(againstAxis); | |
687 | |
688 MenuItem betweenMenuItem = new MenuItem("Between ..."); | |
689 Menu betweenMenu = new Menu(); | |
690 for (int i = 0; i < nThemes; i++) { | |
691 final Theme theme = themes.getThemeAt(i+1); | |
692 if (theme.getDescription().equals(thisItem) | |
693 || theme.getFacet().equals("area") | |
694 || theme.getFacet().equals("cross_section.area") | |
695 ) { | |
696 continue; | |
697 } | |
698 MenuItem againster = new MenuItem(theme.getDescription()); | |
699 betweenMenu.addItem(againster); | |
700 | |
701 againster.addClickHandler(new ClickHandler() { | |
702 public void onClick(MenuItemClickEvent evt) { | |
703 disable(); | |
704 createAreaArtifact(facetTheme, theme, true); | |
705 } | |
706 }); | |
707 } | |
708 betweenMenu.addItem(createSeparator()); | |
709 betweenMenu.addItem(againstAxis); | |
710 | |
711 overMenuItem.setSubmenu(overMenu); | |
712 underMenuItem.setSubmenu(underMenu); | |
713 betweenMenuItem.setSubmenu(betweenMenu); | |
714 | |
715 areaMenu.addItem(overMenuItem); | |
716 areaMenu.addItem(underMenuItem); | |
717 areaMenu.addItem(betweenMenuItem); | |
718 | |
719 areaMenuItem.setSubmenu(areaMenu); | |
720 menu.addItem(areaMenuItem); | |
721 | |
722 return menu; | |
723 } | 512 } |
724 } | 513 } |
725 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 514 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |