comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java @ 1309:a95e82d6bcc1

Refactored the code to create a context menu and a style editor so that it is also available for maps. flys-client/trunk@2943 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 12 Oct 2011 08:53:17 +0000
parents d9cb362b8b34
children 6bb6d43eeb2d
comparison
equal deleted inserted replaced
1308:d194bee456d3 1309:a95e82d6bcc1
1 package de.intevation.flys.client.client.ui.chart; 1 package de.intevation.flys.client.client.ui.chart;
2 2
3 import com.google.gwt.core.client.GWT; 3 import com.google.gwt.core.client.GWT;
4 import com.google.gwt.user.client.rpc.AsyncCallback;
5 4
6 import com.smartgwt.client.types.ListGridFieldType; 5 import com.smartgwt.client.types.ListGridFieldType;
7 import com.smartgwt.client.widgets.grid.ListGridField; 6 import com.smartgwt.client.widgets.grid.ListGridField;
8 import com.smartgwt.client.widgets.layout.VLayout; 7 import com.smartgwt.client.widgets.layout.VLayout;
9 import com.smartgwt.client.widgets.grid.events.RowContextClickEvent;
10 import com.smartgwt.client.widgets.grid.events.RowContextClickHandler;
11 import com.smartgwt.client.widgets.menu.Menu;
12 import com.smartgwt.client.widgets.menu.MenuItem;
13 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
14 import com.smartgwt.client.widgets.menu.events.ClickHandler;
15 8
16 import de.intevation.flys.client.shared.model.Collection; 9 import de.intevation.flys.client.shared.model.Collection;
17 import de.intevation.flys.client.shared.model.Theme; 10 import de.intevation.flys.client.shared.model.Theme;
18 import de.intevation.flys.client.shared.model.OutputMode; 11 import de.intevation.flys.client.shared.model.OutputMode;
19 import de.intevation.flys.client.shared.model.FacetRecord;
20 import de.intevation.flys.client.shared.model.CollectionItemAttribute;
21 12
22 import de.intevation.flys.client.client.FLYSConstants; 13 import de.intevation.flys.client.client.FLYSConstants;
23 import de.intevation.flys.client.client.ui.ThemePanel; 14 import de.intevation.flys.client.client.ui.ThemePanel;
24 import de.intevation.flys.client.client.Config;
25 import de.intevation.flys.client.client.ui.CollectionView;
26 15
27 import de.intevation.flys.client.client.services.FeedService; 16 import de.intevation.flys.client.client.services.FeedService;
28 import de.intevation.flys.client.client.services.FeedServiceAsync; 17 import de.intevation.flys.client.client.services.FeedServiceAsync;
29 import de.intevation.flys.client.client.services.CollectionItemAttributeService;
30 import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync;
31 18
32 /** 19 /**
33 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
34 */ 21 */
35 public class ChartThemePanel extends ThemePanel { 22 public class ChartThemePanel extends ThemePanel {
37 /** The interface that provides i18n messages. */ 24 /** The interface that provides i18n messages. */
38 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); 25 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
39 26
40 /** The collection */ 27 /** The collection */
41 protected Collection collection; 28 protected Collection collection;
42
43 /** The collection view*/
44 protected CollectionView view;
45
46 /** The service used to get collection item attributes. */
47 protected CollectionItemAttributeServiceAsync itemAttributeService =
48 GWT.create(CollectionItemAttributeService.class);
49 29
50 public static final String GRID_FIELD_ACTIVE = "active"; 30 public static final String GRID_FIELD_ACTIVE = "active";
51 public static final String GRID_FIELD_NAME = "name"; 31 public static final String GRID_FIELD_NAME = "name";
52 public static final String GRID_FIELD_ACTIONS = "actions"; 32 public static final String GRID_FIELD_ACTIONS = "actions";
53 33
95 list.setShowHeaderContextMenu(false); 75 list.setShowHeaderContextMenu(false);
96 list.setWidth100(); 76 list.setWidth100();
97 list.setHeight100(); 77 list.setHeight100();
98 78
99 list.addEditCompleteHandler(this); 79 list.addEditCompleteHandler(this);
100 list.addRowContextClickHandler(new RowContextClickHandler() {
101 public void onRowContextClick(RowContextClickEvent event) {
102 FacetRecord record = (FacetRecord) event.getRecord();
103
104 Menu menu = createContextMenu(record);
105 list.setContextMenu(menu);
106 menu.showContextMenu();
107
108 event.cancel();
109 }
110 });
111 80
112 ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); 81 ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20);
113 active.setType(ListGridFieldType.BOOLEAN); 82 active.setType(ListGridFieldType.BOOLEAN);
114 83
115 ListGridField name = new ListGridField( 84 ListGridField name = new ListGridField(
118 87
119 list.setFields(active, name); 88 list.setFields(active, name);
120 } 89 }
121 90
122 91
123 protected Menu createContextMenu(final FacetRecord record) {
124 Menu menu = new Menu();
125
126 MenuItem properties = new MenuItem(MSG.properties());
127 properties.addClickHandler(new ClickHandler() {
128 public void onClick(MenuItemClickEvent evt) {
129 GWT.log("clicked properties");
130 getItemAttributes(record);
131 }
132 });
133 menu.addItem(properties);
134 return menu;
135 }
136
137
138 @Override 92 @Override
139 public void activateTheme(Theme theme, boolean active) { 93 public void activateTheme(Theme theme, boolean active) {
140 theme.setActive(active ? 1 : 0); 94 theme.setActive(active ? 1 : 0);
141 } 95 }
142
143
144 protected void getItemAttributes(final FacetRecord record) {
145 Config config = Config.getInstance();
146 String url = config.getServerUrl();
147 String locale = config.getLocale();
148
149 String artifact = record.getTheme().getArtifact();
150
151 itemAttributeService.getCollectionItemAttribute(
152 this.collection,
153 artifact,
154 url,
155 locale,
156 new AsyncCallback<CollectionItemAttribute>() {
157 public void onFailure (Throwable caught) {
158 GWT.log("Could not get Collection item attributes.");
159 }
160 public void onSuccess(CollectionItemAttribute cia) {
161 GWT.log("Successfully loaded collectionitem attributes.");
162 StyleEditorWindow win = new StyleEditorWindow(
163 collection,
164 cia,
165 record);
166 win.setCollectionView(view);
167 win.show();
168 }
169 });
170 }
171
172
173 public void setCollectionView (CollectionView view) {
174 this.view = view;
175 }
176 } 96 }
177 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 97 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org