author | dadubrow |
Wed, 25 Aug 2010 20:02:15 -0500 | |
changeset 1888 | fc9d5d520518 |
parent 1885 | 988b4ab1b8c1 |
child 1889 | 7232c671a6c7 |
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; |
|
25 |
import java.text.MessageFormat; |
|
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
26 |
import java.util.ArrayList; |
1810 | 27 |
import java.util.Collection; |
28 |
||
29 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
30 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
31 |
import org.eclipse.jface.wizard.Wizard; |
|
32 |
import org.eclipse.ui.IExportWizard; |
|
33 |
import org.eclipse.ui.IWorkbench; |
|
34 |
||
35 |
import com.nokia.carbide.discovery.ui.Activator; |
|
1824 | 36 |
import com.nokia.carbide.discovery.ui.Messages; |
1810 | 37 |
|
38 |
/** |
|
39 |
* Wizard for exporting installed features to a file |
|
40 |
*/ |
|
41 |
public class ExportWizard extends Wizard implements IExportWizard { |
|
42 |
||
43 |
private ExportPage exportPage; |
|
44 |
||
45 |
public ExportWizard() { |
|
46 |
} |
|
47 |
||
48 |
public boolean performFinish() { |
|
49 |
Collection<FeatureInfo> featureInfos = exportPage.getFeatureInfos(); |
|
50 |
File file = exportPage.getFile(); |
|
51 |
OutputStream os; |
|
52 |
try { |
|
53 |
os = new FileOutputStream(file); |
|
1818 | 54 |
ImportExportData data = new ImportExportData(false, P2Utils.getKnownRepositories(), featureInfos); |
55 |
Streamer.writeToXML(os, data); |
|
1810 | 56 |
} catch (Exception e) { |
1824 | 57 |
MessageDialog.openError(getShell(), Messages.ExportWizard_ErrorTitle, |
58 |
MessageFormat.format(Messages.ExportWizard_WriteFileError, e.getMessage())); |
|
1810 | 59 |
} |
60 |
return true; |
|
61 |
} |
|
62 |
||
63 |
public void init(IWorkbench workbench, IStructuredSelection selection) { |
|
64 |
setDefaultPageImageDescriptor(Activator.getImageDescriptor("icons\\install_wiz.gif")); //$NON-NLS-1$ |
|
1824 | 65 |
setWindowTitle(Messages.ExportWizard_Title); |
1888
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
66 |
exportPage = new ExportPage(getInitialFeatureIds()); |
1810 | 67 |
addPage(exportPage); |
68 |
} |
|
69 |
||
1888
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
70 |
private Collection<String> getInitialFeatureIds() { |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
71 |
// make sure it exists if not written already |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
72 |
File file = P2Utils.getInitialFeaturesFile(); |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
73 |
if (!file.exists()) { |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
74 |
P2Utils.writeFeaturesToFile(file); |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
75 |
} |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
76 |
|
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
77 |
Collection<FeatureInfo> installedFeatures = null; |
1888
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
78 |
try { |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
79 |
ImportExportData data = Streamer.readFromXML(new FileInputStream(file)); |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
80 |
installedFeatures = data.getFeatureInfos(); |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
81 |
} catch (Exception e) { |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
82 |
Activator.logError(Messages.ExportWizard_ReadInstalledFeaturesError + file, e); |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
83 |
} |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
84 |
|
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
85 |
Collection<String> featureIds = new ArrayList<String>(); |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
86 |
if (installedFeatures != null) { |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
87 |
for (FeatureInfo featureInfo : installedFeatures) { |
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
88 |
featureIds.add(featureInfo.getId()); |
1884
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
89 |
} |
94c9fe3693ea
Filter initial features from export wizard + sort wizards by feature id + version
dadubrow
parents:
1824
diff
changeset
|
90 |
} |
1888
fc9d5d520518
Write initial features file at startup to ensure it exists prior to any user installation
dadubrow
parents:
1885
diff
changeset
|
91 |
return featureIds; |
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 |
|
1810 | 94 |
} |