Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -1,55 +1,29 @@
1 1 package com.temp.client.foundation.widget.table;
2 2
3 - import java.util.HashMap;
4 - import java.util.List;
5 - import java.util.Map;
6 - import java.util.Stack;
7 -
8 - import com.temp.client.foundation.util.CommonElementHelper;
9 - import com.temp.client.foundation.widget.table.column.TextDataColumn;
10 - import com.temp.client.foundation.widget.table.datatableadapter.EIS_DataTable;
11 - import com.temp.client.foundation.widget.table.datatableadapter.EIS_DataTableResources;
12 - import com.temp.client.foundation.widget.table.datatableadapter.EIS_DataTableStyle;
13 - import com.temp.shared.LoadingProgressListener;
14 - import com.temp.shared.utils.CollectionsUtils;
15 - import com.temp.shared.utils.ObjectUtils;
16 - import com.temp.shared.utils.SafeHtmlizer;
17 - import com.temp.shared.utils.StringUtils;
18 -
19 - import com.google.gwt.cell.client.TextCell;
20 - import com.google.gwt.core.client.GWT;
21 - import com.google.gwt.dom.client.Style.Unit;
22 - import com.google.gwt.event.dom.client.ClickEvent;
23 - import com.google.gwt.event.dom.client.ClickHandler;
24 - import com.google.gwt.safehtml.shared.SafeHtmlUtils;
25 - import com.google.gwt.user.cellview.client.Column;
26 - import com.google.gwt.user.cellview.client.ColumnSortEvent;
27 - import com.google.gwt.user.cellview.client.LoadingStateChangeEvent.LoadingState;
28 - import com.google.gwt.user.client.ui.Composite;
29 - import com.google.gwt.user.client.ui.DockPanel;
30 - import com.google.gwt.user.client.ui.DockPanel.DockLayoutConstant;
31 - import com.google.gwt.user.client.ui.HasHorizontalAlignment;
32 - import com.google.gwt.user.client.ui.HasVerticalAlignment;
33 - import com.google.gwt.user.client.ui.HorizontalPanel;
34 - import com.google.gwt.user.client.ui.Image;
35 - import com.google.gwt.user.client.ui.Label;
36 - import com.google.gwt.user.client.ui.Panel;
37 - import com.google.gwt.user.client.ui.PushButton;
38 - import com.google.gwt.user.client.ui.ResizeLayoutPanel;
39 - import com.google.gwt.user.client.ui.VerticalPanel;
40 - import com.google.gwt.user.client.ui.Widget;
41 - import com.google.gwt.view.client.DefaultSelectionEventManager;
42 - import com.google.gwt.view.client.ListDataProvider;
43 - import com.google.gwt.view.client.SelectionModel;
3 + import com.google.gwt.cell.client.*;
4 + import com.google.gwt.core.client.*;
5 + import com.google.gwt.dom.client.Style.*;
6 + import com.google.gwt.event.dom.client.*;
7 + import com.google.gwt.safehtml.shared.*;
8 + import com.google.gwt.user.cellview.client.*;
9 + import com.google.gwt.user.cellview.client.LoadingStateChangeEvent.*;
10 + import com.google.gwt.user.client.ui.*;
11 + import com.google.gwt.user.client.ui.DockPanel.*;
12 + import com.google.gwt.view.client.*;
13 + import com.temp.client.foundation.util.*;
14 + import com.temp.client.foundation.widget.table.column.*;
15 + import com.temp.client.foundation.widget.table.datatableadapter.*;
16 + import com.temp.shared.*;
17 + import com.temp.shared.utils.*;
18 +
19 + import java.util.*;
44 20
45 21 /**
22 + * @param <R> the row type (e.g. MessageRow)
46 23 *
47 24 * @author paule
48 - *
49 - * @param <R>
50 - * the row type (e.g. MessageRow)
51 25 */
52 - public class CustomDataTable<R extends DataRow<F>,F> extends Composite implements LoadingProgressListener {
26 + public class CustomDataTable<R extends DataRow<F>, F> extends Composite implements LoadingProgressListener {
53 27
54 28 public static final String NO_RESULTS_FOUND_MESSAGE = "No results found.";
55 29 public static final String STYLE_NO_RESULTS_FOUND_MESSAGE = "DataTable-NoResults-message";
  @@ -75,12 +49,16 @@
75 49 private static final String DEFAULT_WIDTH = "100%";
76 50 private static final String DATA_TABLE_TOP_WIDGET_PANEL_STYLE_NAME = "dataTable-top-widget-panel";
77 51
78 - /** The Sort Direction values to pass to EIS Service calls. */
52 + /**
53 + * The Sort Direction values to pass to EIS Service calls.
54 + */
79 55 public static enum SortDirection {
80 56 ASC, DESC;
81 57 }
82 58
83 - /** Interface for data methods needed to update the data table. */
59 + /**
60 + * Interface for data methods needed to update the data table.
61 + */
84 62 public static interface DataTableUpdater {
85 63
86 64 /**
  @@ -95,7 +73,7 @@
95 73 *
96 74 * @param event
97 75 */
98 - void onDataTableDownloadCSVButtonClick(ClickEvent event);
76 + void onDataTableDownloadCSVButtonClick( ClickEvent event );
99 77 }
100 78
101 79 private int defaultRowsPerPage;
  @@ -119,9 +97,9 @@
119 97 private PushButton tenPerPageLink;
120 98 private VerticalPanel mainPanel;
121 99 private final Image DOWNLOAD_BUTTON_UP_IMAGE = new Image(
122 - "images/downCSV.png");
100 + "images/downCSV.png" );
123 101 private final Image DOWNLOAD_BUTTON_DOWN_IMAGE = new Image(
124 - "images/downCSVPress.png");
102 + "images/downCSVPress.png" );
125 103 private PushButton downloadCSVButton;
126 104
127 105 private static final String TABLE_HEADER_STYLE_NAME = "dataTable-table-header";
  @@ -137,314 +115,295 @@
137 115 /**
138 116 * Constructor.
139 117 *
140 - * @param title
141 - * - the table title
142 - * @param dataTableUpdater
143 - * - the table updater
118 + * @param title - the table title
119 + * @param dataTableUpdater - the table updater
144 120 */
145 - public CustomDataTable(String title, final DataTableUpdater dataTableUpdater) {
146 - this(title, dataTableUpdater, null, null, true, true);
121 + public CustomDataTable( String title, final DataTableUpdater dataTableUpdater ) {
122 + this( title, dataTableUpdater, null, null, true, true );
147 123 }
148 124
149 125 /**
150 126 * Constructor.
151 127 *
152 - * @param title
153 - * - the table title
154 - * @param dataTableUpdater
155 - * - the table updater
156 - */
157 - public CustomDataTable(String title,
158 - final DataTableUpdater dataTableUpdater, boolean includeTitleBar,
159 - boolean includeDownloadCSVButton) {
160 - this(title, dataTableUpdater, null, null, includeTitleBar,
161 - includeDownloadCSVButton);
128 + * @param title - the table title
129 + * @param dataTableUpdater - the table updater
130 + */
131 + public CustomDataTable( String title,
132 + final DataTableUpdater dataTableUpdater, boolean includeTitleBar,
133 + boolean includeDownloadCSVButton ) {
134 + this( title, dataTableUpdater, null, null, includeTitleBar,
135 + includeDownloadCSVButton );
162 136 }
163 137
164 138 /**
165 - *
166 - * @param title
167 - * - the table title
168 - * @param dataTableUpdater
169 - * - the table updater
170 - * @param topWidget
171 - * - optional widget at the top of the table
172 - * @param bottomWidget
173 - * - optional widget at the bottom of the table
174 - * @param includeTitleBar
175 - * - whether or not to include the title bar
176 - * @param includeDownloadCSVButton
177 - * - whether or not to include the download CSV button
178 - * @param includePagingBar
179 - * - whether or not to include the paging bar
180 - */
181 - public CustomDataTable(String title,
182 - final DataTableUpdater dataTableUpdater, Widget topWidget,
183 - Widget bottomWidget, boolean includeTitleBar,
184 - boolean includeDownloadCSVButton) {
185 - this(null, true, title, dataTableUpdater, topWidget, bottomWidget, includeTitleBar,
186 - includeDownloadCSVButton, true, DEFAULT_WIDTH, DEFAULT_HEIGHT);
139 + * @param title - the table title
140 + * @param dataTableUpdater - the table updater
141 + * @param topWidget - optional widget at the top of the table
142 + * @param bottomWidget - optional widget at the bottom of the table
143 + * @param includeTitleBar - whether or not to include the title bar
144 + * @param includeDownloadCSVButton - whether or not to include the download CSV button
145 + * @param includePagingBar - whether or not to include the paging bar
146 + */
147 + public CustomDataTable( String title,
148 + final DataTableUpdater dataTableUpdater, Widget topWidget,
149 + Widget bottomWidget, boolean includeTitleBar,
150 + boolean includeDownloadCSVButton ) {
151 + this( null, true, title, dataTableUpdater, topWidget, bottomWidget, includeTitleBar,
152 + includeDownloadCSVButton, true, DEFAULT_WIDTH, DEFAULT_HEIGHT );
187 153 }
188 154
189 155 /**
190 - *
191 - * @param title
192 - * - the table title
193 - * @param dataTableUpdater
194 - * - the table updater
195 - * @param topWidget
196 - * - optional widget at the top of the table
197 - * @param bottomWidget
198 - * - optional widget at the bottom of the table
199 - * @param includeTitleBar
200 - * - whether or not to include the title bar
201 - * @param includeDownloadCSVButton
202 - * - whether or not to include the download CSV button
203 - * @param includePagingBar
204 - * - whether or not to include the paging bar
205 - * @param width
206 - * - width of the table
207 - * @param height
208 - * - height of the table, required to display properly in IE
209 - */
210 - public CustomDataTable(Integer defaultRowsPerPage, boolean supportPaging, String title,
211 - final DataTableUpdater dataTableUpdater, Widget topWidget,
212 - Widget bottomWidget, boolean includeTitleBar,
213 - boolean includeDownloadCSVButton, boolean includeRowNumber,
214 - String width, String height) {
156 + * @param title - the table title
157 + * @param dataTableUpdater - the table updater
158 + * @param topWidget - optional widget at the top of the table
159 + * @param bottomWidget - optional widget at the bottom of the table
160 + * @param includeTitleBar - whether or not to include the title bar
161 + * @param includeDownloadCSVButton - whether or not to include the download CSV button
162 + * @param includePagingBar - whether or not to include the paging bar
163 + * @param width - width of the table
164 + * @param height - height of the table, required to display properly in IE
165 + */
166 + public CustomDataTable( Integer defaultRowsPerPage, boolean supportPaging, String title,
167 + final DataTableUpdater dataTableUpdater, Widget topWidget,
168 + Widget bottomWidget, boolean includeTitleBar,
169 + boolean includeDownloadCSVButton, boolean includeRowNumber,
170 + String width, String height ) {
215 171
216 172 resultsPerPage = this.defaultRowsPerPage = (defaultRowsPerPage != null) ? defaultRowsPerPage : DEFAULT_RESULTS_PER_PAGE;
217 173 tableUpdater = dataTableUpdater;
218 174
219 175 VerticalPanel dataTableContainer = new VerticalPanel();
220 - dataTableContainer.addStyleName("dataTable-container");
221 - dataTableContainer.setWidth(width);
176 + dataTableContainer.addStyleName( "dataTable-container" );
177 + dataTableContainer.setWidth( width );
222 178
223 179 // title bar
224 - appendTo(dataTableContainer, createTableHeader(includeTitleBar, title,includeDownloadCSVButton));
180 + appendTo( dataTableContainer, createTableHeader( includeTitleBar, title, includeDownloadCSVButton ) );
225 181
226 182 // top widget
227 - appendTo(dataTableContainer, createTopWidgetWidget(topWidget));
183 + appendTo( dataTableContainer, createTopWidgetWidget( topWidget ) );
228 184
229 185 boolean anyTopWidgets = (dataTableContainer.getWidgetCount() > 0);
230 186
231 - dataTableContainer.add(finiTable(dataTable = createTable(createTableStateLabel("Loading...", "DataTable-Loading-message")), width, height, includeRowNumber));
232 - dataProvider.addDataDisplay(dataTable);
187 + dataTableContainer.add( finiTable( dataTable = createTable( createTableStateLabel( "Loading...", "DataTable-Loading-message" ) ), width, height,
188 + includeRowNumber ) );
189 + dataProvider.addDataDisplay( dataTable );
233 190 dataProvider.refresh();
234 191
235 - Panel bottomPanel = createBottomPanel(width, //
236 - bottomWidget, //
237 - resultsPerPagePanel = createVerticallyCenteredHorizontalPanel( //
238 - tenPerPageLink = createPageSizeChangeButton(TEN), //
239 - createPagingSeparator(), //
240 - twentyFivePerPageLink = createPageSizeChangeButton(TWENTY_FIVE)), //
241 - createVerticallyCenteredHorizontalPanel( //
242 - prevPageLink = createPrevPageLink(), //
243 - pagingSeparatorLabel = createPagingSeparator(), //
244 - nextPageLink = createNextPageLink()));
245 - if (supportPaging) {
246 - dataTableContainer.add(bottomPanel);
247 - hide(pagingSeparatorLabel);
248 - hide(resultsPerPagePanel);
192 + Panel bottomPanel = createBottomPanel( width, //
193 + bottomWidget, //
194 + resultsPerPagePanel = createVerticallyCenteredHorizontalPanel( //
195 + tenPerPageLink = createPageSizeChangeButton( TEN ),
196 + //
197 + createPagingSeparator(), //
198 + twentyFivePerPageLink =
199 + createPageSizeChangeButton( TWENTY_FIVE ) ),
200 + //
201 + createVerticallyCenteredHorizontalPanel( //
202 + prevPageLink = createPrevPageLink(), //
203 + pagingSeparatorLabel = createPagingSeparator(), //
204 + nextPageLink = createNextPageLink() ) );
205 + if ( supportPaging ) {
206 + dataTableContainer.add( bottomPanel );
207 + hide( pagingSeparatorLabel );
208 + hide( resultsPerPagePanel );
249 209 }
250 210
251 211 mainPanel = new VerticalPanel();
252 - mainPanel.addStyleName("dataTableMainPanel");
212 + mainPanel.addStyleName( "dataTableMainPanel" );
253 213 if ( !anyTopWidgets ) {
254 - mainPanel.addStyleName("dataTableMainPanelNoTopWidgets");
214 + mainPanel.addStyleName( "dataTableMainPanelNoTopWidgets" );
255 215 }
256 - mainPanel.setWidth(width);
257 - mainPanel.add(dataTableContainer);
258 - initWidget(mainPanel);
216 + mainPanel.setWidth( width );
217 + mainPanel.add( dataTableContainer );
218 + initWidget( mainPanel );
259 219
260 220 reset();
261 221 }
262 222
263 - private DockPanel createBottomPanel(String width, Widget bottomWidget, HorizontalPanel resultsPerPagePanel, HorizontalPanel pagerButtonsPanel) {
223 + private DockPanel createBottomPanel( String width, Widget bottomWidget, HorizontalPanel resultsPerPagePanel, HorizontalPanel pagerButtonsPanel ) {
264 224 // bottom panel
265 225 DockPanel bottomPanel = new DockPanel();
266 - bottomPanel.setStylePrimaryName(BOTTOM_PANEL_STYLE_NAME);
267 - bottomPanel.setWidth(width);
268 - addSection(bottomPanel, (bottomWidget != null) ? bottomWidget : new Image("images/empty.png"), DockPanel.WEST, "40%");
269 - addSection(bottomPanel, resultsPerPagePanel, DockPanel.CENTER, "40%");
270 - addSection(bottomPanel, pagerButtonsPanel, DockPanel.EAST, "20%");
226 + bottomPanel.setStylePrimaryName( BOTTOM_PANEL_STYLE_NAME );
227 + bottomPanel.setWidth( width );
228 + addSection( bottomPanel, (bottomWidget != null) ? bottomWidget : new Image( "images/empty.png" ), DockPanel.WEST, "40%" );
229 + addSection( bottomPanel, resultsPerPagePanel, DockPanel.CENTER, "40%" );
230 + addSection( bottomPanel, pagerButtonsPanel, DockPanel.EAST, "20%" );
271 231 return bottomPanel;
272 232 }
273 233
274 - private void addSection(DockPanel panel, Widget widget, DockLayoutConstant section, String width) {
275 - panel.add(widget, section);
276 - panel.setCellWidth(widget, width);
277 - panel.setCellVerticalAlignment(widget,HasVerticalAlignment.ALIGN_MIDDLE);
234 + private void addSection( DockPanel panel, Widget widget, DockLayoutConstant section, String width ) {
235 + panel.add( widget, section );
236 + panel.setCellWidth( widget, width );
237 + panel.setCellVerticalAlignment( widget, HasVerticalAlignment.ALIGN_MIDDLE );
278 238 }
279 239
280 - private HorizontalPanel createVerticallyCenteredHorizontalPanel(Widget... widgets) {
240 + private HorizontalPanel createVerticallyCenteredHorizontalPanel( Widget... widgets ) {
281 241 HorizontalPanel panel = new HorizontalPanel();
282 - panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
283 - for (Widget widget : widgets) {
284 - panel.add(widget);
242 + panel.setVerticalAlignment( HasVerticalAlignment.ALIGN_MIDDLE );
243 + for ( Widget widget : widgets ) {
244 + panel.add( widget );
285 245 }
286 246 return panel;
287 247 }
288 248
289 - private PushButton createPageSizeChangeButton(final int newPageSize) {
290 - return new PushButton(newPageSize + " at a time", new ClickHandler() {
291 - public void onClick(ClickEvent arg0) {
292 - setResultsPerPage(newPageSize);
249 + private PushButton createPageSizeChangeButton( final int newPageSize ) {
250 + return new PushButton( newPageSize + " at a time", new ClickHandler() {
251 + public void onClick( ClickEvent arg0 ) {
252 + setResultsPerPage( newPageSize );
293 253 resetPager();
294 254 updateTable();
295 255 }
296 - });
256 + } );
297 257 }
298 258
299 259 private Label createPagingSeparator() {
300 - Label label = new Label("|");
301 - label.setWidth("20px");
302 - label.setStylePrimaryName(INACTIVE_LINK_STYLE_NAME);
303 - label.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
260 + Label label = new Label( "|" );
261 + label.setWidth( "20px" );
262 + label.setStylePrimaryName( INACTIVE_LINK_STYLE_NAME );
263 + label.setHorizontalAlignment( HasHorizontalAlignment.ALIGN_CENTER );
304 264 return label;
305 265 }
306 266
307 267 private PushButton createNextPageLink() {
308 - PushButton button = new PushButton("Next", new ClickHandler() {
309 - public void onClick(ClickEvent event) {
310 - prevPageMarkerStack.push(currPageMarker);
268 + PushButton button = new PushButton( "Next", new ClickHandler() {
269 + public void onClick( ClickEvent event ) {
270 + prevPageMarkerStack.push( currPageMarker );
311 271 currPageMarker = nextPageMarker;
312 272 updateTable();
313 273 }
314 - });
315 - button.setStylePrimaryName(LINK_STYLE_NAME);
316 - hide(button);
274 + } );
275 + button.setStylePrimaryName( LINK_STYLE_NAME );
276 + hide( button );
317 277 return button;
318 278 }
319 279
320 280 private PushButton createPrevPageLink() {
321 - PushButton button = new PushButton("Prev", new ClickHandler() {
322 - public void onClick(ClickEvent event) {
281 + PushButton button = new PushButton( "Prev", new ClickHandler() {
282 + public void onClick( ClickEvent event ) {
323 283 currPageMarker = prevPageMarkerStack.pop();
324 284 updateTable();
325 285 }
326 - });
327 - button.setStylePrimaryName(LINK_STYLE_NAME);
328 - hide(button);
286 + } );
287 + button.setStylePrimaryName( LINK_STYLE_NAME );
288 + hide( button );
329 289 return button;
330 290 }
331 291
332 - private LoadingProgressManagingDataTable createTable(Widget loadingIndicatorWidget) {
333 - LoadingProgressManagingDataTable dataTable = new LoadingProgressManagingDataTable(resultsPerPage, loadingIndicatorWidget);
334 - dataTable.addStyleName("dataGridWidget");
292 + private LoadingProgressManagingDataTable createTable( Widget loadingIndicatorWidget ) {
293 + LoadingProgressManagingDataTable dataTable = new LoadingProgressManagingDataTable( resultsPerPage, loadingIndicatorWidget );
294 + dataTable.addStyleName( "dataGridWidget" );
335 295 return dataTable;
336 296 }
337 297
338 - private Widget finiTable(EIS_DataTable<R> dataTable, String width, String height, boolean includeRowNumber) {
339 - dataTable.addColumnSortHandler(new ColumnSortEvent.Handler() {
340 - public void onColumnSort(ColumnSortEvent sortEvent) {
341 - sortByField = columnFieldNames.get(sortEvent.getColumn());
298 + private Widget finiTable( EIS_DataTable<R> dataTable, String width, String height, boolean includeRowNumber ) {
299 + dataTable.addColumnSortHandler( new ColumnSortEvent.Handler() {
300 + public void onColumnSort( ColumnSortEvent sortEvent ) {
301 + sortByField = columnFieldNames.get( sortEvent.getColumn() );
342 302 sortDirection = sortEvent.isSortAscending() ? SortDirection.ASC
343 - : SortDirection.DESC;
303 + : SortDirection.DESC;
344 304 resetPager();
345 305 updateTable();
346 306 }
347 - });
348 - if (includeRowNumber) {
349 - this.addColumn(new Column<R, String>(new TextCell()) {
350 - public String getValue(R dataRow) {
307 + } );
308 + if ( includeRowNumber ) {
309 + this.addColumn( new Column<R, String>( new TextCell() ) {
310 + public String getValue( R dataRow ) {
351 311 return "" + dataRow.getRowNumber();
352 312 }
353 - }, "", "", ROW_NUMBER_COLUMN_WIDTH_PX, Unit.PX);
313 + }, "", "", ROW_NUMBER_COLUMN_WIDTH_PX, Unit.PX );
354 314 }
355 315 ResizeLayoutPanel tablePanel = new ResizeLayoutPanel();
356 - tablePanel.add(dataTable);
357 - tablePanel.setWidth(width);
358 - tablePanel.setHeight(height);
359 - dataTable.setWidth(width);
360 - dataTable.setHeight(height);
316 + tablePanel.add( dataTable );
317 + tablePanel.setWidth( width );
318 + tablePanel.setHeight( height );
319 + dataTable.setWidth( width );
320 + dataTable.setHeight( height );
361 321 return tablePanel;
362 322 }
363 323
364 - private HorizontalPanel createTopWidgetWidget(Widget topWidget) {
365 - if (topWidget == null) {
324 + private HorizontalPanel createTopWidgetWidget( Widget topWidget ) {
325 + if ( topWidget == null ) {
366 326 return null;
367 327 }
368 328 HorizontalPanel topWidgetPanel = new HorizontalPanel();
369 - topWidgetPanel.add(topWidget);
370 - topWidgetPanel.addStyleName(DATA_TABLE_TOP_WIDGET_PANEL_STYLE_NAME);
329 + topWidgetPanel.add( topWidget );
330 + topWidgetPanel.addStyleName( DATA_TABLE_TOP_WIDGET_PANEL_STYLE_NAME );
371 331 return topWidgetPanel;
372 332 }
373 333
374 - private void appendTo(Panel dataTableContainer, Widget widget) {
375 - if (widget != null) {
376 - dataTableContainer.add(widget);
334 + private void appendTo( Panel dataTableContainer, Widget widget ) {
335 + if ( widget != null ) {
336 + dataTableContainer.add( widget );
377 337 }
378 338 }
379 339
380 340 public void reset() {
381 - setData(null, null);
341 + setData( null, null );
382 342 resetPager();
383 - setResultsPerPage(defaultRowsPerPage);
343 + setResultsPerPage( defaultRowsPerPage );
384 344 }
385 345
386 - public void setTitle(String title) {
387 - titleLabel.setText(title);
346 + public void setTitle( String title ) {
347 + titleLabel.setText( title );
388 348 }
389 349
390 - private Widget createTableHeader(boolean includeTitleBar, String title,
391 - boolean includeDownloadCSVButton) {
392 - if (!includeTitleBar) {
350 + private Widget createTableHeader( boolean includeTitleBar, String title,
351 + boolean includeDownloadCSVButton ) {
352 + if ( !includeTitleBar ) {
393 353 return null;
394 354 }
395 355 DockPanel tableHeader = new DockPanel();
396 - tableHeader.setWidth("100%");
397 - tableHeader.setStylePrimaryName(TABLE_HEADER_PANEL_STYLE_NAME);
398 - titleLabel = new Label(title);
399 - titleLabel.setStylePrimaryName(TABLE_HEADER_STYLE_NAME);
400 - tableHeader.add(titleLabel, DockPanel.WEST);
401 - tableHeader.setCellWidth(titleLabel, "85%");
402 -
403 - if (includeDownloadCSVButton) {
404 - downloadCSVButton = new PushButton(DOWNLOAD_BUTTON_UP_IMAGE,
405 - DOWNLOAD_BUTTON_DOWN_IMAGE, new ClickHandler() {
406 - public void onClick(ClickEvent clickEvent) {
407 - if (!CollectionsUtils.isEmpty(getData())) {
408 - tableUpdater.onDataTableDownloadCSVButtonClick(clickEvent);
409 - }
410 - }
411 - });
412 - tableHeader.add(downloadCSVButton, DockPanel.EAST);
413 - tableHeader.setCellWidth(downloadCSVButton, "15%");
356 + tableHeader.setWidth( "100%" );
357 + tableHeader.setStylePrimaryName( TABLE_HEADER_PANEL_STYLE_NAME );
358 + titleLabel = new Label( title );
359 + titleLabel.setStylePrimaryName( TABLE_HEADER_STYLE_NAME );
360 + tableHeader.add( titleLabel, DockPanel.WEST );
361 + tableHeader.setCellWidth( titleLabel, "85%" );
362 +
363 + if ( includeDownloadCSVButton ) {
364 + downloadCSVButton = new PushButton( DOWNLOAD_BUTTON_UP_IMAGE,
365 + DOWNLOAD_BUTTON_DOWN_IMAGE, new ClickHandler() {
366 + public void onClick( ClickEvent clickEvent ) {
367 + if ( !CollectionsUtils.isEmpty( getData() ) ) {
368 + tableUpdater.onDataTableDownloadCSVButtonClick( clickEvent );
369 + }
370 + }
371 + } );
372 + tableHeader.add( downloadCSVButton, DockPanel.EAST );
373 + tableHeader.setCellWidth( downloadCSVButton, "15%" );
414 374 } else {
415 - Label spacer = new Label(" ");
416 - tableHeader.add(spacer, DockPanel.EAST);
417 - tableHeader.setCellWidth(spacer, "15%");
418 -
375 + Label spacer = new Label( " " );
376 + tableHeader.add( spacer, DockPanel.EAST );
377 + tableHeader.setCellWidth( spacer, "15%" );
419 378 }
420 379
421 380 HorizontalPanel tableHeaderPanel = new HorizontalPanel();
422 - tableHeaderPanel.setWidth("100%");
423 - tableHeaderPanel.addStyleName("dataTableHeaderPanel");
424 - tableHeaderPanel.add(tableHeader);
381 + tableHeaderPanel.setWidth( "100%" );
382 + tableHeaderPanel.addStyleName( "dataTableHeaderPanel" );
383 + tableHeaderPanel.add( tableHeader );
425 384 return tableHeaderPanel;
426 385 }
427 386
428 - private void setResultsPerPage(int _resultsPerPage) {
429 - show(resultsPerPagePanel);
387 + private void setResultsPerPage( int _resultsPerPage ) {
388 + show( resultsPerPagePanel );
430 389 resultsPerPage = _resultsPerPage;
431 - if (resultsPerPage == TWENTY_FIVE) {
432 - setEnabled(twentyFivePerPageLink, false);
433 - setEnabled(tenPerPageLink, true);
390 + if ( resultsPerPage == TWENTY_FIVE ) {
391 + setEnabled( twentyFivePerPageLink, false );
392 + setEnabled( tenPerPageLink, true );
434 393 } else {
435 - setEnabled(twentyFivePerPageLink, true);
436 - setEnabled(tenPerPageLink, false);
394 + setEnabled( twentyFivePerPageLink, true );
395 + setEnabled( tenPerPageLink, false );
437 396 }
438 - dataTable.setPageSize(resultsPerPage);
397 + dataTable.setPageSize( resultsPerPage );
439 398 }
440 399
441 - private void setEnabled(PushButton link, boolean enabled) {
400 + private void setEnabled( PushButton link, boolean enabled ) {
442 401 String styleName = enabled ? LINK_STYLE_NAME : INACTIVE_LINK_STYLE_NAME;
443 - link.setStyleName(styleName);
444 - link.setEnabled(enabled);
402 + link.setStyleName( styleName );
403 + link.setEnabled( enabled );
445 404 }
446 405
447 - public void redraw(){
406 + public void redraw() {
448 407 dataTable.redraw();
449 408 }
450 409
  @@ -458,44 +417,43 @@
458 417 /**
459 418 * Update the data in the table.
460 419 *
461 - * @param dataList
462 - * - the dataset
420 + * @param dataList - the dataset
463 421 */
464 - public void setData(List<R> dataList, String nextPageMarker) {
465 - setData(dataList, nextPageMarker, true);
422 + public void setData( List<R> dataList, String nextPageMarker ) {
423 + setData( dataList, nextPageMarker, true );
466 424 }
467 425
468 426 /**
469 427 * Update the data in the table.
470 428 *
471 - * @param dataList
472 - * - the dataset
429 + * @param dataList - the dataset
473 430 */
474 - public void setData(List<R> dataList, String nextPageMarker, Boolean clear) {
475 - if (Boolean.TRUE.equals(clear)) {
431 + public void setData( List<R> dataList, String nextPageMarker, Boolean clear ) {
432 + if ( Boolean.TRUE.equals( clear ) ) {
476 433 dataProvider.getList().clear();
477 434 }
478 - if (CollectionsUtils.isEmpty(dataList)) {
435 + if ( CollectionsUtils.isEmpty( dataList ) ) {
479 436 dataProvider.refresh();
480 437 resetPager();
481 - if (downloadCSVButton != null) {
482 - downloadCSVButton.setVisible(false);
438 + if ( downloadCSVButton != null ) {
439 + downloadCSVButton.setVisible( false );
483 440 }
484 441 } else {
485 442 int rowId = (prevPageMarkerStack.size() * resultsPerPage);
486 - for (R data : dataList) {
487 - data.setId(++rowId);
443 + for ( R data : dataList ) {
444 + data.setId( ++rowId );
488 445 }
489 446
490 - dataProvider.getList().addAll(dataList);
447 + dataProvider.getList().addAll( dataList );
491 448 dataProvider.refresh();
492 - if (downloadCSVButton != null) {
493 - downloadCSVButton.setVisible(true);
449 + if ( downloadCSVButton != null ) {
450 + downloadCSVButton.setVisible( true );
451 + }
452 + if ( dataList.size() >= resultsPerPage ) {
453 + setNextPageMarker( nextPageMarker );
454 + } else {
455 + setNextPageMarker( null );
494 456 }
495 - if (dataList.size() >= resultsPerPage)
496 - setNextPageMarker(nextPageMarker);
497 - else
498 - setNextPageMarker(null);
499 457 }
500 458 }
501 459
  @@ -510,8 +468,8 @@
510 468 }
511 469
512 470 @Override
513 - public void loadingCompleted(boolean successfully) {
514 - dataTable.loadingCompleted(successfully);
471 + public void loadingCompleted( boolean successfully ) {
472 + dataTable.loadingCompleted( successfully );
515 473 }
516 474
517 475 /**
  @@ -528,7 +486,7 @@
528 486 */
529 487 public void refreshTable() {
530 488 resetPager();
531 - setResultsPerPage(defaultRowsPerPage);
489 + setResultsPerPage( defaultRowsPerPage );
532 490 updateTable();
533 491 }
534 492
  @@ -558,13 +516,12 @@
558 516 /**
559 517 * Adds a column
560 518 *
561 - * @param fields
562 - * - the column / "field" definitions
519 + * @param fields - the column / "field" definitions
563 520 */
564 - public <FIELD extends DataRowField> void addColumns(FIELD... fields) {
565 - if (fields != null) {
566 - for (FIELD field : fields) {
567 - addColumn(field);
521 + public <FIELD extends DataRowField> void addColumns( FIELD... fields ) {
522 + if ( fields != null ) {
523 + for ( FIELD field : fields ) {
524 + addColumn( field );
568 525 }
569 526 }
570 527 }
  @@ -572,74 +529,66 @@
572 529 /**
573 530 * Adds a column
574 531 *
575 - * @param field
576 - * - the column or "field" definition
532 + * @param field - the column or "field" definition
577 533 */
578 - public <FIELD extends DataRowField> Column<R, ?> addColumn(FIELD field) {
579 - if (field == null) {
534 + public <FIELD extends DataRowField> Column<R, ?> addColumn( FIELD field ) {
535 + if ( field == null ) {
580 536 return null;
581 537 }
582 - F fieldAsF = ObjectUtils.cast(field);
583 - Column<R, ?> column = new TextDataColumn<R, F>(fieldAsF, field.isSortable(), field.isNumeric());
584 - addColumn(column, field);
538 + F fieldAsF = ObjectUtils.cast( field );
539 + Column<R, ?> column = new TextDataColumn<R, F>( fieldAsF, field.isSortable(), field.isNumeric() );
540 + addColumn( column, field );
585 541 return column;
586 542 }
587 543
588 544 /**
589 545 * Adds a column
590 546 *
591 - * @param column
592 - * - the column
593 - * @param field
594 - * - the column definition "field"
595 - */
596 - public <FIELD extends DataRowField> Column<R, ?> addColumn(Column<R, ?> column, FIELD field) {
597 - addTwoLineColumn(column, field.label(), field.name());
598 - setColumnWidth(column, field.getWidth(), field.getWidthUnit());
547 + * @param column - the column
548 + * @param field - the column definition "field"
549 + */
550 + public <FIELD extends DataRowField> Column<R, ?> addColumn( Column<R, ?> column, FIELD field ) {
551 + addTwoLineColumn( column, field.label(), field.name() );
552 + setColumnWidth( column, field.getWidth(), field.getWidthUnit() );
599 553 return column;
600 554 }
601 555
602 556 /**
603 557 * Adds a column
604 558 *
605 - * @param column
606 - * - the column
607 - * @param columnHeader
608 - * - the column header
559 + * @param column - the column
560 + * @param columnHeader - the column header
609 561 */
610 - public void addColumn(Column<R, ?> column, String columnHeader, String fieldName) {
611 - addTwoLineColumn(column, columnHeader, fieldName);
562 + public void addColumn( Column<R, ?> column, String columnHeader, String fieldName ) {
563 + addTwoLineColumn( column, columnHeader, fieldName );
612 564 }
613 565
614 566 /**
615 567 * Adds a column
616 568 *
617 - * @param column
618 - * - the column
619 - * @param columnHeader
620 - * - the column header
621 - */
622 - public void addColumn(Column<R, ?> column, String columnHeader,
623 - String fieldName, int width, Unit widthUnit) {
624 - addTwoLineColumn(column, columnHeader, fieldName);
625 - setColumnWidth(column, width, widthUnit);
569 + * @param column - the column
570 + * @param columnHeader - the column header
571 + */
572 + public void addColumn( Column<R, ?> column, String columnHeader,
573 + String fieldName, int width, Unit widthUnit ) {
574 + addTwoLineColumn( column, columnHeader, fieldName );
575 + setColumnWidth( column, width, widthUnit );
626 576 }
627 577
628 - public void setColumnWidth(Column<R, ?> column, int width, Unit unit) {
629 - if (width > 0) {
630 - dataTable.setColumnWidth(column, width, (unit != null) ? unit : Unit.PX);
578 + public void setColumnWidth( Column<R, ?> column, int width, Unit unit ) {
579 + if ( width > 0 ) {
580 + dataTable.setColumnWidth( column, width, (unit != null) ? unit : Unit.PX );
631 581 }
632 582 }
633 583
634 584 /**
635 585 * Sets the selection model
636 586 *
637 - * @param selectionModel
638 - * - the selection model
587 + * @param selectionModel - the selection model
639 588 */
640 - public void setSelectionModel(SelectionModel<? super R> selectionModel) {
641 - dataTable.setSelectionModel(selectionModel,
642 - DefaultSelectionEventManager.<R> createCheckboxManager());
589 + public void setSelectionModel( SelectionModel<? super R> selectionModel ) {
590 + dataTable.setSelectionModel( selectionModel,
591 + DefaultSelectionEventManager.<R>createCheckboxManager() );
643 592 }
644 593
645 594 public SelectionModel<? super R> getSelectionModel() {
  @@ -648,13 +597,13 @@
648 597
649 598 // ============ PRIVATE METHODS ================
650 599
651 - private void addTwoLineColumn(Column<R, ?> column, String columnHeader, String fieldName) {
600 + private void addTwoLineColumn( Column<R, ?> column, String columnHeader, String fieldName ) {
652 601 String trustedTwoLineHeader = "<div style='display:inline;'>" + //
653 - "<table cellpadding='0' cellspacing='0'><tr><td valign='middle' class='dataGridHeaderText'>" + //
654 - SafeHtmlizer.getInstance().noEmpty(StringUtils.deNull(columnHeader).trim().replace(' ', '\n')) + //
655 - "</td></tr></table></div>";
656 - dataTable.addColumn(column, SafeHtmlUtils.fromTrustedString(trustedTwoLineHeader));
657 - columnFieldNames.put(column, fieldName);
602 + "<table cellpadding='0' cellspacing='0'><tr><td valign='middle' class='dataGridHeaderText'>" + //
603 + SafeHtmlizer.getInstance().noEmpty( StringUtils.deNull( columnHeader ).trim().replace( ' ', '\n' ) ) + //
604 + "</td></tr></table></div>";
605 + dataTable.addColumn( column, SafeHtmlUtils.fromTrustedString( trustedTwoLineHeader ) );
606 + columnFieldNames.put( column, fieldName );
658 607 }
659 608
660 609 private void updateTable() {
  @@ -670,42 +619,42 @@
670 619 nextPageMarker = null;
671 620 }
672 621
673 - public void setNextPageMarker(String nextPageMarker) {
622 + public void setNextPageMarker( String nextPageMarker ) {
674 623 this.nextPageMarker = nextPageMarker;
675 624 boolean showNextPageLink = nextPageMarker != null;
676 625 boolean showPrevPageLink = !prevPageMarkerStack.empty();
677 - show(prevPageLink, showPrevPageLink);
678 - show(nextPageLink, showNextPageLink);
679 - show(pagingSeparatorLabel, showPrevPageLink && showNextPageLink);
626 + show( prevPageLink, showPrevPageLink );
627 + show( nextPageLink, showNextPageLink );
628 + show( pagingSeparatorLabel, showPrevPageLink && showNextPageLink );
680 629 }
681 630
682 - private void hide(Widget widget) {
683 - CommonElementHelper.hide(widget.getElement());
631 + private void hide( Widget widget ) {
632 + CommonElementHelper.hide( widget.getElement() );
684 633 }
685 634
686 - private void show(Widget widget) {
687 - CommonElementHelper.unhide(widget.getElement());
635 + private void show( Widget widget ) {
636 + CommonElementHelper.unhide( widget.getElement() );
688 637 }
689 638
690 - private void show(Widget widget, boolean visible) {
691 - CommonElementHelper.setHidden(widget.getElement(), !visible);
639 + private void show( Widget widget, boolean visible ) {
640 + CommonElementHelper.setHidden( widget.getElement(), !visible );
692 641 }
693 642
694 - private static Label createTableStateLabel(String text, String styleClassname) {
695 - Label label = new Label(text);
696 - label.setStyleName(styleClassname);
697 - label.getElement().getStyle().setMarginTop(30.0, Unit.PX);
643 + private static Label createTableStateLabel( String text, String styleClassname ) {
644 + Label label = new Label( text );
645 + label.setStyleName( styleClassname );
646 + label.getElement().getStyle().setMarginTop( 30.0, Unit.PX );
698 647 return label;
699 648 }
700 649
701 - public static String determineState(LoadingState state) {
702 - if (state == LoadingState.LOADING) {
650 + public static String determineState( LoadingState state ) {
651 + if ( state == LoadingState.LOADING ) {
703 652 return "Loading";
704 - }
705 - if (state == LoadingState.LOADED ) {
653 + }
654 + if ( state == LoadingState.LOADED ) {
706 655 return "Loaded";
707 656 }
708 - if (state == LoadingState.PARTIALLY_LOADED ) {
657 + if ( state == LoadingState.PARTIALLY_LOADED ) {
709 658 return "Partial";
710 659 }
711 660 return "????";
  @@ -713,42 +662,42 @@
713 662
714 663 private class LoadingProgressManagingDataTable extends EIS_DataTable<R> implements LoadingProgressListener {
715 664 private LoadingState expectedState = null;
716 - private Label noTableResultsLabel = createTableStateLabel(NO_RESULTS_FOUND_MESSAGE, STYLE_NO_RESULTS_FOUND_MESSAGE);
665 + private Label noTableResultsLabel = createTableStateLabel( NO_RESULTS_FOUND_MESSAGE, STYLE_NO_RESULTS_FOUND_MESSAGE );
717 666
718 - public LoadingProgressManagingDataTable(int resultsPerPage, Widget loadingIndicatorWidget) {
719 - super(resultsPerPage, //
720 - GWT.<CustomDataTableResources> create(CustomDataTableResources.class), //
721 - null, loadingIndicatorWidget);
722 - setEmptyTableWidget(noTableResultsLabel);
667 + public LoadingProgressManagingDataTable( int resultsPerPage, Widget loadingIndicatorWidget ) {
668 + super( resultsPerPage, //
669 + GWT.<CustomDataTableResources>create( CustomDataTableResources.class ), //
670 + null, loadingIndicatorWidget );
671 + setEmptyTableWidget( noTableResultsLabel );
723 672 }
724 673
725 674 @Override
726 675 public void loadingReset() {
727 - noTableResultsLabel.setText(NO_RESULTS_FOUND_INITIAL_MESSAGE);
728 - noTableResultsLabel.setStyleName(STYLE_NO_RESULTS_FOUND_INITIAL_MESSAGE);
676 + noTableResultsLabel.setText( NO_RESULTS_FOUND_INITIAL_MESSAGE );
677 + noTableResultsLabel.setStyleName( STYLE_NO_RESULTS_FOUND_INITIAL_MESSAGE );
729 678 }
730 679
731 680 @Override
732 681 public void loadingStarted() {
733 682 // System.out.print("Started: ");
734 - onLoadingStateChanged(expectedState = LoadingState.LOADING);
683 + onLoadingStateChanged( expectedState = LoadingState.LOADING );
735 684 }
736 685
737 686 @Override
738 - public void loadingCompleted(boolean successfully) {
687 + public void loadingCompleted( boolean successfully ) {
739 688 // System.out.print("Completed ("+successfully+")");
740 689
741 - noTableResultsLabel.setText(successfully ? NO_RESULTS_FOUND_SUCCESS_MESSAGE : NO_RESULTS_FOUND_ERROR_MESSAGE);
742 - noTableResultsLabel.setStyleName(successfully ? STYLE_NO_RESULTS_FOUND_SUCCESS_MESSAGE : STYLE_NO_RESULTS_FOUND_ERROR_MESSAGE);
690 + noTableResultsLabel.setText( successfully ? NO_RESULTS_FOUND_SUCCESS_MESSAGE : NO_RESULTS_FOUND_ERROR_MESSAGE );
691 + noTableResultsLabel.setStyleName( successfully ? STYLE_NO_RESULTS_FOUND_SUCCESS_MESSAGE : STYLE_NO_RESULTS_FOUND_ERROR_MESSAGE );
743 692
744 693 expectedState = null;
745 - onLoadingStateChanged(LoadingState.LOADED);
694 + onLoadingStateChanged( LoadingState.LOADED );
746 695 }
747 696
748 697 @Override
749 - public void onLoadingStateChanged(LoadingState state) {
750 - if ((expectedState == null) || (state == expectedState)) {
751 - super.onLoadingStateChanged(state);
698 + public void onLoadingStateChanged( LoadingState state ) {
699 + if ( (expectedState == null) || (state == expectedState) ) {
700 + super.onLoadingStateChanged( state );
752 701 }
753 702 // String expected = determineState( expectedState );
754 703 // String newState = determineState( state );