root / web_client / src / gr / grnet / pithos / web / client / DisplayHelper.java @ ab1eb3f8
History | View | Annotate | Download (4.4 kB)
1 | ab1eb3f8 | Christos Stathis | /*
|
---|---|---|---|
2 | ab1eb3f8 | Christos Stathis | * Copyright 2009, 2010 Electronic Business Systems Ltd.
|
3 | ab1eb3f8 | Christos Stathis | *
|
4 | ab1eb3f8 | Christos Stathis | * This file is part of GSS.
|
5 | ab1eb3f8 | Christos Stathis | *
|
6 | ab1eb3f8 | Christos Stathis | * GSS is free software: you can redistribute it and/or modify
|
7 | ab1eb3f8 | Christos Stathis | * it under the terms of the GNU General Public License as published by
|
8 | ab1eb3f8 | Christos Stathis | * the Free Software Foundation, either version 3 of the License, or
|
9 | ab1eb3f8 | Christos Stathis | * (at your option) any later version.
|
10 | ab1eb3f8 | Christos Stathis | *
|
11 | ab1eb3f8 | Christos Stathis | * GSS is distributed in the hope that it will be useful,
|
12 | ab1eb3f8 | Christos Stathis | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | ab1eb3f8 | Christos Stathis | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | ab1eb3f8 | Christos Stathis | * GNU General Public License for more details.
|
15 | ab1eb3f8 | Christos Stathis | *
|
16 | ab1eb3f8 | Christos Stathis | * You should have received a copy of the GNU General Public License
|
17 | ab1eb3f8 | Christos Stathis | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | ab1eb3f8 | Christos Stathis | */
|
19 | ab1eb3f8 | Christos Stathis | package gr.grnet.pithos.web.client; |
20 | ab1eb3f8 | Christos Stathis | |
21 | ab1eb3f8 | Christos Stathis | import java.util.List; |
22 | ab1eb3f8 | Christos Stathis | |
23 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.FlexTable; |
24 | ab1eb3f8 | Christos Stathis | import com.google.gwt.user.client.ui.ListBox; |
25 | ab1eb3f8 | Christos Stathis | |
26 | ab1eb3f8 | Christos Stathis | |
27 | ab1eb3f8 | Christos Stathis | /**
|
28 | ab1eb3f8 | Christos Stathis | * A helper class with static methods that manipulate display
|
29 | ab1eb3f8 | Christos Stathis | * widgets in various useful ways, not available in GWT.
|
30 | ab1eb3f8 | Christos Stathis | *
|
31 | ab1eb3f8 | Christos Stathis | * @author past
|
32 | ab1eb3f8 | Christos Stathis | */
|
33 | ab1eb3f8 | Christos Stathis | public class DisplayHelper { |
34 | ab1eb3f8 | Christos Stathis | |
35 | ab1eb3f8 | Christos Stathis | /**
|
36 | ab1eb3f8 | Christos Stathis | * A flag that denotes that no selection should be made while
|
37 | ab1eb3f8 | Christos Stathis | * displaying the rows of a table.
|
38 | ab1eb3f8 | Christos Stathis | */
|
39 | ab1eb3f8 | Christos Stathis | public static final int NO_SELECTION = -1; |
40 | ab1eb3f8 | Christos Stathis | |
41 | ab1eb3f8 | Christos Stathis | /**
|
42 | ab1eb3f8 | Christos Stathis | * Clear any current selection in the specified ListBox.
|
43 | ab1eb3f8 | Christos Stathis | */
|
44 | ab1eb3f8 | Christos Stathis | public static void clearSelections(ListBox listBox) { |
45 | ab1eb3f8 | Christos Stathis | for (int i=0; i<listBox.getItemCount(); i++) |
46 | ab1eb3f8 | Christos Stathis | if (listBox.isItemSelected(i))
|
47 | ab1eb3f8 | Christos Stathis | listBox.setItemSelected(i, false);
|
48 | ab1eb3f8 | Christos Stathis | } |
49 | ab1eb3f8 | Christos Stathis | |
50 | ab1eb3f8 | Christos Stathis | /**
|
51 | ab1eb3f8 | Christos Stathis | * Select the item in the listBox whose value matches the provided
|
52 | ab1eb3f8 | Christos Stathis | * value.
|
53 | ab1eb3f8 | Christos Stathis | */
|
54 | ab1eb3f8 | Christos Stathis | public static void selectMatch(ListBox listBox, String value) { |
55 | ab1eb3f8 | Christos Stathis | for (int i=0; i<listBox.getItemCount(); i++) |
56 | ab1eb3f8 | Christos Stathis | if (listBox.getValue(i).equals(value))
|
57 | ab1eb3f8 | Christos Stathis | listBox.setItemSelected(i, true);
|
58 | ab1eb3f8 | Christos Stathis | else
|
59 | ab1eb3f8 | Christos Stathis | listBox.setItemSelected(i, false);
|
60 | ab1eb3f8 | Christos Stathis | } |
61 | ab1eb3f8 | Christos Stathis | |
62 | ab1eb3f8 | Christos Stathis | /**
|
63 | ab1eb3f8 | Christos Stathis | * Select the items in the listBox whose value matches the provided
|
64 | ab1eb3f8 | Christos Stathis | * value list. Every value that is matched in the listBox is removed
|
65 | ab1eb3f8 | Christos Stathis | * from the value list, in order to let the caller know what values
|
66 | ab1eb3f8 | Christos Stathis | * were not matched. Therefore the caller must be prepared for the
|
67 | ab1eb3f8 | Christos Stathis | * value list to be modified.
|
68 | ab1eb3f8 | Christos Stathis | *
|
69 | ab1eb3f8 | Christos Stathis | * @param listBox the ListBox
|
70 | ab1eb3f8 | Christos Stathis | * @param values the list of values to be selected
|
71 | ab1eb3f8 | Christos Stathis | */
|
72 | ab1eb3f8 | Christos Stathis | public static void selectMultiMatch(ListBox listBox, List values) { |
73 | ab1eb3f8 | Christos Stathis | for (int i=0; i<listBox.getItemCount(); i++) |
74 | ab1eb3f8 | Christos Stathis | if (values.contains(listBox.getValue(i))) {
|
75 | ab1eb3f8 | Christos Stathis | listBox.setItemSelected(i, true);
|
76 | ab1eb3f8 | Christos Stathis | values.remove(listBox.getValue(i)); |
77 | ab1eb3f8 | Christos Stathis | } else
|
78 | ab1eb3f8 | Christos Stathis | listBox.setItemSelected(i, false);
|
79 | ab1eb3f8 | Christos Stathis | } |
80 | ab1eb3f8 | Christos Stathis | |
81 | ab1eb3f8 | Christos Stathis | public static native void log(String message) /*-{ |
82 | ab1eb3f8 | Christos Stathis | var logger = $wnd.console;
|
83 | ab1eb3f8 | Christos Stathis | if (logger && logger.debug)
|
84 | ab1eb3f8 | Christos Stathis | logger.debug(message);
|
85 | ab1eb3f8 | Christos Stathis | else if (logger && logger.log)
|
86 | ab1eb3f8 | Christos Stathis | logger.log(message);
|
87 | ab1eb3f8 | Christos Stathis | }-*/;
|
88 | ab1eb3f8 | Christos Stathis | |
89 | ab1eb3f8 | Christos Stathis | /**
|
90 | ab1eb3f8 | Christos Stathis | * Make the specified row look like selected or not, according to the
|
91 | ab1eb3f8 | Christos Stathis | * <code>selected</code> flag.
|
92 | ab1eb3f8 | Christos Stathis | *
|
93 | ab1eb3f8 | Christos Stathis | * @param row the row number in the list of entries (i.e. ignoring the header line)
|
94 | ab1eb3f8 | Christos Stathis | * @param selected the flag that denotes whether the <code>styleName</code> should
|
95 | ab1eb3f8 | Christos Stathis | * be added or removed
|
96 | ab1eb3f8 | Christos Stathis | * @param styleName the name of the CSS style
|
97 | ab1eb3f8 | Christos Stathis | */
|
98 | ab1eb3f8 | Christos Stathis | public static void styleRow(final FlexTable table, final int row, final boolean selected, String styleName) { |
99 | ab1eb3f8 | Christos Stathis | if (row != -1) |
100 | ab1eb3f8 | Christos Stathis | if (selected)
|
101 | ab1eb3f8 | Christos Stathis | table.getRowFormatter().addStyleName(row + 1, styleName);
|
102 | ab1eb3f8 | Christos Stathis | else
|
103 | ab1eb3f8 | Christos Stathis | table.getRowFormatter().removeStyleName(row + 1, styleName);
|
104 | ab1eb3f8 | Christos Stathis | } |
105 | ab1eb3f8 | Christos Stathis | |
106 | ab1eb3f8 | Christos Stathis | /**
|
107 | ab1eb3f8 | Christos Stathis | * Select the specified row in the table. This entails modifying its style
|
108 | ab1eb3f8 | Christos Stathis | * as well as the style of the previously selected row.
|
109 | ab1eb3f8 | Christos Stathis | *
|
110 | ab1eb3f8 | Christos Stathis | * @param table the FlexTable widget
|
111 | ab1eb3f8 | Christos Stathis | * @param row the newly selected row
|
112 | ab1eb3f8 | Christos Stathis | * @param previousRow the previously selected row
|
113 | ab1eb3f8 | Christos Stathis | * @param styleName the name of the CSS style
|
114 | ab1eb3f8 | Christos Stathis | * @return the newly selected row
|
115 | ab1eb3f8 | Christos Stathis | */
|
116 | ab1eb3f8 | Christos Stathis | public static int selectRow(final FlexTable table, final int row, final int previousRow, String styleName) { |
117 | ab1eb3f8 | Christos Stathis | // Reset the style of the previously selected row.
|
118 | ab1eb3f8 | Christos Stathis | styleRow(table, previousRow, false, styleName);
|
119 | ab1eb3f8 | Christos Stathis | // Select the row that was clicked.
|
120 | ab1eb3f8 | Christos Stathis | styleRow(table, row, true, styleName);
|
121 | ab1eb3f8 | Christos Stathis | return row;
|
122 | ab1eb3f8 | Christos Stathis | } |
123 | ab1eb3f8 | Christos Stathis | /**
|
124 | ab1eb3f8 | Christos Stathis | * The implementation of this trim method also checks for
|
125 | ab1eb3f8 | Christos Stathis | * no brake space characters (nbsp) = '\00A0'
|
126 | ab1eb3f8 | Christos Stathis | * and removes them
|
127 | ab1eb3f8 | Christos Stathis | *
|
128 | ab1eb3f8 | Christos Stathis | * @param input
|
129 | ab1eb3f8 | Christos Stathis | * @return the new trimmed string without whitespace or no brake space
|
130 | ab1eb3f8 | Christos Stathis | */
|
131 | ab1eb3f8 | Christos Stathis | public static native String trim(String input) /*-{ |
132 | ab1eb3f8 | Christos Stathis | if(input.length == 0)
|
133 | ab1eb3f8 | Christos Stathis | return input;
|
134 | ab1eb3f8 | Christos Stathis | if((input[0]||input[input.length-1]) != '\u0020' && (input[0]||input[input.length-1]) != '\u00A0')
|
135 | ab1eb3f8 | Christos Stathis | return input;
|
136 | ab1eb3f8 | Christos Stathis | var r1 = input.replace(/^(\s*)/, '');
|
137 | ab1eb3f8 | Christos Stathis | var r2 = r1.replace(/\s*$/, '');
|
138 | ab1eb3f8 | Christos Stathis | return r2;
|
139 | ab1eb3f8 | Christos Stathis | }-*/;
|
140 | ab1eb3f8 | Christos Stathis | |
141 | ab1eb3f8 | Christos Stathis | } |