Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartThemePanel.java @ 523:0785a8ba5e6d
Implemented the first step of a theme control panel for charts.
flys-client/trunk@2002 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 25 May 2011 11:34:34 +0000 |
parents | |
children | ba238f917b94 |
comparison
equal
deleted
inserted
replaced
522:2e02db03e576 | 523:0785a8ba5e6d |
---|---|
1 package de.intevation.flys.client.client.ui.chart; | |
2 | |
3 import java.util.List; | |
4 | |
5 import com.google.gwt.core.client.GWT; | |
6 | |
7 import com.smartgwt.client.types.ListGridFieldType; | |
8 import com.smartgwt.client.widgets.Canvas; | |
9 import com.smartgwt.client.widgets.grid.events.EditCompleteEvent; | |
10 import com.smartgwt.client.widgets.grid.events.EditCompleteHandler; | |
11 import com.smartgwt.client.widgets.grid.ListGrid; | |
12 import com.smartgwt.client.widgets.grid.ListGridField; | |
13 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
14 import com.smartgwt.client.widgets.layout.VLayout; | |
15 | |
16 import de.intevation.flys.client.shared.model.Collection; | |
17 import de.intevation.flys.client.shared.model.Facet; | |
18 import de.intevation.flys.client.shared.model.FacetRecord; | |
19 import de.intevation.flys.client.shared.model.OutputMode; | |
20 | |
21 import de.intevation.flys.client.client.FLYSConstants; | |
22 | |
23 | |
24 /** | |
25 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
26 */ | |
27 public class ChartThemePanel extends Canvas implements EditCompleteHandler { | |
28 | |
29 /** The interface that provides i18n messages. */ | |
30 private FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
31 | |
32 public static final String GRID_FIELD_ACTIVE = "active"; | |
33 public static final String GRID_FIELD_NAME = "name"; | |
34 | |
35 | |
36 protected Collection collection; | |
37 | |
38 protected OutputMode mode; | |
39 | |
40 protected ListGrid list; | |
41 | |
42 | |
43 | |
44 public ChartThemePanel(Collection collection, OutputMode mode) { | |
45 this.collection = collection; | |
46 this.mode = mode; | |
47 this.list = new ListGrid(); | |
48 | |
49 initGrid(); | |
50 initLayout(); | |
51 | |
52 updateGrid(); | |
53 } | |
54 | |
55 | |
56 /** | |
57 * Initializes the layout of this panel. | |
58 */ | |
59 protected void initLayout() { | |
60 setWidth100(); | |
61 setHeight100(); | |
62 | |
63 VLayout layout = new VLayout(); | |
64 layout.setWidth100(); | |
65 layout.setHeight100(); | |
66 | |
67 layout.addMember(list); | |
68 | |
69 addChild(layout); | |
70 } | |
71 | |
72 | |
73 /** | |
74 * Initializes the components (columns) of the theme grid. | |
75 */ | |
76 protected void initGrid() { | |
77 list.setCanEdit(true); | |
78 list.setCanSort(false); | |
79 list.setShowRecordComponents(false); | |
80 list.setShowRecordComponentsByCell(true); | |
81 list.setShowHeader(true); | |
82 list.setShowHeaderContextMenu(false); | |
83 list.setWidth100(); | |
84 list.setHeight100(); | |
85 | |
86 list.addEditCompleteHandler(this); | |
87 | |
88 ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20); | |
89 active.setType(ListGridFieldType.BOOLEAN); | |
90 | |
91 ListGridField name = new ListGridField( | |
92 GRID_FIELD_NAME, MSG.chart_themepanel_header_themes()); | |
93 name.setType(ListGridFieldType.TEXT); | |
94 | |
95 list.setFields(active, name); | |
96 } | |
97 | |
98 | |
99 /** | |
100 * A method that removes all records from theme grid. | |
101 */ | |
102 protected void clearGrid() { | |
103 ListGridRecord[] records = list.getRecords(); | |
104 | |
105 if (records == null || records.length == 0) { | |
106 return; | |
107 } | |
108 | |
109 for (ListGridRecord record: records) { | |
110 list.removeData(record); | |
111 } | |
112 } | |
113 | |
114 | |
115 /** | |
116 * This method is used to clear the current theme grid and add new updated | |
117 * data. | |
118 */ | |
119 protected void updateGrid() { | |
120 clearGrid(); | |
121 | |
122 List<Facet> facets = mode.getFacets(); | |
123 | |
124 for (Facet facet: facets) { | |
125 list.addData(new FacetRecord(facet)); | |
126 } | |
127 } | |
128 | |
129 | |
130 /** | |
131 * This method is called after a cell in the theme grid has been modified. | |
132 * | |
133 * @param event The event that stores information about the modified record. | |
134 */ | |
135 public void onEditComplete(EditCompleteEvent event) { | |
136 GWT.log("Edited record."); | |
137 | |
138 int row = event.getRowNum(); | |
139 FacetRecord rec = (FacetRecord) list.getRecord(row); | |
140 | |
141 // TODO Save modified facets | |
142 } | |
143 } | |
144 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |