2 * Copyright 2009, 2010 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);
85 else if (logger && logger.log)
90 * Make the specified row look like selected or not, according to the
91 * <code>selected</code> flag.
93 * @param row the row number in the list of entries (i.e. ignoring the header line)
94 * @param selected the flag that denotes whether the <code>styleName</code> should
96 * @param styleName the name of the CSS style
98 public static void styleRow(final FlexTable table, final int row, final boolean selected, String styleName) {
101 table.getRowFormatter().addStyleName(row + 1, styleName);
103 table.getRowFormatter().removeStyleName(row + 1, styleName);
107 * Select the specified row in the table. This entails modifying its style
108 * as well as the style of the previously selected row.
110 * @param table the FlexTable widget
111 * @param row the newly selected row
112 * @param previousRow the previously selected row
113 * @param styleName the name of the CSS style
114 * @return the newly selected row
116 public static int selectRow(final FlexTable table, final int row, final int previousRow, String styleName) {
117 // Reset the style of the previously selected row.
118 styleRow(table, previousRow, false, styleName);
119 // Select the row that was clicked.
120 styleRow(table, row, true, styleName);
124 * The implementation of this trim method also checks for
125 * no brake space characters (nbsp) = '\00A0'
129 * @return the new trimmed string without whitespace or no brake space
131 public static native String trim(String input) /*-{
132 if(input.length == 0)
134 if((input[0]||input[input.length-1]) != '\u0020' && (input[0]||input[input.length-1]) != '\u00A0')
136 var r1 = input.replace(/^(\s*)/, '');
137 var r2 = r1.replace(/\s*$/, '');