KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > launch > LaunchView


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  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.views.launch;
12
13
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.MultiStatus;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.core.runtime.jobs.Job;
22 import org.eclipse.debug.core.DebugException;
23 import org.eclipse.debug.core.DebugPlugin;
24 import org.eclipse.debug.core.ILaunch;
25 import org.eclipse.debug.core.ILaunchManager;
26 import org.eclipse.debug.core.model.IDebugElement;
27 import org.eclipse.debug.core.model.IDebugTarget;
28 import org.eclipse.debug.core.model.IProcess;
29 import org.eclipse.debug.core.model.IStackFrame;
30 import org.eclipse.debug.core.model.ITerminate;
31 import org.eclipse.debug.internal.ui.DebugUIPlugin;
32 import org.eclipse.debug.internal.ui.DelegatingModelPresentation;
33 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
34 import org.eclipse.debug.internal.ui.actions.AddToFavoritesAction;
35 import org.eclipse.debug.internal.ui.actions.EditLaunchConfigurationAction;
36 import org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction;
37 import org.eclipse.debug.internal.ui.commands.actions.DisconnectCommandAction;
38 import org.eclipse.debug.internal.ui.commands.actions.DropToFrameCommandAction;
39 import org.eclipse.debug.internal.ui.commands.actions.ResumeCommandAction;
40 import org.eclipse.debug.internal.ui.commands.actions.StepIntoCommandAction;
41 import org.eclipse.debug.internal.ui.commands.actions.StepOverCommandAction;
42 import org.eclipse.debug.internal.ui.commands.actions.StepReturnCommandAction;
43 import org.eclipse.debug.internal.ui.commands.actions.SuspendCommandAction;
44 import org.eclipse.debug.internal.ui.commands.actions.TerminateAllAction;
45 import org.eclipse.debug.internal.ui.commands.actions.TerminateAndRelaunchAction;
46 import org.eclipse.debug.internal.ui.commands.actions.TerminateAndRemoveAction;
47 import org.eclipse.debug.internal.ui.commands.actions.TerminateCommandAction;
48 import org.eclipse.debug.internal.ui.commands.actions.ToggleStepFiltersAction;
49 import org.eclipse.debug.internal.ui.sourcelookup.EditSourceLookupPathAction;
50 import org.eclipse.debug.internal.ui.sourcelookup.LookupSourceAction;
51 import org.eclipse.debug.internal.ui.viewers.model.InternalTreeModelViewer;
52 import org.eclipse.debug.internal.ui.viewers.model.VirtualFindAction;
53 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener;
54 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
55 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDeltaVisitor;
56 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy;
57 import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer;
58 import org.eclipse.debug.internal.ui.views.DebugModelPresentationContext;
59 import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages;
60 import org.eclipse.debug.ui.AbstractDebugView;
61 import org.eclipse.debug.ui.DebugUITools;
62 import org.eclipse.debug.ui.IDebugModelPresentation;
63 import org.eclipse.debug.ui.IDebugUIConstants;
64 import org.eclipse.debug.ui.contexts.AbstractDebugContextProvider;
65 import org.eclipse.debug.ui.contexts.DebugContextEvent;
66 import org.eclipse.jface.action.GroupMarker;
67 import org.eclipse.jface.action.IMenuManager;
68 import org.eclipse.jface.action.IToolBarManager;
69 import org.eclipse.jface.action.Separator;
70 import org.eclipse.jface.dialogs.MessageDialog;
71 import org.eclipse.jface.viewers.DoubleClickEvent;
72 import org.eclipse.jface.viewers.ISelection;
73 import org.eclipse.jface.viewers.ISelectionChangedListener;
74 import org.eclipse.jface.viewers.IStructuredSelection;
75 import org.eclipse.jface.viewers.SelectionChangedEvent;
76 import org.eclipse.jface.viewers.StructuredViewer;
77 import org.eclipse.jface.viewers.TreeSelection;
78 import org.eclipse.jface.viewers.Viewer;
79 import org.eclipse.swt.SWT;
80 import org.eclipse.swt.events.KeyAdapter;
81 import org.eclipse.swt.events.KeyEvent;
82 import org.eclipse.swt.widgets.Composite;
83 import org.eclipse.ui.IMemento;
84 import org.eclipse.ui.IPageListener;
85 import org.eclipse.ui.IPartListener2;
86 import org.eclipse.ui.IPerspectiveDescriptor;
87 import org.eclipse.ui.IPerspectiveListener2;
88 import org.eclipse.ui.IViewSite;
89 import org.eclipse.ui.IWorkbenchActionConstants;
90 import org.eclipse.ui.IWorkbenchPage;
91 import org.eclipse.ui.IWorkbenchPart;
92 import org.eclipse.ui.IWorkbenchPartReference;
93 import org.eclipse.ui.IWorkbenchWindow;
94 import org.eclipse.ui.PartInitException;
95 import org.eclipse.ui.actions.SelectionListenerAction;
96 import org.eclipse.ui.dialogs.PropertyDialogAction;
97 import org.eclipse.ui.part.IShowInSource;
98 import org.eclipse.ui.part.IShowInTarget;
99 import org.eclipse.ui.part.IShowInTargetList;
100 import org.eclipse.ui.part.ShowInContext;
101 import org.eclipse.ui.progress.UIJob;
102
103 public class LaunchView extends AbstractDebugView implements ISelectionChangedListener, IPerspectiveListener2, IPageListener, IShowInTarget, IShowInSource, IShowInTargetList, IPartListener2 {
104     
105     public static final String JavaDoc ID_CONTEXT_ACTIVITY_BINDINGS = "contextActivityBindings"; //$NON-NLS-1$
106

107     private static final String JavaDoc TERMINATE = "terminate"; //$NON-NLS-1$
108

109     private static final String JavaDoc DISCONNECT = "disconnect"; //$NON-NLS-1$
110

111     private static final String JavaDoc SUSPEND = "suspend"; //$NON-NLS-1$
112

113     private static final String JavaDoc RESUME = "resume"; //$NON-NLS-1$
114

115     private static final String JavaDoc STEP_RETURN = "step_return"; //$NON-NLS-1$
116

117     private static final String JavaDoc STEP_OVER = "step_over"; //$NON-NLS-1$
118

119     private static final String JavaDoc DROP_TO_FRAME = "drop_to_frame"; //$NON-NLS-1$
120

121     private static final String JavaDoc STEP_INTO = "step_into"; //$NON-NLS-1$
122

123     private static final String JavaDoc TERMINATE_AND_REMOVE = "terminate_and_remove"; //$NON-NLS-1$
124

125     private static final String JavaDoc TERMINATE_ALL = "terminate_all"; //$NON-NLS-1$
126

127     private static final String JavaDoc TERMINATE_AND_RELAUNCH = "terminate_relaunch"; //$NON-NLS-1$
128

129     private static final String JavaDoc TOGGLE_STEP_FILTERS = "toggle_step_filters"; //$NON-NLS-1$
130

131     /**
132      * Whether this view is in the active page of a perspective.
133      */

134     private boolean fIsActive = true;
135         
136     /**
137      * Model presentation or <code>null</code> if none
138      */

139     private IDebugModelPresentation fPresentation = null;
140     
141     private EditLaunchConfigurationAction fEditConfigAction = null;
142     private AddToFavoritesAction fAddToFavoritesAction = null;
143     private EditSourceLookupPathAction fEditSourceAction = null;
144     private LookupSourceAction fLookupAction = null;
145
146     class ContextProvider extends AbstractDebugContextProvider implements IModelChangedListener {
147         
148         private ISelection fContext = null;
149         private TreeModelViewer fViewer = null;
150         private Visitor fVisitor = new Visitor();
151         
152         class Visitor implements IModelDeltaVisitor {
153             public boolean visit(IModelDelta delta, int depth) {
154                 Object JavaDoc element = delta.getElement();
155                 if ((delta.getFlags() & (IModelDelta.STATE | IModelDelta.CONTENT)) > 0) {
156                     // state and/or content change
157
if ((delta.getFlags() & IModelDelta.SELECT) == 0) {
158                         // no select flag
159
if ((delta.getFlags() & IModelDelta.CONTENT) > 0) {
160                             // content has changed without select >> possible re-activation
161
possibleChange(element, DebugContextEvent.ACTIVATED);
162                         } else if ((delta.getFlags() & IModelDelta.STATE) > 0) {
163                             // state has changed without select >> possible state change of active context
164
possibleChange(element, DebugContextEvent.STATE);
165                         }
166                     }
167                 }
168                 return true;
169             }
170         }
171         
172         public ContextProvider(TreeModelViewer viewer) {
173             super(LaunchView.this);
174             fViewer = viewer;
175             fViewer.addModelChangedListener(this);
176         }
177         
178         protected void dispose() {
179             fContext = null;
180             fViewer.removeModelChangedListener(this);
181         }
182         
183         /* (non-Javadoc)
184          * @see org.eclipse.debug.ui.contexts.IDebugContextProvider#getActiveContext()
185          */

186         public synchronized ISelection getActiveContext() {
187             return fContext;
188         }
189         
190         protected void activate(ISelection selection) {
191             synchronized (this) {
192                 fContext = selection;
193             }
194             fire(new DebugContextEvent(this, selection, DebugContextEvent.ACTIVATED));
195         }
196         
197         protected void possibleChange(Object JavaDoc element, int type) {
198             DebugContextEvent event = null;
199             synchronized (this) {
200                 if (fContext instanceof IStructuredSelection) {
201                     IStructuredSelection ss = (IStructuredSelection) fContext;
202                     if (!(ss.size() == 1 && ss.getFirstElement().equals(element))) {
203                         return;
204                     }
205                 } else {
206                     return;
207                 }
208                 event = new DebugContextEvent(this, fContext, type);
209             }
210             if (getControl().getDisplay().getThread() == Thread.currentThread()) {
211                 fire(event);
212             } else {
213                 final DebugContextEvent finalEvent = event;
214                 Job job = new UIJob("context change") { //$NON-NLS-1$
215
public IStatus runInUIThread(IProgressMonitor monitor) {
216                         // verify selection is still the same context since job was scheduled
217
synchronized (ContextProvider.this) {
218                             if (fContext instanceof IStructuredSelection) {
219                                 IStructuredSelection ss = (IStructuredSelection) fContext;
220                                 Object JavaDoc changed = ((IStructuredSelection)finalEvent.getContext()).getFirstElement();
221                                 if (!(ss.size() == 1 && ss.getFirstElement().equals(changed))) {
222                                     return Status.OK_STATUS;
223                                 }
224                             }
225                         }
226                         fire(finalEvent);
227                         return Status.OK_STATUS;
228                     }
229                 };
230                 job.setSystem(true);
231                 job.schedule();
232             }
233         }
234
235         /* (non-Javadoc)
236          * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener#modelChanged(org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta)
237          */

238         public void modelChanged(IModelDelta delta, IModelProxy proxy) {
239             delta.accept(fVisitor);
240         }
241         
242     }
243     
244     /**
245      * Context provider
246      */

247     private ContextProvider fProvider;
248     
249     /* (non-Javadoc)
250      * @see org.eclipse.debug.ui.AbstractDebugView#getHelpContextId()
251      */

252     protected String JavaDoc getHelpContextId() {
253         return IDebugHelpContextIds.DEBUG_VIEW;
254     }
255     
256     /* (non-Javadoc)
257      * @see org.eclipse.debug.ui.AbstractDebugView#createActions()
258      */

259     protected void createActions() {
260         setAction("Properties", new PropertyDialogAction(getSite(), getSite().getSelectionProvider())); //$NON-NLS-1$
261
fEditConfigAction = new EditLaunchConfigurationAction();
262         fAddToFavoritesAction = new AddToFavoritesAction();
263         fEditSourceAction = new EditSourceLookupPathAction(this);
264         fLookupAction = new LookupSourceAction(this);
265         setAction(FIND_ACTION, new VirtualFindAction((InternalTreeModelViewer) getViewer()));
266         
267         addCapabilityAction(new TerminateCommandAction(), TERMINATE);
268         addCapabilityAction(new DisconnectCommandAction(), DISCONNECT);
269         addCapabilityAction(new SuspendCommandAction(), SUSPEND);
270         addCapabilityAction(new ResumeCommandAction(), RESUME);
271         addCapabilityAction(new StepReturnCommandAction(), STEP_RETURN);
272         addCapabilityAction(new StepOverCommandAction(), STEP_OVER);
273         addCapabilityAction(new StepIntoCommandAction(), STEP_INTO);
274         addCapabilityAction(new DropToFrameCommandAction(), DROP_TO_FRAME);
275         addCapabilityAction(new TerminateAndRemoveAction(), TERMINATE_AND_REMOVE);
276         addCapabilityAction(new TerminateAndRelaunchAction(), TERMINATE_AND_RELAUNCH);
277         addCapabilityAction(new TerminateAllAction(), TERMINATE_ALL);
278         addCapabilityAction(new ToggleStepFiltersAction(), TOGGLE_STEP_FILTERS);
279     }
280     
281
282     /**
283      * Initializes the action and associates it with the given id.
284      *
285      * @param capability
286      * @param actionID
287      */

288     private void addCapabilityAction(DebugCommandAction capability, String JavaDoc actionID) {
289         capability.init(this);
290         setAction(actionID, capability);
291     }
292     
293     /**
294      * Disposes the given action.
295      *
296      * @param actionID
297      */

298     private void disposeCommandAction(String JavaDoc actionID) {
299         DebugCommandAction action = (DebugCommandAction) getAction(actionID);
300         action.dispose();
301     }
302     
303     /* (non-Javadoc)
304      * @see org.eclipse.debug.ui.AbstractDebugView#createViewer(org.eclipse.swt.widgets.Composite)
305      */

306     protected Viewer createViewer(Composite parent) {
307         fPresentation = new DelegatingModelPresentation();
308         TreeModelViewer viewer = new TreeModelViewer(parent,
309                 SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL,
310                 new DebugModelPresentationContext(IDebugUIConstants.ID_DEBUG_VIEW, fPresentation));
311         
312         viewer.addSelectionChangedListener(this);
313         viewer.getControl().addKeyListener(new KeyAdapter() {
314             public void keyPressed(KeyEvent event) {
315                 if (event.character == SWT.DEL && event.stateMask == 0) {
316                     handleDeleteKeyPressed();
317                 }
318             }
319         });
320         // add my viewer as a selection provider, so selective re-launch works
321
getSite().setSelectionProvider(viewer);
322         viewer.setInput(DebugPlugin.getDefault().getLaunchManager());
323         //setEventHandler(new LaunchViewEventHandler(this));
324
fProvider = new ContextProvider(viewer);
325         DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow()).addDebugContextProvider(fProvider);
326         return viewer;
327     }
328         
329     private void handleDeleteKeyPressed() {
330         IStructuredSelection selection= (IStructuredSelection) getViewer().getSelection();
331         Iterator JavaDoc iter= selection.iterator();
332         Object JavaDoc item;
333         boolean itemsToTerminate= false;
334         ITerminate terminable;
335         while (iter.hasNext()) {
336             item= iter.next();
337             if (item instanceof ITerminate) {
338                 terminable= (ITerminate) item;
339                 if (terminable.canTerminate() && !terminable.isTerminated()) {
340                     itemsToTerminate= true;
341                     break;
342                 }
343             }
344         }
345         if (itemsToTerminate) {
346             // Prompt the user to proceed with termination
347
if (!MessageDialog.openQuestion(getSite().getShell(), DebugUIViewsMessages.LaunchView_Terminate_and_Remove_1, DebugUIViewsMessages.LaunchView_Terminate_and_remove_selected__2)) {
348                 return;
349             }
350         }
351         MultiStatus status= new MultiStatus(DebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, DebugUIViewsMessages.LaunchView_Exceptions_occurred_attempting_to_terminate_and_remove_3, null);
352         iter= selection.iterator();
353         while (iter.hasNext()) {
354             try {
355                 terminateAndRemove(iter.next());
356             } catch (DebugException exception) {
357                 status.merge(exception.getStatus());
358             }
359         }
360         if (!status.isOK()) {
361             IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow();
362             if (window != null) {
363                 DebugUIPlugin.errorDialog(window.getShell(), DebugUIViewsMessages.LaunchView_Terminate_and_Remove_4, DebugUIViewsMessages.LaunchView_Terminate_and_remove_failed_5, status);
364             } else {
365                 DebugUIPlugin.log(status);
366             }
367         }
368     }
369     
370     /**
371      * Terminates and removes the given element from the launch manager
372      */

373     public static void terminateAndRemove(Object JavaDoc element) throws DebugException {
374         ILaunch launch= null;
375         ITerminate terminable = null;
376         if (element instanceof ILaunch) {
377             launch= (ILaunch) element;
378         } else if (element instanceof IDebugElement) {
379             launch= ((IDebugElement) element).getLaunch();
380         } else if (element instanceof IProcess) {
381             launch= ((IProcess) element).getLaunch();
382         }
383         terminable = launch;
384         if (terminable == null) {
385             if (element instanceof ITerminate) {
386                 terminable = (ITerminate) element;
387             }
388         }
389         if (terminable == null) {
390             return;
391         }
392         if (!(terminable.canTerminate() || terminable.isTerminated())) {
393             // Don't try to terminate or remove attached launches
394
return;
395         }
396         try {
397             if (!terminable.isTerminated()) {
398                 terminable.terminate();
399             }
400         } finally {
401             if (launch != null) {
402                 ILaunchManager lManager= DebugPlugin.getDefault().getLaunchManager();
403                 lManager.removeLaunch(launch);
404             }
405         }
406     }
407
408     private void commonInit(IViewSite site) {
409         site.getPage().addPartListener((IPartListener2) this);
410         site.getWorkbenchWindow().addPageListener(this);
411         site.getWorkbenchWindow().addPerspectiveListener(this);
412     }
413     
414     /* (non-Javadoc)
415      * @see org.eclipse.ui.IViewPart#init(org.eclipse.ui.IViewSite)
416      */

417     public void init(IViewSite site) throws PartInitException {
418         super.init(site);
419         commonInit(site);
420     }
421
422     /* (non-Javadoc)
423      * @see org.eclipse.ui.IViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
424      */

425     public void init(IViewSite site, IMemento memento) throws PartInitException {
426         super.init(site, memento);
427         commonInit(site);
428     }
429         
430     /* (non-Javadoc)
431      * @see org.eclipse.debug.ui.AbstractDebugView#configureToolBar(org.eclipse.jface.action.IToolBarManager)
432      */

433     protected void configureToolBar(IToolBarManager tbm) {
434         tbm.add(new Separator(IDebugUIConstants.THREAD_GROUP));
435         tbm.add(new Separator(IDebugUIConstants.STEP_GROUP));
436         tbm.add(new GroupMarker(IDebugUIConstants.STEP_INTO_GROUP));
437         tbm.add(new GroupMarker(IDebugUIConstants.STEP_OVER_GROUP));
438         tbm.add(new GroupMarker(IDebugUIConstants.STEP_RETURN_GROUP));
439         tbm.add(new GroupMarker(IDebugUIConstants.EMPTY_STEP_GROUP));
440         tbm.add(new Separator(IDebugUIConstants.RENDER_GROUP));
441         
442         tbm.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(RESUME));
443         tbm.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(SUSPEND));
444         tbm.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(TERMINATE));
445         tbm.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(DISCONNECT));
446         
447         tbm.appendToGroup(IDebugUIConstants.STEP_INTO_GROUP, getAction(STEP_INTO));
448         tbm.appendToGroup(IDebugUIConstants.STEP_OVER_GROUP, getAction(STEP_OVER));
449         tbm.appendToGroup(IDebugUIConstants.STEP_RETURN_GROUP, getAction(STEP_RETURN));
450         
451         tbm.appendToGroup(IDebugUIConstants.EMPTY_STEP_GROUP, getAction(DROP_TO_FRAME));
452         
453         tbm.appendToGroup(IDebugUIConstants.RENDER_GROUP, getAction(TOGGLE_STEP_FILTERS));
454     }
455
456     /* (non-Javadoc)
457      * @see org.eclipse.ui.IWorkbenchPart#dispose()
458      */

459     public void dispose() {
460         DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow()).removeDebugContextProvider(fProvider);
461         disposeActions();
462         fProvider.dispose();
463         Viewer viewer = getViewer();
464         if (viewer != null) {
465             viewer.removeSelectionChangedListener(this);
466         }
467         IWorkbenchPage page = getSite().getPage();
468         page.removePartListener((IPartListener2) this);
469         IWorkbenchWindow window = getSite().getWorkbenchWindow();
470         window.removePerspectiveListener(this);
471         window.removePageListener(this);
472         
473         super.dispose();
474     }
475         
476     private void disposeActions() {
477         PropertyDialogAction properties = (PropertyDialogAction) getAction("Properties"); //$NON-NLS-1$
478
properties.dispose();
479         
480         disposeCommandAction(TERMINATE);
481         disposeCommandAction(DISCONNECT);
482         disposeCommandAction(SUSPEND);
483         disposeCommandAction(RESUME);
484         disposeCommandAction(STEP_RETURN);
485         disposeCommandAction(STEP_OVER);
486         disposeCommandAction(STEP_INTO);
487         disposeCommandAction(DROP_TO_FRAME);
488         disposeCommandAction(TERMINATE_AND_REMOVE);
489         disposeCommandAction(TERMINATE_AND_RELAUNCH);
490         disposeCommandAction(TERMINATE_ALL);
491     }
492
493     /**
494      * The selection has changed in the viewer. Show the
495      * associated source code if it is a stack frame.
496      *
497      * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
498      */

499     public void selectionChanged(SelectionChangedEvent event) {
500         fProvider.activate(event.getSelection());
501         updateObjects();
502     }
503
504     /* (non-Javadoc)
505      * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
506      */

507     public void doubleClick(DoubleClickEvent event) {
508         ISelection selection= event.getSelection();
509         if (!(selection instanceof IStructuredSelection)) {
510             return;
511         }
512         IStructuredSelection ss= (IStructuredSelection)selection;
513         Object JavaDoc o= ss.getFirstElement();
514         if (o == null || o instanceof IStackFrame) {
515             return;
516         }
517         StructuredViewer viewer = (StructuredViewer) getViewer();
518         viewer.refresh(o);
519     }
520         
521     /* (non-Javadoc)
522      * @see org.eclipse.ui.IPerspectiveListener#perspectiveActivated(org.eclipse.ui.IWorkbenchPage, org.eclipse.ui.IPerspectiveDescriptor)
523      */

524     public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
525         setActive(page.findView(getSite().getId()) != null);
526         updateObjects();
527     }
528
529     /* (non-Javadoc)
530      * @see org.eclipse.ui.IPerspectiveListener#perspectiveChanged(org.eclipse.ui.IWorkbenchPage, org.eclipse.ui.IPerspectiveDescriptor, java.lang.String)
531      */

532     public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String JavaDoc changeId) {
533         setActive(page.findView(getSite().getId()) != null);
534     }
535     
536     /* (non-Javadoc)
537      * @see org.eclipse.ui.IPerspectiveListener2#perspectiveChanged(org.eclipse.ui.IWorkbenchPage, org.eclipse.ui.IPerspectiveDescriptor, org.eclipse.ui.IWorkbenchPartReference, java.lang.String)
538      */

539     public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, IWorkbenchPartReference partRef, String JavaDoc changeId) {
540     }
541
542     /* (non-Javadoc)
543      * @see org.eclipse.ui.IPageListener#pageActivated(org.eclipse.ui.IWorkbenchPage)
544      */

545     public void pageActivated(IWorkbenchPage page) {
546         if (getSite().getPage().equals(page)) {
547             setActive(true);
548             updateObjects();
549         }
550     }
551
552     /* (non-Javadoc)
553      * @see org.eclipse.ui.IPageListener#pageClosed(org.eclipse.ui.IWorkbenchPage)
554      */

555     public void pageClosed(IWorkbenchPage page) {
556     }
557
558     /* (non-Javadoc)
559      * @see org.eclipse.ui.IPageListener#pageOpened(org.eclipse.ui.IWorkbenchPage)
560      */

561     public void pageOpened(IWorkbenchPage page) {
562     }
563     
564     /* (non-Javadoc)
565      * @see org.eclipse.debug.ui.IDebugView#getPresentation(java.lang.String)
566      */

567     public IDebugModelPresentation getPresentation(String JavaDoc id) {
568         return ((DelegatingModelPresentation)fPresentation).getPresentation(id);
569     }
570     
571     /* (non-Javadoc)
572      * @see org.eclipse.debug.ui.AbstractDebugView#fillContextMenu(org.eclipse.jface.action.IMenuManager)
573      */

574     protected void fillContextMenu(IMenuManager menu) {
575         
576         menu.add(new Separator(IDebugUIConstants.EMPTY_EDIT_GROUP));
577         menu.add(new Separator(IDebugUIConstants.EDIT_GROUP));
578         menu.add(getAction(FIND_ACTION));
579         menu.add(new Separator(IDebugUIConstants.EMPTY_STEP_GROUP));
580         menu.add(new Separator(IDebugUIConstants.STEP_GROUP));
581         menu.add(new GroupMarker(IDebugUIConstants.STEP_INTO_GROUP));
582         menu.add(new GroupMarker(IDebugUIConstants.STEP_OVER_GROUP));
583         menu.add(new GroupMarker(IDebugUIConstants.STEP_RETURN_GROUP));
584         menu.add(new Separator(IDebugUIConstants.RENDER_GROUP));
585         menu.add(new Separator(IDebugUIConstants.EMPTY_THREAD_GROUP));
586         menu.add(new Separator(IDebugUIConstants.THREAD_GROUP));
587         menu.add(new Separator(IDebugUIConstants.EMPTY_LAUNCH_GROUP));
588         menu.add(new Separator(IDebugUIConstants.LAUNCH_GROUP));
589         IStructuredSelection selection = (IStructuredSelection) getSite().getSelectionProvider().getSelection();
590         updateAndAdd(menu, fEditConfigAction, selection);
591         updateAndAdd(menu, fAddToFavoritesAction, selection);
592         updateAndAdd(menu, fEditSourceAction, selection);
593         updateAndAdd(menu, fLookupAction, selection);
594         menu.add(new Separator(IDebugUIConstants.EMPTY_RENDER_GROUP));
595         menu.add(new Separator(IDebugUIConstants.RENDER_GROUP));
596         menu.add(new Separator(IDebugUIConstants.PROPERTY_GROUP));
597         PropertyDialogAction action = (PropertyDialogAction)getAction("Properties"); //$NON-NLS-1$
598
/**
599          * TODO hack to get around bug 148424, remove if UI ever fixes the PropertyDialogAction to respect enablesWhen conditions
600          */

601         TreeSelection sel = (TreeSelection) fProvider.getActiveContext();
602         boolean enabled = true;
603         if(sel != null && sel.size() > 0) {
604             enabled = !(sel.getFirstElement() instanceof ILaunch);
605         }
606         action.setEnabled(action.isApplicableForSelection() && enabled);
607         menu.add(action);
608         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
609         
610         menu.appendToGroup(IDebugUIConstants.LAUNCH_GROUP, getAction(TERMINATE_AND_REMOVE));
611         menu.appendToGroup(IDebugUIConstants.LAUNCH_GROUP, getAction(TERMINATE_ALL));
612         
613         menu.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(RESUME));
614         menu.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(SUSPEND));
615         menu.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(TERMINATE));
616         menu.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(TERMINATE_AND_RELAUNCH));
617         menu.appendToGroup(IDebugUIConstants.THREAD_GROUP, getAction(DISCONNECT));
618         
619         menu.appendToGroup(IDebugUIConstants.STEP_INTO_GROUP, getAction(STEP_INTO));
620         menu.appendToGroup(IDebugUIConstants.STEP_OVER_GROUP, getAction(STEP_OVER));
621         menu.appendToGroup(IDebugUIConstants.STEP_RETURN_GROUP, getAction(STEP_RETURN));
622         
623         menu.appendToGroup(IDebugUIConstants.EMPTY_STEP_GROUP, getAction(DROP_TO_FRAME));
624         
625         menu.appendToGroup(IDebugUIConstants.RENDER_GROUP, getAction(TOGGLE_STEP_FILTERS));
626     }
627     
628     /**
629      * Updates the enabled state of the given action based on the selection
630      * and adds to the menu if enabled.
631      *
632      * @param menu menu to add the action to
633      * @param action action to add if enabled
634      * @param selection selection to update enabled state for
635      */

636     private void updateAndAdd(IMenuManager menu, SelectionListenerAction action, IStructuredSelection selection) {
637         action.selectionChanged(selection);
638         if (action.isEnabled()) {
639             menu.add(action);
640         }
641     }
642         
643     /**
644      * Sets whether this view is in the active page of a
645      * perspective. Since a page can have more than one
646      * perspective, this view only show's source when in
647      * the active perspective/page.
648      *
649      * @param active whether this view is in the active page of a
650      * perspective
651      */

652     protected void setActive(boolean active) {
653         fIsActive = active;
654     }
655
656     /**
657      * Returns whether this view is in the active page of
658      * the active perspective and has been fully created.
659      *
660      * @return whether this view is in the active page of
661      * the active perspective and has been fully created.
662      */

663     protected boolean isActive() {
664         return fIsActive && getViewer() != null;
665     }
666     
667     /* (non-Javadoc)
668      * @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext)
669      */

670     public boolean show(ShowInContext context) {
671         ISelection selection = context.getSelection();
672         if (selection != null) {
673             if (selection instanceof IStructuredSelection) {
674                 IStructuredSelection ss = (IStructuredSelection)selection;
675                 if (ss.size() == 1) {
676                     Object JavaDoc obj = ss.getFirstElement();
677                     if (obj instanceof IDebugTarget || obj instanceof IProcess) {
678                         Viewer viewer = getViewer();
679                         if (viewer instanceof InternalTreeModelViewer) {
680                             InternalTreeModelViewer tv = (InternalTreeModelViewer) viewer;
681                             tv.setSelection(selection, true, true);
682                         } else {
683                             viewer.setSelection(selection, true);
684                         }
685                         return true;
686                     }
687                 }
688             }
689         }
690         return false;
691     }
692
693     /* (non-Javadoc)
694      * @see org.eclipse.ui.part.IShowInSource#getShowInContext()
695      */

696     public ShowInContext getShowInContext() {
697         if (isActive()) {
698             IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection();
699             if (selection.size() == 1) {
700                 Object JavaDoc object = selection.getFirstElement();
701                 if (object instanceof IAdaptable) {
702                     IAdaptable adaptable = (IAdaptable) object;
703                     IShowInSource show = (IShowInSource) adaptable.getAdapter(IShowInSource.class);
704                     if (show != null) {
705                         return show.getShowInContext();
706                     }
707                 }
708             }
709         }
710         return null;
711     }
712     
713     /* (non-Javadoc)
714      * @see org.eclipse.ui.part.IShowInTargetList#getShowInTargetIds()
715      */

716     public String JavaDoc[] getShowInTargetIds() {
717         if (isActive()) {
718             IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection();
719             if (selection.size() == 1) {
720                 Object JavaDoc object = selection.getFirstElement();
721                 if (object instanceof IAdaptable) {
722                     IAdaptable adaptable = (IAdaptable) object;
723                     IShowInTargetList show = (IShowInTargetList) adaptable.getAdapter(IShowInTargetList.class);
724                     if (show != null) {
725                         return show.getShowInTargetIds();
726                     }
727                 }
728             }
729         }
730         return new String JavaDoc[0];
731     }
732
733     /* (non-Javadoc)
734      * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
735      */

736     public void partClosed(IWorkbenchPartReference partRef) {
737     }
738
739     /* (non-Javadoc)
740      * @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference)
741      */

742     public void partVisible(IWorkbenchPartReference partRef) {
743         IWorkbenchPart part = partRef.getPart(false);
744         if (part == this) {
745             setActive(true);
746 // TODO: Workaround for Bug #63332. Reexamine after M9.
747
// updateContextListener();
748
// When the launch view becomes visible, turn on the
749
// debug action set. Note that the workbench will handle the
750
// case where the user really doesn't want the action set
751
// enabled - showActionSet(String) will do nothing for an
752
// action set that's been manually disabled.
753
getSite().getPage().showActionSet(IDebugUIConstants.DEBUG_ACTION_SET);
754         }
755     }
756
757     /* (non-Javadoc)
758      * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
759      */

760     public void partOpened(IWorkbenchPartReference partRef) {
761     }
762
763     /* (non-Javadoc)
764      * @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference)
765      */

766     public void partActivated(IWorkbenchPartReference partRef) {
767     }
768
769     /* (non-Javadoc)
770      * @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference)
771      */

772     public void partBroughtToTop(IWorkbenchPartReference partRef) {
773     }
774
775     /* (non-Javadoc)
776      * @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
777      */

778     public void partDeactivated(IWorkbenchPartReference partRef) {
779     }
780
781     /* (non-Javadoc)
782      * @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference)
783      */

784     public void partHidden(IWorkbenchPartReference partRef) {
785     }
786
787     /* (non-Javadoc)
788      * @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference)
789      */

790     public void partInputChanged(IWorkbenchPartReference partRef) {
791     }
792
793     /* (non-Javadoc)
794      * @see org.eclipse.debug.ui.AbstractDebugView#becomesVisible()
795      */

796     protected void becomesVisible() {
797         super.becomesVisible();
798         getViewer().refresh();
799     }
800     
801     
802
803 }
804
Popular Tags