blob: ce45bb87145d555e398b69d86e18a032d51b6b96 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/*******************************************************************************
* Copyright (c) 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Patrick Tasse - Initial API and implementation
* Bernd Hufmann - Improved trace selection
*******************************************************************************/
package org.eclipse.linuxtools.internal.gdbtrace.ui.views.project.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.linuxtools.internal.gdbtrace.trace.GdbTrace;
import org.eclipse.linuxtools.internal.gdbtrace.ui.views.project.dialogs.SelectTraceExecutableDialog;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* Handler for the Select Trace Executable command
* @author Patrick Tasse
*/
public class SelectTraceExecutableHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
// Get the selection before opening the dialog because otherwise the
// getCurrentSelection() call will always return null
ISelection selection = HandlerUtil.getCurrentSelection(event);
SelectTraceExecutableDialog dialog = new SelectTraceExecutableDialog(shell);
dialog.open();
if (dialog.getReturnCode() != Window.OK) {
return null;
}
IPath tracedExecutable = dialog.getExecutablePath();
if (selection instanceof IStructuredSelection) {
for (Object o : ((IStructuredSelection) selection).toList()) {
TmfTraceElement traceElement = (TmfTraceElement) o;
IResource resource = traceElement.getResource();
try {
resource.setPersistentProperty(GdbTrace.EXEC_KEY, tracedExecutable.toString());
} catch (CoreException e) {
final MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
mb.setText(e.getClass().getName());
mb.setMessage(e.getMessage());
mb.open();
}
}
}
return null;
}
}
|