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;
25 import com.google.gwt.user.client.ui.SuggestBox;
29 * A helper class with static methods that manipulate display
30 * widgets in various useful ways, not available in GWT.
34 public class DisplayHelper {
37 * A flag that denotes that no selection should be made while
38 * displaying the rows of a table.
40 public static final int NO_SELECTION = -1;
43 * Hide the SuggestBox's PopupPanel before updating the oracle suggestions.
44 * Since SuggestBox is not meant to be extended and its internals are
45 * inaccessible, we have to resort to JSNI to call the required methods.
47 * @param sb the SuggestBox whose panel will be hidden
49 public static final native void hideSuggestions(SuggestBox sb) /*-{
50 sb.@com.google.gwt.user.client.ui.SuggestBox::suggestionPopup.@com.google.gwt.user.client.ui.PopupPanel::hide()();
51 sb.@com.google.gwt.user.client.ui.SuggestBox::suggestionMenu.@com.google.gwt.user.client.ui.MenuBar::clearItems()();
55 * Display the SuggestBox's PopupPanel after updating the oracle suggestions.
56 * Since SuggestBox is not meant to be extended and its internals are
57 * inaccessible, we have to resort to JSNI to call the required method.
59 * @param sb the SuggestBox whose panel will be shown
60 * @param query the query whose suggestions will be shown
62 public static final native void showSuggestions(SuggestBox sb, String query) /*-{
63 sb.@com.google.gwt.user.client.ui.SuggestBox::showSuggestions(Ljava/lang/String;)(query);
67 * Clear any current selection in the specified ListBox.
69 public static void clearSelections(ListBox listBox) {
70 for (int i=0; i<listBox.getItemCount(); i++)
71 if (listBox.isItemSelected(i))
72 listBox.setItemSelected(i, false);
76 * Select the item in the listBox whose value matches the provided
79 public static void selectMatch(ListBox listBox, String value) {
80 for (int i=0; i<listBox.getItemCount(); i++)
81 if (listBox.getValue(i).equals(value))
82 listBox.setItemSelected(i, true);
84 listBox.setItemSelected(i, false);
88 * Select the items in the listBox whose value matches the provided
89 * value list. Every value that is matched in the listBox is removed
90 * from the value list, in order to let the caller know what values
91 * were not matched. Therefore the caller must be prepared for the
92 * value list to be modified.
94 * @param listBox the ListBox
95 * @param values the list of values to be selected
97 public static void selectMultiMatch(ListBox listBox, List values) {
98 for (int i=0; i<listBox.getItemCount(); i++)
99 if (values.contains(listBox.getValue(i))) {
100 listBox.setItemSelected(i, true);
101 values.remove(listBox.getValue(i));
103 listBox.setItemSelected(i, false);
106 public static native void log(String message) /*-{
107 var logger = $wnd.console;
108 if (logger && logger.debug)
109 logger.debug(message);
113 * Make the specified row look like selected or not, according to the
114 * <code>selected</code> flag.
116 * @param row the row number in the list of entries (i.e. ignoring the header line)
117 * @param selected the flag that denotes whether the <code>styleName</code> should
118 * be added or removed
119 * @param styleName the name of the CSS style
121 public static void styleRow(final FlexTable table, final int row, final boolean selected, String styleName) {
124 table.getRowFormatter().addStyleName(row + 1, styleName);
126 table.getRowFormatter().removeStyleName(row + 1, styleName);
130 * Select the specified row in the table. This entails modifying its style
131 * as well as the style of the previously selected row.
133 * @param table the FlexTable widget
134 * @param row the newly selected row
135 * @param previousRow the previously selected row
136 * @param styleName the name of the CSS style
137 * @return the newly selected row
139 public static int selectRow(final FlexTable table, final int row, final int previousRow, String styleName) {
140 // Reset the style of the previously selected row.
141 styleRow(table, previousRow, false, styleName);
142 // Select the row that was clicked.
143 styleRow(table, row, true, styleName);