diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:36:50 +0100 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 15:25:03 +0100 |
commit | 41ac47d732eed8392d60d0f6773e5a279d49b999 (patch) | |
tree | cf19d099db9cfdb8d73aa21c31e7aa1cc86ff860 /plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java | |
download | eclipse-poky-juno-master.tar.gz |
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java')
-rw-r--r-- | plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java | 262 |
1 files changed, 262 insertions, 0 deletions
diff --git a/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java new file mode 100644 index 0000000..810a014 --- /dev/null +++ b/plugins/org.yocto.bc.ui/src/org/yocto/bc/ui/wizards/variable/VariablePage.java | |||
@@ -0,0 +1,262 @@ | |||
1 | package org.yocto.bc.ui.wizards.variable; | ||
2 | |||
3 | import java.util.Comparator; | ||
4 | import java.util.Map; | ||
5 | |||
6 | import org.eclipse.jface.viewers.ILabelProviderListener; | ||
7 | import org.eclipse.jface.viewers.IStructuredContentProvider; | ||
8 | import org.eclipse.jface.viewers.ITableLabelProvider; | ||
9 | import org.eclipse.jface.viewers.TableViewer; | ||
10 | import org.eclipse.jface.viewers.Viewer; | ||
11 | import org.eclipse.jface.viewers.ViewerFilter; | ||
12 | import org.eclipse.jface.viewers.ViewerSorter; | ||
13 | import org.eclipse.swt.SWT; | ||
14 | import org.eclipse.swt.events.SelectionAdapter; | ||
15 | import org.eclipse.swt.events.SelectionEvent; | ||
16 | import org.eclipse.swt.graphics.Image; | ||
17 | import org.eclipse.swt.layout.GridData; | ||
18 | import org.eclipse.swt.layout.GridLayout; | ||
19 | import org.eclipse.swt.widgets.Composite; | ||
20 | import org.eclipse.swt.widgets.Table; | ||
21 | import org.eclipse.swt.widgets.TableColumn; | ||
22 | import org.eclipse.swt.widgets.Text; | ||
23 | |||
24 | import org.yocto.bc.ui.wizards.FiniteStateWizardPage; | ||
25 | |||
26 | /** | ||
27 | * The wizard page for the Variable Wizard. | ||
28 | * @author kgilmer | ||
29 | * | ||
30 | */ | ||
31 | public class VariablePage extends FiniteStateWizardPage { | ||
32 | |||
33 | private Text txtName; | ||
34 | private Text txtValue; | ||
35 | private TableViewer viewer; | ||
36 | private TableColumn c1; | ||
37 | private TableColumn c2; | ||
38 | |||
39 | protected VariablePage(Map model) { | ||
40 | super("Yocto Project BitBake Commander", model); | ||
41 | setTitle("Yocto Project BitBake Variable Viewer"); | ||
42 | setDescription("Sort and fitler global BitBake variables by name or value."); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public void createControl(Composite parent) { | ||
47 | Composite top = new Composite(parent, SWT.None); | ||
48 | top.setLayout(new GridLayout(2, true)); | ||
49 | top.setLayoutData(new GridData(GridData.FILL_BOTH)); | ||
50 | |||
51 | ValidationListener listener = new ValidationListener(); | ||
52 | |||
53 | txtName = new Text(top, SWT.BORDER); | ||
54 | txtName.addModifyListener(listener); | ||
55 | txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | ||
56 | |||
57 | txtValue = new Text(top, SWT.BORDER); | ||
58 | txtValue.addModifyListener(listener); | ||
59 | txtValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | ||
60 | |||
61 | viewer = new TableViewer(top); | ||
62 | |||
63 | Table table = viewer.getTable(); | ||
64 | table.setLinesVisible(true); | ||
65 | table.setHeaderVisible(true); | ||
66 | GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); | ||
67 | data.heightHint = 200; | ||
68 | data.horizontalSpan = 2; | ||
69 | table.setLayoutData(data); | ||
70 | c1 = new TableColumn(table, SWT.NONE); | ||
71 | c1.setText("Name"); | ||
72 | c1.setWidth(200); | ||
73 | c1.addSelectionListener(new SelectionAdapter() { | ||
74 | public void widgetSelected(SelectionEvent event) { | ||
75 | ((VariableViewerSorter) viewer.getSorter()).doSort(0); | ||
76 | viewer.refresh(); | ||
77 | } | ||
78 | }); | ||
79 | |||
80 | c2 = new TableColumn(table, SWT.NONE); | ||
81 | c2.setText("Value"); | ||
82 | c2.setWidth(200); | ||
83 | c2.addSelectionListener(new SelectionAdapter() { | ||
84 | public void widgetSelected(SelectionEvent event) { | ||
85 | ((VariableViewerSorter) viewer.getSorter()).doSort(1); | ||
86 | viewer.refresh(); | ||
87 | } | ||
88 | }); | ||
89 | |||
90 | viewer.setContentProvider(new VariableContentProvider()); | ||
91 | viewer.setLabelProvider(new VariableLabelProvider()); | ||
92 | viewer.setSorter(new VariableViewerSorter()); | ||
93 | |||
94 | viewer.setFilters(new ViewerFilter[] {new MapViewerFilter()}); | ||
95 | setControl(top); | ||
96 | } | ||
97 | |||
98 | @Override | ||
99 | public void pageCleanup() { | ||
100 | |||
101 | } | ||
102 | |||
103 | @Override | ||
104 | public void pageDisplay() { | ||
105 | viewer.setInput(model); | ||
106 | } | ||
107 | |||
108 | @Override | ||
109 | protected void updateModel() { | ||
110 | viewer.refresh(); | ||
111 | } | ||
112 | |||
113 | @Override | ||
114 | protected boolean validatePage() { | ||
115 | return true; | ||
116 | } | ||
117 | |||
118 | /** | ||
119 | * A content provider for the variable wizard dialog. | ||
120 | * @author kgilmer | ||
121 | * | ||
122 | */ | ||
123 | private class VariableContentProvider implements IStructuredContentProvider { | ||
124 | |||
125 | public Object[] getElements(Object inputElement) { | ||
126 | return model.keySet().toArray(); | ||
127 | } | ||
128 | |||
129 | public void dispose() { | ||
130 | |||
131 | } | ||
132 | |||
133 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | ||
134 | |||
135 | } | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * A label provider for variable wizard dialog. | ||
140 | * @author kgilmer | ||
141 | * | ||
142 | */ | ||
143 | private class VariableLabelProvider implements ITableLabelProvider { | ||
144 | |||
145 | public Image getColumnImage(Object element, int columnIndex) { | ||
146 | return null; | ||
147 | } | ||
148 | |||
149 | public String getColumnText(Object element, int columnIndex) { | ||
150 | String val; | ||
151 | |||
152 | switch (columnIndex) { | ||
153 | case 0: | ||
154 | val = element.toString(); | ||
155 | break; | ||
156 | case 1: | ||
157 | val = (String) model.get(element); | ||
158 | break; | ||
159 | default: | ||
160 | val = ""; | ||
161 | break; | ||
162 | } | ||
163 | |||
164 | return val; | ||
165 | } | ||
166 | |||
167 | public void addListener(ILabelProviderListener listener) { | ||
168 | |||
169 | } | ||
170 | |||
171 | public void dispose() { | ||
172 | |||
173 | } | ||
174 | |||
175 | public boolean isLabelProperty(Object element, String property) { | ||
176 | return false; | ||
177 | } | ||
178 | |||
179 | public void removeListener(ILabelProviderListener listener) { | ||
180 | |||
181 | } | ||
182 | |||
183 | } | ||
184 | |||
185 | /** | ||
186 | * | ||
187 | * A tableviewer sorter found on the internet. | ||
188 | * | ||
189 | */ | ||
190 | class VariableViewerSorter extends ViewerSorter { | ||
191 | private static final int ASCENDING = 0; | ||
192 | |||
193 | private static final int DESCENDING = 1; | ||
194 | |||
195 | private int column; | ||
196 | |||
197 | private int direction; | ||
198 | |||
199 | public void doSort(int column) { | ||
200 | if (column == this.column) { | ||
201 | // Same column as last sort; toggle the direction | ||
202 | direction = 1 - direction; | ||
203 | } else { | ||
204 | // New column; do an ascending sort | ||
205 | this.column = column; | ||
206 | direction = ASCENDING; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | public int compare(Viewer viewer, Object e1, Object e2) { | ||
211 | int rc = 0; | ||
212 | Comparator c = this.getComparator(); | ||
213 | // Determine which column and do the appropriate sort | ||
214 | switch (column) { | ||
215 | case 0: | ||
216 | rc = c.compare(e1, e2); | ||
217 | break; | ||
218 | case 1: | ||
219 | rc = c.compare(model.get(e1), model.get(e2)); | ||
220 | break; | ||
221 | } | ||
222 | |||
223 | // If descending order, flip the direction | ||
224 | if (direction == DESCENDING) | ||
225 | rc = -rc; | ||
226 | |||
227 | return rc; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * A filter for the name/value model. | ||
233 | * @author kgilmer | ||
234 | * | ||
235 | */ | ||
236 | private class MapViewerFilter extends ViewerFilter { | ||
237 | |||
238 | public MapViewerFilter() { | ||
239 | } | ||
240 | |||
241 | @Override | ||
242 | public boolean select(Viewer viewer, Object parentElement, Object element) { | ||
243 | String keyFilter = txtName.getText(); | ||
244 | String valFilter = txtValue.getText(); | ||
245 | |||
246 | String elem = (String) element; | ||
247 | String val = (String) model.get(element); | ||
248 | |||
249 | if (keyFilter.length() > 0 && elem.indexOf(keyFilter) == -1 ) { | ||
250 | return false; | ||
251 | } | ||
252 | |||
253 | if (valFilter.length() > 0 && val.indexOf(valFilter) == -1 ) { | ||
254 | return false; | ||
255 | } | ||
256 | |||
257 | return true; | ||
258 | } | ||
259 | |||
260 | } | ||
261 | |||
262 | } | ||