Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2fa07415c756158d81e675d70c1abe5ef1949907 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package org.eclipse.debug.internal.ui;

/*
 * Licensed Materials - Property of IBM,
 * WebSphere Studio Workbench
 * (c) Copyright IBM Corp 2000
 */

import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.*;

/**
 * This view shows variables and their values for a particular stack frame
 */
public class VariablesView extends AbstractDebugView implements ISelectionListener {
	
	protected final static String PREFIX= "variables_view.";

	protected ShowQualifiedAction fShowQualifiedAction;
	protected ShowTypesAction fShowTypesAction;
	protected ChangeVariableValueAction fChangeVariableAction;
	protected AddToInspectorAction fAddToInspectorAction;

	/**
	 * Remove myself as a selection listener to the <code>LaunchesView</code> in this perspective.
	 *
	 * @see IWorkbenchPart
	 */
	public void dispose() {
		DebugUIPlugin.getDefault().removeSelectionListener(this);
		super.dispose();
	}

	/** 
	 * The <code>VariablesView</code> listens for selection changes in the <code>LaunchesView</code>
	 *
	 * @see ISelectionListener
	 */
	public void selectionChanged(IWorkbenchPart part, ISelection sel) {
		if (!(part instanceof DebugView)) {
			return;
		}
		if (!(sel instanceof IStructuredSelection)) {
			return;
		}

		setViewerInput((IStructuredSelection)sel);
	}

	protected void setViewerInput(IStructuredSelection ssel) {
		IDebugElement de= null;
		if (ssel.size() == 1) {
			Object input= ssel.getFirstElement();
			if (input != null && input instanceof IDebugElement) {
				de= ((IDebugElement) input).getStackFrame();
			}
		}

		Object current= fViewer.getInput();
		if (current == null && de == null) {
			return;
		}

		if (current != null && current.equals(de)) {
			return;
		}

		fViewer.setInput(de);
	}
	/**
	 * @see IWorkbenchPart
	 */
	public void createPartControl(Composite parent) {
		DebugUIPlugin.getDefault().addSelectionListener(this);
		TreeViewer vv = new TreeViewer(parent, SWT.MULTI);
		fViewer= vv;
		fViewer.setContentProvider(new VariablesContentProvider());
		fViewer.setLabelProvider(new DelegatingModelPresentation());
		fViewer.setUseHashlookup(true);
		// add a context menu
		createContextMenu(vv.getTree());

		initializeActions();
		initializeToolBar();
	
		setInitialContent();
		setTitleToolTip(getTitleToolTipText(PREFIX));
	}

	protected void setInitialContent() {
		IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow();
		if (window == null) {
			return;
		}
		IWorkbenchPage p= window.getActivePage();
		if (p == null) {
			return;
		}
		DebugView view= (DebugView) p.findView(IDebugUIConstants.ID_DEBUG_VIEW);
		if (view != null) {
			ISelectionProvider provider= view.getSite().getSelectionProvider();
			if (provider != null) {
				provider.getSelection();
				ISelection selection= provider.getSelection();
				if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
					setViewerInput((IStructuredSelection) selection);
				}
			}
		}
	}
	
	/**
	 * Initializes the actions of this view.
	 */
	protected void initializeActions() {
		fShowTypesAction= new ShowTypesAction(fViewer);
		fShowTypesAction.setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_TYPE_NAMES));
		fShowTypesAction.setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TYPE_NAMES));
		fShowTypesAction.setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TYPE_NAMES));
		fShowTypesAction.setChecked(false);
		
		fShowQualifiedAction= new ShowQualifiedAction(fViewer);
		fShowQualifiedAction.setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_QUALIFIED_NAMES));
		fShowQualifiedAction.setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_QUALIFIED_NAMES));
		fShowQualifiedAction.setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_QUALIFIED_NAMES));
		fShowQualifiedAction.setChecked(false);
		
		fAddToInspectorAction= new AddToInspectorAction(fViewer);
		
		fChangeVariableAction= new ChangeVariableValueAction(fViewer);
		fChangeVariableAction.setEnabled(false);
	} 

	/**
	 * Configures the toolBar
	 */
	protected void configureToolBar(IToolBarManager tbm) {
		tbm.add(new Separator(this.getClass().getName()));
		tbm.add(fShowTypesAction);
		tbm.add(fShowQualifiedAction);
	}

  /**
	* Adds items to the context menu including any extension defined actions.
	*/
	protected void fillContextMenu(IMenuManager menu) {

		menu.add(new Separator(IDebugUIConstants.EMPTY_VARIABLE_GROUP));
		menu.add(new Separator(IDebugUIConstants.VARIABLE_GROUP));
		menu.add(fAddToInspectorAction);
		menu.add(fChangeVariableAction);
		menu.add(new Separator(IDebugUIConstants.EMPTY_RENDER_GROUP));
		menu.add(new Separator(IDebugUIConstants.RENDER_GROUP));
		menu.add(fShowTypesAction);
		menu.add(fShowQualifiedAction);
		
		menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
	}
}

Back to the top