1 /*******************************************************************************
2  * Copyright (c) 2000, 2019 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.ui.wizards.datatransfer;
15 
16 import java.util.List;
17 
18 import org.eclipse.core.resources.IResource;
19 import org.eclipse.jface.dialogs.IDialogSettings;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.jface.viewers.StructuredSelection;
22 import org.eclipse.jface.wizard.Wizard;
23 import org.eclipse.ui.IExportWizard;
24 import org.eclipse.ui.IWorkbench;
25 import org.eclipse.ui.ide.IDE;
26 import org.eclipse.ui.internal.WorkbenchPlugin;
27 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
28 import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages;
29 import org.eclipse.ui.internal.wizards.datatransfer.WizardArchiveFileResourceExportPage1;
30 
31 /**
32  * Standard workbench wizard for exporting resources from the workspace to a zip
33  * file.
34  * <p>
35  * This class may be instantiated and used without further configuration; this
36  * class is not intended to be subclassed.
37  * </p>
38  * <p>
39  * Example:
40  * </p>
41  *
42  * <pre>
43  * IWizard wizard = new ZipFileExportWizard();
44  * wizard.init(workbench, selection);
45  * WizardDialog dialog = new WizardDialog(shell, wizard);
46  * dialog.open();
47  * </pre>
48  * <p>
49  * During the call to <code>open</code>, the wizard dialog is presented to the
50  * user. When the user hits Finish, the user-selected workspace resources are
51  * exported to the user-specified zip file, the dialog closes, and the call to
52  * <code>open</code> returns.
53  * </p>
54  *
55  * @noextend This class is not intended to be subclassed by clients.
56  */
57 public class ZipFileExportWizard extends Wizard implements IExportWizard {
58 	private IStructuredSelection selection;
59 
60 	private WizardArchiveFileResourceExportPage1 mainPage;
61 
62 	/**
63 	 * Creates a wizard for exporting workspace resources to a zip file.
64 	 */
ZipFileExportWizard()65 	public ZipFileExportWizard() {
66 		IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault().getDialogSettings();
67 		IDialogSettings section = workbenchSettings
68 				.getSection("ZipFileExportWizard");//$NON-NLS-1$
69 		if (section == null) {
70 			section = workbenchSettings.addNewSection("ZipFileExportWizard");//$NON-NLS-1$
71 		}
72 		setDialogSettings(section);
73 	}
74 
75 	@Override
addPages()76 	public void addPages() {
77 		super.addPages();
78 		mainPage = new WizardArchiveFileResourceExportPage1(selection);
79 		addPage(mainPage);
80 	}
81 
82 	@Override
init(IWorkbench workbench, IStructuredSelection currentSelection)83 	public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
84 		this.selection = currentSelection;
85 		List<IResource> selectedResources = IDE.computeSelectedResources(currentSelection);
86 		if (!selectedResources.isEmpty()) {
87 			this.selection = new StructuredSelection(selectedResources);
88 		}
89 
90 		setWindowTitle(DataTransferMessages.DataTransfer_export);
91 		setDefaultPageImageDescriptor(IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/exportzip_wiz.png"));//$NON-NLS-1$
92 		setNeedsProgressMonitor(true);
93 	}
94 
95 	@Override
performFinish()96 	public boolean performFinish() {
97 		return mainPage.finish();
98 	}
99 }
100