~ubuntu-branches/ubuntu/utopic/eclipse-linuxtools/utopic

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.dashboard/src/org/eclipse/linuxtools/systemtap/ui/dashboard/actions/hidden/GetSelectedModule.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2014-05-12 18:11:40 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140512181140-w237r3vsah1tmybz
Tags: 2.2.1-1
* New upstream release.
* Refreshed d/patches.
* Removed eclipse-cdt-valgrind-remote package, all its functionality
  is now provided by eclipse-cdt-profiling-framework-remote.
* Added remove-license-feature.patch.
* Bump Standards-Version to 3.9.5.
* Enable eclipse-changelog package.
* Enable eclipse-rpm-editor package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2006 IBM Corporation.
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
 
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J, Anithra P J
10
 
 *******************************************************************************/
11
 
 
12
 
package org.eclipse.linuxtools.systemtap.ui.dashboard.actions.hidden;
13
 
 
14
 
import org.eclipse.jface.viewers.ISelection;
15
 
import org.eclipse.jface.viewers.IStructuredSelection;
16
 
import org.eclipse.jface.viewers.TreeViewer;
17
 
import org.eclipse.ui.IViewPart;
18
 
import org.eclipse.ui.PlatformUI;
19
 
 
20
 
import org.eclipse.linuxtools.systemtap.ui.structures.TreeNode;
21
 
import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.ActiveModuleData;
22
 
import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardModule;
23
 
import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.ModuleTreeNode;
24
 
import org.eclipse.linuxtools.systemtap.ui.dashboard.views.ActiveModuleBrowserView;
25
 
import org.eclipse.linuxtools.systemtap.ui.dashboard.views.DashboardModuleBrowserView;
26
 
 
27
 
/**
28
 
 * This class is used for determining what module is currently selected. It examins both
29
 
 * the DashboardModuleBrowserView and the ActiveModuleBrowserView to determine which is
30
 
 * active, and what is selected inside that view.
31
 
 * @author Ryan Morse
32
 
 */
33
 
public final class GetSelectedModule {
34
 
        /**
35
 
         * This class examins the provided view and if it is an instance of either
36
 
         * DashboardModuleBrowserView or ActiveModuleBrowserView it retreives the selected
37
 
         * item and returns it.  Else, it returns null.
38
 
         * @param view The view that is currently open.
39
 
         * @return The selected DashboardModule contained in the provided view
40
 
         */
41
 
        public static DashboardModule getModule(IViewPart view) {
42
 
                if(null == view)
43
 
                        view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(DashboardModuleBrowserView.ID);
44
 
                
45
 
                if(view instanceof DashboardModuleBrowserView)
46
 
                        return getModule2((DashboardModuleBrowserView)view);
47
 
                else if(view instanceof ActiveModuleBrowserView)
48
 
                        return getModule2((ActiveModuleBrowserView)view);
49
 
                return null;
50
 
        }
51
 
        
52
 
        
53
 
        /**
54
 
         * This class examins the provied view and retreives the selected item from
55
 
         * it.  It then converts the selected item into a DashboardModule and returns it.
56
 
         * @param view The DashboardModuleBrowserView that is currently open
57
 
         * @return The selected DashboardModule from the view
58
 
         */
59
 
        private static DashboardModule getModule2(DashboardModuleBrowserView view) {
60
 
                TreeViewer viewer = view.getViewer();
61
 
                ISelection selected = viewer.getSelection();
62
 
                if(null != selected && selected instanceof IStructuredSelection) {
63
 
                        Object element = ((IStructuredSelection)selected).getFirstElement();
64
 
                        if(element instanceof ModuleTreeNode) {
65
 
                                ModuleTreeNode mod = (ModuleTreeNode)element;
66
 
                                
67
 
                                return (DashboardModule)mod.getData();
68
 
                        }
69
 
                }
70
 
                return null;
71
 
        }
72
 
        
73
 
        public static TreeNode getNode(IViewPart view) {
74
 
                TreeViewer viewer = null;
75
 
                if(null == view)
76
 
                        view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(DashboardModuleBrowserView.ID);
77
 
                if(view instanceof DashboardModuleBrowserView)
78
 
                        viewer = ((DashboardModuleBrowserView)view).getViewer();
79
 
                else 
80
 
                        viewer = ((ActiveModuleBrowserView)view).getViewer();
81
 
                ISelection selected = viewer.getSelection();
82
 
                if(null != selected && selected instanceof IStructuredSelection) {
83
 
                        Object element = ((IStructuredSelection)selected).getFirstElement();
84
 
                        if(element instanceof TreeNode) {
85
 
                                TreeNode node = (TreeNode)element;
86
 
                                
87
 
                                return node;
88
 
                        }
89
 
                }
90
 
                return null;
91
 
        }
92
 
 
93
 
        /**
94
 
         * This class examins the provied view and retreives the selected item from
95
 
         * it.  It then gets the DashboardModule contained within the selected item
96
 
         * and returns it.
97
 
         * @param view The ActiveModuleBrowserView that is currently open
98
 
         * @return The selected DashboardModule from the view
99
 
         */
100
 
        
101
 
        
102
 
        private static DashboardModule getModule2(ActiveModuleBrowserView view) {
103
 
                TreeViewer viewer = view.getViewer();
104
 
                ISelection selected = viewer.getSelection();
105
 
                if(null != selected && selected instanceof IStructuredSelection) {
106
 
                        Object element = ((IStructuredSelection)selected).getFirstElement();
107
 
                        if(element instanceof TreeNode) {
108
 
                                TreeNode mod = (TreeNode)element;
109
 
                                
110
 
                                return ((ActiveModuleData)mod.getData()).module;
111
 
                        }
112
 
                }
113
 
                return null;
114
 
        }
115
 
}