1
/*******************************************************************************
2
* (C) Copyright 2010 IBM Corp. 2010
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Thavidu Ranatunga (IBM) - Initial implementation.
10
*******************************************************************************/
11
package org.eclipse.linuxtools.internal.perf.ui;
13
import java.util.HashMap;
15
import org.eclipse.cdt.core.model.ICProject;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.jface.action.Action;
18
import org.eclipse.jface.text.BadLocationException;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.TreeViewer;
22
import org.eclipse.linuxtools.internal.perf.PerfPlugin;
23
import org.eclipse.linuxtools.internal.perf.model.PMDso;
24
import org.eclipse.linuxtools.internal.perf.model.PMFile;
25
import org.eclipse.linuxtools.internal.perf.model.PMLineRef;
26
import org.eclipse.linuxtools.internal.perf.model.PMSymbol;
27
import org.eclipse.linuxtools.profiling.ui.ProfileUIUtils;
28
import org.eclipse.ui.PartInitException;
30
public class PerfDoubleClickAction extends Action {
32
private TreeViewer viewer;
34
public PerfDoubleClickAction(TreeViewer v) {
39
ISelection selection = viewer.getSelection();
40
Object obj = ((IStructuredSelection)selection).getFirstElement();
42
if (obj instanceof PMLineRef) {
44
PMLineRef line = (PMLineRef) obj;
45
PMFile file = (PMFile) ((PMSymbol) line.getParent()).getParent();
47
ProfileUIUtils.openEditorAndSelect(file.getPath(), Integer.parseInt(line.getName()));
48
} catch (PartInitException e) {
50
} catch (BadLocationException e) {
53
} else if (obj instanceof PMFile) {
54
PMFile file = (PMFile)obj;
56
ProfileUIUtils.openEditorAndSelect(file.getName(), 1);
57
} catch (PartInitException e) {
59
} catch (BadLocationException e) {
62
} else if (obj instanceof PMSymbol) {
63
PMSymbol sym = (PMSymbol)obj;
64
PMFile file = (PMFile) sym.getParent();
65
PMDso dso = (PMDso) file.getParent();
67
if (file.getName().equals(PerfPlugin.STRINGS_UnfiledSymbols))
68
return; //Don't try to do anything if we don't know where or what the symbol is.
70
String binaryPath = dso.getPath();
73
project = ProfileUIUtils.findCProjectWithAbsolutePath(binaryPath);
74
HashMap<String, int[]> map = ProfileUIUtils.findFunctionsInProject(project, sym.getFunctionName(), -1, file.getPath(), true);
75
boolean bFound = false;
76
for (String loc : map.keySet()) {
77
ProfileUIUtils.openEditorAndSelect(loc, map.get(loc)[0], map.get(loc)[1]);
81
ProfileUIUtils.openEditorAndSelect(file.getPath(), 1);
83
} catch (CoreException e) {
85
} catch (BadLocationException e) {