~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfDoubleClickAction.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *    Thavidu Ranatunga (IBM) - Initial implementation.
 
10
 *******************************************************************************/ 
 
11
package org.eclipse.linuxtools.internal.perf.ui;
 
12
 
 
13
import java.util.HashMap;
 
14
 
 
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;
 
29
 
 
30
public class PerfDoubleClickAction extends Action {
 
31
        
 
32
        private TreeViewer viewer;
 
33
        
 
34
        public PerfDoubleClickAction(TreeViewer v) {
 
35
                super();
 
36
                viewer = v;
 
37
        }
 
38
        public void run() {
 
39
                ISelection selection = viewer.getSelection();
 
40
                Object obj = ((IStructuredSelection)selection).getFirstElement();
 
41
 
 
42
                if (obj instanceof PMLineRef) {
 
43
                        //Open in editor
 
44
                        PMLineRef line = (PMLineRef) obj;
 
45
                        PMFile file = (PMFile) ((PMSymbol) line.getParent()).getParent();
 
46
                        try {
 
47
                                ProfileUIUtils.openEditorAndSelect(file.getPath(), Integer.parseInt(line.getName()));
 
48
                        } catch (PartInitException e) {
 
49
                                e.printStackTrace();
 
50
                        } catch (BadLocationException e) {
 
51
                                e.printStackTrace();
 
52
                        }
 
53
                } else if (obj instanceof PMFile) {
 
54
                        PMFile file = (PMFile)obj;
 
55
                        try {
 
56
                                ProfileUIUtils.openEditorAndSelect(file.getName(), 1);
 
57
                        } catch (PartInitException e) {
 
58
                                e.printStackTrace();
 
59
                        } catch (BadLocationException e) {
 
60
                                e.printStackTrace();
 
61
                        }
 
62
                } else if (obj instanceof PMSymbol) {
 
63
                        PMSymbol sym = (PMSymbol)obj;
 
64
                        PMFile file = (PMFile) sym.getParent();
 
65
                        PMDso dso = (PMDso) file.getParent();
 
66
 
 
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.
 
69
 
 
70
                        String binaryPath = dso.getPath();
 
71
                        ICProject project;
 
72
                        try {
 
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]);
 
78
                                        bFound = true;
 
79
                                }
 
80
                                if (!bFound) {
 
81
                                        ProfileUIUtils.openEditorAndSelect(file.getPath(), 1);
 
82
                                }
 
83
                        } catch (CoreException e) {
 
84
                                e.printStackTrace();
 
85
                        } catch (BadLocationException e) {
 
86
                                e.printStackTrace();
 
87
                        }
 
88
                }
 
89
        }
 
90
 
 
91
}