1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.ui
.project
.handlers
;
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
;
19 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
20 import org
.eclipse
.jface
.viewers
.TreeSelection
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceElement
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.model
.TmfTraceFolder
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.wizards
.CopyTraceDialog
;
24 import org
.eclipse
.swt
.widgets
.Shell
;
25 import org
.eclipse
.ui
.IWorkbenchPage
;
26 import org
.eclipse
.ui
.IWorkbenchPart
;
27 import org
.eclipse
.ui
.IWorkbenchWindow
;
28 import org
.eclipse
.ui
.PlatformUI
;
31 * <b><u>CopyTraceHandler</u></b>
34 public class CopyTraceHandler
extends AbstractHandler
{
36 private TmfTraceElement fTrace
= null;
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
43 public boolean isEnabled() {
45 // Check if we are closing down
46 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
52 IWorkbenchPage page
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage();
53 IWorkbenchPart part
= page
.getActivePart();
57 ISelectionProvider selectionProvider
= part
.getSite().getSelectionProvider();
58 if (selectionProvider
== null) {
61 ISelection selection
= selectionProvider
.getSelection();
63 // Make sure a trace is selected
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 TmfTraceElement
) {
70 fTrace
= (TmfTraceElement
) element
;
74 // We only enable opening from the Traces folder for now
75 return (fTrace
!= null && fTrace
.getParent() instanceof TmfTraceFolder
);
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
83 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
85 // Check if we are closing down
86 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
91 // Fire the Copy Experiment dialog
92 Shell shell
= window
.getShell();
93 CopyTraceDialog dialog
= new CopyTraceDialog(shell
, fTrace
);