ctf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.gdbtrace.ui / src / org / eclipse / linuxtools / internal / gdbtrace / ui / views / project / handlers / SelectTraceExecutableHandler.java
1 /*******************************************************************************
2 * Copyright (c) 2013 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 * Patrick Tasse - Initial API and implementation
11 * Bernd Hufmann - Improved trace selection
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.internal.gdbtrace.ui.views.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.core.resources.IResource;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IPath;
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.jface.viewers.IStructuredSelection;
24 import org.eclipse.jface.window.Window;
25 import org.eclipse.linuxtools.internal.gdbtrace.core.trace.GdbTrace;
26 import org.eclipse.linuxtools.internal.gdbtrace.ui.views.project.dialogs.SelectTraceExecutableDialog;
27 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
28 import org.eclipse.swt.widgets.MessageBox;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.ui.PlatformUI;
31 import org.eclipse.ui.handlers.HandlerUtil;
32
33 /**
34 * Handler for the Select Trace Executable command
35 * @author Patrick Tasse
36 */
37 public class SelectTraceExecutableHandler extends AbstractHandler {
38
39 @Override
40 public Object execute(ExecutionEvent event) throws ExecutionException {
41 Shell shell = HandlerUtil.getActiveShell(event);
42
43 // Get the selection before opening the dialog because otherwise the
44 // getCurrentSelection() call will always return null
45 ISelection selection = HandlerUtil.getCurrentSelection(event);
46
47 SelectTraceExecutableDialog dialog = new SelectTraceExecutableDialog(shell);
48 dialog.open();
49 if (dialog.getReturnCode() != Window.OK) {
50 return null;
51 }
52 IPath tracedExecutable = dialog.getExecutablePath();
53
54 if (selection instanceof IStructuredSelection) {
55 for (Object o : ((IStructuredSelection) selection).toList()) {
56 TmfTraceElement traceElement = (TmfTraceElement) o;
57 IResource resource = traceElement.getResource();
58 try {
59 resource.setPersistentProperty(GdbTrace.EXEC_KEY, tracedExecutable.toString());
60 } catch (CoreException e) {
61 final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
62 mb.setText(e.getClass().getName());
63 mb.setMessage(e.getMessage());
64 mb.open();
65 }
66 }
67 }
68 return null;
69 }
70
71 }
This page took 0.038645 seconds and 5 git commands to generate.