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

Area creation UI update. flys-client/trunk@3440 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 16 Dec 2011 13:36:23 +0000
parents 432180235caf
children df7ebcbff984
comparison
equal deleted inserted replaced
1443:ec0460dbbae2 1444:bdac8a72f7e6
17 import com.smartgwt.client.widgets.grid.ListGrid; 17 import com.smartgwt.client.widgets.grid.ListGrid;
18 import com.smartgwt.client.widgets.grid.ListGridField; 18 import com.smartgwt.client.widgets.grid.ListGridField;
19 import com.smartgwt.client.widgets.grid.ListGridRecord; 19 import com.smartgwt.client.widgets.grid.ListGridRecord;
20 import com.smartgwt.client.widgets.layout.HLayout; 20 import com.smartgwt.client.widgets.layout.HLayout;
21 import com.smartgwt.client.widgets.layout.VLayout; 21 import com.smartgwt.client.widgets.layout.VLayout;
22 import com.smartgwt.client.widgets.menu.events.ClickHandler;
23 import com.smartgwt.client.widgets.menu.Menu;
24 import com.smartgwt.client.widgets.menu.MenuItem;
25 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
22 import com.smartgwt.client.widgets.form.fields.SpinnerItem; 26 import com.smartgwt.client.widgets.form.fields.SpinnerItem;
23 import com.smartgwt.client.widgets.form.DynamicForm; 27 import com.smartgwt.client.widgets.form.DynamicForm;
24 28
25 import com.smartgwt.client.widgets.form.fields.SelectItem; 29 import com.smartgwt.client.widgets.form.fields.SelectItem;
26 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; 30 import com.smartgwt.client.widgets.form.fields.events.ChangeEvent;
37 import de.intevation.flys.client.shared.model.DefaultArtifact; 41 import de.intevation.flys.client.shared.model.DefaultArtifact;
38 import de.intevation.flys.client.shared.model.DefaultData; 42 import de.intevation.flys.client.shared.model.DefaultData;
39 import de.intevation.flys.client.shared.model.DefaultDataItem; 43 import de.intevation.flys.client.shared.model.DefaultDataItem;
40 import de.intevation.flys.client.shared.model.FacetRecord; 44 import de.intevation.flys.client.shared.model.FacetRecord;
41 import de.intevation.flys.client.shared.model.OutputMode; 45 import de.intevation.flys.client.shared.model.OutputMode;
46 import de.intevation.flys.client.shared.model.Recommendation;
42 import de.intevation.flys.client.shared.model.Theme; 47 import de.intevation.flys.client.shared.model.Theme;
43 import de.intevation.flys.client.shared.model.ThemeList; 48 import de.intevation.flys.client.shared.model.ThemeList;
44 49
50 import de.intevation.flys.client.client.services.CrossSectionKMServiceAsync;
45 import de.intevation.flys.client.client.services.FeedServiceAsync; 51 import de.intevation.flys.client.client.services.FeedServiceAsync;
46 import de.intevation.flys.client.client.services.CrossSectionKMServiceAsync; 52 import de.intevation.flys.client.client.services.LoadArtifactService;
53 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync;
54
55
47 56
48 /** 57 /**
49 * ThemePanel much like ChartThemePanel, but shows an "Actions" column, 58 * ThemePanel much like ChartThemePanel, but shows an "Actions" column,
50 * needed for interaction in the CrossSection Charts and a selctor to 59 * needed for interaction in the CrossSection Charts and a selctor to
51 * declare which cross section profile is "master". 60 * declare which cross section profile is "master".
52 */ 61 */
53 public class CrossSectionChartThemePanel 62 public class CrossSectionChartThemePanel
54 extends ChartThemePanel { 63 extends ChartThemePanel {
64 /** Artifact Clone/Creation service. */
65 protected LoadArtifactServiceAsync loadService =
66 GWT.create(LoadArtifactService.class);
55 67
56 /** Service to query measurement points of cross sections. */ 68 /** Service to query measurement points of cross sections. */
57 CrossSectionKMServiceAsync kmService = GWT.create( 69 CrossSectionKMServiceAsync kmService = GWT.create(
58 de.intevation.flys.client.client.services.CrossSectionKMService.class); 70 de.intevation.flys.client.client.services.CrossSectionKMService.class);
59 71
102 }); 114 });
103 } 115 }
104 116
105 117
106 /** 118 /**
119 * Tell an area artifact where to get the upper and lower curve from.
120 */
121 public void feedTellArea(final String artifact, Theme under, Theme over) {
122 Data[] feedData = new Data[] {
123 DefaultData.createSimpleStringData("area.curve_under",
124 under.getArtifact() + under.getIndex()),
125 DefaultData.createSimpleStringData("area.curve_over",
126 over.getArtifact() + over.getIndex()),
127 };
128
129 feedService.feed(
130 Config.getInstance().getLocale(),
131 new DefaultArtifact(artifact, "TODO:hash"),
132 feedData,
133 new AsyncCallback<Artifact>() {
134 public void onFailure(Throwable caught) {
135 GWT.log("Could not feed artifact (" + artifact
136 + ") with area info: " + caught.getMessage());
137 SC.warn(MSG.getString(caught.getMessage()));
138 enable();
139 }
140 public void onSuccess(Artifact artifact) {
141 GWT.log("Successfully set area params to " + artifact);
142 requestRedraw();
143 enable();
144 // TODO: Update the grid/collection, to include this new
145 // facet.
146 //updateCollection?
147 }
148 });
149 }
150
151 /**
107 * sets currentMasterUUID. 152 * sets currentMasterUUID.
108 */ 153 */
109 public String findCurrentMaster() { 154 public String findCurrentMaster() {
110 ThemeList themeList = getThemeList(); 155 ThemeList themeList = getThemeList();
111 int count = getThemeList().getThemeCount(); 156 int count = getThemeList().getThemeCount();
119 return theme.getDescription(); 164 return theme.getDescription();
120 } 165 }
121 } 166 }
122 return null; 167 return null;
123 } 168 }
169
124 170
125 /** 171 /**
126 * Create Layout, add a master selection box beneath. 172 * Create Layout, add a master selection box beneath.
127 */ 173 */
128 @Override 174 @Override
473 519
474 /** Set Current Cross-section Masters uuid. */ 520 /** Set Current Cross-section Masters uuid. */
475 public void setCurrentMaster(String currentMasterUuid) { 521 public void setCurrentMaster(String currentMasterUuid) {
476 this.currentMasterUUID = currentMasterUuid; 522 this.currentMasterUUID = currentMasterUuid;
477 } 523 }
524
525
526 /**
527 * Create and parameterize a new area artifact.
528 */
529 public void createAreaArtifact(final Theme under, final Theme over) {
530 Config config = Config.getInstance();
531 String locale = config.getLocale();
532
533 Recommendation area = new Recommendation(
534 "area",
535 "",
536 "",
537 null);
538 Recommendation[] recommendations = new Recommendation[] {area};
539
540 loadService.loadMany(
541 this.collection,
542 recommendations,
543 null, //use individual factories.
544 locale,
545 new AsyncCallback<Artifact[]>() {
546 public void onFailure(Throwable caught) {
547 GWT.log("Failed, no area artifact: " + caught.getMessage());
548 enable();
549 // TODO SC.warn
550 }
551 public void onSuccess(Artifact[] artifacts) {
552 GWT.log("Success, created area artifact: "
553 + artifacts[0].getUuid());
554 // Now, feed the artifact with the relevant data.
555 feedTellArea(artifacts[0].getUuid(), under, over);
556 }
557 }
558 );
559 }
560
561 /**
562 * Include area specific menu items.
563 */
564 protected Menu getSingleContextMenu(final ListGridRecord[] records) {
565 Menu menu = super.getSingleContextMenu(records);
566
567 final Theme facetTheme = ((FacetRecord)records[0]).getTheme();
568 String thisItem = facetTheme.getDescription();
569 if (facetTheme.getFacet().equals("area")) {
570 return menu;
571 }
572
573 menu.addItem(createSeparator());
574
575 // TODO i18n
576 //MenuItem properties = new MenuItem(MSG.properties());
577 MenuItem areaMenuItem = new MenuItem("New Area...");
578 Menu areaMenu = new Menu();
579
580 ThemeList themes = getThemeList();
581 int nThemes = themes.getThemeCount();
582 for (int i = 0; i < nThemes; i++) {
583 final Theme theme = themes.getThemeAt(i+1);
584 if (theme.getDescription().equals(thisItem)
585 || theme.getFacet().equals("area")) {
586 continue;
587 }
588 MenuItem againster = new MenuItem(theme.getDescription());
589 areaMenu.addItem(againster);
590
591 againster.addClickHandler(new ClickHandler() {
592 public void onClick(MenuItemClickEvent evt) {
593 disable();
594 createAreaArtifact(facetTheme, theme);
595 }
596 });
597 }
598
599 MenuItem underMenuItem = new MenuItem("Under ...");
600 MenuItem overMenuItem = new MenuItem("Over ...");
601 areaMenu.addItem(createSeparator());
602 areaMenu.addItem(underMenuItem);
603 areaMenu.addItem(overMenuItem);
604
605 areaMenuItem.setSubmenu(areaMenu);
606 menu.addItem(areaMenuItem);
607
608 return menu;
609 }
478 } 610 }
479 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 611 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org