2 * Copyright 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client;
21 import java.util.List;
23 import com.google.gwt.user.client.ui.FlexTable;
24 import com.google.gwt.user.client.ui.ListBox;
28 * A helper class with static methods that manipulate display
29 * widgets in various useful ways, not available in GWT.
33 public class DisplayHelper {
36 * A flag that denotes that no selection should be made while
37 * displaying the rows of a table.
39 public static final int NO_SELECTION = -1;
42 * Clear any current selection in the specified ListBox.
44 public static void clearSelections(ListBox listBox) {
45 for (int i=0; i<listBox.getItemCount(); i++)
46 if (listBox.isItemSelected(i))
47 listBox.setItemSelected(i, false);
51 * Select the item in the listBox whose value matches the provided
54 public static void selectMatch(ListBox listBox, String value) {
55 for (int i=0; i<listBox.getItemCount(); i++)
56 if (listBox.getValue(i).equals(value))
57 listBox.setItemSelected(i, true);
59 listBox.setItemSelected(i, false);
63 * Select the items in the listBox whose value matches the provided
64 * value list. Every value that is matched in the listBox is removed
65 * from the value list, in order to let the caller know what values
66 * were not matched. Therefore the caller must be prepared for the
67 * value list to be modified.
69 * @param listBox the ListBox
70 * @param values the list of values to be selected
72 public static void selectMultiMatch(ListBox listBox, List values) {
73 for (int i=0; i<listBox.getItemCount(); i++)
74 if (values.contains(listBox.getValue(i))) {
75 listBox.setItemSelected(i, true);
76 values.remove(listBox.getValue(i));
78 listBox.setItemSelected(i, false);
81 public static native void log(String message) /*-{
82 var logger = $wnd.console;
83 if (logger && logger.debug)
84 logger.debug(message);
88 * Make the specified row look like selected or not, according to the
89 * <code>selected</code> flag.
91 * @param row the row number in the list of entries (i.e. ignoring the header line)
92 * @param selected the flag that denotes whether the <code>styleName</code> should
94 * @param styleName the name of the CSS style
96 public static void styleRow(final FlexTable table, final int row, final boolean selected, String styleName) {
99 table.getRowFormatter().addStyleName(row + 1, styleName);
101 table.getRowFormatter().removeStyleName(row + 1, styleName);
105 * Select the specified row in the table. This entails modifying its style
106 * as well as the style of the previously selected row.
108 * @param table the FlexTable widget
109 * @param row the newly selected row
110 * @param previousRow the previously selected row
111 * @param styleName the name of the CSS style
112 * @return the newly selected row
114 public static int selectRow(final FlexTable table, final int row, final int previousRow, String styleName) {
115 // Reset the style of the previously selected row.
116 styleRow(table, previousRow, false, styleName);
117 // Select the row that was clicked.
118 styleRow(table, row, true, styleName);