Use SSL transport all over the place, for the production deployment.
[pithos] / src / gr / ebs / gss / client / DisplayHelper.java
1 /*
2  * Copyright 2009 Electronic Business Systems Ltd.
3  *
4  * This file is part of GSS.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 package gr.ebs.gss.client;
20
21 import java.util.List;
22
23 import com.google.gwt.user.client.ui.FlexTable;
24 import com.google.gwt.user.client.ui.ListBox;
25
26
27 /**
28  * A helper class with static methods that manipulate display
29  * widgets in various useful ways, not available in GWT.
30  *
31  * @author past
32  */
33 public class DisplayHelper {
34
35         /**
36          * A flag that denotes that no selection should be made while
37          * displaying the rows of a table.
38          */
39         public static final int NO_SELECTION = -1;
40
41         /**
42          * Clear any current selection in the specified ListBox.
43          */
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);
48         }
49
50         /**
51          * Select the item in the listBox whose value matches the provided
52          * value.
53          */
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);
58                         else
59                                 listBox.setItemSelected(i, false);
60         }
61
62         /**
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.
68          *
69          * @param listBox the ListBox
70          * @param values the list of values to be selected
71          */
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));
77                         } else
78                                 listBox.setItemSelected(i, false);
79         }
80
81         public static native void log(String message) /*-{
82                 var logger = $wnd.console;
83                 if (logger && logger.debug)
84                         logger.debug(message);
85         }-*/;
86
87         /**
88          * Make the specified row look like selected or not, according to the
89          * <code>selected</code> flag.
90          *
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
93          *                              be added or removed
94          * @param styleName the name of the CSS style
95          */
96         public static void styleRow(final FlexTable table, final int row, final boolean selected, String styleName) {
97                 if (row != -1)
98                         if (selected)
99                                 table.getRowFormatter().addStyleName(row + 1, styleName);
100                         else
101                                 table.getRowFormatter().removeStyleName(row + 1, styleName);
102         }
103
104         /**
105          * Select the specified row in the table. This entails modifying its style
106          * as well as the style of the previously selected row.
107          *
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
113          */
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);
119                 return row;
120         }
121
122 }