Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/table/datatableadapter/EIS_DataTable.java

Diff revisions: vs.
  @@ -1,62 +1,36 @@
1 1 package com.temp.client.foundation.widget.table.datatableadapter;
2 2
3 -
4 - import java.util.ArrayList;
5 - import java.util.HashSet;
6 - import java.util.LinkedHashMap;
7 - import java.util.List;
8 - import java.util.Map;
9 - import java.util.Set;
10 -
11 -
12 - import com.google.gwt.cell.client.AbstractCell;
13 - import com.google.gwt.cell.client.Cell;
14 - import com.google.gwt.cell.client.Cell.Context;
15 - import com.google.gwt.cell.client.ValueUpdater;
16 - 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.*;
17 6 import com.google.gwt.dom.client.Element;
18 - import com.google.gwt.dom.client.EventTarget;
19 - import com.google.gwt.dom.client.NativeEvent;
20 - import com.google.gwt.dom.client.Node;
21 - import com.google.gwt.dom.client.NodeList;
22 - import com.google.gwt.dom.client.Style.Unit;
23 - import com.google.gwt.dom.client.TableCellElement;
24 - import com.google.gwt.event.dom.client.MouseDownEvent;
25 - import com.google.gwt.event.dom.client.MouseDownHandler;
26 - import com.google.gwt.event.dom.client.MouseMoveEvent;
27 - import com.google.gwt.event.dom.client.MouseMoveHandler;
28 - import com.google.gwt.event.dom.client.MouseUpEvent;
29 - import com.google.gwt.event.dom.client.MouseUpHandler;
30 - import com.google.gwt.event.shared.HandlerRegistration;
31 - import com.google.gwt.safehtml.client.SafeHtmlTemplates;
32 - import com.google.gwt.safehtml.shared.SafeHtml;
33 - import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
34 - import com.google.gwt.safehtml.shared.SafeHtmlUtils;
35 - import com.google.gwt.user.cellview.client.Column;
36 - import com.google.gwt.user.cellview.client.DataGrid;
37 - import com.google.gwt.user.cellview.client.Header;
38 - import com.google.gwt.user.cellview.client.SafeHtmlHeader;
39 - import com.google.gwt.user.cellview.client.TextHeader;
7 + import com.google.gwt.dom.client.*;
8 + import com.google.gwt.dom.client.Style.*;
9 + import com.google.gwt.event.dom.client.*;
10 + import com.google.gwt.event.shared.*;
11 + import com.google.gwt.safehtml.client.*;
12 + import com.google.gwt.safehtml.shared.*;
13 + import com.google.gwt.user.cellview.client.*;
40 14 import com.google.gwt.user.client.Timer;
41 - import com.google.gwt.user.client.ui.RequiresResize;
42 - import com.google.gwt.user.client.ui.RootLayoutPanel;
43 - import com.google.gwt.user.client.ui.Widget;
44 - import com.google.gwt.view.client.ProvidesKey;
45 - import com.google.gwt.view.client.SimpleKeyProvider;
15 + import com.google.gwt.user.client.ui.*;
16 + import com.google.gwt.view.client.*;
17 +
18 + import java.util.*;
46 19
47 20 /**
48 21 * Derived from:
49 - * https://p4db.amazon.com/source-views/p4db/brazil/fileViewer.cgi?FSPC=//brazil/src/appgroup/webservices/apps/AWSConsole-GWT-Widgets/mainline/src/com/amazonaws/console/gwt/ui/DataTable.java&REV=3
50 - *
22 + * https://p4db.amazon.com/source-views/p4db/brazil/fileViewer
23 + * .cgi?FSPC=//brazil/src/appgroup/webservices/apps/AWSConsole-GWT-Widgets/mainline/src/com/amazonaws/console/gwt/ui/DataTable.java&REV=3
24 + * <p/>
51 25 * This widget is derived from DataGrid, and behaves very similar to it,
52 26 * except that it adds interactively resize-able columns, and an AWS
53 27 * console look and feel.
54 - *
55 - * <p>
28 + * <p/>
29 + * <p/>
56 30 * Although this widget is functionally equivalent to a DataGrid, it can't
57 31 * be used in exactly the same way as a DataGrid can be used. The following
58 32 * additional rules must be followed for this table to work correctly.
59 - *
33 + * <p/>
60 34 * <p><ol>
61 35 * <li>
62 36 * Since the data area of this widget scrolls and therefore has no predetermined
  @@ -82,13 +56,15 @@
82 56 * column will not be visible.
83 57 * </ol>
84 58 *
85 - * @author Stephen Saville (saville@amazon.com)
59 + * @param <T> Type of data object stored in the table.
86 60 *
87 - * @param <T>
88 - * Type of data object stored in the table.
61 + * @author Stephen Saville (saville@amazon.com)
89 62 */
90 63
91 - public class EIS_DataTable<T> extends DataGrid<T> implements RequiresResize, MouseDownHandler, MouseMoveHandler, MouseUpHandler {
64 + public class EIS_DataTable<T> extends DataGrid<T> implements RequiresResize,
65 + MouseDownHandler,
66 + MouseMoveHandler,
67 + MouseUpHandler {
92 68 public static final int DEFAULT_PAGE_SIZE = 15;
93 69
94 70 public static final String RESIZE_HANDLE_ATTRIBUTE = "resize-col";
  @@ -97,18 +73,18 @@
97 73
98 74 interface Templates extends SafeHtmlTemplates {
99 75 @Template("<div class=\"{0}\">")
100 - SafeHtml resizableHeaderCellPrefix(String headerClassName);
76 + SafeHtml resizableHeaderCellPrefix( String headerClassName );
101 77
102 78 @Template("<div " + RESIZE_HANDLE_ATTRIBUTE + "=\"{0}\" class=\"{1}\"> </div></div>")
103 - SafeHtml resizableHeaderCellSuffix(int col, String resizeHandleClassName);
79 + SafeHtml resizableHeaderCellSuffix( int col, String resizeHandleClassName );
104 80 }
105 81
106 - private static final Templates TEMPLATES = GWT.create(Templates.class);
82 + private static final Templates TEMPLATES = GWT.create( Templates.class );
107 83
108 84 public class DataTableOverlayHeaderCell<V> implements Cell<V> {
109 85 private final Cell<V> delegate;
110 86
111 - public DataTableOverlayHeaderCell(Cell<V> delegate) {
87 + public DataTableOverlayHeaderCell( Cell<V> delegate ) {
112 88 this.delegate = delegate;
113 89 }
114 90
  @@ -126,43 +102,43 @@
126 102
127 103 public boolean isEditing(
128 104 com.google.gwt.cell.client.Cell.Context context,
129 - Element parent, V value) {
130 - return delegate.isEditing(context, parent, value);
105 + Element parent, V value ) {
106 + return delegate.isEditing( context, parent, value );
131 107 }
132 108
133 109 public void onBrowserEvent(
134 110 com.google.gwt.cell.client.Cell.Context context,
135 111 Element parent, V value, NativeEvent event,
136 - ValueUpdater<V> valueUpdater) {
137 - delegate.onBrowserEvent(context, parent, value, event, valueUpdater);
112 + ValueUpdater<V> valueUpdater ) {
113 + delegate.onBrowserEvent( context, parent, value, event, valueUpdater );
138 114 }
139 115
140 - public void render(com.google.gwt.cell.client.Cell.Context context,
141 - V value, SafeHtmlBuilder sb) {
142 - sb.append(TEMPLATES.resizableHeaderCellPrefix(
143 - styles.dataTableHeader()));
144 - delegate.render(context, value, sb);
145 - sb.append(TEMPLATES.resizableHeaderCellSuffix(
146 - context.getColumn(), styles.dataTableResizeHandle()));
116 + public void render( com.google.gwt.cell.client.Cell.Context context,
117 + V value, SafeHtmlBuilder sb ) {
118 + sb.append( TEMPLATES.resizableHeaderCellPrefix(
119 + styles.dataTableHeader() ) );
120 + delegate.render( context, value, sb );
121 + sb.append( TEMPLATES.resizableHeaderCellSuffix(
122 + context.getColumn(), styles.dataTableResizeHandle() ) );
147 123 }
148 124
149 125 public boolean resetFocus(
150 126 com.google.gwt.cell.client.Cell.Context context,
151 - Element parent, V value) {
152 - return delegate.resetFocus(context, parent, value);
127 + Element parent, V value ) {
128 + return delegate.resetFocus( context, parent, value );
153 129 }
154 130
155 - public void setValue(com.google.gwt.cell.client.Cell.Context context,
156 - Element parent, V value) {
157 - delegate.setValue(context, parent, value);
131 + public void setValue( com.google.gwt.cell.client.Cell.Context context,
132 + Element parent, V value ) {
133 + delegate.setValue( context, parent, value );
158 134 }
159 135 }
160 136
161 137 public class DataTableOverlayHeader<V> extends Header<V> {
162 138 private final Header<V> delegate;
163 139
164 - public DataTableOverlayHeader(Header<V> delegate) {
165 - super(new DataTableOverlayHeaderCell<V>(delegate.getCell()));
140 + public DataTableOverlayHeader( Header<V> delegate ) {
141 + super( new DataTableOverlayHeaderCell<V>( delegate.getCell() ) );
166 142 this.delegate = delegate;
167 143 }
168 144
  @@ -174,42 +150,42 @@
174 150 return delegate.getValue();
175 151 }
176 152
177 - public void onBrowserEvent(Context context, Element elem,
178 - NativeEvent event) {
179 - delegate.onBrowserEvent(context, elem, event);
153 + public void onBrowserEvent( Context context, Element elem,
154 + NativeEvent event ) {
155 + delegate.onBrowserEvent( context, elem, event );
180 156 }
181 157
182 - public void setUpdater(ValueUpdater<V> updater) {
183 - delegate.setUpdater(updater);
158 + public void setUpdater( ValueUpdater<V> updater ) {
159 + delegate.setUpdater( updater );
184 160 }
185 161 }
186 162
187 - public <V> DataTableOverlayHeader<V> overlayHeader(Header<V> header) {
188 - return new DataTableOverlayHeader<V>(header);
163 + public <V> DataTableOverlayHeader<V> overlayHeader( Header<V> header ) {
164 + return new DataTableOverlayHeader<V>( header );
189 165 }
190 166
191 167 public class DataTableSafeHtmlHeaderCell extends AbstractCell<SafeHtml> {
192 168 @Override
193 - public void render(com.google.gwt.cell.client.Cell.Context context,
194 - SafeHtml value, SafeHtmlBuilder sb) {
195 - sb.append(TEMPLATES.resizableHeaderCellPrefix(
196 - styles.dataTableHeader()));
197 - sb.append(value);
198 - sb.append(TEMPLATES.resizableHeaderCellSuffix(
199 - context.getColumn(), styles.dataTableResizeHandle()));
169 + public void render( com.google.gwt.cell.client.Cell.Context context,
170 + SafeHtml value, SafeHtmlBuilder sb ) {
171 + sb.append( TEMPLATES.resizableHeaderCellPrefix(
172 + styles.dataTableHeader() ) );
173 + sb.append( value );
174 + sb.append( TEMPLATES.resizableHeaderCellSuffix(
175 + context.getColumn(), styles.dataTableResizeHandle() ) );
200 176 }
201 177 }
202 178
203 179 public class DataTableSafeHtmlHeader extends Header<SafeHtml> {
204 180 private SafeHtml value;
205 181
206 - public DataTableSafeHtmlHeader(SafeHtml html) {
207 - super(new DataTableSafeHtmlHeaderCell());
182 + public DataTableSafeHtmlHeader( SafeHtml html ) {
183 + super( new DataTableSafeHtmlHeaderCell() );
208 184 this.value = html;
209 185 }
210 186
211 - public DataTableSafeHtmlHeader(String text) {
212 - this(SafeHtmlUtils.fromString(text));
187 + public DataTableSafeHtmlHeader( String text ) {
188 + this( SafeHtmlUtils.fromString( text ) );
213 189 }
214 190
215 191 @Override
  @@ -218,174 +194,174 @@
218 194 }
219 195 }
220 196
221 - private final Map<Column<T,?>, Double> relativeWidthColumns =
222 - new LinkedHashMap<Column<T,?>, Double>();
197 + private final Map<Column<T, ?>, Double> relativeWidthColumns =
198 + new LinkedHashMap<Column<T, ?>, Double>();
223 199
224 - private final Set<Column<T,?>> fixedWidthColumns =
225 - new HashSet<Column<T,?>>();
200 + private final Set<Column<T, ?>> fixedWidthColumns =
201 + new HashSet<Column<T, ?>>();
226 202
227 203 private final EIS_DataTableStyle styles;
228 204
229 205 private static final int MIN_RESIZED_WIDTH = 10;
230 206
231 207 private boolean resizingColumns = false;
232 - private Column<T,?> resizeLeftColumn, resizeRightColumn;
208 + private Column<T, ?> resizeLeftColumn, resizeRightColumn;
233 209 private int resizeLeftX, resizeRightX, resizeTotalWidth, borderOverhead;
234 210 private HandlerRegistration mouseMoveRegistration, mouseUpRegistration;
235 211
236 212 private static BrowserTableResizeSupport RESIZE_SUPPORT;
237 213
238 214 public EIS_DataTable() {
239 - this(DEFAULT_PAGE_SIZE);
215 + this( DEFAULT_PAGE_SIZE );
240 216 }
241 217
242 - public EIS_DataTable(int pageSize, ProvidesKey<T> keyProvider) {
243 - this(pageSize, GWT.<EIS_DataTableResources>create(EIS_DataTableResources.class), keyProvider);
218 + public EIS_DataTable( int pageSize, ProvidesKey<T> keyProvider ) {
219 + this( pageSize, GWT.<EIS_DataTableResources>create( EIS_DataTableResources.class ), keyProvider );
244 220 }
245 221
246 - public EIS_DataTable(int pageSize) {
247 - this(pageSize, new SimpleKeyProvider<T>());
222 + public EIS_DataTable( int pageSize ) {
223 + this( pageSize, new SimpleKeyProvider<T>() );
248 224 }
249 225
250 - public EIS_DataTable(ProvidesKey<T> keyProvider) {
251 - this(DEFAULT_PAGE_SIZE, keyProvider);
226 + public EIS_DataTable( ProvidesKey<T> keyProvider ) {
227 + this( DEFAULT_PAGE_SIZE, keyProvider );
252 228 }
253 229
254 - public EIS_DataTable(int pageSize, EIS_DataTableResources resources, ProvidesKey<T> keyProvider) {
255 - super(pageSize, resources, keyProvider);
230 + public EIS_DataTable( int pageSize, EIS_DataTableResources resources, ProvidesKey<T> keyProvider ) {
231 + super( pageSize, resources, keyProvider );
256 232 styles = resources.dataGridStyle();
257 233 borderOverhead = styles.cellBorderWidth();
258 234 finiInit();
259 235 }
260 236
261 - public EIS_DataTable(int pageSize, EIS_DataTableResources resources, ProvidesKey<T> keyProvider, Widget loadingIndicator) {
262 - super(pageSize, resources, keyProvider, loadingIndicator);
237 + public EIS_DataTable( int pageSize, EIS_DataTableResources resources, ProvidesKey<T> keyProvider, Widget loadingIndicator ) {
238 + super( pageSize, resources, keyProvider, loadingIndicator );
263 239 styles = resources.dataGridStyle();
264 240 borderOverhead = styles.cellBorderWidth();
265 241 finiInit();
266 242 }
267 243
268 244 private void finiInit() {
269 - if (RESIZE_SUPPORT == null) {
270 - RESIZE_SUPPORT = GWT.create(BrowserTableResizeSupport.class);
245 + if ( RESIZE_SUPPORT == null ) {
246 + RESIZE_SUPPORT = GWT.create( BrowserTableResizeSupport.class );
271 247 }
272 - addDomHandler(this, MouseDownEvent.getType());
248 + addDomHandler( this, MouseDownEvent.getType() );
273 249 }
274 250
275 251 @Override
276 - public void addColumn(Column<T, ?> col) {
277 - super.addColumn(col, new DataTableSafeHtmlHeader(SafeHtmlUtils.EMPTY_SAFE_HTML));
252 + public void addColumn( Column<T, ?> col ) {
253 + super.addColumn( col, new DataTableSafeHtmlHeader( SafeHtmlUtils.EMPTY_SAFE_HTML ) );
278 254 }
279 255
280 256 @Override
281 - public void addColumn(Column<T, ?> col, SafeHtml headerHtml) {
282 - super.addColumn(col, new DataTableSafeHtmlHeader(headerHtml));
257 + public void addColumn( Column<T, ?> col, SafeHtml headerHtml ) {
258 + super.addColumn( col, new DataTableSafeHtmlHeader( headerHtml ) );
283 259 }
284 260
285 261 @Override
286 - public void addColumn(Column<T, ?> col, String headerString) {
287 - super.addColumn(col, new DataTableSafeHtmlHeader(headerString));
262 + public void addColumn( Column<T, ?> col, String headerString ) {
263 + super.addColumn( col, new DataTableSafeHtmlHeader( headerString ) );
288 264 }
289 265
290 266 @Override
291 - public void addColumn(Column<T, ?> col, Header<?> header) {
292 - super.addColumn(col, overlayHeader(header));
267 + public void addColumn( Column<T, ?> col, Header<?> header ) {
268 + super.addColumn( col, overlayHeader( header ) );
293 269 }
294 270
295 271 @Override
296 - public void addColumn(Column<T, ?> col, Header<?> header, Header<?> footer) {
297 - super.addColumn(col, overlayHeader(header), footer);
272 + public void addColumn( Column<T, ?> col, Header<?> header, Header<?> footer ) {
273 + super.addColumn( col, overlayHeader( header ), footer );
298 274 }
299 275
300 276 @Override
301 - public void addColumn(Column<T, ?> col, String headerString, String footerString) {
302 - super.addColumn(col, new DataTableSafeHtmlHeader(headerString), new TextHeader(footerString));
277 + public void addColumn( Column<T, ?> col, String headerString, String footerString ) {
278 + super.addColumn( col, new DataTableSafeHtmlHeader( headerString ), new TextHeader( footerString ) );
303 279 }
304 280
305 281 @Override
306 - public void addColumn(Column<T, ?> col, SafeHtml headerHtml, SafeHtml footerHtml) {
307 - super.addColumn(col, new DataTableSafeHtmlHeader(headerHtml), new SafeHtmlHeader(footerHtml));
282 + public void addColumn( Column<T, ?> col, SafeHtml headerHtml, SafeHtml footerHtml ) {
283 + super.addColumn( col, new DataTableSafeHtmlHeader( headerHtml ), new SafeHtmlHeader( footerHtml ) );
308 284 }
309 285
310 286 @Override
311 - public void insertColumn(int beforeIndex, Column<T, ?> col) {
287 + public void insertColumn( int beforeIndex, Column<T, ?> col ) {
312 288 // todo: we need to proxy so that we can control all this!
313 - super.insertColumn(beforeIndex, col);
289 + super.insertColumn( beforeIndex, col );
314 290 }
315 291
316 292 @Override
317 - public void insertColumn(int beforeIndex, Column<T, ?> col, Header<?> header) {
293 + public void insertColumn( int beforeIndex, Column<T, ?> col, Header<?> header ) {
318 294 // todo: we need to proxy so that we can control all this!
319 - super.insertColumn(beforeIndex, col, header);
295 + super.insertColumn( beforeIndex, col, header );
320 296 }
321 297
322 298 @Override
323 - public void insertColumn(int beforeIndex, Column<T, ?> col, SafeHtml headerHtml) {
299 + public void insertColumn( int beforeIndex, Column<T, ?> col, SafeHtml headerHtml ) {
324 300 // todo: we need to proxy so that we can control all this!
325 - super.insertColumn(beforeIndex, col, headerHtml);
301 + super.insertColumn( beforeIndex, col, headerHtml );
326 302 }
327 303
328 304 @Override
329 - public void insertColumn(int beforeIndex, Column<T, ?> col, SafeHtml headerHtml, SafeHtml footerHtml) {
305 + public void insertColumn( int beforeIndex, Column<T, ?> col, SafeHtml headerHtml, SafeHtml footerHtml ) {
330 306 // todo: we need to proxy so that we can control all this!
331 - super.insertColumn(beforeIndex, col, headerHtml, footerHtml);
307 + super.insertColumn( beforeIndex, col, headerHtml, footerHtml );
332 308 }
333 309
334 310 @Override
335 - public void insertColumn(int beforeIndex, Column<T, ?> col, String headerString) {
311 + public void insertColumn( int beforeIndex, Column<T, ?> col, String headerString ) {
336 312 // todo: we need to proxy so that we can control all this!
337 - super.insertColumn(beforeIndex, col, headerString);
313 + super.insertColumn( beforeIndex, col, headerString );
338 314 }
339 315
340 316 @Override
341 - public void insertColumn(int beforeIndex, Column<T, ?> col, String headerString, String footerString) {
317 + public void insertColumn( int beforeIndex, Column<T, ?> col, String headerString, String footerString ) {
342 318 // todo: we need to proxy so that we can control all this!
343 - super.insertColumn(beforeIndex, col, headerString, footerString);
319 + super.insertColumn( beforeIndex, col, headerString, footerString );
344 320 }
345 321
346 322 /**
347 323 * Everything goes thru here!
348 324 */
349 325 @Override
350 - public void insertColumn(int beforeIndex, Column<T, ?> col, Header<?> header, Header<?> footer) {
326 + public void insertColumn( int beforeIndex, Column<T, ?> col, Header<?> header, Header<?> footer ) {
351 327 // todo: we need to proxy so that we can control all this!
352 - super.insertColumn(beforeIndex, col, header, footer);
328 + super.insertColumn( beforeIndex, col, header, footer );
353 329 }
354 330
355 331 @Override
356 - public void removeColumn(int index) {
357 - removeColumn(getColumn(index));
332 + public void removeColumn( int index ) {
333 + removeColumn( getColumn( index ) );
358 334 }
359 335
360 336 @Override
361 - public void removeColumn(Column<T, ?> col) {
362 - super.removeColumn(col);
363 - removeTrackedColumnWidths(col);
337 + public void removeColumn( Column<T, ?> col ) {
338 + super.removeColumn( col );
339 + removeTrackedColumnWidths( col );
364 340 }
365 341
366 342 @Override
367 - public void setColumnWidth(Column<T, ?> column, String width) {
368 - if (!width.endsWith(Unit.PCT.getType())) {
369 - setFixedColumnWidth(column, width);
343 + public void setColumnWidth( Column<T, ?> column, String width ) {
344 + if ( !width.endsWith( Unit.PCT.getType() ) ) {
345 + setFixedColumnWidth( column, width );
370 346 } else {
371 - setRelativeColumnWidth(column, Double.parseDouble(width.substring(0, width.length() - Unit.PCT.getType().length())));
347 + setRelativeColumnWidth( column, Double.parseDouble( width.substring( 0, width.length() - Unit.PCT.getType().length() ) ) );
372 348 }
373 349 }
374 350
375 - protected void superSetColumnWidth(Column<T, ?> column, String width) {
376 - super.setColumnWidth(column, width);
351 + protected void superSetColumnWidth( Column<T, ?> column, String width ) {
352 + super.setColumnWidth( column, width );
377 353 }
378 354
379 - protected void setOnResizeColumnWidthInPixels(Column<T, ?> column, int resizedWidth) {
380 - superSetColumnWidth(column, "" + RESIZE_SUPPORT.adjustColumnWidthInPixelsForBorder(borderOverhead, resizedWidth) + Unit.PX);
355 + protected void setOnResizeColumnWidthInPixels( Column<T, ?> column, int resizedWidth ) {
356 + superSetColumnWidth( column, "" + RESIZE_SUPPORT.adjustColumnWidthInPixelsForBorder( borderOverhead, resizedWidth ) + Unit.PX );
381 357 }
382 358
383 - private void setFixedColumnWidth(Column<T, ?> column, String fixedWidth) {
384 - removeTrackedColumnWidths(column);
385 - if (-1 != getColumnIndex(column)) {
386 - fixedWidthColumns.add(column);
359 + private void setFixedColumnWidth( Column<T, ?> column, String fixedWidth ) {
360 + removeTrackedColumnWidths( column );
361 + if ( -1 != getColumnIndex( column ) ) {
362 + fixedWidthColumns.add( column );
387 363 }
388 - superSetColumnWidth(column, fixedWidth);
364 + superSetColumnWidth( column, fixedWidth );
389 365 }
390 366
391 367 /**
  @@ -398,64 +374,56 @@
398 374 * width of 1, then the columns would take up 25%, 50% and 25% of the
399 375 * available space, respectively.
400 376 *
401 - * @param column
402 - * Column to set the relative width of.
403 - * @param relativeWidth
404 - * Relative column width.
377 + * @param column Column to set the relative width of.
378 + * @param relativeWidth Relative column width.
405 379 */
406 - public void setRelativeColumnWidth(Column<T, ?> column, double relativeWidth) {
407 - clearColumnWidth(column);
408 - if (-1 != getColumnIndex(column)) {
409 - relativeWidthColumns.put(column, relativeWidth);
380 + public void setRelativeColumnWidth( Column<T, ?> column, double relativeWidth ) {
381 + clearColumnWidth( column );
382 + if ( -1 != getColumnIndex( column ) ) {
383 + relativeWidthColumns.put( column, relativeWidth );
410 384 }
411 385 }
412 386
413 387 /**
414 388 * Set the width of a fixed-width column.
415 389 *
416 - * @param column
417 - * Column to set the width of.
418 - * @param fixedWidth
419 - * Fixed width in the given units.
420 - * @param unit
421 - * Fixed width unit, such as {@link Unit#PX}. Must <it>not</it> be {@link Unit#PCT}.
390 + * @param column Column to set the width of.
391 + * @param fixedWidth Fixed width in the given units.
392 + * @param unit Fixed width unit, such as {@link Unit#PX}. Must <it>not</it> be {@link Unit#PCT}.
422 393 */
423 - public void setFixedColumnWidth(Column<T, ?> column, double fixedWidth, Unit unit) {
424 - if (Unit.PCT.equals(unit)) {
425 - throw new IllegalArgumentException("PCT (percent) is NOT applicable to Fixed Column Width");
394 + public void setFixedColumnWidth( Column<T, ?> column, double fixedWidth, Unit unit ) {
395 + if ( Unit.PCT.equals( unit ) ) {
396 + throw new IllegalArgumentException( "PCT (percent) is NOT applicable to Fixed Column Width" );
426 397 }
427 - setFixedColumnWidth(column, "" + fixedWidth + unit);
398 + setFixedColumnWidth( column, "" + fixedWidth + unit );
428 399 }
429 400
430 401 /**
431 402 * Set the width of a fixed-width column.
432 403 *
433 - * @param column
434 - * Column to set the width of.
435 - * @param pixelWidth
436 - * Fixed width in pixels.
404 + * @param column Column to set the width of.
405 + * @param pixelWidth Fixed width in pixels.
437 406 */
438 - public void setFixedColumnWidth(Column<T, ?> column, int pixelWidth) {
439 - setFixedColumnWidth(column, "" + pixelWidth + Unit.PX);
407 + public void setFixedColumnWidth( Column<T, ?> column, int pixelWidth ) {
408 + setFixedColumnWidth( column, "" + pixelWidth + Unit.PX );
440 409 }
441 410
442 411 /**
443 412 * Clear the width of a column. This will make the column disappear.
444 413 *
445 - * @param column
446 - * Column to clear the width of.
414 + * @param column Column to clear the width of.
447 415 */
448 416 @Override
449 - public void clearColumnWidth(Column<T, ?> column) {
450 - removeTrackedColumnWidths(column);
417 + public void clearColumnWidth( Column<T, ?> column ) {
418 + removeTrackedColumnWidths( column );
451 419
452 420 // clear the width of this column
453 - super.clearColumnWidth(column);
421 + super.clearColumnWidth( column );
454 422 }
455 423
456 - private void removeTrackedColumnWidths(Column<T, ?> col) {
457 - relativeWidthColumns.remove(col);
458 - fixedWidthColumns.remove(col);
424 + private void removeTrackedColumnWidths( Column<T, ?> col ) {
425 + relativeWidthColumns.remove( col );
426 + fixedWidthColumns.remove( col );
459 427 }
460 428
461 429 @Override
  @@ -482,7 +450,7 @@
482 450 @Override
483 451 protected void onDetach() {
484 452 super.onDetach();
485 - onMouseUp(null); // Cleanup dynamic Handlers
453 + onMouseUp( null ); // Cleanup dynamic Handlers
486 454 killResizer();
487 455 }
488 456
  @@ -513,50 +481,50 @@
513 481 currentResizeDelay += currentResizeDelay;
514 482 Timer timer = resizeTimer; // Snag a reference
515 483 if ( (timer != null) && (currentResizeDelay < 12800) ) {
516 - timer.schedule(currentResizeDelay);
484 + timer.schedule( currentResizeDelay );
517 485 return;
518 486 }
519 487 }
520 488 resizeTimer = null;
521 489 }
522 - }).schedule(currentResizeDelay = INITIAL_RESIZE_DELAY_MILLIS);
490 + }).schedule( currentResizeDelay = INITIAL_RESIZE_DELAY_MILLIS );
523 491 }
524 492
525 493 /**
526 494 * @return true is resizing was successful!
527 495 */
528 496 protected boolean resizeColumns() {
529 - Element headerRow = getTableHeadElement().getRows().getItem(0);
530 - if (headerRow == null) {
497 + Element headerRow = getTableHeadElement().getRows().getItem( 0 );
498 + if ( headerRow == null ) {
531 499 return false; // No Header Row?
532 500 }
533 501 NodeList<Node> headerRowChildren = headerRow.getChildNodes();
534 502 int headerRowChildCount = headerRowChildren.getLength();
535 - if (headerRowChildCount == 0) {
503 + if ( headerRowChildCount == 0 ) {
536 504 return false; // No Columns?
537 505 }
538 506 int availableWidth = getElement().getClientWidth();
539 - if (availableWidth < (headerRowChildCount * 10)) {
507 + if ( availableWidth < (headerRowChildCount * 10) ) {
540 508 return false; // Overall Sizing is probably not Working Yet or ?
541 509 }
542 510
543 511 // find the width of all fixed-width columns, in pixels
544 512 Set<Column<T, ?>> unspecifiedColumnWidths = new HashSet<Column<T, ?>>();
545 513 int totalWidthOfFixedColumns = 0;
546 - for (int i = 0, col = 0; i < headerRowChildCount; i++, col++) {
547 - Node child = headerRowChildren.getItem(i);
548 - if (Element.is(child)) {
549 - Element childElement = Element.as(child);
550 - int columnWidth = RESIZE_SUPPORT.getColumnWidthInPixels(borderOverhead, childElement);
551 - if (columnWidth < 1) {
514 + for ( int i = 0, col = 0; i < headerRowChildCount; i++, col++ ) {
515 + Node child = headerRowChildren.getItem( i );
516 + if ( Element.is( child ) ) {
517 + Element childElement = Element.as( child );
518 + int columnWidth = RESIZE_SUPPORT.getColumnWidthInPixels( borderOverhead, childElement );
519 + if ( columnWidth < 1 ) {
552 520 return false; // Sizing Not Working Yet
553 521 }
554 - Column<T, ?> column = getColumn(col);
555 - if (!relativeWidthColumns.containsKey(column)) {
556 - if ( fixedWidthColumns.contains(column) ) {
522 + Column<T, ?> column = getColumn( col );
523 + if ( !relativeWidthColumns.containsKey( column ) ) {
524 + if ( fixedWidthColumns.contains( column ) ) {
557 525 totalWidthOfFixedColumns += columnWidth;
558 526 } else {
559 - unspecifiedColumnWidths.add(column);
527 + unspecifiedColumnWidths.add( column );
560 528 }
561 529 }
562 530 }
  @@ -568,8 +536,8 @@
568 536 }
569 537 if ( !unspecifiedColumnWidths.isEmpty() ) {
570 538 double relativeWidth = getCurrentRelativeMinimumWidth();
571 - for (Column<T, ?> column : unspecifiedColumnWidths) {
572 - setRelativeColumnWidth(column, relativeWidth);
539 + for ( Column<T, ?> column : unspecifiedColumnWidths ) {
540 + setRelativeColumnWidth( column, relativeWidth );
573 541 }
574 542 }
575 543 distributeToRelativeWidthColumns( availableWidth - totalWidthOfFixedColumns );
  @@ -581,7 +549,7 @@
581 549
582 550 private double getCurrentRelativeMinimumWidth() {
583 551 double lowest = 100; // 100%
584 - for (Double value : relativeWidthColumns.values()) {
552 + for ( Double value : relativeWidthColumns.values() ) {
585 553 if ( value < lowest ) {
586 554 lowest = value;
587 555 }
  @@ -589,14 +557,14 @@
589 557 return lowest;
590 558 }
591 559
592 - protected void applyColumnResize(final int clientX) {
593 - if (((resizeLeftX + MIN_RESIZED_WIDTH) < clientX) && (clientX < (resizeRightX - MIN_RESIZED_WIDTH))) {
594 - int leftWidth = clientX - resizeLeftX;
560 + protected void applyColumnResize( final int clientX ) {
561 + if ( ((resizeLeftX + MIN_RESIZED_WIDTH) < clientX) && (clientX < (resizeRightX - MIN_RESIZED_WIDTH)) ) {
562 + int leftWidth = clientX - resizeLeftX;
595 563 int rightWidth = resizeRightX - clientX;
596 564
597 565 // fix up new widths in case they don't add up correctly
598 566 int totalWidth = leftWidth + rightWidth;
599 - if (totalWidth != resizeTotalWidth) {
567 + if ( totalWidth != resizeTotalWidth ) {
600 568 int totalAdjustment = resizeTotalWidth - totalWidth;
601 569 int leftAdjustment = totalAdjustment / 2;
602 570 int rightAdjustment = totalAdjustment - leftAdjustment;
  @@ -604,48 +572,48 @@
604 572 rightWidth += rightAdjustment;
605 573 }
606 574
607 - setFixedColumnWidth(resizeLeftColumn, leftWidth, Unit.PX);
608 - setFixedColumnWidth(resizeRightColumn, rightWidth, Unit.PX);
575 + setFixedColumnWidth( resizeLeftColumn, leftWidth, Unit.PX );
576 + setFixedColumnWidth( resizeRightColumn, rightWidth, Unit.PX );
609 577 }
610 578 redraw();
611 579 }
612 580
613 - protected void startColumnResize(final int col, final Element target, final int clientX) {
614 - resizeLeftColumn = getColumn(col);
615 - resizeRightColumn = getColumn(col + 1);
616 -
617 - NodeList<TableCellElement> headerCells = getTableHeadElement().getRows().getItem(0).getCells();
618 - TableCellElement leftTableHeader = headerCells.getItem(col);
619 - TableCellElement rightTableHeader = headerCells.getItem(col + 1);
581 + protected void startColumnResize( final int col, final Element target, final int clientX ) {
582 + resizeLeftColumn = getColumn( col );
583 + resizeRightColumn = getColumn( col + 1 );
584 +
585 + NodeList<TableCellElement> headerCells = getTableHeadElement().getRows().getItem( 0 ).getCells();
586 + TableCellElement leftTableHeader = headerCells.getItem( col );
587 + TableCellElement rightTableHeader = headerCells.getItem( col + 1 );
620 588
621 - int leftWidth = RESIZE_SUPPORT.getColumnWidthInPixels(borderOverhead, leftTableHeader);
622 - int rightWidth = RESIZE_SUPPORT.getColumnWidthInPixels(borderOverhead, rightTableHeader);
589 + int leftWidth = RESIZE_SUPPORT.getColumnWidthInPixels( borderOverhead, leftTableHeader );
590 + int rightWidth = RESIZE_SUPPORT.getColumnWidthInPixels( borderOverhead, rightTableHeader );
623 591 resizeLeftX = clientX - leftWidth;
624 592 resizeRightX = clientX + rightWidth;
625 593 resizeTotalWidth = leftWidth + rightWidth;
626 594 }
627 595
628 596 @Override
629 - public void onMouseDown(MouseDownEvent event) {
630 - if (!resizingColumns) {
597 + public void onMouseDown( MouseDownEvent event ) {
598 + if ( !resizingColumns ) {
631 599 EventTarget eventTarget = event.getNativeEvent().getEventTarget();
632 - if (!Element.is(eventTarget)) {
600 + if ( !Element.is( eventTarget ) ) {
633 601 return;
634 602 }
635 - final Element target = Element.as(eventTarget);
603 + final Element target = Element.as( eventTarget );
636 604
637 - if (target.hasAttribute(RESIZE_HANDLE_ATTRIBUTE)) {
605 + if ( target.hasAttribute( RESIZE_HANDLE_ATTRIBUTE ) ) {
638 606 // figure out which column this event is for
639 - int col = Integer.parseInt(target.getAttribute(RESIZE_HANDLE_ATTRIBUTE));
640 - if (col < getColumnCount() - 1) {
641 - startColumnResize(col, target, event.getClientX());
607 + int col = Integer.parseInt( target.getAttribute( RESIZE_HANDLE_ATTRIBUTE ) );
608 + if ( col < getColumnCount() - 1 ) {
609 + startColumnResize( col, target, event.getClientX() );
642 610 resizingColumns = true;
643 611 RootLayoutPanel root = RootLayoutPanel.get();
644 - if (mouseMoveRegistration == null) {
645 - mouseMoveRegistration = root.addDomHandler(this, MouseMoveEvent.getType());
612 + if ( mouseMoveRegistration == null ) {
613 + mouseMoveRegistration = root.addDomHandler( this, MouseMoveEvent.getType() );
646 614 }
647 - if (mouseUpRegistration == null) {
648 - mouseUpRegistration = root.addDomHandler(this, MouseUpEvent.getType());
615 + if ( mouseUpRegistration == null ) {
616 + mouseUpRegistration = root.addDomHandler( this, MouseUpEvent.getType() );
649 617 }
650 618 }
651 619 }
  @@ -653,20 +621,20 @@
653 621 }
654 622
655 623 @Override
656 - public void onMouseMove(MouseMoveEvent event) {
657 - if (resizingColumns) {
658 - applyColumnResize(event.getClientX());
624 + public void onMouseMove( MouseMoveEvent event ) {
625 + if ( resizingColumns ) {
626 + applyColumnResize( event.getClientX() );
659 627 }
660 628 }
661 629
662 - public void onMouseUp(com.google.gwt.event.dom.client.MouseUpEvent event) {
663 - if (resizingColumns) {
630 + public void onMouseUp( com.google.gwt.event.dom.client.MouseUpEvent event ) {
631 + if ( resizingColumns ) {
664 632 resizingColumns = false;
665 - if (mouseMoveRegistration != null) {
633 + if ( mouseMoveRegistration != null ) {
666 634 mouseMoveRegistration.removeHandler();
667 635 mouseMoveRegistration = null;
668 636 }
669 - if (mouseUpRegistration != null) {
637 + if ( mouseUpRegistration != null ) {
670 638 mouseUpRegistration.removeHandler();
671 639 mouseUpRegistration = null;
672 640 }
  @@ -678,7 +646,7 @@
678 646 private double width;
679 647 private int desiredPixelWidth;
680 648
681 - public RelativeWidthColumnControl(Column<T, ?> column, double width) {
649 + public RelativeWidthColumnControl( Column<T, ?> column, double width ) {
682 650 this.column = column;
683 651 this.width = width;
684 652 }
  @@ -687,7 +655,6 @@
687 655 return column;
688 656 }
689 657
690 -
691 658 public double getWidth() {
692 659 return width;
693 660 }
  @@ -700,45 +667,46 @@
700 667 * Note CompareTo NOT compatible with equals()!
701 668 */
702 669 @Override
703 - public int compareTo(RelativeWidthColumnControl<T> them) {
704 - if (them.width > this.width) {
670 + public int compareTo( RelativeWidthColumnControl<T> them ) {
671 + if ( them.width > this.width ) {
705 672 return 1;
706 673 }
707 - if (them.width < this.width) {
674 + if ( them.width < this.width ) {
708 675 return -1;
709 676 }
710 677 return 0;
711 678 }
712 679
713 - public int distribute(int available, int overColumnsRemaining, double remainingTotalWidths) {
714 - if (overColumnsRemaining == 1) {
715 - desiredPixelWidth = Math.max(available, MIN_RESIZED_WIDTH);
680 + public int distribute( int available, int overColumnsRemaining, double remainingTotalWidths ) {
681 + if ( overColumnsRemaining == 1 ) {
682 + desiredPixelWidth = Math.max( available, MIN_RESIZED_WIDTH );
716 683 return 0;
717 684 }
718 685 double proportionatePixels = available * (width / remainingTotalWidths); // percentage
719 - if (overColumnsRemaining < 10) { // favor the end...
686 + if ( overColumnsRemaining < 10 ) { // favor the end...
720 687 proportionatePixels += (10 - overColumnsRemaining) / 10f;
721 688 }
722 - int pixels = Math.min((int) proportionatePixels, available);
723 - desiredPixelWidth = Math.max(pixels, MIN_RESIZED_WIDTH);
689 + int pixels = Math.min( (int) proportionatePixels, available );
690 + desiredPixelWidth = Math.max( pixels, MIN_RESIZED_WIDTH );
724 691 return available - pixels;
725 692 }
726 693 }
727 694
728 - private void distributeToRelativeWidthColumns(int pixelsToDistribute) {
695 + private void distributeToRelativeWidthColumns( int pixelsToDistribute ) {
729 696 // create List & sum Relative Widths
730 - List<RelativeWidthColumnControl<T>> controls = new ArrayList<RelativeWidthColumnControl<T>>(relativeWidthColumns.size());
697 + List<RelativeWidthColumnControl<T>> controls = new ArrayList<RelativeWidthColumnControl<T>>( relativeWidthColumns.size() );
731 698 double totalWidths = 0;
732 - for (Map.Entry<Column<T,?>, Double> entry : relativeWidthColumns.entrySet()) {
699 + for ( Map.Entry<Column<T, ?>, Double> entry : relativeWidthColumns.entrySet() ) {
733 700 Double proportionateWidth = entry.getValue();
734 - controls.add(new RelativeWidthColumnControl<T>(entry.getKey(), proportionateWidth));
701 + controls.add( new RelativeWidthColumnControl<T>( entry.getKey(), proportionateWidth ) );
735 702 totalWidths += proportionateWidth;
736 703 }
737 704 // Distribute the Pixels
738 - for ( int i = 0; i < controls.size() ; i++ ) {
739 - RelativeWidthColumnControl<T> control = controls.get(i);
740 - pixelsToDistribute = control.distribute(pixelsToDistribute, controls.size() - i, totalWidths);
741 - setOnResizeColumnWidthInPixels(control.getColumn(), RESIZE_SUPPORT.adjustColumnWidthInPixelsForBorder(borderOverhead, control.getDesiredPixelWidth()));
705 + for ( int i = 0; i < controls.size(); i++ ) {
706 + RelativeWidthColumnControl<T> control = controls.get( i );
707 + pixelsToDistribute = control.distribute( pixelsToDistribute, controls.size() - i, totalWidths );
708 + setOnResizeColumnWidthInPixels( control.getColumn(),
709 + RESIZE_SUPPORT.adjustColumnWidthInPixelsForBorder( borderOverhead, control.getDesiredPixelWidth() ) );
742 710 totalWidths -= control.getWidth();
743 711 }
744 712 }