author | haismail <hussein.ismail@nokia.com> |
Thu, 18 Feb 2010 08:20:36 +0200 | |
changeset 5 | d5efbe6c22e8 |
parent 2 | a91cb670dd8e |
permissions | -rw-r--r-- |
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 |
package com.nokia.s60tools.imaker.internal.model; |
|
18 |
||
19 |
import java.lang.reflect.InvocationTargetException; |
|
20 |
import java.util.Iterator; |
|
21 |
import java.util.List; |
|
22 |
||
23 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
24 |
import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
|
25 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
|
26 |
import org.eclipse.swt.widgets.Display; |
|
27 |
import org.eclipse.ui.PlatformUI; |
|
28 |
||
29 |
import com.nokia.s60tools.imaker.IEnvironment; |
|
30 |
import com.nokia.s60tools.imaker.IIMakerWrapper; |
|
31 |
import com.nokia.s60tools.imaker.IMakerUtils; |
|
32 |
import com.nokia.s60tools.imaker.Messages; |
|
33 |
import com.nokia.s60tools.imaker.UIConfiguration; |
|
34 |
import com.nokia.s60tools.imaker.exceptions.IMakerCoreExecutionException; |
|
35 |
import com.nokia.s60tools.imaker.exceptions.IMakerCoreNotFoundException; |
|
36 |
import com.nokia.s60tools.imaker.internal.wrapper.IMakerWrapper; |
|
37 |
||
38 |
public class Environment implements IEnvironment { |
|
39 |
private String drive; |
|
40 |
private String iMakerCoreVersion=null; |
|
41 |
private boolean loaded; |
|
42 |
private List<UIConfiguration> configurations; |
|
43 |
private UIConfiguration currentProduct; |
|
44 |
private IIMakerWrapper wrapper = null; |
|
45 |
private String targetSteps = null; |
|
46 |
private ImakerProperties runProperties=null; //runtime selected properties |
|
47 |
||
48 |
public Environment(String drive) { |
|
49 |
this.drive = drive; |
|
50 |
this.setImakerWrapper(new IMakerWrapper(IMakerUtils.getImakerTool(drive))); |
|
51 |
runProperties = new ImakerProperties(); |
|
52 |
} |
|
53 |
||
54 |
public IIMakerWrapper getImakerWrapper() { |
|
55 |
return this.wrapper; |
|
56 |
} |
|
57 |
||
58 |
public void setImakerWrapper(IIMakerWrapper wrapper) { |
|
59 |
this.wrapper = wrapper; |
|
60 |
} |
|
61 |
||
62 |
/* (non-Javadoc) |
|
63 |
* @see com.nokia.s60tools.imaker.internal.model.IEnvironment#getDrive() |
|
64 |
*/ |
|
65 |
public String getDrive() { |
|
66 |
return drive; |
|
67 |
} |
|
68 |
||
69 |
/* (non-Javadoc) |
|
70 |
* @see com.nokia.s60tools.imaker.internal.model.IEnvironment#isLoaded() |
|
71 |
*/ |
|
72 |
public boolean isLoaded() { |
|
73 |
return loaded; |
|
74 |
} |
|
75 |
||
76 |
/* (non-Javadoc) |
|
77 |
* @see com.nokia.s60tools.imaker.internal.model.IEnvironment#reLoad() |
|
78 |
*/ |
|
79 |
public List<UIConfiguration> reLoad() throws InvocationTargetException { |
|
80 |
loaded = false; |
|
81 |
return load(); |
|
82 |
} |
|
83 |
||
84 |
/* (non-Javadoc) |
|
85 |
* @see com.nokia.s60tools.imaker.internal.model.IEnvironment#load() |
|
86 |
*/ |
|
87 |
public List<UIConfiguration> load() throws InvocationTargetException { |
|
88 |
if(loaded) { |
|
89 |
return configurations; |
|
90 |
} |
|
91 |
IRunnableWithProgress op = new IMakerCoreRunnable(); |
|
92 |
ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getDisplay().getActiveShell()); |
|
93 |
try { |
|
94 |
progressMonitorDialog.run(true, true, op); |
|
95 |
} catch (InvocationTargetException e) { |
|
96 |
configurations = null; |
|
97 |
loaded = false; |
|
98 |
throw e; |
|
99 |
} catch (InterruptedException e) { |
|
100 |
e.printStackTrace(); |
|
101 |
} |
|
102 |
loaded=true; |
|
103 |
return configurations; |
|
104 |
} |
|
105 |
||
106 |
private Display getDisplay() { |
|
107 |
Display display = PlatformUI.getWorkbench().getDisplay(); |
|
108 |
return display; |
|
109 |
} |
|
110 |
||
111 |
/* (non-Javadoc) |
|
112 |
* @see com.nokia.s60tools.imaker.internal.model.IEnvironment#getConfigurations() |
|
113 |
*/ |
|
114 |
public List<UIConfiguration> getConfigurations() throws InvocationTargetException { |
|
115 |
if(loaded) { |
|
116 |
return configurations; |
|
117 |
} else { |
|
118 |
load(); |
|
119 |
return configurations; |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
/* (non-Javadoc) |
|
124 |
* @see com.nokia.s60tools.imaker.internal.model.IEnvironment#getConfigurationByFilePath(java.lang.String) |
|
125 |
*/ |
|
126 |
public UIConfiguration getConfigurationByFilePath(String filePath) { |
|
127 |
if(configurations==null) { |
|
128 |
return null; |
|
129 |
} |
|
130 |
for (Iterator<UIConfiguration> iterator = configurations.iterator(); iterator.hasNext();) { |
|
131 |
UIConfiguration config = iterator.next(); |
|
132 |
if(config.getFilePath().equals(filePath)) { |
|
133 |
return config; |
|
134 |
} |
|
135 |
} |
|
136 |
return null; |
|
137 |
} |
|
138 |
||
139 |
private class IMakerCoreRunnable implements IRunnableWithProgress { |
|
140 |
public void run(IProgressMonitor monitor) |
|
141 |
throws InvocationTargetException, InterruptedException { |
|
142 |
try { |
|
2 | 143 |
configurations = getImakerWrapper().getConfigurations(monitor,null); |
0 | 144 |
if(configurations.size()==0) { |
145 |
IMakerCoreExecutionException ex = new IMakerCoreExecutionException(Messages.getString("Error.1")); |
|
146 |
InvocationTargetException te = new InvocationTargetException(ex); |
|
147 |
throw te; |
|
148 |
} |
|
149 |
} catch (IMakerCoreExecutionException e) { |
|
150 |
InvocationTargetException te = new InvocationTargetException(e); |
|
151 |
throw te; |
|
152 |
} catch (IMakerCoreNotFoundException e) { |
|
153 |
InvocationTargetException te = new InvocationTargetException(e); |
|
154 |
throw te; |
|
155 |
} |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
/* (non-Javadoc) |
|
160 |
* @see com.nokia.s60tools.imaker.internal.model.IEnvironment#getIMakerCoreVersion() |
|
161 |
*/ |
|
162 |
public String getIMakerCoreVersion() throws IMakerCoreNotFoundException, IMakerCoreExecutionException { |
|
163 |
if(iMakerCoreVersion==null) { |
|
164 |
iMakerCoreVersion = getImakerWrapper().getIMakerCoreVersion(); |
|
165 |
} |
|
166 |
return iMakerCoreVersion; |
|
167 |
} |
|
168 |
||
169 |
/* (non-Javadoc) |
|
170 |
* @see com.nokia.s60tools.imaker.internal.model.IEnvironment#setCurrentProduct(com.nokia.s60tools.imaker.internal.model.UIConfiguration) |
|
171 |
*/ |
|
172 |
public void setCurrentProduct(UIConfiguration uic) { |
|
173 |
this.currentProduct = uic; |
|
174 |
} |
|
175 |
||
176 |
/* (non-Javadoc) |
|
177 |
* @see com.nokia.s60tools.imaker.internal.model.IEnvironment#getCurrentProduct() |
|
178 |
*/ |
|
179 |
public UIConfiguration getCurrentProduct() { |
|
180 |
return currentProduct; |
|
181 |
} |
|
182 |
||
183 |
public String getTargetSteps(final String target) { |
|
184 |
targetSteps = null; |
|
185 |
ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getDisplay().getActiveShell()); |
|
186 |
try { |
|
187 |
progressMonitorDialog.run(true, false, new IRunnableWithProgress() { |
|
188 |
||
189 |
// @Override |
|
190 |
public void run(IProgressMonitor monitor) throws InvocationTargetException, |
|
191 |
InterruptedException { |
|
5
d5efbe6c22e8
Ticket #1245: Update target selection required to avoid yellow warnings on content tab
haismail <hussein.ismail@nokia.com>
parents:
2
diff
changeset
|
192 |
try { |
d5efbe6c22e8
Ticket #1245: Update target selection required to avoid yellow warnings on content tab
haismail <hussein.ismail@nokia.com>
parents:
2
diff
changeset
|
193 |
targetSteps = wrapper.getTargetSteps(target, getCurrentProduct().getFilePath(), monitor); |
d5efbe6c22e8
Ticket #1245: Update target selection required to avoid yellow warnings on content tab
haismail <hussein.ismail@nokia.com>
parents:
2
diff
changeset
|
194 |
} catch (IMakerCoreExecutionException e) { |
d5efbe6c22e8
Ticket #1245: Update target selection required to avoid yellow warnings on content tab
haismail <hussein.ismail@nokia.com>
parents:
2
diff
changeset
|
195 |
throw new InvocationTargetException(e); |
d5efbe6c22e8
Ticket #1245: Update target selection required to avoid yellow warnings on content tab
haismail <hussein.ismail@nokia.com>
parents:
2
diff
changeset
|
196 |
} |
0 | 197 |
} |
198 |
}); |
|
199 |
} catch (InvocationTargetException e) { |
|
200 |
} catch (InterruptedException e) { |
|
201 |
} |
|
202 |
return targetSteps; |
|
203 |
} |
|
204 |
||
205 |
public ImakerProperties getRunProperties() { |
|
206 |
return runProperties; |
|
207 |
} |
|
208 |
} |