| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2010, 2013 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Francois Chouinard - Initial API and implementation |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.linuxtools.tmf.ui.project.wizards; |
| 14 | |
| 15 | import java.util.List; |
| 16 | |
| 17 | import org.eclipse.jface.dialogs.IDialogSettings; |
| 18 | import org.eclipse.jface.viewers.IStructuredSelection; |
| 19 | import org.eclipse.jface.viewers.StructuredSelection; |
| 20 | import org.eclipse.jface.wizard.Wizard; |
| 21 | import org.eclipse.linuxtools.internal.tmf.ui.Activator; |
| 22 | import org.eclipse.ui.IImportWizard; |
| 23 | import org.eclipse.ui.IWorkbench; |
| 24 | import org.eclipse.ui.ide.IDE; |
| 25 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
| 26 | |
| 27 | /** |
| 28 | * The import trace wizard implementation. |
| 29 | * <p> |
| 30 | * @version 1.0 |
| 31 | * @author Francois Chouinard |
| 32 | */ |
| 33 | public class ImportTraceWizard extends Wizard implements IImportWizard { |
| 34 | |
| 35 | // ------------------------------------------------------------------------ |
| 36 | // Constants |
| 37 | // ------------------------------------------------------------------------ |
| 38 | |
| 39 | static private final String PLUGIN_ID = Activator.PLUGIN_ID; |
| 40 | static private final String IMPORT_WIZARD = "ImportTraceWizard"; //$NON-NLS-1$ |
| 41 | static private final String ICON_PATH = "icons/wizban/trace_import_wiz.png"; //$NON-NLS-1$ |
| 42 | |
| 43 | // ------------------------------------------------------------------------ |
| 44 | // Attributes |
| 45 | // ------------------------------------------------------------------------ |
| 46 | |
| 47 | private IWorkbench fWorkbench; |
| 48 | private IStructuredSelection fSelection; |
| 49 | private ImportTraceWizardPage fTraceImportWizardPage; |
| 50 | |
| 51 | // ------------------------------------------------------------------------ |
| 52 | // Constructor |
| 53 | // ------------------------------------------------------------------------ |
| 54 | /** |
| 55 | * Default constructor |
| 56 | */ |
| 57 | public ImportTraceWizard() { |
| 58 | IDialogSettings workbenchSettings = Activator.getDefault().getDialogSettings(); |
| 59 | IDialogSettings section = workbenchSettings.getSection(IMPORT_WIZARD); |
| 60 | if (section == null) { |
| 61 | section = workbenchSettings.addNewSection(IMPORT_WIZARD); |
| 62 | } |
| 63 | setDialogSettings(section); |
| 64 | } |
| 65 | |
| 66 | // ------------------------------------------------------------------------ |
| 67 | // Wizard |
| 68 | // ------------------------------------------------------------------------ |
| 69 | |
| 70 | @Override |
| 71 | public void init(IWorkbench workbench, IStructuredSelection selection) { |
| 72 | fWorkbench = workbench; |
| 73 | fSelection = selection; |
| 74 | |
| 75 | List<?> selectedResources = IDE.computeSelectedResources(selection); |
| 76 | if (!selectedResources.isEmpty()) { |
| 77 | fSelection = new StructuredSelection(selectedResources); |
| 78 | } |
| 79 | |
| 80 | setWindowTitle(Messages.ImportTraceWizard_DialogTitle); |
| 81 | setDefaultPageImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH)); |
| 82 | setNeedsProgressMonitor(true); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public void addPages() { |
| 87 | super.addPages(); |
| 88 | fTraceImportWizardPage = new ImportTraceWizardPage(fWorkbench, fSelection); |
| 89 | addPage(fTraceImportWizardPage); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public boolean performFinish() { |
| 94 | return fTraceImportWizardPage.finish(); |
| 95 | } |
| 96 | |
| 97 | } |