Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9915273585603f0a348f49602af4825507315fa8 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
package org.eclipse.debug.internal.ui;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */
 
import java.util.Vector;

import org.eclipse.core.resources.IMarker;
import org.eclipse.debug.core.*;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.ui.IDebugModelPresentation;
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.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.*;
import org.eclipse.ui.help.ViewContextComputer;
import org.eclipse.ui.help.WorkbenchHelp;
import org.eclipse.ui.model.WorkbenchViewerSorter;

/**
 * This view shows the breakpoints registered with the breakpoint manager
 */
public class BreakpointsView extends AbstractDebugView implements IDoubleClickListener {
	
	protected final static String PREFIX= "breakpoints_view.";
	
	/**
	 * The various actions of the context menu of this view
	 */
	private OpenMarkerAction fOpenMarkerAction;
	private RemoveBreakpointAction fRemoveBreakpointAction;
	private RemoveAllBreakpointsAction fRemoveAllBreakpointsAction;
	private EnableDisableBreakpointAction fEnableDisableBreakpointAction;
	private ShowQualifiedAction fShowQualifiedNamesAction;
	private Vector fBreakpointListenerActions;
	
	/**
	 * @see IWorkbenchPart
	 */
	public void createPartControl(Composite parent) {
		fViewer= new TableViewer(parent, SWT.MULTI| SWT.H_SCROLL | SWT.V_SCROLL);
		fViewer.setContentProvider(new BreakpointsContentProvider());
		fViewer.setLabelProvider(new DelegatingModelPresentation());
		fViewer.setSorter(new WorkbenchViewerSorter());
		initializeActions();
		initializeToolBar();

		createContextMenu(((TableViewer)fViewer).getTable());
				
		fViewer.setInput(DebugPlugin.getDefault().getBreakpointManager());
		fViewer.addDoubleClickListener(this);
		fViewer.getControl().addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				handleKeyPressed(e);
			}
		});
		
		setTitleToolTip(getTitleToolTipText(PREFIX));
		WorkbenchHelp.setHelp(
			parent,
			new ViewContextComputer(this, IDebugHelpContextIds.BREAKPOINT_VIEW));
	}

	/**
	 * @see IWorkbenchPart
	 */
	public void dispose() {
		super.dispose();
		if (fViewer != null) {
			fViewer.removeDoubleClickListener(this);
		}
		cleanupActions();
	}

	/**
	 * Initializes the actions of this view
	 */
	protected void initializeActions() {
		fBreakpointListenerActions = new Vector(2);		
		fRemoveBreakpointAction= new RemoveBreakpointAction(fViewer);
		
		fRemoveAllBreakpointsAction= new RemoveAllBreakpointsAction();
		boolean enable= DebugPlugin.getDefault().getBreakpointManager().getBreakpoints().length == 0 ? false : true;
		fRemoveAllBreakpointsAction.setEnabled(enable);
		
		fShowQualifiedNamesAction = new ShowQualifiedAction(fViewer);
		fShowQualifiedNamesAction.setChecked(true);
		
		fOpenMarkerAction= new OpenBreakpointMarkerAction(fViewer);

		fEnableDisableBreakpointAction= new EnableDisableBreakpointAction(fViewer);
		addBreakpointListenerAction(fEnableDisableBreakpointAction);
		addBreakpointListenerAction(fRemoveAllBreakpointsAction);
	}

	/**
	 * Cleans up the actions when this part is disposed
	 */
	protected void cleanupActions() {
		if (fBreakpointListenerActions == null) {
			return;
		}
		DebugPlugin dp= DebugPlugin.getDefault();
		IBreakpointManager bm= dp.getBreakpointManager();
		
		for (int i=0; i < fBreakpointListenerActions.size(); i++) {
			bm.removeBreakpointListener((IBreakpointListener)fBreakpointListenerActions.get(i));
		} 
	}

	/**
	 * Opens a marker for the current selection.
	 * This will only occur for selections containing a single existing breakpoint.
	 */
	public void openMarkerForCurrentSelection() {
		IStructuredSelection selection= (IStructuredSelection) fViewer.getSelection();
		if (selection.size() != 1) {
			//Single selection only
			return;
		}
		//Get the selected marker
		IMarker breakpoint= (IMarker) selection.getFirstElement();
		if (!breakpoint.exists()) {
			return;
		}
		IWorkbenchWindow dwindow= getSite().getWorkbenchWindow();
		IWorkbenchPage page= dwindow.getActivePage();
		if (page == null) {
			return;
		}
		
		openEditorForBreakpoint(breakpoint, page);
	}
	
	/**
	 * Open an editor for the breakpoint.  
	 */	
	protected void openEditorForBreakpoint(IMarker marker, IWorkbenchPage page) {
		IBreakpoint breakpoint= getBreakpointManager().getBreakpoint(marker);
		String id= breakpoint.getModelIdentifier();
		IDebugModelPresentation presentation= getPresentation(id);
		IEditorInput input= presentation.getEditorInput(marker);
		String editorId= presentation.getEditorId(input, marker);
		if (input != null) {
			try {
				IEditorPart editor;
				editor= page.openEditor(input, editorId);
				editor.gotoMarker(marker);
			} catch (PartInitException e) {
				DebugUIUtils.logError(e);
			}
		}		
	}

	/**
	 * Adds items to the context menu
	 */
	protected void fillContextMenu(IMenuManager menu) {
		menu.add(new Separator(IDebugUIConstants.EMPTY_NAVIGATION_GROUP));
		menu.add(new Separator(IDebugUIConstants.NAVIGATION_GROUP));
		menu.add(fOpenMarkerAction);
		menu.add(new Separator(IDebugUIConstants.EMPTY_BREAKPOINT_GROUP));
		menu.add(new Separator(IDebugUIConstants.BREAKPOINT_GROUP));
		menu.add(fEnableDisableBreakpointAction);
		menu.add(fRemoveBreakpointAction);
		menu.add(fRemoveAllBreakpointsAction);
		menu.add(new Separator(IDebugUIConstants.EMPTY_RENDER_GROUP));
		menu.add(new Separator(IDebugUIConstants.RENDER_GROUP));
		menu.add(fShowQualifiedNamesAction);
		menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
	}
	
	/**
	 * Add an action to the contributed actions collection
	 */
	public void addBreakpointListenerAction(IBreakpointListener action) {
		fBreakpointListenerActions.add(action);
		DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(action);		
	}	
	
	/**
	 * @see IDoubleClickListener
	 */
	public void doubleClick(DoubleClickEvent event) {
		openMarkerForCurrentSelection();
	}

	/**
	 * Returns whether an editor is open on this breakpoint's
	 * resource
	 */
	protected IEditorPart getOpenEditor(IMarker marker, IWorkbenchPage page) {
		//attempt to find the editor for the input
		IBreakpoint breakpoint= getBreakpointManager().getBreakpoint(marker);
		String id= breakpoint.getModelIdentifier();
		IDebugModelPresentation presentation= getPresentation(id);
		IEditorInput editorElement = presentation.getEditorInput(marker);
		IEditorPart[] editors= page.getEditors();
		for (int i= 0; i < editors.length; i++) {
			IEditorPart part= editors[i];
			if (part.getEditorInput().equals(editorElement)) {
				page.bringToTop(part);
				return part;
			}
		}
		//did not find an open editor
		return null;
	}
	
	/**
	 * Configures the toolBar
	 */
	protected void configureToolBar(IToolBarManager tbm) {
		tbm.add(fRemoveBreakpointAction);
		tbm.add(fRemoveAllBreakpointsAction);
		tbm.add(fOpenMarkerAction);
		tbm.add(fShowQualifiedNamesAction);
	}
	
	/**
	 * Convience method to retrieve the breakpoint manager
	 */
	protected IBreakpointManager getBreakpointManager() {
		return DebugPlugin.getDefault().getBreakpointManager();
	}
	
	/**
	 * Handles key events in viewer.  Specifically interested in
	 * the Delete key.
	 */
	protected void handleKeyPressed(KeyEvent event) {
		if (event.character == SWT.DEL && event.stateMask == 0 
			&& fRemoveBreakpointAction.isEnabled()) {
				fRemoveBreakpointAction.run();
		}
	}
}

Back to the top