|
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 |
|
19 package com.nokia.s60tools.appdep.ui.wizards; |
|
20 |
|
21 import org.eclipse.swt.SWTException; |
|
22 import org.eclipse.ui.PlatformUI; |
|
23 |
|
24 import com.nokia.s60tools.appdep.core.AppDepSettings; |
|
25 import com.nokia.s60tools.appdep.core.IBuildType; |
|
26 import com.nokia.s60tools.appdep.core.ITargetPlatform; |
|
27 import com.nokia.s60tools.appdep.core.data.CacheIndex; |
|
28 import com.nokia.s60tools.appdep.resources.Messages; |
|
29 import com.nokia.s60tools.appdep.ui.wizards.BuildTargetEntry.BuildTargetStatusEnum; |
|
30 import com.nokia.s60tools.sdk.SdkInformation; |
|
31 |
|
32 /** |
|
33 * This build target info object can be bound with UI object |
|
34 * presenting build target related info, but this class binds |
|
35 * <code>BuildTargetEntry</code> class into concrete world |
|
36 * and provides information for it about the real build target. |
|
37 * @see BuildTargetEntry |
|
38 */ |
|
39 public class BuildTargetEntryInfo implements ICacheIndexCreatorObserver { |
|
40 |
|
41 // |
|
42 // Public constants |
|
43 // |
|
44 /** |
|
45 * Constant for unresolved component count. |
|
46 */ |
|
47 public static final int UNRESOLVED_COMPONENT_COUNT = -1; |
|
48 |
|
49 // |
|
50 // Constants and members |
|
51 // |
|
52 |
|
53 /** |
|
54 * Target type of the available build target e.g. armv5 Release. |
|
55 */ |
|
56 private ITargetPlatform targetPlatform; |
|
57 |
|
58 /** |
|
59 * Target's build type (urel/udeb). |
|
60 */ |
|
61 private IBuildType buildType; |
|
62 |
|
63 /** |
|
64 * Build target status. Initially unresolved. |
|
65 */ |
|
66 private BuildTargetStatusEnum status = BuildTargetStatusEnum.EUnresolved; |
|
67 |
|
68 /** |
|
69 * Amount of components found from the target. |
|
70 */ |
|
71 private int componentCount = UNRESOLVED_COMPONENT_COUNT; |
|
72 |
|
73 /** |
|
74 * SDK information object the target belongs to. |
|
75 */ |
|
76 private final SdkInformation sdkInfo; |
|
77 |
|
78 /** |
|
79 * Currently used settings. |
|
80 */ |
|
81 private final AppDepSettings settings; |
|
82 |
|
83 /** |
|
84 * Interface to notify about need to refresh UI. |
|
85 * Used to notify component count finishing for the target. |
|
86 */ |
|
87 private final IRefreshable notifyUIRefreshIf; |
|
88 |
|
89 /** |
|
90 * Constructor. |
|
91 * @param settings Currently active settings. |
|
92 * @param notifyUIRefreshIf Interface to notify about need to refresh UI. Used to notify component count finishing for the target. |
|
93 * @param sdkInfo SDK information object the target belongs to. |
|
94 * @param targetType target type of the available build target e.g. armv5 Release |
|
95 * @param buildType target's build type (urel/udeb). |
|
96 * @param isSuppported set to <code>true</code> if target type is supported, otherwise <code>false</code>. |
|
97 */ |
|
98 public BuildTargetEntryInfo(IRefreshable notifyUIRefreshIf, AppDepSettings settings, SdkInformation sdkInfo, ITargetPlatform targetType, IBuildType buildType, boolean isSuppported){ |
|
99 validateArguments(notifyUIRefreshIf, settings, sdkInfo, targetType, buildType); |
|
100 this.notifyUIRefreshIf = notifyUIRefreshIf; |
|
101 this.settings = settings; |
|
102 this.sdkInfo = sdkInfo; |
|
103 this.targetPlatform = targetType; |
|
104 this.buildType = buildType; |
|
105 if(!isSuppported){ |
|
106 // In case target is not supported => no need to resolve any other information further |
|
107 this.status = BuildTargetStatusEnum.ENotSupported; |
|
108 } |
|
109 } |
|
110 |
|
111 /** |
|
112 * Validates that entry fields passed have some values. |
|
113 * @param notifyUIRefreshIf Interface to notify about need to refresh UI. Used to notify component count finishing for the target. |
|
114 * @param settings Currently active settings. |
|
115 * @param sdkInfo SDK information object the target belongs to. |
|
116 * @param targetType target type of the available build target e.g. armv5 Release |
|
117 * @param buildType target's build type (urel/udeb). |
|
118 * @throws IllegalArgumentException |
|
119 */ |
|
120 private void validateArguments(IRefreshable notifyUIRefreshIf, AppDepSettings settings, SdkInformation sdkInfo, ITargetPlatform targetType, IBuildType buildType) throws IllegalArgumentException{ |
|
121 if( (notifyUIRefreshIf == null || settings == null || sdkInfo == null || targetType == null || buildType == null)){ |
|
122 throw new IllegalArgumentException(new String(Messages.getString("BuildTargetEntryInfo.BuildTargetInfoValidateFailed_ErrMsg"))); //$NON-NLS-1$ |
|
123 } |
|
124 } |
|
125 |
|
126 /** |
|
127 * @return the targetType |
|
128 */ |
|
129 public String getTargetType() { |
|
130 return targetPlatform.getId(); |
|
131 } |
|
132 |
|
133 /** |
|
134 * Get build target's build type. |
|
135 * @return build target's build type. |
|
136 */ |
|
137 public IBuildType getBuildType() { |
|
138 return buildType; |
|
139 } |
|
140 |
|
141 /** |
|
142 * Gets status for the entry. |
|
143 * @return status for the entry. |
|
144 */ |
|
145 public BuildTargetStatusEnum getStatus() { |
|
146 if(status != BuildTargetStatusEnum.ENotSupported){ |
|
147 checkAndUpdateTargetStatus(); |
|
148 } |
|
149 return status; |
|
150 } |
|
151 |
|
152 /** |
|
153 * Checks current build target status and updates status field accordingly. |
|
154 */ |
|
155 private void checkAndUpdateTargetStatus() { |
|
156 |
|
157 // By default cache is not yet created for target or not under creation. |
|
158 BuildTargetStatusEnum resolveStatus = BuildTargetStatusEnum.ENoCache; |
|
159 |
|
160 // Resolving current target status |
|
161 if(getComponentCount() == 0){ |
|
162 resolveStatus = BuildTargetStatusEnum.EEmptyTarget; |
|
163 } |
|
164 else if (settings.isCacheGenerationOngoingForTarget(sdkInfo, targetPlatform.getId(), buildType)){ |
|
165 resolveStatus = BuildTargetStatusEnum.ECacheIsBeingGenerated; |
|
166 } |
|
167 else if (isTargetCached()){ |
|
168 String cacheFileAbsolutePathName = settings.getCacheFileAbsolutePathNameForSdkAndPlatform( |
|
169 sdkInfo, |
|
170 targetPlatform.getId(), |
|
171 buildType |
|
172 ); |
|
173 if (! CacheIndex.cacheIndexCreatedFor(cacheFileAbsolutePathName)){ |
|
174 resolveStatus = BuildTargetStatusEnum.ECachesIsBeingIndexed; |
|
175 } |
|
176 else if(settings.cacheNeedsUpdate(sdkInfo, new ITargetPlatform[]{targetPlatform}, buildType)){ |
|
177 resolveStatus = BuildTargetStatusEnum.ECacheNeedsUpdate; |
|
178 } |
|
179 else{ |
|
180 resolveStatus = BuildTargetStatusEnum.ECacheReady; |
|
181 } |
|
182 } |
|
183 // Updating status field with latest status info |
|
184 status = resolveStatus; |
|
185 } |
|
186 |
|
187 /** |
|
188 * Gets component count for the entry. |
|
189 * @return component count for the entry. |
|
190 */ |
|
191 public int getComponentCount() { |
|
192 // Getting component count only once |
|
193 if(componentCount == UNRESOLVED_COMPONENT_COUNT){ |
|
194 getComponentCountForSdkAndPlatform(settings, sdkInfo, targetPlatform.getId(), buildType); |
|
195 } |
|
196 return componentCount; |
|
197 } |
|
198 |
|
199 /* (non-Javadoc) |
|
200 * @see com.nokia.s60tools.appdep.ui.wizards.ICacheIndexCreatorObserver#cacheIndexCreated(com.nokia.s60tools.appdep.core.data.CacheIndex) |
|
201 */ |
|
202 public void cacheIndexCreated(CacheIndex cacheIndexObj) { |
|
203 // Not needing this information now but may be useful later on to get handle to created index object. |
|
204 } |
|
205 |
|
206 /** |
|
207 * Checks targets caching status. |
|
208 * @return Returns <code>true</code> if target is cached, otherwise <code>false</code>. |
|
209 */ |
|
210 public boolean isTargetCached() { |
|
211 return settings.isTargetPlatformCached(sdkInfo.getSdkId(), targetPlatform.getId(), buildType); |
|
212 } |
|
213 |
|
214 /** |
|
215 * Gets component count for the target build pointed by given |
|
216 * parameters. This is wrapper method for the corresponding method |
|
217 * in AppDepSettings class. |
|
218 * |
|
219 * NOTE: The query may take some time! Therefore the actual query |
|
220 * is run in background thread withouth blockin UI. |
|
221 * |
|
222 * @param settings Used AppDep settings. |
|
223 * @param sdkInfo SDK information for the queried SDK/Platform |
|
224 * @param targetName Target from the SDK/Platform. |
|
225 * @param buildType Build type for the target. |
|
226 * @return Component count for the selected target and build type. |
|
227 * @see com.nokia.s60tools.appdep.core.AppDepSettings#getComponentCountForSdkAndPlatform |
|
228 */ |
|
229 void getComponentCountForSdkAndPlatform(AppDepSettings settings, SdkInformation sdkInfo, |
|
230 String targetName, IBuildType buildType){ |
|
231 |
|
232 final AppDepSettings settingsFinal = settings; |
|
233 final SdkInformation sdkInfoFinal = sdkInfo; |
|
234 final String targetNameFinal = targetName; |
|
235 final IBuildType buildTypeFinal = buildType; |
|
236 |
|
237 Thread queryComponentCountRunnable = new Thread(){ |
|
238 public void run(){ |
|
239 // Triggering component count calculation |
|
240 int count = settingsFinal.getComponentCountForSdkAndPlatform(sdkInfoFinal, |
|
241 targetNameFinal, |
|
242 buildTypeFinal); |
|
243 // Updating component count member variable |
|
244 componentCount = count; |
|
245 // Requesting UI refresh |
|
246 notifyUiRefresh(); |
|
247 } |
|
248 }; |
|
249 // Run component |
|
250 queryComponentCountRunnable.start(); |
|
251 } |
|
252 |
|
253 /** |
|
254 * Notifies UI to refresh itself. |
|
255 */ |
|
256 private void notifyUiRefresh() { |
|
257 Runnable queryComponentCountRunnable = new Runnable(){ |
|
258 public void run(){ |
|
259 try { |
|
260 notifyUIRefreshIf.refresh(); |
|
261 } catch (SWTException e) { |
|
262 // We'll get 'SWTException: Widget is disposed' exceptions whenever |
|
263 // wizard dialog's page has been closed and try to do refresh. |
|
264 // This exception can be therefore ignored safely. |
|
265 } catch (Exception e) { |
|
266 e.printStackTrace(); |
|
267 } |
|
268 } |
|
269 }; |
|
270 // Refresh request is scheduled to UI thread because there is need to modify |
|
271 // UI components which cannot be done from background thread. |
|
272 PlatformUI.getWorkbench().getDisplay().asyncExec(queryComponentCountRunnable); |
|
273 } |
|
274 |
|
275 } |