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 $wnd.console.debug(message);
111 * Make the specified row look like selected or not, according to the
112 * <code>selected</code> flag.
114 * @param row the row number in the list of entries (i.e. ignoring the header line)
115 * @param selected the flag that denotes whether the <code>styleName</code> should
116 * be added or removed
117 * @param styleName the name of the CSS style
119 public static void styleRow(final FlexTable table, final int row, final boolean selected, String styleName) {
122 table.getRowFormatter().addStyleName(row + 1, styleName);
124 table.getRowFormatter().removeStyleName(row + 1, styleName);
128 * Select the specified row in the table. This entails modifying its style
129 * as well as the style of the previously selected row.
131 * @param table the FlexTable widget
132 * @param row the newly selected row
133 * @param previousRow the previously selected row
134 * @param styleName the name of the CSS style
135 * @return the newly selected row
137 public static int selectRow(final FlexTable table, final int row, final int previousRow, String styleName) {
138 // Reset the style of the previously selected row.
139 styleRow(table, previousRow, false, styleName);
140 // Select the row that was clicked.
141 styleRow(table, row, true, styleName);