0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// ${file_name}
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
package com.symbian.smt.gui.smtwidgets;
|
|
19 |
|
|
20 |
import java.util.ArrayList;
|
|
21 |
import java.util.List;
|
|
22 |
|
|
23 |
import org.eclipse.swt.SWT;
|
|
24 |
import org.eclipse.swt.events.ModifyEvent;
|
|
25 |
import org.eclipse.swt.events.ModifyListener;
|
|
26 |
import org.eclipse.swt.layout.FillLayout;
|
|
27 |
import org.eclipse.swt.layout.GridData;
|
|
28 |
import org.eclipse.swt.layout.GridLayout;
|
|
29 |
import org.eclipse.swt.widgets.Combo;
|
|
30 |
import org.eclipse.swt.widgets.Composite;
|
|
31 |
import org.eclipse.swt.widgets.Label;
|
|
32 |
import org.eclipse.swt.widgets.Text;
|
|
33 |
|
|
34 |
import com.symbian.smt.gui.Helper;
|
|
35 |
import com.symbian.smt.gui.PersistentDataStore;
|
|
36 |
import com.symbian.smt.gui.smtwidgets.ValidModelEvent.Type;
|
|
37 |
|
|
38 |
public class ModelLabelsWidget extends Composite implements
|
|
39 |
ValidModelObservable {
|
|
40 |
private Combo distributionTextCombo;
|
|
41 |
private Text modelVersionText;
|
|
42 |
private Text systemVersionText;
|
|
43 |
private Text copyrightTextText;
|
|
44 |
private Combo modelVersionTextCombo;
|
|
45 |
private Text modelNameText;
|
|
46 |
private Text systemNameText;
|
|
47 |
private ArrayList<ValidModelDefinedListener> listeners = new ArrayList<ValidModelDefinedListener>();
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Creates a ModelLabelsWidget composite object
|
|
51 |
*
|
|
52 |
* @return void
|
|
53 |
*/
|
|
54 |
public ModelLabelsWidget(final Composite parent, int style) {
|
|
55 |
super(parent, style);
|
|
56 |
|
|
57 |
this.setLayout(new FillLayout());
|
|
58 |
|
|
59 |
final Composite gridLayoutComposite = new Composite(this, SWT.NONE);
|
|
60 |
final GridLayout gridLayout = new GridLayout();
|
|
61 |
gridLayout.numColumns = 4;
|
|
62 |
gridLayoutComposite.setLayout(gridLayout);
|
|
63 |
|
|
64 |
final Label systemNameLabel = new Label(gridLayoutComposite, SWT.NONE);
|
|
65 |
systemNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
|
|
66 |
false));
|
|
67 |
systemNameLabel.setText("System Name");
|
|
68 |
|
|
69 |
systemNameText = new Text(gridLayoutComposite, SWT.BORDER);
|
|
70 |
systemNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
|
|
71 |
false));
|
|
72 |
|
|
73 |
final Label systemVersionLabel = new Label(gridLayoutComposite,
|
|
74 |
SWT.NONE);
|
|
75 |
systemVersionLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
|
|
76 |
false, false));
|
|
77 |
systemVersionLabel.setText("System Version");
|
|
78 |
|
|
79 |
systemVersionText = new Text(gridLayoutComposite, SWT.BORDER);
|
|
80 |
systemVersionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
|
|
81 |
true, false));
|
|
82 |
|
|
83 |
final Label modelNameLabel = new Label(gridLayoutComposite, SWT.NONE);
|
|
84 |
modelNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
|
|
85 |
false));
|
|
86 |
modelNameLabel.setText("Model Name");
|
|
87 |
|
|
88 |
modelNameText = new Text(gridLayoutComposite, SWT.BORDER);
|
|
89 |
modelNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
|
|
90 |
false));
|
|
91 |
|
|
92 |
final Label modelVersionLabel = new Label(gridLayoutComposite, SWT.NONE);
|
|
93 |
modelVersionLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
|
|
94 |
false, false));
|
|
95 |
modelVersionLabel.setText("Model Version");
|
|
96 |
|
|
97 |
modelVersionText = new Text(gridLayoutComposite, SWT.BORDER);
|
|
98 |
modelVersionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
|
|
99 |
false));
|
|
100 |
|
|
101 |
final Label modelVersionTextLabel = new Label(gridLayoutComposite,
|
|
102 |
SWT.NONE);
|
|
103 |
modelVersionTextLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
|
|
104 |
false, false));
|
|
105 |
modelVersionTextLabel.setText("Model Version Text");
|
|
106 |
|
|
107 |
modelVersionTextCombo = new Combo(gridLayoutComposite, SWT.NONE);
|
|
108 |
modelVersionTextCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
|
|
109 |
true, false));
|
|
110 |
|
|
111 |
final Label distributionTextLabel = new Label(gridLayoutComposite,
|
|
112 |
SWT.NONE);
|
|
113 |
distributionTextLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER,
|
|
114 |
false, false));
|
|
115 |
distributionTextLabel.setText("Distribution Text");
|
|
116 |
|
|
117 |
distributionTextCombo = new Combo(gridLayoutComposite, SWT.NONE);
|
|
118 |
distributionTextCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
|
|
119 |
true, false));
|
|
120 |
|
|
121 |
final Label copyrightTextLabel = new Label(gridLayoutComposite,
|
|
122 |
SWT.NONE);
|
|
123 |
copyrightTextLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
|
|
124 |
false, false));
|
|
125 |
copyrightTextLabel.setText("Copyright Text");
|
|
126 |
|
|
127 |
copyrightTextText = new Text(gridLayoutComposite, SWT.BORDER);
|
|
128 |
copyrightTextText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
|
|
129 |
true, false));
|
|
130 |
}
|
|
131 |
|
|
132 |
/**
|
|
133 |
* @see com.symbian.smt.gui.smtwidgets.ValidModelObservable#addModelListener(ValidModelDefinedListener)
|
|
134 |
*/
|
|
135 |
public void addModelListener(ValidModelDefinedListener listener) {
|
|
136 |
synchronized (listeners) {
|
|
137 |
listeners.add(listener);
|
|
138 |
}
|
|
139 |
}
|
|
140 |
|
|
141 |
private void checkDistributionText() {
|
|
142 |
if (listeners.size() > 0) {
|
|
143 |
Boolean modelDefined = true;
|
|
144 |
String message = "";
|
|
145 |
Type type = Type.SUCCESS;
|
|
146 |
|
|
147 |
String text = distributionTextCombo.getText().trim();
|
|
148 |
|
|
149 |
if (text.length() > 0) {
|
|
150 |
// TODO:BRS:Specify any validation here, such as what to do with
|
|
151 |
// the empty string
|
|
152 |
// if (xxx) {
|
|
153 |
// modelDefined = false;
|
|
154 |
// message =
|
|
155 |
// "";
|
|
156 |
// type = Type.ERROR;
|
|
157 |
// }
|
|
158 |
}
|
|
159 |
|
|
160 |
ValidModelEvent event = new ValidModelEvent(modelDefined, message,
|
|
161 |
type);
|
|
162 |
|
|
163 |
for (ValidModelDefinedListener listener : listeners) {
|
|
164 |
listener.validModelDefined(event);
|
|
165 |
}
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
private void checkModelVersionText() {
|
|
170 |
if (listeners.size() > 0) {
|
|
171 |
Boolean modelDefined = true;
|
|
172 |
String message = "";
|
|
173 |
Type type = Type.SUCCESS;
|
|
174 |
|
|
175 |
String text = modelVersionTextCombo.getText().trim();
|
|
176 |
|
|
177 |
if (text.length() > 0) {
|
|
178 |
// TODO:BRS:Specify any validation here, such as what to do with
|
|
179 |
// the empty string
|
|
180 |
// if (xxx) {
|
|
181 |
// modelDefined = false;
|
|
182 |
// message =
|
|
183 |
// "";
|
|
184 |
// type = Type.ERROR;
|
|
185 |
// }
|
|
186 |
}
|
|
187 |
|
|
188 |
ValidModelEvent event = new ValidModelEvent(modelDefined, message,
|
|
189 |
type);
|
|
190 |
|
|
191 |
for (ValidModelDefinedListener listener : listeners) {
|
|
192 |
listener.validModelDefined(event);
|
|
193 |
}
|
|
194 |
}
|
|
195 |
}
|
|
196 |
|
|
197 |
/**
|
|
198 |
* Returns the copyright text
|
|
199 |
*
|
|
200 |
* @return String
|
|
201 |
*/
|
|
202 |
public String getCopyrightText() {
|
|
203 |
return copyrightTextText.getText();
|
|
204 |
}
|
|
205 |
|
|
206 |
/**
|
|
207 |
* Returns the distribution text values
|
|
208 |
*
|
|
209 |
* @return String[]
|
|
210 |
*/
|
|
211 |
public String[] getDistributionTexts() {
|
|
212 |
List<String> items = Helper.toListOfStrings(distributionTextCombo
|
|
213 |
.getItems());
|
|
214 |
String text = distributionTextCombo.getText().trim();
|
|
215 |
|
|
216 |
if (text.length() > 0) {
|
|
217 |
if (!items.contains(text)) {
|
|
218 |
items.add(0, text);
|
|
219 |
}
|
|
220 |
}
|
|
221 |
|
|
222 |
return items.toArray(new String[items.size()]);
|
|
223 |
}
|
|
224 |
|
|
225 |
/**
|
|
226 |
* Returns the model name
|
|
227 |
*
|
|
228 |
* @return String
|
|
229 |
*/
|
|
230 |
public String getModelName() {
|
|
231 |
return modelNameText.getText();
|
|
232 |
}
|
|
233 |
|
|
234 |
/**
|
|
235 |
* Returns the text for the model version
|
|
236 |
*
|
|
237 |
* @return String
|
|
238 |
*/
|
|
239 |
public String getModelVersion() {
|
|
240 |
return modelVersionText.getText();
|
|
241 |
}
|
|
242 |
|
|
243 |
/**
|
|
244 |
* Returns the model version text values
|
|
245 |
*
|
|
246 |
* @return String[]
|
|
247 |
*/
|
|
248 |
public String[] getModelVersionTexts() {
|
|
249 |
List<String> items = Helper.toListOfStrings(modelVersionTextCombo
|
|
250 |
.getItems());
|
|
251 |
String text = modelVersionTextCombo.getText().trim();
|
|
252 |
|
|
253 |
if (text.length() > 0) {
|
|
254 |
if (!items.contains(text)) {
|
|
255 |
items.add(0, text);
|
|
256 |
}
|
|
257 |
}
|
|
258 |
|
|
259 |
return items.toArray(new String[items.size()]);
|
|
260 |
}
|
|
261 |
|
|
262 |
/**
|
|
263 |
* Returns the selected distribution text value
|
|
264 |
*
|
|
265 |
* @return String
|
|
266 |
*/
|
|
267 |
public String getSelectedDistributionText() {
|
|
268 |
return distributionTextCombo.getText();
|
|
269 |
}
|
|
270 |
|
|
271 |
/**
|
|
272 |
* Returns the selected model version text value
|
|
273 |
*
|
|
274 |
* @return String
|
|
275 |
*/
|
|
276 |
public String getSelectedModelVersionText() {
|
|
277 |
return modelVersionTextCombo.getText();
|
|
278 |
}
|
|
279 |
|
|
280 |
/**
|
|
281 |
* Returns the system name
|
|
282 |
*
|
|
283 |
* @return String
|
|
284 |
*/
|
|
285 |
public String getSystemName() {
|
|
286 |
return systemNameText.getText();
|
|
287 |
}
|
|
288 |
|
|
289 |
/**
|
|
290 |
* Returns the text for the system version
|
|
291 |
*
|
|
292 |
* @return String
|
|
293 |
*/
|
|
294 |
public String getSystemVersion() {
|
|
295 |
return systemVersionText.getText();
|
|
296 |
}
|
|
297 |
|
|
298 |
public void initialiseDistributionText(PersistentDataStore store) {
|
|
299 |
distributionTextCombo.setItems(store.getDistributionTexts());
|
|
300 |
distributionTextCombo.setText(store.getSelectedDistributionText());
|
|
301 |
|
|
302 |
distributionTextCombo.addModifyListener(new ModifyListener() {
|
|
303 |
public void modifyText(ModifyEvent e) {
|
|
304 |
checkDistributionText();
|
|
305 |
}
|
|
306 |
});
|
|
307 |
}
|
|
308 |
|
|
309 |
public void initialiseModelVersionText(PersistentDataStore store) {
|
|
310 |
modelVersionTextCombo.setItems(store.getModelVersionTexts());
|
|
311 |
modelVersionTextCombo.setText(store.getSelectedModelVersionText());
|
|
312 |
|
|
313 |
modelVersionTextCombo.addModifyListener(new ModifyListener() {
|
|
314 |
public void modifyText(ModifyEvent e) {
|
|
315 |
checkModelVersionText();
|
|
316 |
}
|
|
317 |
});
|
|
318 |
}
|
|
319 |
|
|
320 |
/**
|
|
321 |
* @see com.symbian.smt.gui.smtwidgets.ValidModelObservable#removeModelListener(ValidModelDefinedListener)
|
|
322 |
*/
|
|
323 |
public void removeModelListener(ValidModelDefinedListener listener) {
|
|
324 |
synchronized (listeners) {
|
|
325 |
listeners.remove(listener);
|
|
326 |
}
|
|
327 |
}
|
|
328 |
|
|
329 |
/**
|
|
330 |
* Sets the text for the copyright text
|
|
331 |
*
|
|
332 |
* @param copyrightText
|
|
333 |
* String to be used for the copyright text
|
|
334 |
* @return void
|
|
335 |
*/
|
|
336 |
public void setCopyrightText(String copyrightText) {
|
|
337 |
copyrightTextText.setText(copyrightText);
|
|
338 |
}
|
|
339 |
|
|
340 |
/**
|
|
341 |
* Sets the values for the distribution text combo
|
|
342 |
*
|
|
343 |
* @param distributionText
|
|
344 |
* String array to be used for the distribution text values
|
|
345 |
* @return void
|
|
346 |
*/
|
|
347 |
public void setDistributionTexts(String[] distributionTexts) {
|
|
348 |
distributionTextCombo.setItems(distributionTexts);
|
|
349 |
}
|
|
350 |
|
|
351 |
/**
|
|
352 |
* Sets the text for the model name
|
|
353 |
*
|
|
354 |
* @param modelName
|
|
355 |
* String to be used for the model name
|
|
356 |
* @return void
|
|
357 |
*/
|
|
358 |
public void setModelName(String modelName) {
|
|
359 |
modelNameText.setText(modelName);
|
|
360 |
}
|
|
361 |
|
|
362 |
/**
|
|
363 |
* Sets the text for the model version
|
|
364 |
*
|
|
365 |
* @param modelVersion
|
|
366 |
* String to be used for the model version
|
|
367 |
* @return void
|
|
368 |
*/
|
|
369 |
public void setModelVersion(String modelVersion) {
|
|
370 |
modelVersionText.setText(modelVersion);
|
|
371 |
}
|
|
372 |
|
|
373 |
/**
|
|
374 |
* Sets the items for the model version text combo
|
|
375 |
*
|
|
376 |
* @param modelVersionTexts
|
|
377 |
* values of the model version text
|
|
378 |
* @return void
|
|
379 |
*/
|
|
380 |
public void setModelVersionTexts(String[] modelVersionTexts) {
|
|
381 |
modelVersionTextCombo.setItems(modelVersionTexts);
|
|
382 |
}
|
|
383 |
|
|
384 |
/**
|
|
385 |
* Sets the selected distribution text value
|
|
386 |
*
|
|
387 |
* @param distributionText
|
|
388 |
* The distribution text value to set as selected.
|
|
389 |
* @return void
|
|
390 |
*/
|
|
391 |
public void setSelectedDistributionText(String distributionText) {
|
|
392 |
String[] items = distributionTextCombo.getItems();
|
|
393 |
int index = 0;
|
|
394 |
|
|
395 |
for (String item : items) {
|
|
396 |
if (item.equals(distributionText)) {
|
|
397 |
break;
|
|
398 |
}
|
|
399 |
|
|
400 |
index++;
|
|
401 |
}
|
|
402 |
|
|
403 |
distributionTextCombo.select(index);
|
|
404 |
}
|
|
405 |
|
|
406 |
/**
|
|
407 |
* Sets the selected model version text value
|
|
408 |
*
|
|
409 |
* @param modelVersionText
|
|
410 |
* The model version text value to set as selected.
|
|
411 |
* @return void
|
|
412 |
*/
|
|
413 |
public void setSelectedModelVersionText(String modelVersionText) {
|
|
414 |
String[] items = modelVersionTextCombo.getItems();
|
|
415 |
int index = 0;
|
|
416 |
|
|
417 |
for (String item : items) {
|
|
418 |
if (item.equals(modelVersionText)) {
|
|
419 |
break;
|
|
420 |
}
|
|
421 |
|
|
422 |
index++;
|
|
423 |
}
|
|
424 |
|
|
425 |
modelVersionTextCombo.select(index);
|
|
426 |
}
|
|
427 |
|
|
428 |
/**
|
|
429 |
* Sets the text for the system name
|
|
430 |
*
|
|
431 |
* @param systemName
|
|
432 |
* String to be used for the system name
|
|
433 |
* @return void
|
|
434 |
*/
|
|
435 |
public void setSystemName(String systemName) {
|
|
436 |
systemNameText.setText(systemName);
|
|
437 |
}
|
|
438 |
|
|
439 |
/**
|
|
440 |
* Sets the text for the system version
|
|
441 |
*
|
|
442 |
* @param systemVersion
|
|
443 |
* String to be used for the system version
|
|
444 |
* @return void
|
|
445 |
*/
|
|
446 |
public void setSystemVersion(String systemVersion) {
|
|
447 |
systemVersionText.setText(systemVersion);
|
|
448 |
}
|
|
449 |
}
|