Skip to main content
summaryrefslogtreecommitdiffstats
blob: c7d17c49f5a32e0fcccea382721224fa30524f3a (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
244
245
246
247
248
249
250
251
252
253
254
package org.eclipse.debug.internal.ui;

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

import org.eclipse.core.resources.IMarker;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IBreakpointManager;
import org.eclipse.debug.ui.IDebugModelPresentation;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
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.model.WorkbenchViewerSorter;

/**
 * This view shows the breakpoints registered with the breakpoint manager
 */
public class BreakpointsView extends AbstractDebugView implements ISelectionChangedListener, 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;
	
	/**
	 * @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.addSelectionChangedListener(this);
		fViewer.addDoubleClickListener(this);
		fViewer.getControl().addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent e) {
				handleKeyPressed(e);
			}
		});
		
		setTitleToolTip(getTitleToolTipText(PREFIX));
	}

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

	/**
	 * Initializes the actions of this view
	 */
	protected void initializeActions() {
		fRemoveBreakpointAction= new RemoveBreakpointAction(fViewer);
		fRemoveBreakpointAction.setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_REMOVE));
		fRemoveBreakpointAction.setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_REMOVE));
		fRemoveBreakpointAction.setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_REMOVE));
		
		fRemoveAllBreakpointsAction= new RemoveAllBreakpointsAction();
		fRemoveAllBreakpointsAction.setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_REMOVE_ALL));
		fRemoveAllBreakpointsAction.setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_REMOVE_ALL));
		fRemoveAllBreakpointsAction.setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_REMOVE_ALL));
		boolean enable= DebugPlugin.getDefault().getBreakpointManager().getBreakpoints().length == 0 ? false : true;
		fRemoveAllBreakpointsAction.setEnabled(enable);
		
		fShowQualifiedNamesAction = new ShowQualifiedAction(fViewer);
		fShowQualifiedNamesAction.setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_QUALIFIED_NAMES));
		fShowQualifiedNamesAction.setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_QUALIFIED_NAMES));
		fShowQualifiedNamesAction.setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_QUALIFIED_NAMES));
		fShowQualifiedNamesAction.setChecked(true);
		
		fOpenMarkerAction= new OpenBreakpointMarkerAction(fViewer);
		ISharedImages images= DebugUIPlugin.getDefault().getWorkbench().getSharedImages();
		fOpenMarkerAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_OPEN_MARKER));

		fEnableDisableBreakpointAction= new EnableDisableBreakpointAction(fViewer);
		DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(fEnableDisableBreakpointAction);
		DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(fRemoveAllBreakpointsAction);	
	}

	/**
	 * Cleans up the actions when this part is disposed
	 */
	protected void cleanupActions() {
		if (fEnableDisableBreakpointAction != null) {
			DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(fEnableDisableBreakpointAction);
		} 
		if (fRemoveAllBreakpointsAction != null) {		
			DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(fRemoveAllBreakpointsAction);
		}
	}

	/**
	 * Opens a marker for the current selection.
	 * An editor will be opened if <code>open</code> is <code>true</code>
	 * This will only occur for selections containing a single breakpoint.
	 */
	public void openMarkerForCurrentSelection(boolean open) {
		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();
		IEditorPart editor= getOpenEditor(breakpoint, page);
		if (editor != null) {
			editor.gotoMarker(breakpoint);
			return;
		}
		if (!open) {
			return;
		}
		
		openEditorForBreakpoint(breakpoint, page);
	}
	
	/**
	 * Open an editor for the breakpoint.  
	 */	
	protected void openEditorForBreakpoint(IMarker breakpoint, IWorkbenchPage page) {
		String id= getBreakpointManager().getModelIdentifier(breakpoint);
		IDebugModelPresentation presentation= getPresentation(id);
		IEditorInput input= presentation.getEditorInput(breakpoint);
		String editorId= presentation.getEditorId(input, breakpoint);
		if (input != null) {
			try {
				IEditorPart editor;
				editor= page.openEditor(input, editorId);
				editor.gotoMarker(breakpoint);
			} 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));
	}

	/**
	 * @see IDoubleClickListener
	 */
	public void doubleClick(DoubleClickEvent event) {
		openMarkerForCurrentSelection(true);
	}

	/**
	 * @see ISelectionChangedListener
	 */
	public void selectionChanged(SelectionChangedEvent event) {
		if (event.getSelection().isEmpty()) {
			return;
		}
		//FIXME: See PR 1G4CLUB
		openMarkerForCurrentSelection(false);
	}

	/**
	 * Returns whether an editor is open on this breakpoint's
	 * resource
	 */
	protected IEditorPart getOpenEditor(IMarker breakpoint, IWorkbenchPage page) {
		//attempt to find the editor for the input
		String id= getBreakpointManager().getModelIdentifier(breakpoint);
		IDebugModelPresentation presentation= getPresentation(id);
		IEditorInput editorElement = presentation.getEditorInput(breakpoint);
		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