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;
|
|
22 |
import java.util.ArrayList;
|
|
23 |
import java.util.Collection;
|
|
24 |
|
|
25 |
import org.eclipse.core.runtime.IPath;
|
|
26 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
27 |
import org.eclipse.core.runtime.IStatus;
|
|
28 |
import org.eclipse.core.runtime.Path;
|
|
29 |
import org.eclipse.core.runtime.Status;
|
|
30 |
import org.eclipse.jface.dialogs.DialogPage;
|
|
31 |
import org.eclipse.jface.viewers.CheckStateChangedEvent;
|
|
32 |
import org.eclipse.jface.viewers.ICheckStateListener;
|
|
33 |
import org.eclipse.swt.SWT;
|
|
34 |
import org.eclipse.swt.events.SelectionAdapter;
|
|
35 |
import org.eclipse.swt.events.SelectionEvent;
|
|
36 |
import org.eclipse.swt.widgets.Composite;
|
|
37 |
import org.eclipse.swt.widgets.FileDialog;
|
|
38 |
import org.eclipse.ui.progress.UIJob;
|
|
39 |
|
1824
|
40 |
import com.nokia.carbide.discovery.ui.Messages;
|
1810
|
41 |
import com.nokia.cpp.internal.api.utils.ui.BrowseDialogUtils;
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Page in export wizard
|
|
45 |
*/
|
|
46 |
class ExportPage extends AbstractImportExportPage {
|
|
47 |
|
|
48 |
private File file;
|
|
49 |
private Collection<FeatureInfo> featureInfos;
|
|
50 |
private static String saveAsParent;
|
|
51 |
|
|
52 |
protected ExportPage() {
|
|
53 |
super("ExportPage"); //$NON-NLS-1$
|
1824
|
54 |
setTitle(Messages.ExportPage_Title);
|
|
55 |
setDescription(Messages.ExportPage_Description);
|
1810
|
56 |
}
|
|
57 |
|
|
58 |
public void createControl(Composite parent) {
|
|
59 |
super.createControl(parent);
|
|
60 |
Composite composite = (Composite) getControl();
|
|
61 |
|
1824
|
62 |
createViewerGroup(composite, Messages.ExportPage_ViewerGroupLabel);
|
|
63 |
createBrowseGroup(composite, Messages.ExportPage_BrowseGroupLabel);
|
1810
|
64 |
|
|
65 |
featureInfos = new ArrayList<FeatureInfo>();
|
|
66 |
|
|
67 |
setPageComplete(validatePage());
|
|
68 |
}
|
|
69 |
|
|
70 |
@Override
|
|
71 |
protected void createViewerGroup(Composite parent, String labelText) {
|
|
72 |
super.createViewerGroup(parent, labelText);
|
|
73 |
|
|
74 |
viewer.addCheckStateListener(new ICheckStateListener() {
|
|
75 |
public void checkStateChanged(CheckStateChangedEvent event) {
|
|
76 |
setPageComplete(validatePage());
|
|
77 |
}
|
|
78 |
});
|
|
79 |
startGetInputJob();
|
|
80 |
updateViewer();
|
|
81 |
}
|
|
82 |
|
|
83 |
@Override
|
|
84 |
protected void createBrowseGroup(Composite parent, String labelText) {
|
|
85 |
super.createBrowseGroup(parent, labelText);
|
|
86 |
|
|
87 |
if (saveAsParent == null)
|
|
88 |
saveAsParent = System.getProperty("user.home"); //$NON-NLS-1$
|
|
89 |
pathText.setText(new Path(saveAsParent).append("exportedFeatures.xml").toOSString()); //$NON-NLS-1$
|
|
90 |
browseButton.addSelectionListener(new SelectionAdapter() {
|
|
91 |
@Override
|
|
92 |
public void widgetSelected(SelectionEvent e) {
|
|
93 |
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
|
1824
|
94 |
dialog.setText(Messages.ExportPage_FileDialogText);
|
1810
|
95 |
BrowseDialogUtils.initializeFrom(dialog, pathText.getText());
|
|
96 |
dialog.setOverwrite(true); // prompt for overwrite
|
|
97 |
String path = dialog.open();
|
|
98 |
if (path != null) {
|
|
99 |
IPath saveAsPath = new Path(path);
|
|
100 |
saveAsParent = saveAsPath.removeLastSegments(1).toString();
|
|
101 |
pathText.setText(saveAsPath.toOSString());
|
|
102 |
}
|
|
103 |
}
|
|
104 |
});
|
|
105 |
}
|
|
106 |
|
|
107 |
private void startGetInputJob() {
|
1824
|
108 |
UIJob j = new UIJob(Messages.ExportPage_GetFeaturesJobName) {
|
1810
|
109 |
@Override
|
|
110 |
public IStatus runInUIThread(IProgressMonitor monitor) {
|
1818
|
111 |
viewer.setInput(P2Utils.getInstalledFeatures(monitor));
|
1810
|
112 |
updateViewer();
|
|
113 |
return Status.OK_STATUS;
|
|
114 |
}
|
|
115 |
};
|
|
116 |
j.schedule();
|
|
117 |
}
|
|
118 |
|
|
119 |
protected boolean validatePage() {
|
|
120 |
setErrorMessage(null);
|
1818
|
121 |
if (viewer.getTable().getItemCount() == 0) {
|
1824
|
122 |
setErrorMessage(Messages.ExportPage_NoFeaturesError);
|
1818
|
123 |
return false;
|
|
124 |
}
|
1810
|
125 |
if (viewer.getCheckedElements().length == 0) {
|
1824
|
126 |
setErrorMessage(Messages.ExportPage_NoFeaturesSelectedError);
|
1810
|
127 |
return false;
|
|
128 |
}
|
|
129 |
|
|
130 |
IPath path = new Path(pathText.getText());
|
|
131 |
file = path.toFile();
|
|
132 |
if (!file.isAbsolute()) {
|
1824
|
133 |
setErrorMessage(Messages.ExportPage_NoFileError);
|
1810
|
134 |
return false;
|
|
135 |
}
|
|
136 |
if (file.exists()) {
|
1824
|
137 |
setMessage(Messages.ExportPage_FileOverwriteWarning, DialogPage.WARNING);
|
1810
|
138 |
}
|
|
139 |
|
|
140 |
return true;
|
|
141 |
}
|
|
142 |
|
|
143 |
public File getFile() {
|
|
144 |
return file;
|
|
145 |
}
|
|
146 |
|
|
147 |
public Collection<FeatureInfo> getFeatureInfos() {
|
|
148 |
featureInfos.clear();
|
|
149 |
for (Object o : viewer.getCheckedElements()) {
|
|
150 |
featureInfos.add((FeatureInfo) o);
|
|
151 |
}
|
|
152 |
return featureInfos;
|
|
153 |
}
|
|
154 |
|
|
155 |
}
|