Commit | Line | Data |
---|---|---|
6de2f761 PT |
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 | |
93fee9ed | 11 | * Bernd Hufmann - Improved trace selection |
6de2f761 PT |
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; | |
8343b1f5 | 25 | import org.eclipse.linuxtools.internal.gdbtrace.core.trace.GdbTrace; |
6de2f761 PT |
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 | /** | |
93fee9ed | 34 | * Handler for the Select Trace Executable command |
6de2f761 PT |
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); | |
93fee9ed BH |
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 | ||
6de2f761 PT |
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 | ||
6de2f761 PT |
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 | } |