|
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 the License "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.carbide.cpp.internal.pi.wizards.ui; |
|
19 |
|
20 import java.util.ArrayList; |
|
21 import java.util.List; |
|
22 |
|
23 import org.eclipse.core.resources.IProject; |
|
24 import org.eclipse.jface.viewers.DecoratingLabelProvider; |
|
25 import org.eclipse.jface.viewers.ISelection; |
|
26 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
27 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
28 import org.eclipse.jface.viewers.TreePath; |
|
29 import org.eclipse.jface.viewers.TreeSelection; |
|
30 import org.eclipse.swt.SWT; |
|
31 import org.eclipse.swt.events.SelectionAdapter; |
|
32 import org.eclipse.swt.events.SelectionEvent; |
|
33 import org.eclipse.swt.layout.GridData; |
|
34 import org.eclipse.swt.layout.GridLayout; |
|
35 import org.eclipse.swt.widgets.Button; |
|
36 import org.eclipse.swt.widgets.Composite; |
|
37 import org.eclipse.swt.widgets.FileDialog; |
|
38 import org.eclipse.ui.PlatformUI; |
|
39 |
|
40 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration; |
|
41 import com.nokia.carbide.cdt.builder.project.ISISBuilderInfo; |
|
42 import com.nokia.carbide.cpp.internal.pi.wizards.ui.util.CarbidePiWizardHelpIds; |
|
43 import com.nokia.carbide.cpp.internal.pi.wizards.ui.util.IPkgEntry; |
|
44 import com.nokia.carbide.cpp.internal.pi.wizards.ui.util.PkgEntryList; |
|
45 import com.nokia.carbide.cpp.internal.pi.wizards.ui.util.PkgListTree; |
|
46 import com.nokia.carbide.cpp.internal.pi.wizards.ui.util.PkgListTreeContentProvider; |
|
47 import com.nokia.carbide.cpp.internal.pi.wizards.ui.util.PkgListTreeLabelProvider; |
|
48 import com.nokia.carbide.cpp.internal.pi.wizards.ui.util.PkgListTreeViewer; |
|
49 |
|
50 public class NewPIWizardPagePkgListTask |
|
51 extends NewPIWizardPage |
|
52 implements INewPIWizardSettings { |
|
53 |
|
54 // control |
|
55 private Composite composite = null; |
|
56 // private Label label = null; |
|
57 private PkgListTreeViewer projectTreeViewer; |
|
58 private Composite filelistComposite = null; |
|
59 private Composite buttonComposite = null; |
|
60 private Button addPkgButton = null; |
|
61 private Button removeButton = null; |
|
62 |
|
63 // data model |
|
64 PkgListTree pkgListRoot = null; |
|
65 |
|
66 protected NewPIWizardPagePkgListTask() { |
|
67 super(""); //$NON-NLS-1$ |
|
68 setTitle(Messages.getString("NewPIWizardPagePkgListTask.title")); //$NON-NLS-1$ |
|
69 setDescription(Messages.getString("NewPIWizardPagePkgListTask.description")); //$NON-NLS-1$ |
|
70 } |
|
71 |
|
72 public void createControl(Composite parent) { |
|
73 super.createControl(parent); |
|
74 GridLayout gridLayout = new GridLayout(); |
|
75 gridLayout.numColumns = 1; |
|
76 composite = new Composite(parent, SWT.NONE); |
|
77 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
78 composite.setLayout(gridLayout); |
|
79 // label = new Label(composite, SWT.NONE); |
|
80 // label.setText(Messages.getString("NewPIWizardPagePkgListTask.label")); //$NON-NLS-1$ |
|
81 createFilelistComposite(); |
|
82 setControl(composite); |
|
83 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), CarbidePiWizardHelpIds.PI_IMPORT_WIZARD_PKG_LIST); |
|
84 } |
|
85 |
|
86 /** |
|
87 * This method initializes filelistComposite |
|
88 * |
|
89 */ |
|
90 private void createFilelistComposite() { |
|
91 GridLayout gridLayout2 = new GridLayout(); |
|
92 gridLayout2.numColumns = 2; |
|
93 filelistComposite = new Composite(composite, SWT.NONE); |
|
94 filelistComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
95 filelistComposite.setLayout(gridLayout2); |
|
96 projectTreeViewer = new PkgListTreeViewer(filelistComposite, SWT.H_SCROLL | SWT.BORDER); |
|
97 pkgListRoot = new PkgListTree(); |
|
98 projectTreeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
99 projectTreeViewer.setContentProvider(new PkgListTreeContentProvider(pkgListRoot)); |
|
100 projectTreeViewer.setLabelProvider(new DecoratingLabelProvider( |
|
101 new PkgListTreeLabelProvider(), PlatformUI.getWorkbench() |
|
102 .getDecoratorManager().getLabelDecorator())); |
|
103 projectTreeViewer.setInput(pkgListRoot); |
|
104 projectTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
|
105 |
|
106 public void selectionChanged(SelectionChangedEvent arg0) { |
|
107 ISelection selection = arg0.getSelection(); |
|
108 // if selecting disabled item, ditch the selection and restore viewer |
|
109 // selection using data object |
|
110 if (selection instanceof TreeSelection) { |
|
111 TreeSelection treeSelection = (TreeSelection) selection; |
|
112 TreePath[] paths = treeSelection.getPaths(); |
|
113 if (paths.length == 1) { |
|
114 if (projectTreeViewer.getElementEnabled(paths[0].getLastSegment()) == false) { |
|
115 setupPageFromFromNewPIWizardSettings(); |
|
116 } |
|
117 } |
|
118 } |
|
119 NewPIWizardSettings npiws = NewPIWizardSettings.getInstance(); |
|
120 npiws.selectedAppFileList.clear(); |
|
121 for (IPkgEntry pkg : projectTreeViewer.getSelectedPkgs()) { |
|
122 npiws.selectedAppFileList.add(pkg); |
|
123 } |
|
124 npiws.selectedProjectList.clear(); |
|
125 for (IProject project : projectTreeViewer.getSelectedProjects()) { |
|
126 npiws.selectedProjectList.add(project); |
|
127 } |
|
128 npiws.selectedBuildConfigList.clear(); |
|
129 for (ICarbideBuildConfiguration config : projectTreeViewer.getSelectedConfigs()) { |
|
130 npiws.selectedBuildConfigList.add(config); |
|
131 } |
|
132 npiws.availableAppFileList.clear(); |
|
133 IPkgEntry[] allPkg = pkgListRoot.getPkgEntries(); |
|
134 for (IPkgEntry pkg: allPkg) { |
|
135 npiws.availableAppFileList.add(pkg); |
|
136 } |
|
137 } |
|
138 }); |
|
139 projectTreeViewer.expandToLevel(2); // just to project level |
|
140 |
|
141 createButtonComposite(); |
|
142 } |
|
143 |
|
144 /** |
|
145 * This method initializes buttonComposite |
|
146 * |
|
147 */ |
|
148 private void createButtonComposite() { |
|
149 GridLayout gridLayout = new GridLayout(); |
|
150 gridLayout.numColumns = 1; |
|
151 buttonComposite = new Composite(filelistComposite, SWT.NONE); |
|
152 buttonComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false)); |
|
153 buttonComposite.setLayout(gridLayout); |
|
154 addPkgButton = new Button(buttonComposite, SWT.PUSH); |
|
155 addPkgButton.setText(Messages.getString("NewPIWizardPagePkgListTask.pkg.button")); //$NON-NLS-1$ |
|
156 removeButton = new Button(buttonComposite, SWT.PUSH); |
|
157 removeButton.setText(Messages.getString("NewPIWizardPagePkgListTask.remove.button")); //$NON-NLS-1$ |
|
158 |
|
159 GridData buttonWidthGridData = new GridData(); |
|
160 buttonWidthGridData.widthHint = Math.max(addPkgButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x, removeButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); |
|
161 addPkgButton.setLayoutData(buttonWidthGridData); |
|
162 removeButton.setLayoutData(buttonWidthGridData); |
|
163 addPkgButton.addSelectionListener(new SelectionAdapter() { |
|
164 public void widgetSelected(SelectionEvent e) { |
|
165 handleAddPkg(); |
|
166 } |
|
167 }); |
|
168 removeButton.addSelectionListener(new SelectionAdapter() { |
|
169 public void widgetSelected(SelectionEvent e) { |
|
170 handleRemovePkg(); |
|
171 } |
|
172 }); |
|
173 } |
|
174 |
|
175 private void handleAddPkg() { |
|
176 String pkgFilePath; |
|
177 FileDialog dialog = new FileDialog(getShell()); |
|
178 String[] pkgExtensions = {"*.pkg", //$NON-NLS-1$ |
|
179 "*.*"}; //$NON-NLS-1$ |
|
180 String[] pkgNames = {Messages.getString("NewPIWizardPagePkgListTask.pkg.filter.name"), //$NON-NLS-1$ |
|
181 Messages.getString("NewPIWizardPagePkgListTask.all.filter.name")}; //$NON-NLS-1$ |
|
182 dialog.setFilterExtensions(pkgExtensions); |
|
183 dialog.setFilterNames(pkgNames); |
|
184 pkgFilePath = dialog.open(); |
|
185 |
|
186 if (pkgFilePath != null) { |
|
187 NewPIWizardPagePkgSdkDialog sdkDialog = new NewPIWizardPagePkgSdkDialog(getShell()); |
|
188 if (sdkDialog.open() == NewPIWizardPagePkgSdkDialog.OK) { |
|
189 IPkgEntry pkgEntry = PkgEntryList.getInstance().getPkgEntry(pkgFilePath, sdkDialog.getSelection()); |
|
190 boolean found = false; |
|
191 for (IPkgEntry entry : pkgListRoot.getPkgEntries()) { |
|
192 if (pkgEntry.equals(entry)) { |
|
193 found = true; |
|
194 break; |
|
195 } |
|
196 } |
|
197 if (found == false) { |
|
198 pkgListRoot.addPkgEntry(pkgEntry); |
|
199 } |
|
200 removeButton.setEnabled(pkgListRoot.getPkgEntries().length != 0); |
|
201 // only expanded/visible items are available for selecting programatically |
|
202 projectTreeViewer.reveal(pkgEntry); |
|
203 // This shows the new PKG in UI and force associate of the new PKG, so we can select later |
|
204 projectTreeViewer.refresh(); |
|
205 //projectTreeViewer.initializeSelectedItems(selectedObjects.toArray()); |
|
206 // reveal is not necessary, but we do it for safety |
|
207 } |
|
208 } |
|
209 } |
|
210 |
|
211 private void handleRemovePkg() { |
|
212 NewPIWizardRemovePkgDialog removeDialog = new NewPIWizardRemovePkgDialog(getShell(), pkgListRoot.getPkgEntries()); |
|
213 removeDialog.open(); |
|
214 IPkgEntry[] removeList = removeDialog.getRemovedList(); |
|
215 if (removeList != null) { |
|
216 for (int i = 0; i < removeList.length; i++) { |
|
217 pkgListRoot.removePkgEntry(removeList[i]); |
|
218 } |
|
219 removeButton.setEnabled(pkgListRoot.getPkgEntries().length != 0); |
|
220 projectTreeViewer.refresh(); |
|
221 } |
|
222 } |
|
223 |
|
224 public void setupPageFromFromNewPIWizardSettings() { |
|
225 NewPIWizardSettings npiws = NewPIWizardSettings.getInstance(); |
|
226 ArrayList<TreePath> selectedPath = new ArrayList<TreePath>(); |
|
227 pkgListRoot.removeAllPkgEntries(); |
|
228 |
|
229 // Build TreePath for all selected configurations and their project parent |
|
230 ICarbideBuildConfiguration needToUnselect = null; |
|
231 for (ICarbideBuildConfiguration selected : npiws.selectedBuildConfigList) { |
|
232 List<ISISBuilderInfo> sisBuilderInfoList = selected.getSISBuilderInfoList(); |
|
233 boolean allPkgGood = true && sisBuilderInfoList.size() > 0; |
|
234 for (ISISBuilderInfo sisBuilderInfo : sisBuilderInfoList) |
|
235 { |
|
236 if (sisBuilderInfo == null) { |
|
237 allPkgGood = false; |
|
238 } else if (sisBuilderInfo.getPKGFullPath().toFile().exists() == false) { |
|
239 allPkgGood = false; |
|
240 } |
|
241 |
|
242 } |
|
243 if (allPkgGood) { |
|
244 TreePath configPath = projectTreeViewer.getTreePathForElement(selected); |
|
245 if (configPath != null) { |
|
246 selectedPath.add(configPath); |
|
247 } |
|
248 // check the project as well |
|
249 TreePath projectPath = projectTreeViewer.getTreePathForElement(selected.getCarbideProject().getProject()); |
|
250 if (projectPath != null) { |
|
251 selectedPath.add(projectPath); |
|
252 } |
|
253 } else { |
|
254 needToUnselect = selected; // selected configuration have non-exist PKG, need to unselect this later |
|
255 } |
|
256 } |
|
257 if(needToUnselect != null) { |
|
258 npiws.selectedBuildConfigList.remove(needToUnselect); |
|
259 } |
|
260 for (IProject selected : npiws.selectedProjectList) { |
|
261 // We deal with this when we set a build config |
|
262 } |
|
263 for (IPkgEntry entry : npiws.availableAppFileList) { |
|
264 pkgListRoot.addPkgEntry(entry); |
|
265 // only expanded/visible items are available for selecting programatically |
|
266 projectTreeViewer.reveal(entry); |
|
267 } |
|
268 removeButton.setEnabled(pkgListRoot.getPkgEntries().length != 0); |
|
269 // Build TreePath for all selected PKG |
|
270 for (IPkgEntry selected : npiws.selectedAppFileList) { |
|
271 TreePath pkgPath = projectTreeViewer.getTreePathForElement(selected); |
|
272 if (pkgPath != null) { |
|
273 selectedPath.add(pkgPath); |
|
274 } |
|
275 } |
|
276 |
|
277 // This shows the change in model(e.g. adding PKG) and force associate of the new tree nodes, so we can select later |
|
278 projectTreeViewer.refresh(); |
|
279 projectTreeViewer.initializeSelectedItems(selectedPath.toArray(new TreePath[selectedPath.size()])); |
|
280 // Show the selection |
|
281 projectTreeViewer.refresh(); |
|
282 } |
|
283 |
|
284 public void validatePage() { |
|
285 } |
|
286 } |