Commit | Line | Data |
---|---|---|
12c155f5 | 1 | /******************************************************************************* |
c8422608 | 2 | * Copyright (c) 2009, 2013 Ericsson |
37d150dd | 3 | * |
12c155f5 FC |
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 | |
37d150dd | 8 | * |
12c155f5 FC |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
d34665f9 | 13 | package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; |
12c155f5 FC |
14 | |
15 | import org.eclipse.core.commands.AbstractHandler; | |
16 | import org.eclipse.core.commands.ExecutionEvent; | |
17 | import org.eclipse.core.commands.ExecutionException; | |
18 | import org.eclipse.jface.viewers.ISelection; | |
1595249b | 19 | import org.eclipse.jface.viewers.ISelectionProvider; |
12c155f5 FC |
20 | import org.eclipse.jface.viewers.StructuredSelection; |
21 | import org.eclipse.jface.viewers.TreeSelection; | |
22 | import org.eclipse.jface.wizard.WizardDialog; | |
23 | import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; | |
24 | import org.eclipse.linuxtools.tmf.ui.project.wizards.ImportTraceWizard; | |
25 | import org.eclipse.swt.widgets.Shell; | |
26 | import org.eclipse.ui.IWorkbench; | |
27 | import org.eclipse.ui.IWorkbenchPage; | |
28 | import org.eclipse.ui.IWorkbenchPart; | |
29 | import org.eclipse.ui.IWorkbenchWindow; | |
30 | import org.eclipse.ui.PlatformUI; | |
31 | ||
32 | /** | |
33 | * <b><u>ImportTraceHandler</u></b> | |
34 | * <p> | |
35 | * Starts an ImportTraceWizard that will handle the lowly details. | |
36 | */ | |
37 | public class ImportTraceHandler extends AbstractHandler { | |
38 | ||
39 | // ------------------------------------------------------------------------ | |
40 | // Execution | |
41 | // ------------------------------------------------------------------------ | |
42 | ||
43 | @Override | |
44 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
45 | ||
46 | // Check if we are closing down | |
47 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
37d150dd | 48 | if (window == null) { |
12c155f5 | 49 | return null; |
37d150dd | 50 | } |
12c155f5 FC |
51 | |
52 | // Get the selection | |
53 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
54 | IWorkbenchPart part = page.getActivePart(); | |
d5210347 PT |
55 | if (part == null) { |
56 | return false; | |
57 | } | |
1595249b | 58 | ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); |
37d150dd | 59 | if (selectionProvider == null) { |
1595249b | 60 | return false; |
37d150dd | 61 | } |
1595249b | 62 | ISelection selection = selectionProvider.getSelection(); |
12c155f5 FC |
63 | |
64 | TmfTraceFolder traceFolder = null; | |
65 | if (selection instanceof TreeSelection) { | |
66 | TreeSelection sel = (TreeSelection) selection; | |
67 | // There should be only one item selected as per the plugin.xml | |
68 | Object element = sel.getFirstElement(); | |
69 | if (element instanceof TmfTraceFolder) { | |
70 | traceFolder = (TmfTraceFolder) element; | |
71 | } | |
72 | } | |
37d150dd | 73 | if (traceFolder == null) { |
12c155f5 | 74 | return null; |
37d150dd | 75 | } |
12c155f5 FC |
76 | |
77 | // Fire the Import Trace Wizard | |
78 | IWorkbench workbench = PlatformUI.getWorkbench(); | |
79 | Shell shell = workbench.getActiveWorkbenchWindow().getShell(); | |
80 | ||
81 | ImportTraceWizard wizard = new ImportTraceWizard(); | |
82 | wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(traceFolder)); | |
83 | WizardDialog dialog = new WizardDialog(shell, wizard); | |
84 | dialog.open(); | |
85 | ||
86 | traceFolder.refresh(); | |
37d150dd | 87 | |
12c155f5 FC |
88 | return null; |
89 | } | |
90 | ||
91 | } |