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
9
* IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse, Anithra P J, Anithra P J
10
*******************************************************************************/
12
package org.eclipse.linuxtools.systemtap.ui.dashboard.actions.hidden;
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;
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;
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.
33
public final class GetSelectedModule {
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
41
public static DashboardModule getModule(IViewPart view) {
43
view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(DashboardModuleBrowserView.ID);
45
if(view instanceof DashboardModuleBrowserView)
46
return getModule2((DashboardModuleBrowserView)view);
47
else if(view instanceof ActiveModuleBrowserView)
48
return getModule2((ActiveModuleBrowserView)view);
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
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;
67
return (DashboardModule)mod.getData();
73
public static TreeNode getNode(IViewPart view) {
74
TreeViewer viewer = null;
76
view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(DashboardModuleBrowserView.ID);
77
if(view instanceof DashboardModuleBrowserView)
78
viewer = ((DashboardModuleBrowserView)view).getViewer();
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;
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
97
* @param view The ActiveModuleBrowserView that is currently open
98
* @return The selected DashboardModule from the view
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;
110
return ((ActiveModuleData)mod.getData()).module;