Skip to main content
summaryrefslogtreecommitdiffstats
blob: a11f20f7b3907edf8e42f43731a3e56c349a9ba0 (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
package org.eclipse.debug.internal.ui;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */

import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.*;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.help.ViewContextComputer;
import org.eclipse.ui.help.WorkbenchHelp;

/**
 * A view that shows items that have been added to a inspector
 */
public class InspectorView extends AbstractDebugView {
	
	protected final static String PREFIX= "inspector_view.";

	protected InspectorContentProvider fContentProvider= null;
	protected ShowQualifiedAction fShowQualifiedAction;
	protected ShowTypesAction fShowTypesAction;
	protected InspectorViewAddToInspectorAction fAddToInspectorAction;
	protected RemoveFromInspectorAction fRemoveFromInspectorAction;
	protected RemoveAllFromInspectorAction fRemoveAllFromInspectorAction;
	protected ChangeVariableValueAction fChangeVariableAction;
	protected ControlAction fCopyToClipboardAction;
	/**
	 * @see IWorkbenchPart
	 */
	public void createPartControl(Composite parent) {
		TreeViewer vv = new TreeViewer(parent, SWT.MULTI);
		fViewer= vv;
		initializeActions();
		initializeToolBar();
		fContentProvider= new InspectorContentProvider(fRemoveAllFromInspectorAction);
		fViewer.setContentProvider(fContentProvider);
		fViewer.setLabelProvider(new DelegatingModelPresentation());
		fViewer.setUseHashlookup(true);

		createContextMenu(vv.getTree());
		
		fViewer.setInput(fContentProvider.getInspectorList());
		fViewer.getControl().addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				handleKeyPressed(e);
			}
		});

		setTitleToolTip(getTitleToolTipText(PREFIX));
		WorkbenchHelp.setHelp(
			parent,
			new ViewContextComputer(this, IDebugHelpContextIds.INSPECTOR_VIEW ));
	}

	/**
	 * Initializes the actions of this view.
	 */
	protected void initializeActions() {
		fShowTypesAction= new ShowTypesAction(fViewer);
		fShowTypesAction.setChecked(false);
		
		fShowQualifiedAction= new ShowQualifiedAction(fViewer);
		fShowQualifiedAction.setChecked(false);
				
		fAddToInspectorAction = new InspectorViewAddToInspectorAction(fViewer);

		fRemoveFromInspectorAction= new RemoveFromInspectorAction(fViewer);

		fRemoveAllFromInspectorAction= new RemoveAllFromInspectorAction(fViewer);
		
		fChangeVariableAction= new ChangeVariableValueAction(fViewer);
		fChangeVariableAction.setEnabled(false);
		
		fCopyToClipboardAction= new ControlAction(fViewer, new CopyVariablesToClipboardActionDelegate());
	}

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

	/**
	 * Adds items to the context menu including any extension defined actions.
	 */
	protected void fillContextMenu(IMenuManager menu) {
		menu.add(new Separator(IDebugUIConstants.EMPTY_EXPRESSION_GROUP));
		menu.add(new Separator(IDebugUIConstants.EXPRESSION_GROUP));
		menu.add(fAddToInspectorAction);
		menu.add(fChangeVariableAction);
		menu.add(fCopyToClipboardAction);
		menu.add(fRemoveFromInspectorAction);
		menu.add(fRemoveAllFromInspectorAction);
		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));
	}

	/**
	 * Adds a inspect item to the list, and sets the selection to either
	 * the first child or to the item if it has no children.
	 */
	public void addToInspector(InspectItem item) {
		fContentProvider.addToInspector(item);
	}

	/**
	 * Removes a items from the list
	 */
	public void removeFromInspector(Object object) {
		// first we have to get the root item to remove
		while (! (object instanceof InspectItem && object != null)) {
			object = fContentProvider.getParent(object);
		}
		if (object != null) {
			fContentProvider.removeFromInspector((InspectItem)object);
		}
	}

	/**
	 * Removes all items from the list
	 */
	public void removeAllFromInspector() {
		fContentProvider.removeAll();
	}
	
	/**
	 * Handles key events in viewer.  Specifically interested in
	 * the Delete key.
	 */
	protected void handleKeyPressed(KeyEvent event) {
		if (event.character == SWT.DEL && event.stateMask == 0 
			&& fRemoveFromInspectorAction.isEnabled()) {
				fRemoveFromInspectorAction.run();
		}
	}
}

Back to the top