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

« 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/StopGraphAction.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
 * 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
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.systemtap.ui.dashboard.actions;
 
13
 
 
14
import org.eclipse.jface.action.Action;
 
15
import org.eclipse.jface.action.IAction;
 
16
import org.eclipse.jface.viewers.ISelection;
 
17
import org.eclipse.jface.viewers.IStructuredSelection;
 
18
import org.eclipse.ui.IViewActionDelegate;
 
19
import org.eclipse.ui.IViewPart;
 
20
import org.eclipse.ui.PlatformUI;
 
21
 
 
22
import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.DashboardGraphData;
 
23
import org.eclipse.linuxtools.systemtap.ui.dashboard.structures.GraphTreeNode;
 
24
import org.eclipse.linuxtools.systemtap.ui.dashboard.views.ActiveModuleBrowserView;
 
25
import org.eclipse.linuxtools.systemtap.ui.dashboard.views.DashboardView;
 
26
 
 
27
/**
 
28
 * This action is responsible for stopping an active graph.  This is used when a module
 
29
 * has already been started, but the user no longer wants to see one of the graphs.
 
30
 * This will make the selected graph inactive, with the option for bringing it back up
 
31
 * at a future time.
 
32
 * @author Ryan Morse
 
33
 */
 
34
public class StopGraphAction extends Action implements IViewActionDelegate {
 
35
        public void init(IViewPart view) {
 
36
                selectedItem = null;
 
37
        }
 
38
        
 
39
        public void run(IAction act) {
 
40
                run();
 
41
        }
 
42
 
 
43
        public void run() {
 
44
                run(selectedItem);
 
45
        }
 
46
        
 
47
        /**
 
48
         * This method retreives the graph information for the selected item and then
 
49
         * disposes of the graph from the display.
 
50
         * @param selected The graph item that is currently selected and needs to be deactivated
 
51
         */
 
52
        public void run(GraphTreeNode selected) {
 
53
                DashboardGraphData data = ((DashboardGraphData)selected.getData());
 
54
                IViewPart ivp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(DashboardView.ID);
 
55
                DashboardView dv = (DashboardView)ivp;
 
56
                dv.removeGraph(data.adapter,data.adapter.getmodulename());
 
57
                data.adapter = null;
 
58
 
 
59
                ivp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(ActiveModuleBrowserView.ID);
 
60
                ActiveModuleBrowserView ambv = (ActiveModuleBrowserView)ivp;
 
61
                ambv.getViewer().refresh();
 
62
        }
 
63
        
 
64
        /**
 
65
         * This method updates what item is currently selected.
 
66
         * @param action The action that started this method.
 
67
         * @param selection The newly selected item
 
68
         */
 
69
        public void selectionChanged(IAction action, ISelection selection) {
 
70
                if(selection instanceof IStructuredSelection) {
 
71
                        IStructuredSelection selected = (IStructuredSelection)selection;
 
72
                        Object o = selected.getFirstElement();
 
73
                        if(o instanceof GraphTreeNode) {
 
74
                                selectedItem = (GraphTreeNode)o;
 
75
                                o = selectedItem.getData();
 
76
                                if(null == ((DashboardGraphData)o).adapter) {
 
77
                                        action.setEnabled(false);
 
78
                                        return;
 
79
                                }
 
80
                        }
 
81
                }
 
82
                action.setEnabled(true);
 
83
        }
 
84
        
 
85
        private GraphTreeNode selectedItem;
 
86
}