author | dadubrow |
Wed, 25 Aug 2010 15:37:23 -0500 | |
changeset 1885 | 988b4ab1b8c1 |
parent 1884 | 94c9fe3693ea |
child 1888 | fc9d5d520518 |
permissions | -rw-r--r-- |
1810 | 1 |
/* |
2 |
* Copyright (c) 2010 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 |
||
19 |
package com.nokia.carbide.internal.discovery.ui.wizard; |
|
20 |
||
21 |
import java.io.File; |
|
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
22 |
import java.io.FileInputStream; |
1810 | 23 |
import java.io.FileOutputStream; |
24 |
import java.io.OutputStream; |
|
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
25 |
import java.net.URI; |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
26 |
import java.net.URL; |
1810 | 27 |
import java.text.MessageFormat; |
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
28 |
import java.util.ArrayList; |
1810 | 29 |
import java.util.Collection; |
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
30 |
import java.util.Collections; |
1810 | 31 |
|
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
32 |
import org.eclipse.core.runtime.IPath; |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
33 |
import org.eclipse.core.runtime.NullProgressMonitor; |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
34 |
import org.eclipse.core.runtime.Path; |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
35 |
import org.eclipse.core.runtime.Platform; |
1810 | 36 |
import org.eclipse.jface.dialogs.MessageDialog; |
37 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
38 |
import org.eclipse.jface.wizard.Wizard; |
|
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
39 |
import org.eclipse.osgi.service.datalocation.Location; |
1810 | 40 |
import org.eclipse.ui.IExportWizard; |
41 |
import org.eclipse.ui.IWorkbench; |
|
42 |
||
43 |
import com.nokia.carbide.discovery.ui.Activator; |
|
1824 | 44 |
import com.nokia.carbide.discovery.ui.Messages; |
1810 | 45 |
|
46 |
/** |
|
47 |
* Wizard for exporting installed features to a file |
|
48 |
*/ |
|
49 |
public class ExportWizard extends Wizard implements IExportWizard { |
|
50 |
||
51 |
private ExportPage exportPage; |
|
52 |
||
53 |
public ExportWizard() { |
|
54 |
} |
|
55 |
||
56 |
public boolean performFinish() { |
|
57 |
Collection<FeatureInfo> featureInfos = exportPage.getFeatureInfos(); |
|
58 |
File file = exportPage.getFile(); |
|
59 |
OutputStream os; |
|
60 |
try { |
|
61 |
os = new FileOutputStream(file); |
|
1818 | 62 |
ImportExportData data = new ImportExportData(false, P2Utils.getKnownRepositories(), featureInfos); |
63 |
Streamer.writeToXML(os, data); |
|
1810 | 64 |
} catch (Exception e) { |
1824 | 65 |
MessageDialog.openError(getShell(), Messages.ExportWizard_ErrorTitle, |
66 |
MessageFormat.format(Messages.ExportWizard_WriteFileError, e.getMessage())); |
|
1810 | 67 |
} |
68 |
return true; |
|
69 |
} |
|
70 |
||
71 |
public void init(IWorkbench workbench, IStructuredSelection selection) { |
|
72 |
setDefaultPageImageDescriptor(Activator.getImageDescriptor("icons\\install_wiz.gif")); //$NON-NLS-1$ |
|
1824 | 73 |
setWindowTitle(Messages.ExportWizard_Title); |
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
74 |
exportPage = new ExportPage(getFilteredFeatureIds()); |
1810 | 75 |
addPage(exportPage); |
76 |
} |
|
77 |
||
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
78 |
private Collection<String> getFilteredFeatureIds() { |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
79 |
Collection<FeatureInfo> installedFeatures = null; |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
80 |
Location installLocation = Platform.getInstallLocation(); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
81 |
URL url = installLocation.getURL(); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
82 |
IPath path = new Path(url.getPath()); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
83 |
path = path.append("configuration/installedFeatures.xml"); //$NON-NLS-1$ |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
84 |
File file = path.toFile(); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
85 |
if (!file.exists()) { |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
86 |
installedFeatures = P2Utils.getInstalledFeatures(new NullProgressMonitor()); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
87 |
ImportExportData data = new ImportExportData(false, Collections.<URI>emptyList(), installedFeatures); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
88 |
try { |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
89 |
Streamer.writeToXML(new FileOutputStream(file), data); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
90 |
} catch (Exception e) { |
1885 | 91 |
Activator.logError(Messages.ExportWizard_WriteInstalledFeaturesError + file, e); |
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
92 |
} |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
93 |
} |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
94 |
else { |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
95 |
try { |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
96 |
ImportExportData data = Streamer.readFromXML(new FileInputStream(file)); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
97 |
installedFeatures = data.getFeatureInfos(); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
98 |
} catch (Exception e) { |
1885 | 99 |
Activator.logError(Messages.ExportWizard_ReadInstalledFeaturesError + file, e); |
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
100 |
} |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
101 |
} |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
102 |
|
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
103 |
Collection<String> filteredIds = new ArrayList<String>(); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
104 |
if (installedFeatures != null) { |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
105 |
for (FeatureInfo featureInfo : installedFeatures) { |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
106 |
filteredIds.add(featureInfo.getId()); |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
107 |
} |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
108 |
} |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
109 |
return filteredIds; |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
110 |
} |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
111 |
|
1810 | 112 |
} |