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.appdep.ui.actions;
|
|
18 |
|
|
19 |
import java.util.ArrayList;
|
|
20 |
import java.util.Arrays;
|
|
21 |
import java.util.List;
|
|
22 |
|
|
23 |
import org.eclipse.jface.resource.ImageDescriptor;
|
|
24 |
import org.eclipse.jface.window.Window;
|
|
25 |
import org.eclipse.swt.SWT;
|
|
26 |
import org.eclipse.swt.widgets.Shell;
|
|
27 |
import org.eclipse.ui.ISharedImages;
|
|
28 |
import org.eclipse.ui.PlatformUI;
|
|
29 |
|
|
30 |
import com.nokia.s60tools.appdep.core.AppDepSettings;
|
|
31 |
import com.nokia.s60tools.appdep.core.ITargetPlatform;
|
|
32 |
import com.nokia.s60tools.appdep.core.job.GenerateCacheJob;
|
|
33 |
import com.nokia.s60tools.appdep.exceptions.InvalidCmdLineToolSettingException;
|
|
34 |
import com.nokia.s60tools.appdep.plugin.AppDepPlugin;
|
|
35 |
import com.nokia.s60tools.appdep.resources.Messages;
|
|
36 |
import com.nokia.s60tools.appdep.ui.dialogs.AddSISFilesDialog;
|
|
37 |
import com.nokia.s60tools.appdep.ui.dialogs.AppDepMessageBox;
|
|
38 |
import com.nokia.s60tools.appdep.ui.views.main.MainView;
|
|
39 |
import com.nokia.s60tools.appdep.util.AppDepConsole;
|
|
40 |
import com.nokia.s60tools.util.console.IConsolePrintUtility;
|
|
41 |
|
|
42 |
public class AddSisAndUpdateCacheMainViewAction extends AbstractMainViewAction {
|
|
43 |
|
|
44 |
public static final String ACTION_ID = "com.nokia.s60tools.appdep.ui.actions.AddSisAndUpdateCacheMainViewAction"; //$NON-NLS-1$
|
|
45 |
|
|
46 |
/**
|
|
47 |
* Constructor.
|
|
48 |
* @param view Reference to the view.
|
|
49 |
*/
|
|
50 |
public AddSisAndUpdateCacheMainViewAction(MainView view){
|
|
51 |
super(view);
|
|
52 |
setText("Add SIS files..."); //$NON-NLS-1$
|
|
53 |
setToolTipText("Add SIS files"); //$NON-NLS-1$
|
|
54 |
|
|
55 |
setId(ACTION_ID);
|
|
56 |
|
|
57 |
ImageDescriptor imageDesc = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD);
|
|
58 |
setImageDescriptor(imageDesc);
|
|
59 |
|
|
60 |
}
|
|
61 |
|
|
62 |
/* (non-Javadoc)
|
|
63 |
* @see org.eclipse.jface.action.IAction#run()
|
|
64 |
*/
|
|
65 |
public void run() {
|
|
66 |
|
|
67 |
String currentRootComponent = null;
|
|
68 |
AppDepSettings activeSettings = AppDepSettings.getActiveSettings();
|
|
69 |
currentRootComponent = activeSettings.getCurrentlyAnalyzedComponentName();
|
|
70 |
|
|
71 |
if(currentRootComponent == null){
|
|
72 |
// User has not selected any components for analysis
|
|
73 |
String infoMsg = Messages.getString("GeneralMessages.Select_SDK_First_ErrMsg"); //$NON-NLS-1$
|
|
74 |
new AppDepMessageBox(infoMsg, SWT.OK | SWT.ICON_INFORMATION).open();
|
|
75 |
return;
|
|
76 |
}
|
|
77 |
|
|
78 |
String[] previouslyAnalysedSISFiles = null;
|
|
79 |
Shell sh = AppDepPlugin.getCurrentlyActiveWbWindowShell();
|
|
80 |
AddSISFilesDialog entryDialog = new AddSISFilesDialog(sh);
|
|
81 |
entryDialog.create();
|
|
82 |
|
|
83 |
// If already selected some set of SIS files getting the list...
|
|
84 |
if(activeSettings.isInSISFileAnalysisMode()){
|
|
85 |
//...and setting the initial list
|
|
86 |
previouslyAnalysedSISFiles = activeSettings.getSISFilesForAnalysis();
|
|
87 |
entryDialog.setInitialSISFileSet(previouslyAnalysedSISFiles);
|
|
88 |
}
|
|
89 |
int userSelection = entryDialog.open();
|
|
90 |
if(userSelection == Window.OK){
|
|
91 |
// Getting selected SIS files
|
|
92 |
String[] selectedSISFiles = entryDialog.getSelectedSISFiles();
|
|
93 |
if(selectedSISFiles.length > 0){
|
|
94 |
activeSettings.setSISFilesForAnalysis(selectedSISFiles );
|
|
95 |
|
|
96 |
if( areNewSISFilesProvided(selectedSISFiles, previouslyAnalysedSISFiles)){
|
|
97 |
// Entering to SIS file mode...
|
|
98 |
activeSettings.setIsInSISFileAnalysisMode(true);
|
|
99 |
// ...and setting files to current settings
|
|
100 |
addSISTarget(activeSettings);
|
|
101 |
//Generate Cache with the modified active settings.
|
|
102 |
GenerateCacheJob.triggerCacheGenerationForCurrentlyActiveSettings();
|
|
103 |
}
|
|
104 |
else{
|
|
105 |
|
|
106 |
String infoMsg = Messages.getString("AddSisAndUpdateCacheMainViewAction.Cache_is_up_to_date_msg"); //$NON-NLS-1$
|
|
107 |
new AppDepMessageBox(infoMsg, SWT.OK | SWT.ICON_INFORMATION).open();
|
|
108 |
}
|
|
109 |
}
|
|
110 |
else{
|
|
111 |
// Disabling SIS file mode
|
|
112 |
activeSettings.setIsInSISFileAnalysisMode(false);
|
|
113 |
activeSettings.setSISFilesForAnalysis(null);
|
|
114 |
}
|
|
115 |
|
|
116 |
}
|
|
117 |
|
|
118 |
// Remember to always call AbstractMainViewAction
|
|
119 |
// base class implementation
|
|
120 |
super.run();
|
|
121 |
|
|
122 |
}
|
|
123 |
|
|
124 |
|
|
125 |
/**
|
|
126 |
* The method adds SIS target to the given settings.
|
|
127 |
* @param settings
|
|
128 |
*/
|
|
129 |
private void addSISTarget(AppDepSettings settings) {
|
|
130 |
|
|
131 |
try{
|
|
132 |
// In SIS mode we need to add an extra target
|
|
133 |
if(settings.isInSISFileAnalysisMode()){
|
|
134 |
|
|
135 |
ITargetPlatform[] targetPlatforms = settings.getCurrentlyUsedTargetPlatforms();
|
|
136 |
|
|
137 |
ArrayList<String> targetPlatformNames = new ArrayList<String>();
|
|
138 |
|
|
139 |
for(ITargetPlatform platform: targetPlatforms)
|
|
140 |
targetPlatformNames.add(platform.getId());
|
|
141 |
|
|
142 |
if(! targetPlatformNames.contains(AppDepSettings.TARGET_TYPE_ID_SIS)){
|
|
143 |
settings.addTargetPlatform(AppDepSettings.TARGET_TYPE_ID_SIS);
|
|
144 |
}
|
|
145 |
}
|
|
146 |
}catch (InvalidCmdLineToolSettingException e) {
|
|
147 |
e.printStackTrace();
|
|
148 |
AppDepConsole.getInstance().println(Messages.getString("GeneralMessages.Failed_To_Update_Current_Settings"), IConsolePrintUtility.MSG_ERROR); //$NON-NLS-1$
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
/**
|
|
153 |
* The method compares list of newly provided sis files with the previous list of analysed files.
|
|
154 |
* The method returns true if some files have been added or removed.
|
|
155 |
*/
|
|
156 |
private boolean areNewSISFilesProvided(String [] newFiles, String [] previouslyAnalysedFiles)
|
|
157 |
{
|
|
158 |
if(previouslyAnalysedFiles == null)
|
|
159 |
return true;
|
|
160 |
else if (newFiles.length != previouslyAnalysedFiles.length)
|
|
161 |
return true;
|
|
162 |
else
|
|
163 |
{
|
|
164 |
List<String> analysedFilesList = Arrays.asList(previouslyAnalysedFiles);
|
|
165 |
|
|
166 |
for(String file:newFiles)
|
|
167 |
{
|
|
168 |
if(!analysedFilesList.contains(file))
|
|
169 |
return true;
|
|
170 |
}
|
|
171 |
|
|
172 |
return false;
|
|
173 |
}
|
|
174 |
}
|
|
175 |
}
|