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