Commit | Line | Data |
---|---|---|
6e512b93 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 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.lttng.ui.views.project.dialogs; | |
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.ui.IImportWizard; | |
22 | import org.eclipse.ui.IWorkbench; | |
23 | import org.eclipse.ui.ide.IDE; | |
24 | import org.eclipse.ui.internal.WorkbenchPlugin; | |
25 | import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; | |
26 | import org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages; | |
27 | ||
28 | /** | |
29 | * <b><u>ImportTraceWizard</u></b> | |
30 | * <p> | |
31 | * | |
32 | * TODO: Implement me. Please. | |
33 | */ | |
34 | @SuppressWarnings("restriction") | |
35 | public class ImportTraceWizard extends Wizard implements IImportWizard { | |
36 | ||
37 | private IWorkbench fWorkbench; | |
38 | private IStructuredSelection fSelection; | |
39 | private ImportTraceWizardPage fMainPage; | |
40 | ||
8e30d685 | 41 | /** |
6e512b93 ASL |
42 | * |
43 | */ | |
3b38ea61 | 44 | private final String IMPORT_WIZARD = "LTTngTraceImportWizard"; //$NON-NLS-1$ |
6e512b93 ASL |
45 | public ImportTraceWizard() { |
46 | IDialogSettings workbenchSettings = WorkbenchPlugin.getDefault().getDialogSettings(); | |
3b38ea61 | 47 | IDialogSettings section = workbenchSettings.getSection(IMPORT_WIZARD); |
6e512b93 | 48 | if (section == null) { |
3b38ea61 | 49 | section = workbenchSettings.addNewSection(IMPORT_WIZARD); |
6e512b93 | 50 | } |
8e30d685 | 51 | |
6e512b93 ASL |
52 | setDialogSettings(section); |
53 | } | |
54 | ||
55 | /* (non-Javadoc) | |
56 | * @see org.eclipse.jface.wizard.Wizard#addPages() | |
57 | */ | |
58 | @Override | |
59 | public void addPages() { | |
60 | super.addPages(); | |
61 | fMainPage = new ImportTraceWizardPage(fWorkbench, fSelection); | |
62 | addPage(fMainPage); | |
63 | } | |
64 | ||
65 | /* (non-Javadoc) | |
66 | * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) | |
67 | */ | |
d4011df2 | 68 | @Override |
8827c197 | 69 | @SuppressWarnings("rawtypes") |
6e512b93 ASL |
70 | public void init(IWorkbench workbench, IStructuredSelection selection) { |
71 | fWorkbench = workbench; | |
72 | fSelection = selection; | |
73 | ||
8827c197 | 74 | List selectedResources = IDE.computeSelectedResources(selection); |
6e512b93 ASL |
75 | if (!selectedResources.isEmpty()) { |
76 | fSelection = new StructuredSelection(selectedResources); | |
77 | } | |
8e30d685 | 78 | |
6e512b93 | 79 | setWindowTitle(DataTransferMessages.DataTransfer_importTitle); |
3b38ea61 | 80 | setDefaultPageImageDescriptor(IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/importdir_wiz.png")); //$NON-NLS-1$ |
6e512b93 ASL |
81 | setNeedsProgressMonitor(true); |
82 | } | |
8e30d685 WB |
83 | |
84 | public ImportTraceWizardPage getMainPage() { | |
85 | return fMainPage; | |
86 | } | |
87 | ||
88 | /** | |
89 | * performFinish is called after the "finish" button is pressed in the import wizard | |
90 | * If we return "false", the wizard will not close. | |
91 | * | |
92 | * We perform here version check on the imported LTTng trace | |
93 | * | |
94 | */ | |
6e512b93 ASL |
95 | @Override |
96 | public boolean performFinish() { | |
8e30d685 WB |
97 | |
98 | if ( fMainPage.getDestination().equals( fMainPage.getInitialContainerString() ) ) { | |
99 | ||
100 | String errMessage[] = { "Error : import destination is wrong." }; | |
101 | errMessage = fMainPage.extendErrorMessage(errMessage, ""); | |
102 | errMessage = fMainPage.extendErrorMessage(errMessage, "You cannot import your trace directly into the \"" + fMainPage.getInitialContainerString() + "\""); | |
103 | errMessage = fMainPage.extendErrorMessage(errMessage, "The trace has to be into a subdirectly, like \"" + fMainPage.getInitialContainerString() + "/MyTrace\"" ); | |
104 | errMessage = fMainPage.extendErrorMessage(errMessage, ""); | |
105 | errMessage = fMainPage.extendErrorMessage(errMessage, "Please change the destination folder."); | |
106 | fMainPage.showVersionErrorPopup(errMessage); | |
107 | ||
108 | return false; | |
109 | } | |
110 | ||
2fbfb67b | 111 | return fMainPage.finish(); |
6e512b93 | 112 | } |
8e30d685 WB |
113 | |
114 | @Override | |
115 | public boolean canFinish() { | |
116 | return fMainPage.isSelectedElementsValidLttngTraces(); | |
117 | } | |
6e512b93 | 118 | |
8e30d685 | 119 | } |