|
@@ -1,71 +1,51 @@ |
1 |
1 |
|
package com.temp.client.foundation.widget.table; |
2 |
2 |
|
|
3 |
|
- |
import java.util.ArrayList; |
4 |
|
- |
import java.util.HashMap; |
5 |
|
- |
import java.util.List; |
6 |
|
- |
import java.util.Map; |
7 |
|
- |
import java.util.Set; |
8 |
|
- |
|
9 |
|
- |
import com.google.gwt.cell.client.AbstractCell; |
10 |
|
- |
import com.google.gwt.cell.client.Cell; |
11 |
|
- |
import com.google.gwt.cell.client.Cell.Context; |
12 |
|
- |
import com.google.gwt.cell.client.ValueUpdater; |
13 |
|
- |
import com.google.gwt.core.client.GWT; |
|
3 |
+ |
import com.google.gwt.cell.client.*; |
|
4 |
+ |
import com.google.gwt.cell.client.Cell.*; |
|
5 |
+ |
import com.google.gwt.core.client.*; |
14 |
6 |
|
import com.google.gwt.dom.client.Element; |
15 |
|
- |
import com.google.gwt.dom.client.EventTarget; |
16 |
|
- |
import com.google.gwt.dom.client.NativeEvent; |
17 |
|
- |
import com.google.gwt.dom.client.Node; |
18 |
|
- |
import com.google.gwt.dom.client.NodeList; |
19 |
|
- |
import com.google.gwt.dom.client.Style.Unit; |
20 |
|
- |
import com.google.gwt.safehtml.client.SafeHtmlTemplates; |
21 |
|
- |
import com.google.gwt.safehtml.shared.SafeHtml; |
22 |
|
- |
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
23 |
|
- |
import com.google.gwt.safehtml.shared.SafeHtmlUtils; |
24 |
|
- |
import com.google.gwt.user.cellview.client.CellTable; |
25 |
|
- |
import com.google.gwt.user.cellview.client.Column; |
26 |
|
- |
import com.google.gwt.user.cellview.client.Header; |
27 |
|
- |
import com.google.gwt.user.cellview.client.SafeHtmlHeader; |
28 |
|
- |
import com.google.gwt.user.cellview.client.TextHeader; |
29 |
|
- |
import com.google.gwt.user.client.Event; |
30 |
|
- |
import com.google.gwt.user.client.ui.DockLayoutPanel; |
31 |
|
- |
import com.google.gwt.user.client.ui.LayoutPanel; |
32 |
|
- |
import com.google.gwt.user.client.ui.ProvidesResize; |
33 |
|
- |
import com.google.gwt.user.client.ui.RequiresResize; |
34 |
|
- |
import com.google.gwt.user.client.ui.ScrollPanel; |
35 |
|
- |
import com.google.gwt.view.client.ProvidesKey; |
36 |
|
- |
import com.google.gwt.view.client.SimpleKeyProvider; |
|
7 |
+ |
import com.google.gwt.dom.client.*; |
|
8 |
+ |
import com.google.gwt.dom.client.Style.*; |
|
9 |
+ |
import com.google.gwt.safehtml.client.*; |
|
10 |
+ |
import com.google.gwt.safehtml.shared.*; |
|
11 |
+ |
import com.google.gwt.user.cellview.client.*; |
|
12 |
+ |
import com.google.gwt.user.client.*; |
|
13 |
+ |
import com.google.gwt.user.client.ui.*; |
|
14 |
+ |
import com.google.gwt.view.client.*; |
|
15 |
+ |
|
|
16 |
+ |
import java.util.*; |
37 |
17 |
|
|
38 |
18 |
|
/** |
39 |
19 |
|
* 2011-07-18: this was TOTALLY CRIBBED from the DataTable.java |
40 |
20 |
|
* in the SQSAWSConsoleWebsiteContent package |
41 |
|
- |
* |
|
21 |
+ |
* <p/> |
42 |
22 |
|
* Cribbed javadoc |
43 |
23 |
|
* ===================== |
44 |
24 |
|
* This widget is derived from CellTable, and behaves very similar to it, |
45 |
25 |
|
* except that it adds the following two features. |
46 |
|
- |
* |
|
26 |
+ |
* <p/> |
47 |
27 |
|
* <p><dl> |
48 |
|
- |
* |
|
28 |
+ |
* <p/> |
49 |
29 |
|
* <dt>Interactive Resizable Colums</dt> |
50 |
30 |
|
* <dd> |
51 |
31 |
|
* - Users can drag the right edge of columns to interactively adjust |
52 |
|
- |
* column widths. |
|
32 |
+ |
* column widths. |
53 |
33 |
|
* </dd> |
54 |
|
- |
* |
|
34 |
+ |
* <p/> |
55 |
35 |
|
* <dt>Scollable Table Body</dt> |
56 |
36 |
|
* <dd> |
57 |
37 |
|
* - If the rows in the table body overflow the space available for the table, |
58 |
|
- |
* then a scroll bar will be added to the table body only, so the body rows |
59 |
|
- |
* can be scrolled independent of the table header and footer. |
|
38 |
+ |
* then a scroll bar will be added to the table body only, so the body rows |
|
39 |
+ |
* can be scrolled independent of the table header and footer. |
60 |
40 |
|
* </dd> |
61 |
41 |
|
* a |
62 |
42 |
|
* </dl> |
63 |
|
- |
* |
64 |
|
- |
* <p> |
|
43 |
+ |
* <p/> |
|
44 |
+ |
* <p/> |
65 |
45 |
|
* Although this widget is functionally equivalent to a CellTable, it can't |
66 |
46 |
|
* be used in exactly the same way as a CellTable can be used. The following |
67 |
47 |
|
* additional rules must be followed for this table to work correctly. |
68 |
|
- |
* |
|
48 |
+ |
* <p/> |
69 |
49 |
|
* <p><ol> |
70 |
50 |
|
* <li> |
71 |
51 |
|
* This class adds the {@link RequiresResize} interface, because it needs to adjust |
|
@@ -96,16 +76,15 @@ |
96 |
76 |
|
* this means that you *must* call setFixedColumnWidth or |
97 |
77 |
|
* setRelativeColumnWidth, or a column will not be visible. |
98 |
78 |
|
* </ol> |
99 |
|
- |
* |
100 |
|
- |
* <p> |
|
79 |
+ |
* <p/> |
|
80 |
+ |
* <p/> |
101 |
81 |
|
* In addition to the features mentioned above, this table also overrides the |
102 |
82 |
|
* CellTable styles to look more like a standard Amazon DataTable widget. |
103 |
83 |
|
* |
104 |
|
- |
* @author Stephen Saville (saville@amazon.com) |
|
84 |
+ |
* @param <T> Type of data object stored in the table. |
|
85 |
+ |
* ===================== |
105 |
86 |
|
* |
106 |
|
- |
* @param <T> |
107 |
|
- |
* Type of data object stored in the table. |
108 |
|
- |
* ===================== |
|
87 |
+ |
* @author Stephen Saville (saville@amazon.com) |
109 |
88 |
|
*/ |
110 |
89 |
|
public class ResizableCellTable<T> extends CellTable<T> implements RequiresResize { |
111 |
90 |
|
public static final int DEFAULT_PAGE_SIZE = 15; |
|
@@ -134,18 +113,18 @@ |
134 |
113 |
|
|
135 |
114 |
|
interface Templates extends SafeHtmlTemplates { |
136 |
115 |
|
@Template("<div class=\"{0}\">") |
137 |
|
- |
SafeHtml resizableHeaderCellPrefix(String headerClassName); |
|
116 |
+ |
SafeHtml resizableHeaderCellPrefix( String headerClassName ); |
138 |
117 |
|
|
139 |
118 |
|
@Template("<div " + RESIZE_HANDLE_ATTRIBUTE + "=\"{0}\" class=\"{1}\"> </div></div>") |
140 |
|
- |
SafeHtml resizableHeaderCellSuffix(int col, String resizeHandleClassName); |
|
119 |
+ |
SafeHtml resizableHeaderCellSuffix( int col, String resizeHandleClassName ); |
141 |
120 |
|
} |
142 |
121 |
|
|
143 |
|
- |
private static final Templates TEMPLATES = GWT.create(Templates.class); |
|
122 |
+ |
private static final Templates TEMPLATES = GWT.create( Templates.class ); |
144 |
123 |
|
|
145 |
124 |
|
public class ResizableCellTableOverlayHeaderCell<V> implements Cell<V> { |
146 |
125 |
|
private final Cell<V> delegate; |
147 |
126 |
|
|
148 |
|
- |
public ResizableCellTableOverlayHeaderCell(Cell<V> delegate) { |
|
127 |
+ |
public ResizableCellTableOverlayHeaderCell( Cell<V> delegate ) { |
149 |
128 |
|
this.delegate = delegate; |
150 |
129 |
|
} |
151 |
130 |
|
|
|
@@ -163,43 +142,43 @@ |
163 |
142 |
|
|
164 |
143 |
|
public boolean isEditing( |
165 |
144 |
|
com.google.gwt.cell.client.Cell.Context context, |
166 |
|
- |
Element parent, V value) { |
167 |
|
- |
return delegate.isEditing(context, parent, value); |
|
145 |
+ |
Element parent, V value ) { |
|
146 |
+ |
return delegate.isEditing( context, parent, value ); |
168 |
147 |
|
} |
169 |
148 |
|
|
170 |
149 |
|
public void onBrowserEvent( |
171 |
150 |
|
com.google.gwt.cell.client.Cell.Context context, |
172 |
151 |
|
Element parent, V value, NativeEvent event, |
173 |
|
- |
ValueUpdater<V> valueUpdater) { |
174 |
|
- |
delegate.onBrowserEvent(context, parent, value, event, valueUpdater); |
|
152 |
+ |
ValueUpdater<V> valueUpdater ) { |
|
153 |
+ |
delegate.onBrowserEvent( context, parent, value, event, valueUpdater ); |
175 |
154 |
|
} |
176 |
155 |
|
|
177 |
|
- |
public void render(com.google.gwt.cell.client.Cell.Context context, |
178 |
|
- |
V value, SafeHtmlBuilder sb) { |
179 |
|
- |
sb.append(TEMPLATES.resizableHeaderCellPrefix( |
180 |
|
- |
styles.resizableCellTableHeader())); |
181 |
|
- |
delegate.render(context, value, sb); |
182 |
|
- |
sb.append(TEMPLATES.resizableHeaderCellSuffix( |
183 |
|
- |
context.getColumn(), styles.resizableCellTableResizeHandle())); |
|
156 |
+ |
public void render( com.google.gwt.cell.client.Cell.Context context, |
|
157 |
+ |
V value, SafeHtmlBuilder sb ) { |
|
158 |
+ |
sb.append( TEMPLATES.resizableHeaderCellPrefix( |
|
159 |
+ |
styles.resizableCellTableHeader() ) ); |
|
160 |
+ |
delegate.render( context, value, sb ); |
|
161 |
+ |
sb.append( TEMPLATES.resizableHeaderCellSuffix( |
|
162 |
+ |
context.getColumn(), styles.resizableCellTableResizeHandle() ) ); |
184 |
163 |
|
} |
185 |
164 |
|
|
186 |
165 |
|
public boolean resetFocus( |
187 |
166 |
|
com.google.gwt.cell.client.Cell.Context context, |
188 |
|
- |
Element parent, V value) { |
189 |
|
- |
return delegate.resetFocus(context, parent, value); |
|
167 |
+ |
Element parent, V value ) { |
|
168 |
+ |
return delegate.resetFocus( context, parent, value ); |
190 |
169 |
|
} |
191 |
170 |
|
|
192 |
|
- |
public void setValue(com.google.gwt.cell.client.Cell.Context context, |
193 |
|
- |
Element parent, V value) { |
194 |
|
- |
delegate.setValue(context, parent, value); |
|
171 |
+ |
public void setValue( com.google.gwt.cell.client.Cell.Context context, |
|
172 |
+ |
Element parent, V value ) { |
|
173 |
+ |
delegate.setValue( context, parent, value ); |
195 |
174 |
|
} |
196 |
175 |
|
} |
197 |
176 |
|
|
198 |
177 |
|
public class ResizableCellTableOverlayHeader<V> extends Header<V> { |
199 |
178 |
|
private final Header<V> delegate; |
200 |
179 |
|
|
201 |
|
- |
public ResizableCellTableOverlayHeader(Header<V> delegate) { |
202 |
|
- |
super(new ResizableCellTableOverlayHeaderCell<V>(delegate.getCell())); |
|
180 |
+ |
public ResizableCellTableOverlayHeader( Header<V> delegate ) { |
|
181 |
+ |
super( new ResizableCellTableOverlayHeaderCell<V>( delegate.getCell() ) ); |
203 |
182 |
|
this.delegate = delegate; |
204 |
183 |
|
} |
205 |
184 |
|
|
|
@@ -211,42 +190,42 @@ |
211 |
190 |
|
return delegate.getValue(); |
212 |
191 |
|
} |
213 |
192 |
|
|
214 |
|
- |
public void onBrowserEvent(Context context, Element elem, |
215 |
|
- |
NativeEvent event) { |
216 |
|
- |
delegate.onBrowserEvent(context, elem, event); |
|
193 |
+ |
public void onBrowserEvent( Context context, Element elem, |
|
194 |
+ |
NativeEvent event ) { |
|
195 |
+ |
delegate.onBrowserEvent( context, elem, event ); |
217 |
196 |
|
} |
218 |
197 |
|
|
219 |
|
- |
public void setUpdater(ValueUpdater<V> updater) { |
220 |
|
- |
delegate.setUpdater(updater); |
|
198 |
+ |
public void setUpdater( ValueUpdater<V> updater ) { |
|
199 |
+ |
delegate.setUpdater( updater ); |
221 |
200 |
|
} |
222 |
201 |
|
} |
223 |
202 |
|
|
224 |
|
- |
public <V> ResizableCellTableOverlayHeader<V> overlayHeader(Header<V> header) { |
225 |
|
- |
return new ResizableCellTableOverlayHeader<V>(header); |
|
203 |
+ |
public <V> ResizableCellTableOverlayHeader<V> overlayHeader( Header<V> header ) { |
|
204 |
+ |
return new ResizableCellTableOverlayHeader<V>( header ); |
226 |
205 |
|
} |
227 |
206 |
|
|
228 |
207 |
|
public class ResizableCellTableSafeHtmlHeaderCell extends AbstractCell<SafeHtml> { |
229 |
208 |
|
@Override |
230 |
|
- |
public void render(com.google.gwt.cell.client.Cell.Context context, |
231 |
|
- |
SafeHtml value, SafeHtmlBuilder sb) { |
232 |
|
- |
sb.append(TEMPLATES.resizableHeaderCellPrefix( |
233 |
|
- |
styles.resizableCellTableHeader())); |
234 |
|
- |
sb.append(value); |
235 |
|
- |
sb.append(TEMPLATES.resizableHeaderCellSuffix( |
236 |
|
- |
context.getColumn(), styles.resizableCellTableResizeHandle())); |
|
209 |
+ |
public void render( com.google.gwt.cell.client.Cell.Context context, |
|
210 |
+ |
SafeHtml value, SafeHtmlBuilder sb ) { |
|
211 |
+ |
sb.append( TEMPLATES.resizableHeaderCellPrefix( |
|
212 |
+ |
styles.resizableCellTableHeader() ) ); |
|
213 |
+ |
sb.append( value ); |
|
214 |
+ |
sb.append( TEMPLATES.resizableHeaderCellSuffix( |
|
215 |
+ |
context.getColumn(), styles.resizableCellTableResizeHandle() ) ); |
237 |
216 |
|
} |
238 |
217 |
|
} |
239 |
218 |
|
|
240 |
219 |
|
public class ResizableCellTableSafeHtmlHeader extends Header<SafeHtml> { |
241 |
220 |
|
private SafeHtml value; |
242 |
221 |
|
|
243 |
|
- |
public ResizableCellTableSafeHtmlHeader(SafeHtml html) { |
244 |
|
- |
super(new ResizableCellTableSafeHtmlHeaderCell()); |
|
222 |
+ |
public ResizableCellTableSafeHtmlHeader( SafeHtml html ) { |
|
223 |
+ |
super( new ResizableCellTableSafeHtmlHeaderCell() ); |
245 |
224 |
|
this.value = html; |
246 |
225 |
|
} |
247 |
226 |
|
|
248 |
|
- |
public ResizableCellTableSafeHtmlHeader(String text) { |
249 |
|
- |
this(SafeHtmlUtils.fromString(text)); |
|
227 |
+ |
public ResizableCellTableSafeHtmlHeader( String text ) { |
|
228 |
+ |
this( SafeHtmlUtils.fromString( text ) ); |
250 |
229 |
|
} |
251 |
230 |
|
|
252 |
231 |
|
@Override |
|
@@ -255,94 +234,94 @@ |
255 |
234 |
|
} |
256 |
235 |
|
} |
257 |
236 |
|
|
258 |
|
- |
private final Map<Column<T,?>, Double> relativeWidthColumns = |
259 |
|
- |
new HashMap<Column<T,?>, Double>(); |
|
237 |
+ |
private final Map<Column<T, ?>, Double> relativeWidthColumns = |
|
238 |
+ |
new HashMap<Column<T, ?>, Double>(); |
260 |
239 |
|
|
261 |
240 |
|
private final ResizableCellTableResources resources; |
262 |
241 |
|
private final ResizableCellTableStyle styles; |
263 |
242 |
|
|
264 |
243 |
|
public ResizableCellTable() { |
265 |
|
- |
this(DEFAULT_PAGE_SIZE); |
|
244 |
+ |
this( DEFAULT_PAGE_SIZE ); |
266 |
245 |
|
} |
267 |
246 |
|
|
268 |
|
- |
public ResizableCellTable(int pageSize, ResizableCellTableResources resources, ProvidesKey<T> keyProvider) { |
269 |
|
- |
super(pageSize, resources, keyProvider); |
|
247 |
+ |
public ResizableCellTable( int pageSize, ResizableCellTableResources resources, ProvidesKey<T> keyProvider ) { |
|
248 |
+ |
super( pageSize, resources, keyProvider ); |
270 |
249 |
|
this.resources = resources; |
271 |
250 |
|
this.styles = resources.cellTableStyle(); |
272 |
|
- |
sinkEvents(Event.ONMOUSEUP); |
273 |
|
- |
setTableLayoutFixed(true); |
|
251 |
+ |
sinkEvents( Event.ONMOUSEUP ); |
|
252 |
+ |
setTableLayoutFixed( true ); |
274 |
253 |
|
} |
275 |
254 |
|
|
276 |
|
- |
public ResizableCellTable(int pageSize, ProvidesKey<T> keyProvider) { |
277 |
|
- |
this(pageSize, GWT.<ResizableCellTableResources>create(ResizableCellTableResources.class), keyProvider); |
|
255 |
+ |
public ResizableCellTable( int pageSize, ProvidesKey<T> keyProvider ) { |
|
256 |
+ |
this( pageSize, GWT.<ResizableCellTableResources>create( ResizableCellTableResources.class ), keyProvider ); |
278 |
257 |
|
} |
279 |
258 |
|
|
280 |
|
- |
public ResizableCellTable(int pageSize) { |
281 |
|
- |
this(pageSize, new SimpleKeyProvider<T>()); |
|
259 |
+ |
public ResizableCellTable( int pageSize ) { |
|
260 |
+ |
this( pageSize, new SimpleKeyProvider<T>() ); |
282 |
261 |
|
} |
283 |
262 |
|
|
284 |
|
- |
public ResizableCellTable(ProvidesKey<T> keyProvider) { |
285 |
|
- |
this(DEFAULT_PAGE_SIZE, keyProvider); |
|
263 |
+ |
public ResizableCellTable( ProvidesKey<T> keyProvider ) { |
|
264 |
+ |
this( DEFAULT_PAGE_SIZE, keyProvider ); |
286 |
265 |
|
} |
287 |
266 |
|
|
288 |
267 |
|
@Override |
289 |
|
- |
public void addColumn(Column<T, ?> col) { |
290 |
|
- |
super.addColumn(col, new ResizableCellTableSafeHtmlHeader(SafeHtmlUtils.EMPTY_SAFE_HTML)); |
|
268 |
+ |
public void addColumn( Column<T, ?> col ) { |
|
269 |
+ |
super.addColumn( col, new ResizableCellTableSafeHtmlHeader( SafeHtmlUtils.EMPTY_SAFE_HTML ) ); |
291 |
270 |
|
} |
292 |
271 |
|
|
293 |
272 |
|
@Override |
294 |
|
- |
public void addColumn(Column<T, ?> col, SafeHtml headerHtml) { |
295 |
|
- |
super.addColumn(col, new ResizableCellTableSafeHtmlHeader(headerHtml)); |
|
273 |
+ |
public void addColumn( Column<T, ?> col, SafeHtml headerHtml ) { |
|
274 |
+ |
super.addColumn( col, new ResizableCellTableSafeHtmlHeader( headerHtml ) ); |
296 |
275 |
|
} |
297 |
276 |
|
|
298 |
277 |
|
@Override |
299 |
|
- |
public void addColumn(Column<T, ?> col, String headerString) { |
300 |
|
- |
super.addColumn(col, new ResizableCellTableSafeHtmlHeader(headerString)); |
|
278 |
+ |
public void addColumn( Column<T, ?> col, String headerString ) { |
|
279 |
+ |
super.addColumn( col, new ResizableCellTableSafeHtmlHeader( headerString ) ); |
301 |
280 |
|
} |
302 |
281 |
|
|
303 |
282 |
|
@Override |
304 |
|
- |
public void addColumn(Column<T, ?> col, Header<?> header) { |
305 |
|
- |
super.addColumn(col, overlayHeader(header)); |
|
283 |
+ |
public void addColumn( Column<T, ?> col, Header<?> header ) { |
|
284 |
+ |
super.addColumn( col, overlayHeader( header ) ); |
306 |
285 |
|
} |
307 |
286 |
|
|
308 |
287 |
|
@Override |
309 |
|
- |
public void addColumn(Column<T, ?> col, Header<?> header, Header<?> footer) { |
310 |
|
- |
super.addColumn(col, overlayHeader(header), footer); |
|
288 |
+ |
public void addColumn( Column<T, ?> col, Header<?> header, Header<?> footer ) { |
|
289 |
+ |
super.addColumn( col, overlayHeader( header ), footer ); |
311 |
290 |
|
} |
312 |
291 |
|
|
313 |
292 |
|
@Override |
314 |
|
- |
public void addColumn(Column<T, ?> col, String headerString, String footerString) { |
315 |
|
- |
super.addColumn(col, new ResizableCellTableSafeHtmlHeader(headerString), new TextHeader(footerString)); |
|
293 |
+ |
public void addColumn( Column<T, ?> col, String headerString, String footerString ) { |
|
294 |
+ |
super.addColumn( col, new ResizableCellTableSafeHtmlHeader( headerString ), new TextHeader( footerString ) ); |
316 |
295 |
|
} |
317 |
296 |
|
|
318 |
297 |
|
@Override |
319 |
|
- |
public void addColumn(Column<T, ?> col, SafeHtml headerHtml, SafeHtml footerHtml) { |
320 |
|
- |
super.addColumn(col, new ResizableCellTableSafeHtmlHeader(headerHtml), new SafeHtmlHeader(footerHtml)); |
|
298 |
+ |
public void addColumn( Column<T, ?> col, SafeHtml headerHtml, SafeHtml footerHtml ) { |
|
299 |
+ |
super.addColumn( col, new ResizableCellTableSafeHtmlHeader( headerHtml ), new SafeHtmlHeader( footerHtml ) ); |
321 |
300 |
|
} |
322 |
301 |
|
|
323 |
302 |
|
@Override |
324 |
|
- |
public void removeColumn(Column<T, ?> col) { |
325 |
|
- |
super.removeColumn(col); |
326 |
|
- |
clearRelativeColumnWidth(col); |
|
303 |
+ |
public void removeColumn( Column<T, ?> col ) { |
|
304 |
+ |
super.removeColumn( col ); |
|
305 |
+ |
clearRelativeColumnWidth( col ); |
327 |
306 |
|
} |
328 |
307 |
|
|
329 |
308 |
|
@Override |
330 |
|
- |
public void removeColumn(int index) { |
331 |
|
- |
Column<T,?> col = getColumn(index); |
332 |
|
- |
super.removeColumn(index); |
333 |
|
- |
clearRelativeColumnWidth(col); |
|
309 |
+ |
public void removeColumn( int index ) { |
|
310 |
+ |
Column<T, ?> col = getColumn( index ); |
|
311 |
+ |
super.removeColumn( index ); |
|
312 |
+ |
clearRelativeColumnWidth( col ); |
334 |
313 |
|
} |
335 |
314 |
|
|
336 |
|
- |
private double adjustRelativeColumnWidths(double totalWidthAdjustment) { |
|
315 |
+ |
private double adjustRelativeColumnWidths( double totalWidthAdjustment ) { |
337 |
316 |
|
// add up relative column widths for normalization |
338 |
317 |
|
double total = totalWidthAdjustment; |
339 |
|
- |
for (Double value: relativeWidthColumns.values()) { |
|
318 |
+ |
for ( Double value : relativeWidthColumns.values() ) { |
340 |
319 |
|
total += value; |
341 |
320 |
|
} |
342 |
321 |
|
|
343 |
322 |
|
// update the widths of existing relative width columns |
344 |
|
- |
for (Map.Entry<Column<T,?>, Double> entry : relativeWidthColumns.entrySet()) { |
345 |
|
- |
setColumnWidth(entry.getKey(), entry.getValue() * 100.0 / total, Unit.PCT); |
|
323 |
+ |
for ( Map.Entry<Column<T, ?>, Double> entry : relativeWidthColumns.entrySet() ) { |
|
324 |
+ |
setColumnWidth( entry.getKey(), entry.getValue() * 100.0 / total, Unit.PCT ); |
346 |
325 |
|
} |
347 |
326 |
|
|
348 |
327 |
|
return total; |
|
@@ -358,80 +337,74 @@ |
358 |
337 |
|
* width of 1, then the columns would take up 25%, 50% and 25% of the |
359 |
338 |
|
* available space, respectively. |
360 |
339 |
|
* |
361 |
|
- |
* @param column |
362 |
|
- |
* Column to set the relative width of. |
363 |
|
- |
* @param relativeWidth |
364 |
|
- |
* Relative column width. |
|
340 |
+ |
* @param column Column to set the relative width of. |
|
341 |
+ |
* @param relativeWidth Relative column width. |
365 |
342 |
|
*/ |
366 |
|
- |
public void setRelativeColumnWidth(Column<T,?> column, double relativeWidth) { |
|
343 |
+ |
public void setRelativeColumnWidth( Column<T, ?> column, double relativeWidth ) { |
367 |
344 |
|
// check if column already had a relative width |
368 |
|
- |
Double existingRelativeWidth = relativeWidthColumns.get(column); |
369 |
|
- |
if (existingRelativeWidth != null) { |
370 |
|
- |
if (existingRelativeWidth == relativeWidth) { |
|
345 |
+ |
Double existingRelativeWidth = relativeWidthColumns.get( column ); |
|
346 |
+ |
if ( existingRelativeWidth != null ) { |
|
347 |
+ |
if ( existingRelativeWidth == relativeWidth ) { |
371 |
348 |
|
// existing is same as new relative width |
372 |
349 |
|
// no change is required |
373 |
350 |
|
return; |
374 |
351 |
|
} else { |
375 |
352 |
|
// existing width is different |
376 |
353 |
|
// start by removing the existing width |
377 |
|
- |
relativeWidthColumns.remove(column); |
|
354 |
+ |
relativeWidthColumns.remove( column ); |
378 |
355 |
|
} |
379 |
356 |
|
} |
380 |
357 |
|
|
381 |
358 |
|
// reduce the widths of existing columns |
382 |
|
- |
double totalWidth = adjustRelativeColumnWidths(relativeWidth); |
|
359 |
+ |
double totalWidth = adjustRelativeColumnWidths( relativeWidth ); |
383 |
360 |
|
|
384 |
361 |
|
// add new column and set its width |
385 |
|
- |
relativeWidthColumns.put(column, relativeWidth); |
386 |
|
- |
setColumnWidth(column, relativeWidth * 100.0 / totalWidth, Unit.PCT); |
|
362 |
+ |
relativeWidthColumns.put( column, relativeWidth ); |
|
363 |
+ |
setColumnWidth( column, relativeWidth * 100.0 / totalWidth, Unit.PCT ); |
387 |
364 |
|
} |
388 |
365 |
|
|
389 |
|
- |
private void clearRelativeColumnWidth(Column<T,?> column) { |
390 |
|
- |
Double relativeWidth = relativeWidthColumns.remove(column); |
391 |
|
- |
if (relativeWidth != null) { |
392 |
|
- |
adjustRelativeColumnWidths(0); |
|
366 |
+ |
private void clearRelativeColumnWidth( Column<T, ?> column ) { |
|
367 |
+ |
Double relativeWidth = relativeWidthColumns.remove( column ); |
|
368 |
+ |
if ( relativeWidth != null ) { |
|
369 |
+ |
adjustRelativeColumnWidths( 0 ); |
393 |
370 |
|
} |
394 |
371 |
|
} |
395 |
372 |
|
|
396 |
373 |
|
/** |
397 |
374 |
|
* Set the width of a fixed-width column. |
398 |
375 |
|
* |
399 |
|
- |
* @param column |
400 |
|
- |
* Column to set the width of. |
401 |
|
- |
* @param fixedWidth |
402 |
|
- |
* Fixed width in the given units. |
403 |
|
- |
* @param unit |
404 |
|
- |
* Fixed width unit, such as {@link Unit#PX}. Must <it>not</it> be {@link Unit#PCT}. |
|
376 |
+ |
* @param column Column to set the width of. |
|
377 |
+ |
* @param fixedWidth Fixed width in the given units. |
|
378 |
+ |
* @param unit Fixed width unit, such as {@link Unit#PX}. Must <it>not</it> be {@link Unit#PCT}. |
405 |
379 |
|
*/ |
406 |
|
- |
public void setFixedColumnWidth(Column<T,?> column, double fixedWidth, Unit unit) { |
407 |
|
- |
assert(unit != Unit.PCT); |
|
380 |
+ |
public void setFixedColumnWidth( Column<T, ?> column, double fixedWidth, Unit unit ) { |
|
381 |
+ |
assert (unit != Unit.PCT); |
408 |
382 |
|
|
409 |
383 |
|
// set new fixed column width |
410 |
|
- |
setColumnWidth(column, fixedWidth, unit); |
|
384 |
+ |
setColumnWidth( column, fixedWidth, unit ); |
411 |
385 |
|
|
412 |
386 |
|
// update relative width columnds if this column used to have a relative width |
413 |
|
- |
clearRelativeColumnWidth(column); |
|
387 |
+ |
clearRelativeColumnWidth( column ); |
414 |
388 |
|
} |
415 |
389 |
|
|
416 |
390 |
|
/** |
417 |
391 |
|
* Clear the width of a column. This will make the column disappear. |
418 |
392 |
|
* |
419 |
|
- |
* @param column |
420 |
|
- |
* Column to clear the width of. |
|
393 |
+ |
* @param column Column to clear the width of. |
421 |
394 |
|
*/ |
422 |
395 |
|
@Override |
423 |
|
- |
public void clearColumnWidth(Column<T, ?> column) { |
|
396 |
+ |
public void clearColumnWidth( Column<T, ?> column ) { |
424 |
397 |
|
// clear the width of this column |
425 |
|
- |
super.clearColumnWidth(column); |
|
398 |
+ |
super.clearColumnWidth( column ); |
426 |
399 |
|
|
427 |
400 |
|
// update relative width columns if this column used to have a relative width |
428 |
|
- |
clearRelativeColumnWidth(column); |
|
401 |
+ |
clearRelativeColumnWidth( column ); |
429 |
402 |
|
} |
430 |
403 |
|
|
431 |
404 |
|
private static final int MIN_RESIZED_WIDTH = 10; |
432 |
405 |
|
|
433 |
406 |
|
private boolean resizingColumns = false; |
434 |
|
- |
private Column<T,?> resizeLeftColumn, resizeRightColumn; |
|
407 |
+ |
private Column<T, ?> resizeLeftColumn, resizeRightColumn; |
435 |
408 |
|
private int resizeLeftX, resizeRightX; |
436 |
409 |
|
|
437 |
410 |
|
private static class TableElements { |
|
@@ -442,39 +415,41 @@ |
442 |
415 |
|
private List<Element> tBodies; |
443 |
416 |
|
private Element tableContainer; |
444 |
417 |
|
|
445 |
|
- |
public TableElements(Element table) { |
|
418 |
+ |
public TableElements( Element table ) { |
446 |
419 |
|
this.table = table; |
447 |
420 |
|
this.tBodies = new ArrayList<Element>(); |
448 |
421 |
|
|
449 |
422 |
|
NodeList<Node> tableChildren = table.getChildNodes(); |
450 |
423 |
|
int childCount = tableChildren.getLength(); |
451 |
|
- |
for (int i = 0; i < childCount; i++) { |
452 |
|
- |
Node child = tableChildren.getItem(i); |
453 |
|
- |
if (child == null) |
|
424 |
+ |
for ( int i = 0; i < childCount; i++ ) { |
|
425 |
+ |
Node child = tableChildren.getItem( i ); |
|
426 |
+ |
if ( child == null ) { |
454 |
427 |
|
break; |
455 |
|
- |
if (Element.is(child)) { |
456 |
|
- |
Element childElement = Element.as(child); |
|
428 |
+ |
} |
|
429 |
+ |
if ( Element.is( child ) ) { |
|
430 |
+ |
Element childElement = Element.as( child ); |
457 |
431 |
|
String childTag = childElement.getTagName(); |
458 |
|
- |
if ("thead".equalsIgnoreCase(childTag)) { |
|
432 |
+ |
if ( "thead".equalsIgnoreCase( childTag ) ) { |
459 |
433 |
|
tHead = childElement; |
460 |
|
- |
} else if ("tfoot".equalsIgnoreCase(childTag)) { |
|
434 |
+ |
} else if ( "tfoot".equalsIgnoreCase( childTag ) ) { |
461 |
435 |
|
tFoot = childElement; |
462 |
|
- |
} else if ("colgroup".equalsIgnoreCase(childTag)) { |
|
436 |
+ |
} else if ( "colgroup".equalsIgnoreCase( childTag ) ) { |
463 |
437 |
|
colGroup = childElement; |
464 |
|
- |
} else if ("tbody".equalsIgnoreCase(childTag)) { |
465 |
|
- |
tBodies.add(childElement); |
|
438 |
+ |
} else if ( "tbody".equalsIgnoreCase( childTag ) ) { |
|
439 |
+ |
tBodies.add( childElement ); |
466 |
440 |
|
} |
467 |
441 |
|
} |
468 |
442 |
|
} |
469 |
443 |
|
|
470 |
444 |
|
tableContainer = table.getParentElement(); |
471 |
|
- |
while (tableContainer != null) { |
472 |
|
- |
if ("absolute".equals(tableContainer.getStyle().getPosition())) { |
|
445 |
+ |
while ( tableContainer != null ) { |
|
446 |
+ |
if ( "absolute".equals( tableContainer.getStyle().getPosition() ) ) { |
473 |
447 |
|
break; |
474 |
448 |
|
} else { |
475 |
449 |
|
Element parent = tableContainer.getParentElement(); |
476 |
|
- |
if (parent == null) |
|
450 |
+ |
if ( parent == null ) { |
477 |
451 |
|
break; |
|
452 |
+ |
} |
478 |
453 |
|
tableContainer = parent; |
479 |
454 |
|
} |
480 |
455 |
|
} |
|
@@ -510,10 +485,10 @@ |
510 |
485 |
|
} |
511 |
486 |
|
|
512 |
487 |
|
private void adjustBodyColumnWidths() { |
513 |
|
- |
adjustBodyColumnWidths(new TableElements(getElement())); |
|
488 |
+ |
adjustBodyColumnWidths( new TableElements( getElement() ) ); |
514 |
489 |
|
} |
515 |
490 |
|
|
516 |
|
- |
private void adjustBodyColumnWidths(TableElements tableElements) { |
|
491 |
+ |
private void adjustBodyColumnWidths( TableElements tableElements ) { |
517 |
492 |
|
/*Element table = tableElements.getTable(); |
518 |
493 |
|
Element thead = tableElements.getTHead(); |
519 |
494 |
|
Element tfoot = tableElements.getTFoot(); |
|
@@ -578,36 +553,36 @@ |
578 |
553 |
|
} |
579 |
554 |
|
|
580 |
555 |
|
@Override |
581 |
|
- |
protected void replaceAllChildren(List<T> values, SafeHtml html) { |
582 |
|
- |
super.replaceAllChildren(values, html); |
|
556 |
+ |
protected void replaceAllChildren( List<T> values, SafeHtml html ) { |
|
557 |
+ |
super.replaceAllChildren( values, html ); |
583 |
558 |
|
adjustBodyColumnWidths(); |
584 |
559 |
|
} |
585 |
560 |
|
|
586 |
561 |
|
@Override |
587 |
|
- |
protected void replaceChildren(List<T> values, int start, SafeHtml html) { |
588 |
|
- |
super.replaceChildren(values, start, html); |
|
562 |
+ |
protected void replaceChildren( List<T> values, int start, SafeHtml html ) { |
|
563 |
+ |
super.replaceChildren( values, start, html ); |
589 |
564 |
|
adjustBodyColumnWidths(); |
590 |
565 |
|
} |
591 |
566 |
|
|
592 |
567 |
|
@Override |
593 |
568 |
|
public void onResize() { |
594 |
569 |
|
// find the width of all fixed-width columns, in pixels |
595 |
|
- |
TableElements tableElements = new TableElements(getElement()); |
596 |
|
- |
Map<Column<T,?>, Integer> fixedColumnWidths = new HashMap<Column<T,?>, Integer>(); |
597 |
|
- |
Column<T,?> lastFixedWidthColumn = null; |
|
570 |
+ |
TableElements tableElements = new TableElements( getElement() ); |
|
571 |
+ |
Map<Column<T, ?>, Integer> fixedColumnWidths = new HashMap<Column<T, ?>, Integer>(); |
|
572 |
+ |
Column<T, ?> lastFixedWidthColumn = null; |
598 |
573 |
|
Element lastFixedWidthColumnElement = null; |
599 |
574 |
|
int totalWidthOfFixedColumns = 0; |
600 |
575 |
|
int relativeWidthColumnCount = 0; |
601 |
576 |
|
NodeList<Node> colGroupChildren = tableElements.getColGroup().getChildNodes(); |
602 |
577 |
|
int colGroupChildCount = colGroupChildren.getLength(); |
603 |
|
- |
for (int i = 0, col = 0; i < colGroupChildCount; i++) { |
604 |
|
- |
Node child = colGroupChildren.getItem(i); |
605 |
|
- |
if (Element.is(child)) { |
606 |
|
- |
Element childElement = Element.as(child); |
607 |
|
- |
Column<T,?> column = getColumn(col++); |
608 |
|
- |
if (!relativeWidthColumns.containsKey(column)) { |
|
578 |
+ |
for ( int i = 0, col = 0; i < colGroupChildCount; i++ ) { |
|
579 |
+ |
Node child = colGroupChildren.getItem( i ); |
|
580 |
+ |
if ( Element.is( child ) ) { |
|
581 |
+ |
Element childElement = Element.as( child ); |
|
582 |
+ |
Column<T, ?> column = getColumn( col++ ); |
|
583 |
+ |
if ( !relativeWidthColumns.containsKey( column ) ) { |
609 |
584 |
|
int columnWidth = childElement.getClientWidth(); |
610 |
|
- |
fixedColumnWidths.put(column, columnWidth); |
|
585 |
+ |
fixedColumnWidths.put( column, columnWidth ); |
611 |
586 |
|
totalWidthOfFixedColumns += columnWidth; |
612 |
587 |
|
lastFixedWidthColumn = column; |
613 |
588 |
|
lastFixedWidthColumnElement = childElement; |
|
@@ -620,21 +595,21 @@ |
620 |
595 |
|
// adjust fixed-width columns if they don't fit after a resize, or if |
621 |
596 |
|
// all columns are fixed width, so they all resize proportionally. |
622 |
597 |
|
int availableWidth = tableElements.getTableContainerWidth(); |
623 |
|
- |
if ( totalWidthOfFixedColumns + MIN_RESIZED_WIDTH*relativeWidthColumnCount > availableWidth || |
624 |
|
- |
0 == relativeWidthColumnCount && totalWidthOfFixedColumns != availableWidth) { |
625 |
|
- |
float adjustmentRatio = (float)availableWidth / totalWidthOfFixedColumns; |
626 |
|
- |
for (Map.Entry<Column<T,?>, Integer> entry : fixedColumnWidths.entrySet()) { |
627 |
|
- |
int newColumnWidth = Math.round(entry.getValue() * adjustmentRatio); |
628 |
|
- |
setColumnWidth(entry.getKey(), newColumnWidth, Unit.PX); |
|
598 |
+ |
if ( totalWidthOfFixedColumns + MIN_RESIZED_WIDTH * relativeWidthColumnCount > availableWidth || |
|
599 |
+ |
0 == relativeWidthColumnCount && totalWidthOfFixedColumns != availableWidth ) { |
|
600 |
+ |
float adjustmentRatio = (float) availableWidth / totalWidthOfFixedColumns; |
|
601 |
+ |
for ( Map.Entry<Column<T, ?>, Integer> entry : fixedColumnWidths.entrySet() ) { |
|
602 |
+ |
int newColumnWidth = Math.round( entry.getValue() * adjustmentRatio ); |
|
603 |
+ |
setColumnWidth( entry.getKey(), newColumnWidth, Unit.PX ); |
629 |
604 |
|
availableWidth -= newColumnWidth; |
630 |
605 |
|
} |
631 |
|
- |
if (availableWidth != 0 && lastFixedWidthColumn != null) { |
|
606 |
+ |
if ( availableWidth != 0 && lastFixedWidthColumn != null ) { |
632 |
607 |
|
// adjust the last fixed width column so that all columns fit |
633 |
608 |
|
// perfectly into the available space, which prevents columns |
634 |
609 |
|
// from jumping around when you resize them later. |
635 |
|
- |
setColumnWidth(lastFixedWidthColumn, |
636 |
|
- |
lastFixedWidthColumnElement.getClientWidth() + availableWidth, |
637 |
|
- |
Unit.PX); |
|
610 |
+ |
setColumnWidth( lastFixedWidthColumn, |
|
611 |
+ |
lastFixedWidthColumnElement.getClientWidth() + availableWidth, |
|
612 |
+ |
Unit.PX ); |
638 |
613 |
|
} |
639 |
614 |
|
} |
640 |
615 |
|
|
|
@@ -643,44 +618,44 @@ |
643 |
618 |
|
adjustBodyColumnWidths(); |
644 |
619 |
|
} |
645 |
620 |
|
|
646 |
|
- |
private void applyColumnResize(int clientX) { |
647 |
|
- |
if (clientX > resizeLeftX + MIN_RESIZED_WIDTH && clientX < resizeRightX - MIN_RESIZED_WIDTH) { |
648 |
|
- |
int leftWidth = clientX - resizeLeftX; |
649 |
|
- |
setFixedColumnWidth(resizeLeftColumn, leftWidth, Unit.PX); |
|
621 |
+ |
private void applyColumnResize( int clientX ) { |
|
622 |
+ |
if ( clientX > resizeLeftX + MIN_RESIZED_WIDTH && clientX < resizeRightX - MIN_RESIZED_WIDTH ) { |
|
623 |
+ |
int leftWidth = clientX - resizeLeftX; |
|
624 |
+ |
setFixedColumnWidth( resizeLeftColumn, leftWidth, Unit.PX ); |
650 |
625 |
|
|
651 |
626 |
|
int rightWidth = resizeRightX - clientX; |
652 |
|
- |
setFixedColumnWidth(resizeRightColumn, rightWidth, Unit.PX); |
|
627 |
+ |
setFixedColumnWidth( resizeRightColumn, rightWidth, Unit.PX ); |
653 |
628 |
|
} |
654 |
629 |
|
redraw(); |
655 |
630 |
|
} |
656 |
631 |
|
|
657 |
632 |
|
@Override |
658 |
|
- |
protected void onBrowserEvent2(Event event) { |
659 |
|
- |
if (resizingColumns) { |
660 |
|
- |
applyColumnResize(event.getClientX()); |
661 |
|
- |
if ("mouseup".equals(event.getType())) { |
|
633 |
+ |
protected void onBrowserEvent2( Event event ) { |
|
634 |
+ |
if ( resizingColumns ) { |
|
635 |
+ |
applyColumnResize( event.getClientX() ); |
|
636 |
+ |
if ( "mouseup".equals( event.getType() ) ) { |
662 |
637 |
|
resizingColumns = false; |
663 |
638 |
|
adjustBodyColumnWidths(); |
664 |
639 |
|
} |
665 |
640 |
|
} else { |
666 |
641 |
|
EventTarget eventTarget = event.getEventTarget(); |
667 |
|
- |
if (!Element.is(eventTarget)) { |
|
642 |
+ |
if ( !Element.is( eventTarget ) ) { |
668 |
643 |
|
return; |
669 |
644 |
|
} |
670 |
|
- |
final Element target = Element.as(eventTarget); |
|
645 |
+ |
final Element target = Element.as( eventTarget ); |
671 |
646 |
|
|
672 |
|
- |
if (target.hasAttribute(RESIZE_HANDLE_ATTRIBUTE)) { |
|
647 |
+ |
if ( target.hasAttribute( RESIZE_HANDLE_ATTRIBUTE ) ) { |
673 |
648 |
|
// figure out which column this event is for |
674 |
|
- |
int col = Integer.parseInt(target.getAttribute(RESIZE_HANDLE_ATTRIBUTE)); |
675 |
|
- |
if (col < getColumnCount() - 1 && "mousedown".equals(event.getType())) { |
676 |
|
- |
resizeLeftColumn = getColumn(col); |
677 |
|
- |
resizeRightColumn = getColumn(col + 1); |
|
649 |
+ |
int col = Integer.parseInt( target.getAttribute( RESIZE_HANDLE_ATTRIBUTE ) ); |
|
650 |
+ |
if ( col < getColumnCount() - 1 && "mousedown".equals( event.getType() ) ) { |
|
651 |
+ |
resizeLeftColumn = getColumn( col ); |
|
652 |
+ |
resizeRightColumn = getColumn( col + 1 ); |
678 |
653 |
|
|
679 |
654 |
|
Element leftTableHeader = target.getParentElement().getParentElement(); |
680 |
|
- |
assert(leftTableHeader != null); |
|
655 |
+ |
assert (leftTableHeader != null); |
681 |
656 |
|
|
682 |
657 |
|
Element rightTableHeader = leftTableHeader.getNextSiblingElement(); |
683 |
|
- |
assert(rightTableHeader != null); |
|
658 |
+ |
assert (rightTableHeader != null); |
684 |
659 |
|
|
685 |
660 |
|
int clientX = event.getClientX(); |
686 |
661 |
|
resizeLeftX = clientX - leftTableHeader.getOffsetWidth(); |
|
@@ -689,7 +664,7 @@ |
689 |
664 |
|
} |
690 |
665 |
|
} else { |
691 |
666 |
|
// defer to CellTable's event handler |
692 |
|
- |
super.onBrowserEvent2(event); |
|
667 |
+ |
super.onBrowserEvent2( event ); |
693 |
668 |
|
} |
694 |
669 |
|
} |
695 |
670 |
|
} |