16 */ |
16 */ |
17 |
17 |
18 package com.nokia.s60tools.imaker; |
18 package com.nokia.s60tools.imaker; |
19 |
19 |
20 |
20 |
|
21 import java.lang.reflect.InvocationTargetException; |
21 import java.util.ArrayList; |
22 import java.util.ArrayList; |
22 import java.util.Collections; |
23 import java.util.Collections; |
23 import java.util.HashSet; |
24 import java.util.HashSet; |
24 import java.util.Iterator; |
25 import java.util.Iterator; |
25 import java.util.List; |
26 import java.util.List; |
26 import java.util.Set; |
27 import java.util.Set; |
27 import java.util.StringTokenizer; |
28 import java.util.StringTokenizer; |
28 |
29 |
|
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; |
29 import com.nokia.s60tools.imaker.internal.iqrf.Configuration; |
38 import com.nokia.s60tools.imaker.internal.iqrf.Configuration; |
30 import com.nokia.s60tools.imaker.internal.iqrf.ConfigurationElement; |
39 import com.nokia.s60tools.imaker.internal.iqrf.ConfigurationElement; |
31 import com.nokia.s60tools.imaker.internal.iqrf.Setting; |
40 import com.nokia.s60tools.imaker.internal.iqrf.Setting; |
32 import com.nokia.s60tools.imaker.internal.iqrf.Target; |
41 import com.nokia.s60tools.imaker.internal.iqrf.Target; |
33 import com.nokia.s60tools.imaker.internal.viewers.ISettingViewer; |
42 import com.nokia.s60tools.imaker.internal.viewers.ISettingViewer; |
63 private String defaultHWID = null; |
72 private String defaultHWID = null; |
64 private List<String> hwids = null; |
73 private List<String> hwids = null; |
65 private List<UITarget> targets = null; |
74 private List<UITarget> targets = null; |
66 private List<UIVariable> variables = null; |
75 private List<UIVariable> variables = null; |
67 private boolean defaultConfig = false; |
76 private boolean defaultConfig = false; |
68 private String defaultTarget = null; |
|
69 |
77 |
70 |
78 |
71 private Set<ISettingViewer> changeListeners = new HashSet<ISettingViewer>(); |
79 private Set<ISettingViewer> changeListeners = new HashSet<ISettingViewer>(); |
|
80 private IIMakerWrapper wrapper; |
|
81 private boolean loaded = false; |
72 |
82 |
73 /** |
83 /** |
74 * Default constructor. Gets a Configuration object as a parameter |
84 * Default constructor. Gets a Configuration object as a parameter |
75 * and goes through it to find the needed data. |
85 * and goes through it to find the needed data. |
76 * |
86 * |
77 * @param conf Configuration object to analyze |
87 * @param conf Configuration object to analyze |
78 */ |
88 * @param wrapper |
79 public UIConfiguration(Configuration conf) { |
89 */ |
|
90 public UIConfiguration(Configuration conf, IIMakerWrapper wrapper) { |
|
91 this.wrapper = wrapper; |
80 if (conf != null) { |
92 if (conf != null) { |
81 makeFileName = conf.getName(); |
93 makeFileName = conf.getName(); |
82 filePath = conf.getFilePath(); |
94 filePath = conf.getFilePath(); |
83 targets = new ArrayList<UITarget>(); |
95 targets = new ArrayList<UITarget>(); |
84 variables = new ArrayList<UIVariable>(); |
96 variables = new ArrayList<UIVariable>(); |
303 } |
311 } |
304 return false; |
312 return false; |
305 } |
313 } |
306 |
314 |
307 public UITarget getTarget(String name) { |
315 public UITarget getTarget(String name) { |
308 String ret = null; |
|
309 for (UITarget t: getAllTargets()) { |
316 for (UITarget t: getAllTargets()) { |
310 if(name.equals(t.getName())) { |
317 if(name.equals(t.getName())) { |
311 return t; |
318 return t; |
312 } |
319 } |
313 } |
320 } |
314 return null; |
321 return null; |
315 } |
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 } |
316 } |
366 } |