Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 43f18a1aa1ba4287360bd778a0b311bee6ed74dc (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2008, 2018 Red Hat, Inc.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    Kent Sebastian <ksebasti@redhat.com> - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.oprofile.ui.view;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.linuxtools.internal.oprofile.core.Oprofile;
import org.eclipse.linuxtools.oprofile.ui.model.IUiModelElement;
import org.eclipse.linuxtools.oprofile.ui.model.UiModelEvent;
import org.eclipse.linuxtools.oprofile.ui.model.UiModelImage;
import org.eclipse.linuxtools.oprofile.ui.model.UiModelSample;
import org.eclipse.linuxtools.oprofile.ui.model.UiModelSession;
import org.eclipse.linuxtools.oprofile.ui.model.UiModelSymbol;
import org.eclipse.linuxtools.profiling.ui.ProfileUIUtils;
import org.eclipse.ui.PartInitException;

/**
 * Listener for the oprofile view when a user double clicks on an element in the tree.
 *
 * Different things occur based on the event:
 *
 *   UiModelEvent         - nothing (?)
 *   UiModelSession     - save the session to a different name
 *   UiModelImage         - nothing (?)
 *   UiModelSymbol        - nothing (?)
 *   UiModelSample        - go to line number in appropriate file
 */
public class OprofileViewDoubleClickListener implements IDoubleClickListener {
    @Override
    public void doubleClick(DoubleClickEvent event) {
        TreeViewer tv = (TreeViewer) event.getSource();
        TreeSelection tsl = (TreeSelection) tv.getSelection();
        IUiModelElement element = (IUiModelElement) tsl.getFirstElement();

        try {
            if (element instanceof UiModelEvent) {
                // UiModelEvent event = (UiModelEvent)element;

            } else if (element instanceof UiModelSession) {
                /* moved into an action menu */
            } else if (element instanceof UiModelImage) {
                // UiModelImage image = (UiModelImage)element;

            } else if (element instanceof UiModelSymbol) {
                final UiModelSymbol symbol = (UiModelSymbol) element;
                final String fileName = symbol.getFileName();
                int line = symbol.getLineNumber();

                ProfileUIUtils.openEditorAndSelect(fileName, line);

            } else if (element instanceof UiModelSample) {
                // jump to line number in the appropriate file
                UiModelSample sample = (UiModelSample) element;
                int line = sample.getLine();

                // get file name from the parent sample
                final String fileName = sample.getFile();
                ProfileUIUtils.openEditorAndSelect(fileName, line, getProject());
            }
        } catch (BadLocationException e1) {
            e1.printStackTrace();
        } catch (PartInitException e2) {
            e2.printStackTrace();
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }

    /**
     *  return the project
     *  @since 2.1
     */
    protected IProject getProject() {
        return Oprofile.OprofileProject.getProject();
    }

}

Back to the top