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 |
//
|
|
15 |
|
|
16 |
package com.symbian.smt.gui.smtwidgets;
|
|
17 |
|
|
18 |
import java.util.ArrayList;
|
|
19 |
import java.util.List;
|
|
20 |
import java.util.regex.Matcher;
|
|
21 |
import java.util.regex.Pattern;
|
|
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.layout.RowLayout;
|
|
30 |
import org.eclipse.swt.widgets.Button;
|
|
31 |
import org.eclipse.swt.widgets.Composite;
|
|
32 |
import org.eclipse.swt.widgets.Group;
|
|
33 |
import org.eclipse.swt.widgets.Label;
|
|
34 |
import org.eclipse.swt.widgets.Text;
|
|
35 |
|
|
36 |
import com.symbian.smt.gui.smtwidgets.ValidModelEvent.Type;
|
|
37 |
|
|
38 |
public class BuildControlWidget extends Composite implements
|
|
39 |
ValidModelObservable {
|
|
40 |
private Text outputFilenameText;
|
|
41 |
private List<ValidModelDefinedListener> listeners = new ArrayList<ValidModelDefinedListener>();
|
|
42 |
|
|
43 |
private Button warningLevel1, warningLevel2, warningLevel3, warningLevel4;
|
|
44 |
|
|
45 |
// private String message;
|
|
46 |
|
|
47 |
private static final Pattern validationPattern = Pattern
|
|
48 |
.compile("[^:*?<>\"/\\\\|]*");
|
|
49 |
|
|
50 |
/**
|
|
51 |
* Creates a BuildControlWidget composite object
|
|
52 |
*
|
|
53 |
* @return void
|
|
54 |
*/
|
|
55 |
public BuildControlWidget(final Composite parent, int style,
|
|
56 |
boolean allOptions) {
|
|
57 |
super(parent, style);
|
|
58 |
|
|
59 |
setLayout(new FillLayout());
|
|
60 |
|
|
61 |
final Composite gridLayoutComposite = new Composite(this, SWT.NONE);
|
|
62 |
gridLayoutComposite.setLayout(new GridLayout(2, false));
|
|
63 |
|
|
64 |
final Label outputFilenameLabel = new Label(gridLayoutComposite,
|
|
65 |
SWT.NONE);
|
|
66 |
outputFilenameLabel.setText("Output filename");
|
|
67 |
|
|
68 |
outputFilenameText = new Text(gridLayoutComposite, SWT.BORDER);
|
|
69 |
outputFilenameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
|
|
70 |
true, false));
|
|
71 |
|
|
72 |
outputFilenameText.addModifyListener(new ModifyListener() {
|
|
73 |
public void modifyText(ModifyEvent e) {
|
|
74 |
checkIfValid();
|
|
75 |
}
|
|
76 |
});
|
|
77 |
|
|
78 |
if (allOptions) {
|
|
79 |
Group group = new Group(gridLayoutComposite, SWT.SHADOW_ETCHED_IN);
|
|
80 |
group.setText("Warning level");
|
|
81 |
group.setLayout(new RowLayout(SWT.VERTICAL));
|
|
82 |
group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
|
|
83 |
2, 1));
|
|
84 |
|
|
85 |
warningLevel1 = new Button(group, SWT.RADIO);
|
|
86 |
warningLevel1.setText("Errors only");
|
|
87 |
warningLevel2 = new Button(group, SWT.RADIO);
|
|
88 |
warningLevel2.setText("Errors and warnings");
|
|
89 |
warningLevel3 = new Button(group, SWT.RADIO);
|
|
90 |
warningLevel3.setText("Verbose");
|
|
91 |
warningLevel4 = new Button(group, SWT.RADIO);
|
|
92 |
warningLevel4.setText("Debug (note: will increase build times)");
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Registers a listener object, which will be notified if the conditions for
|
|
98 |
* proceeding have been met.
|
|
99 |
*
|
|
100 |
* @param listener
|
|
101 |
* A ValidModelDefinedListener object
|
|
102 |
* @return void
|
|
103 |
* @see com.symbian.smt.gui.smtwidgets.ValidModelObservable#addModelListener(ValidModelDefinedListener)
|
|
104 |
*/
|
|
105 |
public void addModelListener(ValidModelDefinedListener listener) {
|
|
106 |
listeners.add(listener);
|
|
107 |
}
|
|
108 |
|
|
109 |
// Check that at least one system definition file has been specified. Any
|
|
110 |
// registered
|
|
111 |
// model listeners are notified with a ValidModelEvent.
|
|
112 |
private void checkIfValid() {
|
|
113 |
if (listeners.size() > 0) {
|
|
114 |
String text = outputFilenameText.getText().trim();
|
|
115 |
String message = "";
|
|
116 |
boolean valid = true;
|
|
117 |
Type type = Type.SUCCESS;
|
|
118 |
|
|
119 |
if (text.length() == 0) {
|
|
120 |
valid = false;
|
|
121 |
message = "Filename must be specified.";
|
|
122 |
type = Type.ERROR;
|
|
123 |
}
|
|
124 |
|
|
125 |
Matcher matcher = validationPattern.matcher(text);
|
|
126 |
matcher.reset();
|
|
127 |
|
|
128 |
if (!matcher.matches()) {
|
|
129 |
valid = false;
|
|
130 |
message = "Forbidden characters in output filename.";
|
|
131 |
type = Type.ERROR;
|
|
132 |
}
|
|
133 |
|
|
134 |
ValidModelEvent event = new ValidModelEvent(valid, message, type);
|
|
135 |
|
|
136 |
for (ValidModelDefinedListener listener : listeners) {
|
|
137 |
listener.validModelDefined(event);
|
|
138 |
}
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
/**
|
|
143 |
* This method is for testing purposes only.
|
|
144 |
*
|
|
145 |
* @return
|
|
146 |
*/
|
|
147 |
public List<ValidModelDefinedListener> getModelListeners() {
|
|
148 |
List<ValidModelDefinedListener> l;
|
|
149 |
|
|
150 |
synchronized (listeners) {
|
|
151 |
l = new ArrayList<ValidModelDefinedListener>(listeners);
|
|
152 |
}
|
|
153 |
|
|
154 |
return l;
|
|
155 |
}
|
|
156 |
|
|
157 |
public String getOutputFilename() {
|
|
158 |
|
|
159 |
String entry = outputFilenameText.getText().trim();
|
|
160 |
|
|
161 |
if (entry.length() > 0) {
|
|
162 |
if (!entry.endsWith(".svg")) {
|
|
163 |
return entry + ".svg";
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
return entry;
|
|
168 |
}
|
|
169 |
|
|
170 |
public String getWarningLevel() {
|
|
171 |
if (warningLevel1.getSelection()) {
|
|
172 |
return "1";
|
|
173 |
} else if (warningLevel2.getSelection()) {
|
|
174 |
return "2";
|
|
175 |
} else if (warningLevel3.getSelection()) {
|
|
176 |
return "3";
|
|
177 |
} else if (warningLevel4.getSelection()) {
|
|
178 |
return "4";
|
|
179 |
} else {
|
|
180 |
return null;
|
|
181 |
}
|
|
182 |
}
|
|
183 |
|
|
184 |
/**
|
|
185 |
* @see com.symbian.smt.gui.smtwidgets.ValidModelObservable#removeModelListener(ValidModelDefinedListener)
|
|
186 |
*/
|
|
187 |
public void removeModelListener(ValidModelDefinedListener listener) {
|
|
188 |
synchronized (listeners) {
|
|
189 |
listeners.remove(listener);
|
|
190 |
}
|
|
191 |
}
|
|
192 |
|
|
193 |
public void setOutputFilename(String arg) {
|
|
194 |
outputFilenameText.setText(arg);
|
|
195 |
}
|
|
196 |
|
|
197 |
public void setWarningLevel(String arg) {
|
|
198 |
if ("1".equals(arg)) {
|
|
199 |
warningLevel1.setSelection(true);
|
|
200 |
} else if ("2".equals(arg)) {
|
|
201 |
warningLevel2.setSelection(true);
|
|
202 |
} else if ("3".equals(arg)) {
|
|
203 |
warningLevel3.setSelection(true);
|
|
204 |
} else if ("4".equals(arg)) {
|
|
205 |
warningLevel4.setSelection(true);
|
|
206 |
}
|
|
207 |
}
|
|
208 |
|
|
209 |
// public String getMessage() {
|
|
210 |
// return message;
|
|
211 |
// }
|
|
212 |
}
|