KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > breakpoints > BreakpointsView


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
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 - initial API and implementation
10  * Brock Janiczak - bug 78494
11  *******************************************************************************/

12 package org.eclipse.debug.internal.ui.views.breakpoints;
13
14  
15 import java.lang.reflect.InvocationTargetException JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.Status;
24 import org.eclipse.core.runtime.jobs.Job;
25 import org.eclipse.debug.core.DebugPlugin;
26 import org.eclipse.debug.core.IBreakpointManagerListener;
27 import org.eclipse.debug.core.model.IBreakpoint;
28 import org.eclipse.debug.core.model.IStackFrame;
29 import org.eclipse.debug.core.model.IThread;
30 import org.eclipse.debug.internal.ui.DebugUIPlugin;
31 import org.eclipse.debug.internal.ui.DelegatingModelPresentation;
32 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
33 import org.eclipse.debug.internal.ui.LazyModelPresentation;
34 import org.eclipse.debug.internal.ui.actions.breakpointGroups.CopyBreakpointsAction;
35 import org.eclipse.debug.internal.ui.actions.breakpointGroups.PasteBreakpointsAction;
36 import org.eclipse.debug.internal.ui.actions.breakpointGroups.RemoveFromWorkingSetAction;
37 import org.eclipse.debug.internal.ui.actions.breakpoints.OpenBreakpointMarkerAction;
38 import org.eclipse.debug.internal.ui.actions.breakpoints.ShowSupportedBreakpointsAction;
39 import org.eclipse.debug.internal.ui.actions.breakpoints.SkipAllBreakpointsAction;
40 import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages;
41 import org.eclipse.debug.ui.AbstractDebugView;
42 import org.eclipse.debug.ui.IDebugModelPresentation;
43 import org.eclipse.debug.ui.IDebugUIConstants;
44 import org.eclipse.jface.action.IAction;
45 import org.eclipse.jface.action.IMenuManager;
46 import org.eclipse.jface.action.IToolBarManager;
47 import org.eclipse.jface.action.Separator;
48 import org.eclipse.jface.operation.IRunnableWithProgress;
49 import org.eclipse.jface.viewers.CheckStateChangedEvent;
50 import org.eclipse.jface.viewers.CheckboxTreeViewer;
51 import org.eclipse.jface.viewers.DoubleClickEvent;
52 import org.eclipse.jface.viewers.IBaseLabelProvider;
53 import org.eclipse.jface.viewers.ICheckStateListener;
54 import org.eclipse.jface.viewers.ISelection;
55 import org.eclipse.jface.viewers.IStructuredSelection;
56 import org.eclipse.jface.viewers.ITreeContentProvider;
57 import org.eclipse.jface.viewers.ITreeViewerListener;
58 import org.eclipse.jface.viewers.StructuredSelection;
59 import org.eclipse.jface.viewers.StructuredViewer;
60 import org.eclipse.jface.viewers.TreeExpansionEvent;
61 import org.eclipse.jface.viewers.Viewer;
62 import org.eclipse.swt.SWT;
63 import org.eclipse.swt.dnd.Clipboard;
64 import org.eclipse.swt.dnd.DND;
65 import org.eclipse.swt.dnd.Transfer;
66 import org.eclipse.swt.widgets.Composite;
67 import org.eclipse.swt.widgets.Display;
68 import org.eclipse.swt.widgets.Tree;
69 import org.eclipse.swt.widgets.TreeItem;
70 import org.eclipse.ui.IMemento;
71 import org.eclipse.ui.IPerspectiveDescriptor;
72 import org.eclipse.ui.IPerspectiveListener2;
73 import org.eclipse.ui.ISelectionListener;
74 import org.eclipse.ui.ISharedImages;
75 import org.eclipse.ui.IViewReference;
76 import org.eclipse.ui.IWorkbenchActionConstants;
77 import org.eclipse.ui.IWorkbenchPage;
78 import org.eclipse.ui.IWorkbenchPart;
79 import org.eclipse.ui.IWorkbenchPartReference;
80 import org.eclipse.ui.PlatformUI;
81 import org.eclipse.ui.XMLMemento;
82 import org.eclipse.ui.actions.ActionFactory;
83 import org.eclipse.ui.actions.SelectionListenerAction;
84 import org.eclipse.ui.contexts.IContextActivation;
85 import org.eclipse.ui.contexts.IContextService;
86 import org.eclipse.ui.progress.IProgressService;
87 import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds;
88 import org.eclipse.ui.views.navigator.LocalSelectionTransfer;
89
90 import com.ibm.icu.text.MessageFormat;
91
92 /**
93  * This view shows the breakpoints registered with the breakpoint manager
94  */

95 public class BreakpointsView extends AbstractDebugView implements ISelectionListener, IBreakpointManagerListener, IPerspectiveListener2 {
96
97     private BreakpointsViewEventHandler fEventHandler;
98     private ICheckStateListener fCheckListener= new ICheckStateListener() {
99         public void checkStateChanged(CheckStateChangedEvent event) {
100             Object JavaDoc source = event.getElement();
101             if (source instanceof BreakpointContainer) {
102                 handleContainerChecked(event, (BreakpointContainer) source);
103             } else if (source instanceof IBreakpoint) {
104                 handleBreakpointChecked(event, (IBreakpoint) source);
105             }
106         }
107     };
108     private boolean fIsTrackingSelection= false;
109     // Persistence constants
110
private static String JavaDoc KEY_IS_TRACKING_SELECTION= "isTrackingSelection"; //$NON-NLS-1$
111
private static String JavaDoc KEY_VALUE="value"; //$NON-NLS-1$
112
private static final String JavaDoc ACTION_REMOVE_FROM_GROUP = "RemoveFromGroup"; //$NON-NLS-1$
113
private BreakpointsContentProvider fContentProvider;
114     private Clipboard fClipboard;
115     private IContextActivation fActivatedContext;
116     
117     /**
118      * This memento allows the Breakpoints view to save and restore state
119      * when it is closed and opened within a session. A different
120      * memento is supplied by the platform for persistence at
121      * workbench shutdown.
122      */

123     private static IMemento fgMemento;
124     
125     /**
126      * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
127      */

128     public void createPartControl(Composite parent) {
129         super.createPartControl(parent);
130         DebugPlugin.getDefault().getBreakpointManager().addBreakpointManagerListener(this);
131         getSite().getWorkbenchWindow().addPerspectiveListener(this);
132     }
133
134     /**
135      * @see AbstractDebugView#createViewer(Composite)
136      */

137     protected Viewer createViewer(Composite parent) {
138         fContentProvider= new BreakpointsContentProvider();
139         CheckboxTreeViewer viewer = new BreakpointsViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK));
140         setViewer(viewer);
141         viewer.setUseHashlookup(true);
142         viewer.setContentProvider(fContentProvider);
143         viewer.setComparator(new BreakpointsComparator());
144         viewer.setInput(DebugPlugin.getDefault().getBreakpointManager());
145         viewer.addCheckStateListener(fCheckListener);
146         viewer.addTreeListener(new ITreeViewerListener() {
147             public void treeExpanded(TreeExpansionEvent event) {
148                 ((BreakpointsViewer)getViewer()).updateCheckedState(event.getElement());
149             }
150             public void treeCollapsed(TreeExpansionEvent event) {
151             }
152         });
153         viewer.setLabelProvider(new BreakpointsLabelProvider());
154         // Necessary so that the PropertySheetView hears about selections in this view
155
getSite().setSelectionProvider(viewer);
156         initIsTrackingSelection();
157         initBreakpointOrganizers();
158         setEventHandler(new BreakpointsViewEventHandler(this));
159         initDragAndDrop();
160         return viewer;
161     }
162     
163     /**
164      * Initializes drag and drop for the breakpoints viewer
165      */

166     private void initDragAndDrop() {
167         BreakpointsViewer viewer = (BreakpointsViewer) getViewer();
168         int ops = DND.DROP_MOVE | DND.DROP_COPY;
169         // drop
170
viewer.addDropSupport(ops, new Transfer[] {LocalSelectionTransfer.getInstance()}, new BreakpointsDropAdapter(viewer));
171         // Drag
172
viewer.addDragSupport(ops, new Transfer[] {LocalSelectionTransfer.getInstance()}, new BreakpointsDragAdapter(viewer));
173     }
174     
175     /**
176      * Initializes whether this view tracks selection in the
177      * debug view from the persisted state.
178      */

179     private void initIsTrackingSelection() {
180         IMemento memento= getMemento();
181         if (memento != null) {
182             IMemento node= memento.getChild(KEY_IS_TRACKING_SELECTION);
183             if (node != null) {
184                 setTrackSelection(Boolean.valueOf(node.getString(KEY_VALUE)).booleanValue());
185                 return;
186             }
187         }
188         setTrackSelection(false);
189     }
190     
191     /**
192      * Initializes the persisted breakpoints organizers
193      */

194     private void initBreakpointOrganizers() {
195         IMemento memento = getMemento();
196         if (memento != null) {
197             IMemento node = memento.getChild(IDebugUIConstants.EXTENSION_POINT_BREAKPOINT_ORGANIZERS);
198             if (node == null) {
199                 fContentProvider.setOrganizers(null);
200             } else {
201                 String JavaDoc value = node.getString(KEY_VALUE);
202                 if (value != null) {
203                     String JavaDoc[] ids = value.split(","); //$NON-NLS-1$
204
BreakpointOrganizerManager manager = BreakpointOrganizerManager.getDefault();
205                     List JavaDoc organziers= new ArrayList JavaDoc();
206                     for (int i = 0; i < ids.length; i++) {
207                         IBreakpointOrganizer organizer = manager.getOrganizer(ids[i]);
208                         if (organizer != null) {
209                             organziers.add(organizer);
210                         }
211                     }
212                     fContentProvider.setOrganizers((IBreakpointOrganizer[]) organziers.toArray(new IBreakpointOrganizer[organziers.size()]));
213                 }
214             }
215         }
216     }
217     
218     /* (non-Javadoc)
219      * @see org.eclipse.debug.ui.AbstractDebugView#getMemento()
220      */

221     protected IMemento getMemento() {
222         if (fgMemento != null) {
223             return fgMemento;
224         }
225         return super.getMemento();
226     }
227     
228     /**
229      * Update the checked state up the given element and all of its children.
230      *
231      * @param element
232      */

233     public void updateCheckedState(Object JavaDoc element) {
234         ((BreakpointsViewer)getViewer()).updateCheckedState(element);
235     }
236         
237     /**
238      * Returns this view's viewer as a checkbox tree viewer.
239      * @return this view's viewer as a checkbox tree viewer
240      */

241     public CheckboxTreeViewer getCheckboxViewer() {
242         return (CheckboxTreeViewer) getViewer();
243     }
244     
245     /**
246      * Returns this view's content provider as a tree content provider.
247      * @return this view's content provider as a tree content provider
248      */

249     public ITreeContentProvider getTreeContentProvider() {
250         return fContentProvider;
251     }
252
253     /**
254      * A breakpoint has been checked/unchecked. Update the group
255      * element's checked/grayed state as appropriate.
256      */

257     private void handleBreakpointChecked(final CheckStateChangedEvent event, final IBreakpoint breakpoint) {
258         final boolean enable= event.getChecked();
259         String JavaDoc jobName = enable ? DebugUIViewsMessages.BreakpointsView_0 : DebugUIViewsMessages.BreakpointsView_1; //
260
new Job(jobName) {
261             protected IStatus run(IProgressMonitor monitor) {
262                 try {
263                     breakpoint.setEnabled(enable);
264                     return Status.OK_STATUS;
265                 } catch (final CoreException e) {
266                     Display.getDefault().asyncExec(new Runnable JavaDoc() {
267                         public void run() {
268                             String JavaDoc titleState= enable ? DebugUIViewsMessages.BreakpointsView_6 : DebugUIViewsMessages.BreakpointsView_7; //
269
String JavaDoc messageState= enable ? DebugUIViewsMessages.BreakpointsView_8 : DebugUIViewsMessages.BreakpointsView_9; //
270
DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), MessageFormat.format(DebugUIViewsMessages.BreakpointsView_10, new String JavaDoc[] { titleState }), MessageFormat.format(DebugUIViewsMessages.BreakpointsView_11, new String JavaDoc[] { messageState }), e); //
271
// If the breakpoint fails to update, reset its check state.
272
getCheckboxViewer().removeCheckStateListener(fCheckListener);
273                             event.getCheckable().setChecked(breakpoint, !event.getChecked());
274                             getCheckboxViewer().addCheckStateListener(fCheckListener);
275                         }
276                     });
277                 }
278                 return Status.CANCEL_STATUS;
279             }
280         }.schedule();
281     }
282
283     /**
284      * A group has been checked or unchecked. Enable/disable all of the
285      * breakpoints in that group to match.
286      */

287     private void handleContainerChecked(CheckStateChangedEvent event, BreakpointContainer container) {
288         final IBreakpoint[] breakpoints = container.getBreakpoints();
289         final boolean enable= event.getChecked();
290         IRunnableWithProgress runnable = new IRunnableWithProgress() {
291             public void run(IProgressMonitor monitor) {
292                 try {
293                     for (int i = 0; i < breakpoints.length; i++) {
294                         IBreakpoint breakpoint = breakpoints[i];
295                         breakpoint.setEnabled(enable);
296                     }
297                 } catch (CoreException e) {
298                     DebugUIPlugin.log(e);
299                 }
300             }
301         };
302         // TODO: should use scheduling rule
303
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
304         try {
305             progressService.busyCursorWhile(runnable);
306         }
307         catch (InvocationTargetException JavaDoc e) {}
308         catch (InterruptedException JavaDoc e) {}
309     }
310
311     /**
312      * @see AbstractDebugView#getHelpContextId()
313      */

314     protected String JavaDoc getHelpContextId() {
315         return IDebugHelpContextIds.BREAKPOINT_VIEW;
316     }
317
318     /**
319      * @see IWorkbenchPart#dispose()
320      */

321     public void dispose() {
322         disposeAction(IWorkbenchActionDefinitionIds.COPY);
323         disposeAction(IWorkbenchActionDefinitionIds.PASTE);
324         disposeAction(ACTION_REMOVE_FROM_GROUP);
325         
326         if (getCheckboxViewer() != null) {
327             getCheckboxViewer().removeCheckStateListener(fCheckListener);
328         }
329         IAction action= getAction("ShowBreakpointsForModel"); //$NON-NLS-1$
330
if (action != null) {
331             ((ShowSupportedBreakpointsAction)action).dispose();
332         }
333         getSite().getPage().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this);
334         DebugPlugin.getDefault().getBreakpointManager().removeBreakpointManagerListener(this);
335         super.dispose();
336         
337         if (getEventHandler() != null) {
338             getEventHandler().dispose();
339         }
340         
341         if (fClipboard != null) {
342             fClipboard.dispose();
343         }
344         
345         getSite().getWorkbenchWindow().removePerspectiveListener(this);
346     }
347
348     /**
349      * @see AbstractDebugView#createActions()
350      */

351     protected void createActions() {
352         IAction action = new OpenBreakpointMarkerAction(getViewer());
353         setAction("GotoMarker", action); //$NON-NLS-1$
354
setAction(DOUBLE_CLICK_ACTION, action);
355         setAction("ShowBreakpointsForModel", new ShowSupportedBreakpointsAction(getStructuredViewer(),this)); //$NON-NLS-1$
356
setAction("SkipBreakpoints", new SkipAllBreakpointsAction()); //$NON-NLS-1$
357

358         fClipboard= new Clipboard(getSite().getShell().getDisplay());
359         
360         PasteBreakpointsAction paste = new PasteBreakpointsAction(this);
361         configure(paste, IWorkbenchActionDefinitionIds.PASTE, ActionFactory.PASTE.getId(),ISharedImages.IMG_TOOL_PASTE);
362         SelectionListenerAction copy = new CopyBreakpointsAction(this, fClipboard, paste);
363         configure(copy, IWorkbenchActionDefinitionIds.COPY, ActionFactory.COPY.getId(), ISharedImages.IMG_TOOL_COPY);
364         
365         SelectionListenerAction remove = new RemoveFromWorkingSetAction(this);
366         setAction(ACTION_REMOVE_FROM_GROUP, remove);
367         getViewer().addSelectionChangedListener(remove);
368     }
369
370     /**
371      * Configures the action to override the global action, registers
372      * the action for selection change notification, and registers
373      * the action with this view.
374      *
375      * @param sla action
376      * @param defId action definition id
377      * @param globalId global action id
378      * @param imgId image identifier
379      */

380     private void configure(SelectionListenerAction action, String JavaDoc defId, String JavaDoc globalId, String JavaDoc imgId) {
381         setAction(defId, action);
382         action.setActionDefinitionId(defId);
383         getViewSite().getActionBars().setGlobalActionHandler(globalId, action);
384         getViewer().addSelectionChangedListener(action);
385         action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imgId));
386     }
387     
388     /**
389      * Cleans up selection listener action
390      *
391      * @param id action id
392      */

393     private void disposeAction(String JavaDoc id) {
394         IAction action = getAction(id);
395         if (action instanceof SelectionListenerAction) {
396             SelectionListenerAction sla = (SelectionListenerAction) action;
397             if (getViewer() != null) {
398                 getViewer().removeSelectionChangedListener(sla);
399             }
400         }
401     }
402
403     /**
404      * Adds items to the context menu.
405      *
406      * @param menu The menu to contribute to
407      */

408     protected void fillContextMenu(IMenuManager menu) {
409         updateObjects();
410         menu.add(new Separator(IDebugUIConstants.EMPTY_NAVIGATION_GROUP));
411         menu.add(new Separator(IDebugUIConstants.NAVIGATION_GROUP));
412         menu.add(getAction("GotoMarker")); //$NON-NLS-1$
413
menu.add(new Separator(IDebugUIConstants.EMPTY_BREAKPOINT_GROUP));
414         menu.add(new Separator(IDebugUIConstants.BREAKPOINT_GROUP));
415         menu.add(getAction(IWorkbenchActionDefinitionIds.COPY));
416         menu.add(getAction(IWorkbenchActionDefinitionIds.PASTE));
417         IAction action = getAction(ACTION_REMOVE_FROM_GROUP);
418         if (action.isEnabled()) {
419             menu.add(action);
420         }
421         menu.add(new Separator(IDebugUIConstants.EMPTY_RENDER_GROUP));
422         menu.add(new Separator(IDebugUIConstants.BREAKPOINT_GROUP_GROUP));
423         
424         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
425     }
426     
427     /**
428      * @see AbstractDebugView#configureToolBar(IToolBarManager)
429      */

430     protected void configureToolBar(IToolBarManager tbm) {
431         tbm.add(new Separator(IDebugUIConstants.BREAKPOINT_GROUP));
432         tbm.add(getAction("ShowBreakpointsForModel")); //$NON-NLS-1$
433
tbm.add(getAction("GotoMarker")); //$NON-NLS-1$
434
tbm.add(getAction("SkipBreakpoints")); //$NON-NLS-1$
435
tbm.add(new Separator(IDebugUIConstants.RENDER_GROUP));
436     }
437     
438     /**
439      * Returns this view's event handler
440      *
441      * @return a breakpoint view event handler
442      */

443     protected BreakpointsViewEventHandler getEventHandler() {
444         return fEventHandler;
445     }
446
447     /**
448      * Sets this view's event handler.
449      *
450      * @param eventHandler a breakpoint view event handler
451      */

452     private void setEventHandler(BreakpointsViewEventHandler eventHandler) {
453         fEventHandler = eventHandler;
454     }
455     /**
456      * @see org.eclipse.debug.ui.AbstractDebugView#becomesVisible()
457      */

458     protected void becomesVisible() {
459         super.becomesVisible();
460         CheckboxTreeViewer viewer = getCheckboxViewer();
461         ISelection selection = viewer.getSelection();
462         viewer.getControl().setRedraw(false);
463         ((BreakpointsContentProvider)viewer.getContentProvider()).reorganize();
464         viewer.setSelection(new StructuredSelection(selection));
465         viewer.getControl().setRedraw(true);
466     }
467
468     /* (non-Javadoc)
469      * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
470      */

471     public void selectionChanged(IWorkbenchPart part, ISelection sel) {
472         if (sel.isEmpty() || !isTrackingSelection()) {
473             return;
474         }
475         IStructuredSelection selection= (IStructuredSelection) sel;
476         Iterator JavaDoc iter= selection.iterator();
477         Object JavaDoc firstElement= iter.next();
478         if (firstElement == null || iter.hasNext()) {
479             return;
480         }
481         IThread thread= null;
482         if (firstElement instanceof IStackFrame) {
483             thread= ((IStackFrame) firstElement).getThread();
484         } else if (firstElement instanceof IThread) {
485             thread= (IThread) firstElement;
486         } else {
487             return;
488         }
489         IBreakpoint[] breakpoints= thread.getBreakpoints();
490         getViewer().setSelection(new StructuredSelection(breakpoints), true);
491     }
492     
493     /**
494      * Returns whether this view is currently tracking the
495      * selection from the debug view.
496      *
497      * @return whether this view is currently tracking the
498      * debug view's selection
499      */

500     public boolean isTrackingSelection() {
501         return fIsTrackingSelection;
502     }
503     
504     /**
505      * Sets whether this view should track the selection from
506      * the debug view.
507      *
508      * @param trackSelection whether or not this view should
509      * track the debug view's selection.
510      */

511     public void setTrackSelection(boolean trackSelection) {
512         fIsTrackingSelection= trackSelection;
513         if (trackSelection) {
514             getSite().getPage().addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this);
515         } else {
516             getSite().getPage().removeSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this);
517         }
518     }
519
520     /* (non-Javadoc)
521      * @see org.eclipse.ui.IViewPart#saveState(org.eclipse.ui.IMemento)
522      */

523     public void saveState(IMemento memento) {
524         super.saveState(memento);
525         IMemento node= memento.createChild(KEY_IS_TRACKING_SELECTION);
526         node.putString(KEY_VALUE, String.valueOf(fIsTrackingSelection));
527         
528         StringBuffer JavaDoc buffer= new StringBuffer JavaDoc();
529         IBreakpointOrganizer[] organizers = fContentProvider.getOrganizers();
530         if (organizers != null) {
531             for (int i = 0; i < organizers.length; i++) {
532                 IBreakpointOrganizer organizer = organizers[i];
533                 buffer.append(organizer.getIdentifier());
534                 if (i < (organizers.length - 1)) {
535                     buffer.append(',');
536                 }
537             }
538             node = memento.createChild(IDebugUIConstants.EXTENSION_POINT_BREAKPOINT_ORGANIZERS);
539             node.putString(KEY_VALUE, buffer.toString());
540         }
541         
542     }
543
544     /* (non-Javadoc)
545      * @see org.eclipse.debug.core.IBreakpointManagerListener#breakpointManagerEnablementChanged(boolean)
546      */

547     public void breakpointManagerEnablementChanged(boolean enabled) {
548         DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
549             public void run() {
550                 IAction action = getAction("SkipBreakpoints"); //$NON-NLS-1$
551
if (action != null) {
552                     ((SkipAllBreakpointsAction) action).updateActionCheckedState();
553                 }
554             }
555         });
556     }
557     
558     /* (non-Javadoc)
559      * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
560      */

561     public void doubleClick(DoubleClickEvent event) {
562           IStructuredSelection selection= (IStructuredSelection) event.getSelection();
563           if (selection.size() == 1) {
564               Object JavaDoc element = selection.getFirstElement();
565               if (element instanceof BreakpointContainer) {
566                   getCheckboxViewer().setExpandedState(element, !getCheckboxViewer().getExpandedState(element));
567                   return;
568               }
569           }
570         super.doubleClick(event);
571     }
572
573     /**
574      * @param selectedContainers
575      */

576     public void setBreakpointOrganizers(IBreakpointOrganizer[] organizers) {
577         Viewer viewer = getViewer();
578         ISelection selection = viewer.getSelection();
579         fContentProvider.setOrganizers(organizers);
580         viewer.setSelection(selection);
581     }
582     
583     /**
584      * returns the complete listing of breakpoints organizers
585      * @return the complete listing of breakpoint organizers
586      */

587     public IBreakpointOrganizer[] getBreakpointOrganizers() {
588         return fContentProvider.getOrganizers();
589     }
590
591     /* (non-Javadoc)
592      * @see org.eclipse.ui.IPerspectiveListener2#perspectiveChanged(org.eclipse.ui.IWorkbenchPage, org.eclipse.ui.IPerspectiveDescriptor, org.eclipse.ui.IWorkbenchPartReference, java.lang.String)
593      */

594     public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, IWorkbenchPartReference partRef, String JavaDoc changeId) {
595         if (partRef instanceof IViewReference && changeId.equals(IWorkbenchPage.CHANGE_VIEW_HIDE)) {
596             String JavaDoc id = ((IViewReference) partRef).getId();
597             if (id.equals(getViewSite().getId())) {
598                 // BreakpointsView closed. Persist settings.
599
fgMemento= XMLMemento.createWriteRoot("BreakpointsViewMemento"); //$NON-NLS-1$
600
saveState(fgMemento);
601             }
602         }
603     }
604
605     /* (non-Javadoc)
606      * @see org.eclipse.ui.IPerspectiveListener#perspectiveActivated(org.eclipse.ui.IWorkbenchPage, org.eclipse.ui.IPerspectiveDescriptor)
607      */

608     public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
609     }
610
611     /* (non-Javadoc)
612      * @see org.eclipse.ui.IPerspectiveListener#perspectiveChanged(org.eclipse.ui.IWorkbenchPage, org.eclipse.ui.IPerspectiveDescriptor, java.lang.String)
613      */

614     public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String JavaDoc changeId) {
615     }
616     
617     /* (non-Javadoc)
618      * @see org.eclipse.debug.ui.IDebugView#getPresentation(java.lang.String)
619      */

620     public IDebugModelPresentation getPresentation(String JavaDoc id) {
621         if (getViewer() instanceof StructuredViewer) {
622             IBaseLabelProvider lp = ((StructuredViewer)getViewer()).getLabelProvider();
623             if (lp instanceof BreakpointsLabelProvider) {
624                 BreakpointsLabelProvider blp = (BreakpointsLabelProvider) lp;
625                 lp = blp.getPresentation();
626             }
627             if (lp instanceof DelegatingModelPresentation) {
628                 return ((DelegatingModelPresentation)lp).getPresentation(id);
629             }
630             if (lp instanceof LazyModelPresentation) {
631                 if (((LazyModelPresentation)lp).getDebugModelIdentifier().equals(id)) {
632                     return (IDebugModelPresentation)lp;
633                 }
634             }
635         }
636         return null;
637     }
638     
639     /**
640      * This method is used solely to preserve the selection state of the viewer in the event that the current selection is to be removed
641      * @param selection the selection to be removed
642      *
643      * @since 3.3
644      */

645     public void preserveSelection(IStructuredSelection selection) {
646         if(selection != null && !selection.isEmpty()) {
647             TreeItem item = (TreeItem) ((BreakpointsViewer)getCheckboxViewer()).searchItem(selection.getFirstElement());
648             Object JavaDoc toselect = null;
649             if(item != null) {
650                 TreeItem parent = item.getParentItem();
651                 if(parent != null) {
652                     int idx = 0;
653                     if(parent.getItemCount() == 1) {
654                         toselect = parent.getData();
655                     }
656                     idx = parent.indexOf(item);
657                     if(idx == 0) {
658                         if(parent.getItemCount() > 1) {
659                             toselect = parent.getItem(1).getData();
660                         }
661                         else {
662                             toselect = parent.getItem(0).getData();
663                         }
664                     }
665                     if(idx > 0) {
666                         toselect = parent.getItem(idx-1).getData();
667                     }
668                 }
669                 else {
670                     Tree tree = item.getParent();
671                     TreeItem[] items = tree.getItems();
672                     for(int i = 0; i < items.length; i++) {
673                         if(item.equals(items[i])) {
674                             if(i - 1 < 0 && items.length > 1) {
675                                 toselect = items[i+1];
676                                 break;
677                             }
678                             else if(items.length > 1){
679                                 toselect = items[i-1].getData();
680                                 break;
681                             }
682                         }
683                     }
684                 }
685             }
686             if(toselect != null) {
687                 getViewer().setSelection(new StructuredSelection(toselect), true);
688             }
689         }
690     }
691     
692     /**
693      * Returns whether the given selection can be pasted into the given target.
694      * <p>
695      * Scheme:
696      * <ul>
697      * <li>Breakpoints can only be pasted into allowable containers (i..e. like workings sets)</li>
698      * <li>Breakpoints can only be pasted into containers that they do not already reside in</li>
699      * <li>Breakpoints can only be pasted into containers, not other breakpoints</li>
700      * </ul>
701      * </p>
702      *
703      * @param target target of the paste
704      * @param selection the selection to paste
705      * @return whether the given selection can be pasted into the given target
706      *
707      * TODO Remove in favour of using <code>TreeItem</code>s and <code>TreePath</code>s to determine paste targets
708      */

709     public boolean canPaste(Object JavaDoc target, ISelection selection) {
710         if(!(target instanceof BreakpointContainer)) {
711             return false;
712         }
713         if(selection.isEmpty()) {
714             return false;
715         }
716         IStructuredSelection ss = (IStructuredSelection) selection;
717         BreakpointContainer container = (BreakpointContainer) target;
718         IBreakpoint breakpoint = null;
719         Object JavaDoc element = null;
720         for(Iterator JavaDoc iter = ss.iterator(); iter.hasNext();) {
721             element = iter.next();
722             if(!(element instanceof IBreakpoint)) {
723                 return false;
724             }
725             breakpoint = (IBreakpoint) element;
726             if (container.contains(breakpoint) || !container.getOrganizer().canAdd(breakpoint, container.getCategory())) {
727                 return false;
728             }
729         }
730         return true;
731     }
732     
733     /**
734      * Pastes the selection into the given target
735      *
736      * @param target target of the paste, either a BreakpointContainer,
737      * or a Breakpoint within a BreakpointContainer
738      * @param selection breakpoints
739      * @return whether successful
740      *
741      * TODO remove in favour of using <code>TreeItem</code> as paste target
742      */

743     public boolean performPaste(Object JavaDoc target, ISelection selection) {
744         if (target instanceof BreakpointContainer && selection instanceof IStructuredSelection) {
745             BreakpointContainer container = (BreakpointContainer) target;
746             Object JavaDoc[] objects = ((IStructuredSelection)selection).toArray();
747             for (int i = 0; i < objects.length; i++) {
748                 container.getOrganizer().addBreakpoint((IBreakpoint)objects[i], container.getCategory());
749             }
750             return true;
751         }
752         return false;
753     }
754     
755     /**
756      * Returns if the breakpoints view is currently showing groups or not
757      * @return true of the breakpoints view showing groups, false otherwise
758      */

759     public boolean isShowingGroups() {
760         return fContentProvider.isShowingGroups();
761     }
762
763     /**
764      * @see org.eclipse.ui.part.PageBookView#partActivated(org.eclipse.ui.IWorkbenchPart)
765      */

766     public void partActivated(IWorkbenchPart part) {
767         IContextService contextService = (IContextService)getSite().getService(IContextService.class);
768         fActivatedContext = contextService.activateContext(IDebugUIConstants.ID_BREAKPOINT_VIEW);
769         super.partActivated(part);
770     }
771
772     /**
773      * @see org.eclipse.ui.part.PageBookView#partDeactivated(org.eclipse.ui.IWorkbenchPart)
774      */

775     public void partDeactivated(IWorkbenchPart part) {
776         IContextService contextService = (IContextService)getSite().getService(IContextService.class);
777         contextService.deactivateContext(fActivatedContext);
778         super.partDeactivated(part);
779     }
780 }
781
Popular Tags