| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009, 2014 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 | * Patrick Tasse - Remove enable check |
| 12 | *******************************************************************************/ |
| 13 | |
| 14 | package org.eclipse.tracecompass.internal.tmf.ui.project.handlers; |
| 15 | |
| 16 | import org.eclipse.core.commands.AbstractHandler; |
| 17 | import org.eclipse.core.commands.ExecutionEvent; |
| 18 | import org.eclipse.core.commands.ExecutionException; |
| 19 | import org.eclipse.jface.viewers.ISelection; |
| 20 | import org.eclipse.jface.viewers.IStructuredSelection; |
| 21 | import org.eclipse.swt.widgets.Shell; |
| 22 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement; |
| 23 | import org.eclipse.tracecompass.tmf.ui.project.wizards.CopyExperimentDialog; |
| 24 | import org.eclipse.ui.handlers.HandlerUtil; |
| 25 | |
| 26 | /** |
| 27 | * <b><u>CopyExperimentHandler</u></b> |
| 28 | * <p> |
| 29 | */ |
| 30 | public class CopyExperimentHandler extends AbstractHandler { |
| 31 | |
| 32 | // ------------------------------------------------------------------------ |
| 33 | // Execution |
| 34 | // ------------------------------------------------------------------------ |
| 35 | |
| 36 | @Override |
| 37 | public Object execute(ExecutionEvent event) throws ExecutionException { |
| 38 | |
| 39 | // Get selection already validated by handler in plugin.xml |
| 40 | ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); |
| 41 | if (!(selection instanceof IStructuredSelection)) { |
| 42 | return null; |
| 43 | } |
| 44 | TmfExperimentElement experiment = (TmfExperimentElement) ((IStructuredSelection) selection).getFirstElement(); |
| 45 | |
| 46 | // Fire the Copy Experiment dialog |
| 47 | Shell shell = HandlerUtil.getActiveShellChecked(event); |
| 48 | CopyExperimentDialog dialog = new CopyExperimentDialog(shell, experiment); |
| 49 | dialog.open(); |
| 50 | |
| 51 | return null; |
| 52 | } |
| 53 | |
| 54 | } |