0
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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.apiquery.cache.core.job;
|
|
19 |
|
|
20 |
import java.io.FileNotFoundException;
|
|
21 |
import java.io.IOException;
|
|
22 |
|
|
23 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
24 |
import org.eclipse.core.runtime.IStatus;
|
|
25 |
import org.eclipse.core.runtime.Platform;
|
|
26 |
import org.eclipse.core.runtime.Status;
|
|
27 |
import org.eclipse.core.runtime.jobs.Job;
|
|
28 |
|
|
29 |
import com.nokia.s60tools.apiquery.cache.configuration.CacheEntryStorage;
|
|
30 |
import com.nokia.s60tools.apiquery.cache.resources.Messages;
|
|
31 |
import com.nokia.s60tools.apiquery.cache.searchmethod.ui.LocalCacheUIComposite;
|
|
32 |
import com.nokia.s60tools.apiquery.shared.datatypes.config.IConfigurationChangedListener;
|
|
33 |
import com.nokia.s60tools.apiquery.shared.job.AbstractJob;
|
|
34 |
import com.nokia.s60tools.apiquery.shared.job.JobCancelledByUserException;
|
|
35 |
import com.nokia.s60tools.apiquery.ui.views.main.MainView;
|
|
36 |
import com.nokia.s60tools.sdk.SdkInformation;
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Job for loading already seeked SDK data to RAM
|
|
40 |
*/
|
|
41 |
public class UpdateSDKSelectionJob extends AbstractJob {
|
|
42 |
|
|
43 |
private final SdkInformation info;
|
|
44 |
private boolean showErrorDialog = true;
|
|
45 |
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Constructor
|
|
49 |
* @param name
|
|
50 |
* @param info
|
|
51 |
*/
|
|
52 |
public UpdateSDKSelectionJob(String name, SdkInformation info) {
|
|
53 |
super(name);
|
|
54 |
this.info = info;
|
|
55 |
setUser(true);
|
|
56 |
}
|
|
57 |
/**
|
|
58 |
* Constructor
|
|
59 |
* @param name
|
|
60 |
* @param info
|
|
61 |
* @param showErrorDialog set <code>false</code> if dont want to show error dialog when there was errors
|
|
62 |
* when updating cache.
|
|
63 |
*/
|
|
64 |
public UpdateSDKSelectionJob(String name, SdkInformation info, boolean showErrorDialog) {
|
|
65 |
super(name);
|
|
66 |
this.info = info;
|
|
67 |
setUser(true);
|
|
68 |
this.showErrorDialog = showErrorDialog;
|
|
69 |
}
|
|
70 |
|
|
71 |
/**
|
|
72 |
* Check if job is allready running
|
|
73 |
* @return true if job with same name is allready running
|
|
74 |
*/
|
|
75 |
public boolean isAllreadyRunning(){
|
|
76 |
|
|
77 |
//Get and check all jobs
|
|
78 |
Job[] jobs = getJobManager().find(null);
|
|
79 |
for (int i = 0; i < jobs.length; i++) {
|
|
80 |
if(jobs[i] instanceof UpdateSDKSelectionJob){
|
|
81 |
UpdateSDKSelectionJob job = (UpdateSDKSelectionJob)jobs[i];
|
|
82 |
//If we found job what is not this job, and it runs for same SDK (same name)
|
|
83 |
//then there is job allready runnig to update this SDK
|
|
84 |
if(!job.equals(this) && job.getName().equals(this.getName())){
|
|
85 |
return true;
|
|
86 |
}
|
|
87 |
}
|
|
88 |
}
|
|
89 |
return false;
|
|
90 |
}
|
|
91 |
|
|
92 |
/* (non-Javadoc)
|
|
93 |
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
|
|
94 |
*/
|
|
95 |
protected IStatus run(IProgressMonitor monitor) {
|
|
96 |
|
|
97 |
|
|
98 |
MainView.enablePropTabcontents(false);
|
|
99 |
//Check if Update is already ongoing, returning warning if is.
|
|
100 |
if(isAllreadyRunning()){
|
|
101 |
IStatus status = new Status(
|
|
102 |
Status.WARNING,Platform.PI_RUNTIME,
|
|
103 |
Status.WARNING, "Job: '" +getName() +"' already runnig.", null);
|
|
104 |
return status;
|
|
105 |
}
|
|
106 |
|
|
107 |
setMonitor(monitor);
|
|
108 |
try{
|
|
109 |
reportStartTime();
|
|
110 |
updateDataStore();
|
|
111 |
reportEndTime();
|
|
112 |
return Status.OK_STATUS;
|
|
113 |
|
|
114 |
}catch (JobCancelledByUserException e) {
|
|
115 |
return Status.CANCEL_STATUS;
|
|
116 |
}catch (Exception e) {
|
|
117 |
e.printStackTrace();
|
|
118 |
return returnErrorStatus(e);
|
|
119 |
}
|
|
120 |
finally{
|
|
121 |
|
|
122 |
MainView.enablePropTabcontents(true);
|
|
123 |
|
|
124 |
|
|
125 |
}
|
|
126 |
|
|
127 |
}
|
|
128 |
|
|
129 |
/**
|
|
130 |
* Return error status
|
|
131 |
* @param e
|
|
132 |
* @return
|
|
133 |
*/
|
|
134 |
private IStatus returnErrorStatus(Exception e){
|
|
135 |
String msg = Messages.getString("UpdateSDKSelectionJob.SDKReadError_Msg") +info.getSdkId() +"'"; //$NON-NLS-1$ //$NON-NLS-2$
|
|
136 |
IStatus status = new Status(
|
|
137 |
Status.ERROR,Platform.PI_RUNTIME,
|
|
138 |
Status.ERROR,msg, e);
|
|
139 |
return status;
|
|
140 |
}
|
|
141 |
|
|
142 |
/**
|
|
143 |
* When known that data source allready found (files seeked under SDK) just
|
|
144 |
* updating datastore selections so that selected SDK is selected.
|
|
145 |
*
|
|
146 |
* @throws IOException
|
|
147 |
* @throws FileNotFoundException
|
|
148 |
* @throws JobCancelledByUserException
|
|
149 |
*/
|
|
150 |
private void updateDataStore() throws FileNotFoundException, IOException, JobCancelledByUserException {
|
|
151 |
|
|
152 |
getMonitor().beginTask(
|
|
153 |
Messages.getString("UpdateSDKSelectionJob.ReadingSDK_ProgressMsg") + info.getSdkId() + "'", //$NON-NLS-1$ //$NON-NLS-2$
|
|
154 |
IProgressMonitor.UNKNOWN);
|
|
155 |
|
|
156 |
CacheEntryStorage storage = CacheEntryStorage.getInstance();
|
|
157 |
|
|
158 |
getMonitor().subTask(Messages.getString("UpdateSDKSelectionJob.ParsingFiles_ProgressMsg")); //$NON-NLS-1$
|
|
159 |
// Cancel situations will throw exception and restore old data
|
|
160 |
storage.selectSDKAndLoadAllSelectedDatasToMemory(getMonitor(), info);
|
|
161 |
|
|
162 |
// Notifying listeners, only one notifying should be enough.
|
|
163 |
storage.notifyConfigurationChangeListeners(IConfigurationChangedListener.ALL_ENTRYS_UPDATED);
|
|
164 |
|
|
165 |
// Show error message or write to log if there is some errors on load.
|
|
166 |
if (storage.isLoadErros()) {
|
|
167 |
if (showErrorDialog) {
|
|
168 |
JobMessageUtils.showLoadErrorDialog();
|
|
169 |
} else {
|
|
170 |
JobMessageUtils.printLoadErrorMessage();
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
}
|