1 /*******************************************************************************
2 * Copyright (c) 2013 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 * Patrick Tasse - Initial API and implementation
11 * Bernd Hufmann - Improved trace selection
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.gdbtrace
.ui
.views
.project
.handlers
;
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
;
34 * Handler for the Select Trace Executable command
35 * @author Patrick Tasse
37 public class SelectTraceExecutableHandler
extends AbstractHandler
{
40 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
41 Shell shell
= HandlerUtil
.getActiveShell(event
);
43 // Get the selection before opening the dialog because otherwise the
44 // getCurrentSelection() call will always return null
45 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
47 SelectTraceExecutableDialog dialog
= new SelectTraceExecutableDialog(shell
);
49 if (dialog
.getReturnCode() != Window
.OK
) {
52 IPath tracedExecutable
= dialog
.getExecutablePath();
54 if (selection
instanceof IStructuredSelection
) {
55 for (Object o
: ((IStructuredSelection
) selection
).toList()) {
56 TmfTraceElement traceElement
= (TmfTraceElement
) o
;
57 IResource resource
= traceElement
.getResource();
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());