Contribute CNF based TMF project handling
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / project / handlers / CopyTraceHandler.java
CommitLineData
12c155f5
FC
1/*******************************************************************************
2 * Copyright (c) 2011 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
13package org.eclipse.linuxtools.tmf.ui.project.handlers;
14
15import org.eclipse.core.commands.AbstractHandler;
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.jface.viewers.ISelection;
19import org.eclipse.jface.viewers.TreeSelection;
20import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
21import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
22import org.eclipse.linuxtools.tmf.ui.project.wizards.CopyTraceDialog;
23import org.eclipse.swt.widgets.Shell;
24import org.eclipse.ui.IWorkbenchPage;
25import org.eclipse.ui.IWorkbenchPart;
26import org.eclipse.ui.IWorkbenchWindow;
27import org.eclipse.ui.PlatformUI;
28
29/**
30 * <b><u>CopyTraceHandler</u></b>
31 * <p>
32 */
33public class CopyTraceHandler extends AbstractHandler {
34
35 private TmfTraceElement fTrace = null;
36
37 // ------------------------------------------------------------------------
38 // Validation
39 // ------------------------------------------------------------------------
40
41 @Override
42 public boolean isEnabled() {
43
44 // Check if we are closing down
45 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
46 if (window == null)
47 return false;
48
49 // Get the selection
50 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
51 IWorkbenchPart part = page.getActivePart();
52 ISelection selection = part.getSite().getSelectionProvider().getSelection();
53
54 // Make sure a trace is selected
55 fTrace = null;
56 if (selection instanceof TreeSelection) {
57 TreeSelection sel = (TreeSelection) selection;
58 // There should be only one item selected as per the plugin.xml
59 Object element = sel.getFirstElement();
60 if (element instanceof TmfTraceElement) {
61 fTrace = (TmfTraceElement) element;
62 }
63 }
64
65 // We only enable opening from the Traces folder for now
66 return (fTrace != null && fTrace.getParent() instanceof TmfTraceFolder);
67 }
68
69 // ------------------------------------------------------------------------
70 // Execution
71 // ------------------------------------------------------------------------
72
73 @Override
74 public Object execute(ExecutionEvent event) throws ExecutionException {
75
76 // Check if we are closing down
77 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
78 if (window == null)
79 return null;
80
81 // Fire the Copy Experiment dialog
82 Shell shell = window.getShell();
83 CopyTraceDialog dialog = new CopyTraceDialog(shell, fTrace);
84 dialog.open();
85
86 return null;
87 }
88
89}
This page took 0.026667 seconds and 5 git commands to generate.