0
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.s60tools.imaker;
|
|
19 |
|
|
20 |
|
2
|
21 |
import java.lang.reflect.InvocationTargetException;
|
0
|
22 |
import java.util.ArrayList;
|
|
23 |
import java.util.Collections;
|
|
24 |
import java.util.HashSet;
|
|
25 |
import java.util.Iterator;
|
|
26 |
import java.util.List;
|
|
27 |
import java.util.Set;
|
|
28 |
import java.util.StringTokenizer;
|
|
29 |
|
2
|
30 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
31 |
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
|
32 |
import org.eclipse.jface.operation.IRunnableWithProgress;
|
|
33 |
import org.eclipse.swt.widgets.Display;
|
|
34 |
import org.eclipse.ui.PlatformUI;
|
|
35 |
|
|
36 |
import com.nokia.s60tools.imaker.exceptions.IMakerCoreExecutionException;
|
|
37 |
import com.nokia.s60tools.imaker.exceptions.IMakerCoreNotFoundException;
|
0
|
38 |
import com.nokia.s60tools.imaker.internal.iqrf.Configuration;
|
|
39 |
import com.nokia.s60tools.imaker.internal.iqrf.ConfigurationElement;
|
|
40 |
import com.nokia.s60tools.imaker.internal.iqrf.Setting;
|
|
41 |
import com.nokia.s60tools.imaker.internal.iqrf.Target;
|
|
42 |
import com.nokia.s60tools.imaker.internal.viewers.ISettingViewer;
|
|
43 |
import com.nokia.s60tools.imaker.internal.wrapper.IMakerWrapperPreferences;
|
|
44 |
|
|
45 |
/**
|
|
46 |
* Class represents a simple container for data presented in Configuration,
|
|
47 |
* Target and Setting objects (EMF). It only contains the most needed data
|
|
48 |
* to be used in upper layers (UI).
|
|
49 |
*
|
|
50 |
*/
|
|
51 |
public class UIConfiguration {
|
|
52 |
// public static final HashMap<String,String> UI_TARGETS = new HashMap<String,String>();
|
|
53 |
// static {
|
|
54 |
// UI_TARGETS.put("all",null);
|
|
55 |
// UI_TARGETS.put("core",null);
|
|
56 |
// UI_TARGETS.put("flash",null);
|
|
57 |
// UI_TARGETS.put("image",null);
|
|
58 |
// UI_TARGETS.put("mmc",null);
|
|
59 |
// UI_TARGETS.put("rofs2",null);
|
|
60 |
// UI_TARGETS.put("rofs3",null);
|
|
61 |
// UI_TARGETS.put("rofs4",null);
|
|
62 |
// UI_TARGETS.put("uda",null);
|
|
63 |
// UI_TARGETS.put("udaerase",null);
|
|
64 |
// UI_TARGETS.put("variant",null);
|
|
65 |
// UI_TARGETS.put("default",null);
|
|
66 |
// };
|
|
67 |
/** Private instance variables */
|
|
68 |
private String productName = null;
|
|
69 |
private String platformName = null;
|
|
70 |
private String makeFileName = null;
|
|
71 |
private String filePath = null;
|
|
72 |
private String defaultHWID = null;
|
|
73 |
private List<String> hwids = null;
|
|
74 |
private List<UITarget> targets = null;
|
|
75 |
private List<UIVariable> variables = null;
|
|
76 |
private boolean defaultConfig = false;
|
|
77 |
|
|
78 |
|
|
79 |
private Set<ISettingViewer> changeListeners = new HashSet<ISettingViewer>();
|
2
|
80 |
private IIMakerWrapper wrapper;
|
|
81 |
private boolean loaded = false;
|
0
|
82 |
|
|
83 |
/**
|
|
84 |
* Default constructor. Gets a Configuration object as a parameter
|
|
85 |
* and goes through it to find the needed data.
|
|
86 |
*
|
|
87 |
* @param conf Configuration object to analyze
|
2
|
88 |
* @param wrapper
|
0
|
89 |
*/
|
2
|
90 |
public UIConfiguration(Configuration conf, IIMakerWrapper wrapper) {
|
|
91 |
this.wrapper = wrapper;
|
0
|
92 |
if (conf != null) {
|
|
93 |
makeFileName = conf.getName();
|
|
94 |
filePath = conf.getFilePath();
|
|
95 |
targets = new ArrayList<UITarget>();
|
|
96 |
variables = new ArrayList<UIVariable>();
|
|
97 |
Target target;
|
|
98 |
|
|
99 |
Iterator<Target> targetIter = conf.getTargetrefs().iterator();
|
|
100 |
|
|
101 |
// Go through targets.
|
|
102 |
while((targetIter != null) && targetIter.hasNext()) {
|
|
103 |
target = targetIter.next();
|
|
104 |
targets.add(new UITarget(target.getName(), target.getDescription()));
|
|
105 |
}
|
|
106 |
|
|
107 |
Iterator<Setting> settingIter = conf.getSettings().iterator();
|
|
108 |
|
|
109 |
// Go through settings.
|
|
110 |
while((settingIter != null) && settingIter.hasNext()) {
|
|
111 |
Setting set = settingIter.next();
|
|
112 |
ConfigurationElement element = set.getRef();
|
|
113 |
String name = set.getName();
|
|
114 |
if (name==null) continue;
|
|
115 |
String value = name.toLowerCase();
|
|
116 |
String elementName = element.getName().toLowerCase();
|
|
117 |
|
|
118 |
// Is setting a product name
|
|
119 |
if ((value != null) && (set != null) && (elementName != null)) {
|
|
120 |
// Put setting into variable list
|
|
121 |
UIVariable var = new UIVariable(name, set.getValue(),
|
|
122 |
"variable", element.getDescription(), element.getValues());
|
|
123 |
variables.add(var);
|
|
124 |
|
|
125 |
if (elementName.equals(IMakerWrapperPreferences.PRODUCT_NAME)) {
|
|
126 |
productName = set.getValue();
|
|
127 |
} else if (elementName.equals(IMakerWrapperPreferences.COREPLATFORM_NAME) ||
|
|
128 |
elementName.equals(IMakerWrapperPreferences.UIPLATFORM_NAME)) {
|
|
129 |
// Is setting a platform name
|
|
130 |
platformName = set.getValue();
|
|
131 |
} else if (elementName.equals(IMakerWrapperPreferences.HWID)) {
|
|
132 |
hwids = new ArrayList<String>();
|
|
133 |
StringTokenizer tokenizer = new StringTokenizer(set.getValue(),
|
|
134 |
IMakerWrapperPreferences.HWID_DELIMITER);
|
|
135 |
// Tokenize the list of HWIDs and loop through it.
|
|
136 |
// Search for a default HWID which is marked by
|
|
137 |
// a special character at the end of it.
|
|
138 |
while (tokenizer.hasMoreTokens()) {
|
|
139 |
String token = tokenizer.nextToken();
|
|
140 |
if ((token != null) && (token.charAt(
|
|
141 |
token.length()-1) ==
|
|
142 |
IMakerWrapperPreferences.HWID_DEFAULT_MARKER)) {
|
|
143 |
token = token.substring(0, token.length()-1);
|
|
144 |
defaultHWID = token;
|
|
145 |
}
|
|
146 |
token = token.trim();
|
|
147 |
hwids.add(token);
|
|
148 |
if ((defaultHWID == null) || defaultHWID.equals("")) {
|
|
149 |
defaultHWID = token;
|
|
150 |
}
|
|
151 |
}
|
|
152 |
Collections.sort(hwids);
|
|
153 |
}
|
|
154 |
} else {
|
|
155 |
// Something else found entirely?
|
|
156 |
}
|
|
157 |
}
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
public boolean isDefaultConfig() {
|
|
162 |
return defaultConfig;
|
|
163 |
}
|
|
164 |
|
|
165 |
public void setDefaultConfig(boolean def) {
|
|
166 |
this.defaultConfig = def;
|
|
167 |
}
|
|
168 |
|
|
169 |
public String getDefaultTarget() {
|
|
170 |
for (UITarget target : getAllTargets()) {
|
|
171 |
if(target.getName().equals("default")) {
|
|
172 |
return target.getName();
|
|
173 |
}
|
|
174 |
}
|
|
175 |
return null;
|
|
176 |
}
|
|
177 |
|
|
178 |
/**
|
|
179 |
* Get method for productName
|
|
180 |
*
|
|
181 |
* @return name of the product
|
|
182 |
*/
|
|
183 |
public String getProductName() {
|
|
184 |
return productName;
|
|
185 |
}
|
|
186 |
|
|
187 |
/**
|
|
188 |
* Get method for makeFileName
|
|
189 |
*
|
|
190 |
* @return name of the makefile
|
|
191 |
*/
|
|
192 |
public String getMakeFileName() {
|
|
193 |
return makeFileName;
|
|
194 |
}
|
|
195 |
|
|
196 |
/**
|
|
197 |
* Get method for filePath
|
|
198 |
*
|
|
199 |
* @return file path
|
|
200 |
*/
|
|
201 |
public String getFilePath() {
|
|
202 |
return filePath;
|
|
203 |
}
|
|
204 |
|
|
205 |
/**
|
|
206 |
* Get method for default HWID
|
|
207 |
*
|
|
208 |
* @return default HWID
|
|
209 |
*/
|
|
210 |
public String getDefaultHWID() {
|
|
211 |
return defaultHWID;
|
|
212 |
}
|
|
213 |
|
|
214 |
/**
|
|
215 |
* Get method for target names
|
|
216 |
*
|
|
217 |
* @return list of targets
|
|
218 |
*/
|
|
219 |
public List<UITarget> getAllTargets() {
|
|
220 |
return targets;
|
|
221 |
}
|
|
222 |
|
|
223 |
/**
|
|
224 |
* Get method for variables
|
|
225 |
*
|
|
226 |
* @return list of variables.
|
|
227 |
*/
|
|
228 |
public List<UIVariable> getVariables() {
|
|
229 |
return variables;
|
|
230 |
}
|
|
231 |
|
|
232 |
/**
|
|
233 |
* Get method for HWIDs
|
|
234 |
*
|
|
235 |
* @return a list of HWIDs
|
|
236 |
*/
|
|
237 |
public List<String> getHWIDs() {
|
|
238 |
return hwids;
|
|
239 |
}
|
|
240 |
|
|
241 |
/**
|
|
242 |
* Get platform name
|
|
243 |
*
|
|
244 |
* @return name of the platform
|
|
245 |
*/
|
|
246 |
public String getPlatformName() {
|
|
247 |
return platformName;
|
|
248 |
}
|
|
249 |
|
|
250 |
public void removeChangeListener(ISettingViewer viewer) {
|
|
251 |
changeListeners.remove(viewer);
|
|
252 |
}
|
|
253 |
|
|
254 |
public void addChangeListener(ISettingViewer viewer) {
|
|
255 |
changeListeners.add(viewer);
|
|
256 |
}
|
|
257 |
|
|
258 |
public void variableChanged(UIVariable variable) {
|
|
259 |
Iterator<ISettingViewer> iterator = changeListeners.iterator();
|
|
260 |
while (iterator.hasNext())
|
|
261 |
iterator.next().updateVariable(variable);
|
|
262 |
}
|
|
263 |
|
|
264 |
public String toString() {
|
|
265 |
StringBuffer out = new StringBuffer();
|
|
266 |
for(UIVariable v: variables) {
|
|
267 |
if(v.isModified()) {
|
|
268 |
out.append(v.toString()+"\n");
|
|
269 |
}
|
|
270 |
}
|
|
271 |
return out.toString();
|
|
272 |
}
|
|
273 |
|
|
274 |
public void setTargets(List<UITarget> targets) {
|
|
275 |
this.targets=targets;
|
|
276 |
}
|
|
277 |
|
|
278 |
public void setVariables(List<UIVariable> variables) {
|
|
279 |
this.variables=variables;
|
|
280 |
}
|
|
281 |
|
|
282 |
public String getConfigurationName() {
|
|
283 |
String path = getFilePath();
|
|
284 |
String start = "image_conf_";
|
|
285 |
int index = path.indexOf(start);
|
|
286 |
return path.substring(index+start.length(), path.length()-3);
|
|
287 |
}
|
|
288 |
|
|
289 |
public List<UITarget> getFilteredTargets() {
|
|
290 |
// List<UITarget> temp = new ArrayList<UITarget>();
|
|
291 |
return getAllTargets();
|
|
292 |
//
|
|
293 |
// String name = null;
|
|
294 |
// for (UITarget target : all) {
|
|
295 |
// name = target.getName();
|
|
296 |
// if(UI_TARGETS.containsKey(name)) {
|
|
297 |
// UI_TARGETS.put(name, target.getDescription());
|
|
298 |
// temp.add(target);
|
|
299 |
// }
|
|
300 |
// }
|
|
301 |
// return temp;
|
|
302 |
}
|
|
303 |
|
|
304 |
public boolean isPlatsimConfiguration() {
|
|
305 |
List<UIVariable> vars = this.getVariables();
|
|
306 |
for (UIVariable var : vars) {
|
|
307 |
if(var.getName().equals(IMakerWrapperPreferences.USE_PLATSIM)) {
|
|
308 |
String value = var.getValue();
|
|
309 |
return (value.equals("1"))?true:false;
|
|
310 |
}
|
|
311 |
}
|
|
312 |
return false;
|
|
313 |
}
|
|
314 |
|
|
315 |
public UITarget getTarget(String name) {
|
|
316 |
for (UITarget t: getAllTargets()) {
|
|
317 |
if(name.equals(t.getName())) {
|
|
318 |
return t;
|
|
319 |
}
|
|
320 |
}
|
|
321 |
return null;
|
2
|
322 |
}
|
|
323 |
|
|
324 |
public void load() throws Throwable {
|
|
325 |
if(loaded ) {
|
|
326 |
return;
|
|
327 |
}
|
|
328 |
Display display = PlatformUI.getWorkbench().getDisplay();
|
|
329 |
IRunnableWithProgress op = new IMakerCoreRunnable();
|
|
330 |
ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(display.getActiveShell());
|
|
331 |
try {
|
|
332 |
progressMonitorDialog.run(true, false, op);
|
|
333 |
} catch (InvocationTargetException e) {
|
|
334 |
throw e.getTargetException();
|
|
335 |
} catch (InterruptedException e) {
|
|
336 |
throw e;
|
|
337 |
}
|
|
338 |
loaded=true;
|
|
339 |
}
|
|
340 |
|
|
341 |
private class IMakerCoreRunnable implements IRunnableWithProgress {
|
|
342 |
public void run(IProgressMonitor monitor)
|
|
343 |
throws InvocationTargetException, InterruptedException {
|
|
344 |
try {
|
|
345 |
List<UIConfiguration> confs = wrapper.getConfigurations(monitor,getFilePath());
|
|
346 |
if(!confs.isEmpty()) {
|
|
347 |
UIConfiguration configuration = confs.get(0);
|
|
348 |
targets.clear();
|
|
349 |
targets.addAll(configuration.getAllTargets());
|
|
350 |
variables.clear();
|
|
351 |
variables.addAll(configuration.getVariables());
|
|
352 |
makeFileName = configuration.getConfigurationName();
|
|
353 |
filePath = configuration.getFilePath();
|
|
354 |
productName = configuration.getProductName();
|
|
355 |
platformName = configuration.getPlatformName();
|
|
356 |
}
|
|
357 |
} catch (IMakerCoreExecutionException e) {
|
|
358 |
InvocationTargetException te = new InvocationTargetException(e);
|
|
359 |
throw te;
|
|
360 |
} catch (IMakerCoreNotFoundException e) {
|
|
361 |
InvocationTargetException te = new InvocationTargetException(e);
|
|
362 |
throw te;
|
|
363 |
}
|
|
364 |
}
|
|
365 |
}
|
0
|
366 |
}
|