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

Added context menu to themes list. flys-client/trunk@2872 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 30 Sep 2011 11:03:33 +0000
parents f6c14ffdfd07
children 95ecb98c6015
comparison
equal deleted inserted replaced
1285:0f3b19df1880 1286:b643622d77fe
1 package de.intevation.flys.client.client.ui.chart; 1 package de.intevation.flys.client.client.ui.chart;
2 2
3 import org.w3c.dom.Document;
4 import de.intevation.artifacts.common.utils.XMLUtils;
5
3 import com.google.gwt.core.client.GWT; 6 import com.google.gwt.core.client.GWT;
7 import com.google.gwt.user.client.rpc.AsyncCallback;
4 8
5 import com.smartgwt.client.types.ListGridFieldType; 9 import com.smartgwt.client.types.ListGridFieldType;
6 import com.smartgwt.client.widgets.grid.ListGridField; 10 import com.smartgwt.client.widgets.grid.ListGridField;
7 import com.smartgwt.client.widgets.layout.VLayout; 11 import com.smartgwt.client.widgets.layout.VLayout;
12 import com.smartgwt.client.widgets.grid.events.RowContextClickEvent;
13 import com.smartgwt.client.widgets.grid.events.RowContextClickHandler;
14 import com.smartgwt.client.widgets.menu.Menu;
15 import com.smartgwt.client.widgets.menu.MenuItem;
16 import com.smartgwt.client.widgets.menu.MenuItemSeparator;
17 import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
18 import com.smartgwt.client.widgets.menu.events.ClickHandler;
8 19
9 import de.intevation.flys.client.shared.model.Collection; 20 import de.intevation.flys.client.shared.model.Collection;
10 import de.intevation.flys.client.shared.model.Theme; 21 import de.intevation.flys.client.shared.model.Theme;
11 import de.intevation.flys.client.shared.model.OutputMode; 22 import de.intevation.flys.client.shared.model.OutputMode;
23 import de.intevation.flys.client.shared.model.FacetRecord;
24 import de.intevation.flys.client.shared.model.Facet;
25 import de.intevation.flys.client.shared.model.Artifact;
26 import de.intevation.flys.client.shared.model.CollectionItemAttribute;
12 27
13 import de.intevation.flys.client.client.FLYSConstants; 28 import de.intevation.flys.client.client.FLYSConstants;
14 import de.intevation.flys.client.client.ui.ThemePanel; 29 import de.intevation.flys.client.client.ui.ThemePanel;
30 import de.intevation.flys.client.client.Config;
15 31
16 import de.intevation.flys.client.client.services.FeedService; 32 import de.intevation.flys.client.client.services.FeedService;
17 import de.intevation.flys.client.client.services.FeedServiceAsync; 33 import de.intevation.flys.client.client.services.FeedServiceAsync;
18 34 import de.intevation.flys.client.client.services.CollectionItemAttributeService;
35 import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync;
19 36
20 /** 37 /**
21 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 38 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
22 */ 39 */
23 public class ChartThemePanel extends ThemePanel { 40 public class ChartThemePanel extends ThemePanel {
24 41
25 /** The interface that provides i18n messages. */ 42 /** The interface that provides i18n messages. */
26 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); 43 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
44
45 /** The collection */
46 protected Collection collection;
47
48 /** The service used to get collection item attributes. */
49 protected CollectionItemAttributeServiceAsync itemAttributeService =
50 GWT.create(CollectionItemAttributeService.class);
27 51
28 public static final String GRID_FIELD_ACTIVE = "active"; 52 public static final String GRID_FIELD_ACTIVE = "active";
29 public static final String GRID_FIELD_NAME = "name"; 53 public static final String GRID_FIELD_NAME = "name";
30 public static final String GRID_FIELD_ACTIONS = "actions"; 54 public static final String GRID_FIELD_ACTIONS = "actions";
31 55
32 FeedServiceAsync feedService = GWT.create( 56 FeedServiceAsync feedService = GWT.create(
33 de.intevation.flys.client.client.services.FeedService.class); 57 de.intevation.flys.client.client.services.FeedService.class);
34 58
35 public ChartThemePanel(Collection collection, OutputMode mode) { 59 public ChartThemePanel(Collection collection, OutputMode mode) {
36 super(collection, mode); 60 super(collection, mode);
61 this.collection = collection;
37 62
38 initGrid(); 63 initGrid();
39 initLayout(); 64 initLayout();
40 65
41 updateGrid(); 66 updateGrid();
72 list.setShowHeaderContextMenu(false); 97 list.setShowHeaderContextMenu(false);
73 list.setWidth100(); 98 list.setWidth100();
74 list.setHeight100(); 99 list.setHeight100();
75 100
76 list.addEditCompleteHandler(this); 101 list.addEditCompleteHandler(this);
102 list.addRowContextClickHandler(new RowContextClickHandler() {
103 public void onRowContextClick(RowContextClickEvent event) {
104 FacetRecord record = (FacetRecord) event.getRecord();
105
106 Menu menu = createContextMenu(record);
107 list.setContextMenu(menu);
108 menu.showContextMenu();
109
110 event.cancel();
111 }
112 });
77 113
78 ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, 114 ListGridField active = new ListGridField(GRID_FIELD_ACTIVE,
79 MSG.chart_themepanel_header_actions(), 20); 115 MSG.chart_themepanel_header_actions(), 20);
80 active.setType(ListGridFieldType.BOOLEAN); 116 active.setType(ListGridFieldType.BOOLEAN);
81 117
85 121
86 list.setFields(active, name); 122 list.setFields(active, name);
87 } 123 }
88 124
89 125
126 protected Menu createContextMenu(final FacetRecord record) {
127 Menu menu = new Menu();
128
129 MenuItem properties = new MenuItem(MSG.properties());
130 properties.addClickHandler(new ClickHandler() {
131 public void onClick(MenuItemClickEvent evt) {
132 GWT.log("clicked properties");
133 getItemAttributes(record);
134 }
135 });
136 menu.addItem(properties);
137 return menu;
138 }
139
140
90 @Override 141 @Override
91 public void activateTheme(Theme theme, boolean active) { 142 public void activateTheme(Theme theme, boolean active) {
92 theme.setActive(active ? 1 : 0); 143 theme.setActive(active ? 1 : 0);
93 } 144 }
145
146
147 protected void getItemAttributes(FacetRecord record) {
148 Config config = Config.getInstance();
149 String url = config.getServerUrl();
150 String locale = config.getLocale();
151
152 String artifact = record.getTheme().getArtifact();
153
154 itemAttributeService.getCollectionItemAttribute(
155 this.collection,
156 artifact,
157 url,
158 locale,
159 new AsyncCallback<CollectionItemAttribute>() {
160 public void onFailure (Throwable caught) {
161 GWT.log("Could not get Collection item attributes.");
162 }
163 public void onSuccess(CollectionItemAttribute cia) {
164 GWT.log("Successfully loaded collectionitem attributes.");
165 }
166 });
167 }
94 } 168 }
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 169 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org