KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > AbstractDebugView


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.ui;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import org.eclipse.debug.internal.ui.DebugUIPlugin;
23 import org.eclipse.debug.internal.ui.DelegatingModelPresentation;
24 import org.eclipse.debug.internal.ui.LazyModelPresentation;
25 import org.eclipse.jface.action.ActionContributionItem;
26 import org.eclipse.jface.action.IAction;
27 import org.eclipse.jface.action.IContributionItem;
28 import org.eclipse.jface.action.IMenuListener;
29 import org.eclipse.jface.action.IMenuManager;
30 import org.eclipse.jface.action.IToolBarManager;
31 import org.eclipse.jface.action.MenuManager;
32 import org.eclipse.jface.preference.IPreferenceStore;
33 import org.eclipse.jface.text.TextViewer;
34 import org.eclipse.jface.viewers.DoubleClickEvent;
35 import org.eclipse.jface.viewers.IBaseLabelProvider;
36 import org.eclipse.jface.viewers.IDoubleClickListener;
37 import org.eclipse.jface.viewers.StructuredViewer;
38 import org.eclipse.jface.viewers.Viewer;
39 import org.eclipse.swt.SWT;
40 import org.eclipse.swt.events.KeyAdapter;
41 import org.eclipse.swt.events.KeyEvent;
42 import org.eclipse.swt.widgets.Composite;
43 import org.eclipse.swt.widgets.Control;
44 import org.eclipse.swt.widgets.Menu;
45 import org.eclipse.ui.IActionBars;
46 import org.eclipse.ui.IMemento;
47 import org.eclipse.ui.IPartListener2;
48 import org.eclipse.ui.IViewPart;
49 import org.eclipse.ui.IViewSite;
50 import org.eclipse.ui.IWorkbenchPage;
51 import org.eclipse.ui.IWorkbenchPart;
52 import org.eclipse.ui.IWorkbenchPartReference;
53 import org.eclipse.ui.PartInitException;
54 import org.eclipse.ui.PlatformUI;
55 import org.eclipse.ui.actions.ActionFactory;
56 import org.eclipse.ui.part.IPage;
57 import org.eclipse.ui.part.MessagePage;
58 import org.eclipse.ui.part.Page;
59 import org.eclipse.ui.part.PageBook;
60 import org.eclipse.ui.part.PageBookView;
61 import org.eclipse.ui.texteditor.IUpdate;
62
63 /**
64  * Common function for views related to debugging. Clients implementing
65  * views for a debugger should subclass this class. Common function
66  * includes:
67  * <ul>
68  * <li>Debug view adapter implementation - <code>IDebugView</code></li>
69  * <li>Action registry - actions can be stored in this view
70  * with a key. Actions that implement <code>IUpdate</code>
71  * are updated when <code>updateActions()</code> is
72  * called.</li>
73  * <li>Hooks the context menu associated with this view's
74  * underlying viewer and registers the menu with this
75  * view's site, such that other plug-ins may contribute.</li>
76  * <li>Hooks a key press listener, and invokes the
77  * <code>REMOVE_ACTION</code> when the delete key
78  * is pressed.</li>
79  * <li>Hooks a double-click listener, and invokes the
80  * <code>DOUBLE_CLICK_ACTION</code> when the mouse
81  * is double-clicked.</li>
82  * <li>Provides a mechanism for displaying an error message
83  * in the view, via the <code>PageBookView</code> mechanism.
84  * By default, a page book is created with a page showing
85  * this view's viewer. A message page is also created
86  * and shown when <code>showMessage(String)</code> is
87  * called.</li>
88  * <li>Notification when this view becomes visible and becomes
89  * hidden via <code>becomesVisible()</code> and <code>becomesHidden()</code>.</li>
90  * <li>Linking of a help context id via <code>getHelpContextId().</code></li>
91  * </ul>
92  * <p>
93  * This class may be sub-classed.
94  * </p>
95  * @since 2.0
96  */

97
98 public abstract class AbstractDebugView extends PageBookView implements IDebugView, IDoubleClickListener {
99     
100     /**
101      * Underlying viewer that displays the contents of
102      * this view.
103      */

104     private Viewer fViewer = null;
105     
106     /**
107      * This view's message page.
108      */

109     private MessagePage fMessagePage = null;
110     
111     /**
112      * Map of actions. Keys are strings, values
113      * are <code>IAction</code>.
114      */

115     private Map JavaDoc fActionMap = null;
116     
117     /**
118      * Map of actions. Keys are strings, values
119      * are <code>IAction</code>.
120      */

121     private List JavaDoc fUpdateables = null;
122     
123     /**
124      * The collection of menu managers that are
125      * relevant for this view.
126      */

127     private List JavaDoc fContextMenuManagers;
128     
129     /**
130      * The memento that was used to persist the state of this view.
131      * May be <code>null</code>.
132      */

133     private IMemento fMemento;
134     
135     /**
136      * Whether this view is currently visible.
137      */

138     private boolean fIsVisible = false;
139     
140     /**
141      * The part listener for this view, used to notify this view when it
142      * becomes visible and hidden. Set to <code>null</code> when this view isn't
143      * currently listening to part changes.
144      */

145     private DebugViewPartListener fPartListener= null;
146     
147     /**
148      * A message was requested to be displayed before the view was fully
149      * created. The message is cached until it can be properly displayed.
150      */

151     private String JavaDoc fEarlyMessage= null;
152     
153     private static Set JavaDoc fgGlobalActionIds;
154     static {
155         fgGlobalActionIds = new HashSet JavaDoc();
156         fgGlobalActionIds.add(SELECT_ALL_ACTION);
157         fgGlobalActionIds.add(COPY_ACTION);
158         fgGlobalActionIds.add(CUT_ACTION);
159         fgGlobalActionIds.add(PASTE_ACTION);
160         fgGlobalActionIds.add(FIND_ACTION);
161         fgGlobalActionIds.add(ActionFactory.UNDO.getId());
162         fgGlobalActionIds.add(ActionFactory.REDO.getId());
163     }
164
165     /**
166      * Part listener that disables updating when the view is not visible and
167      * re-enables updating when the view appears.
168      */

169     private class DebugViewPartListener implements IPartListener2 {
170         /**
171          *
172          * @see org.eclipse.ui.IPartListener2#partVisible(IWorkbenchPartReference)
173          */

174         public void partVisible(IWorkbenchPartReference ref) {
175             IWorkbenchPart part= ref.getPart(false);
176             if (part == AbstractDebugView.this) {
177                 fIsVisible = true;
178                 becomesVisible();
179             }
180         }
181         /**
182          * @see org.eclipse.ui.IPartListener2#partHidden(IWorkbenchPartReference)
183          */

184         public void partHidden(IWorkbenchPartReference ref) {
185             IWorkbenchPart part= ref.getPart(false);
186             if (part == AbstractDebugView.this) {
187                 fIsVisible = false;
188                 becomesHidden();
189             }
190         }
191         /**
192          * @see org.eclipse.ui.IPartListener2#partActivated(IWorkbenchPartReference)
193          */

194         public void partActivated(IWorkbenchPartReference ref) {
195         }
196
197         /**
198          * @see org.eclipse.ui.IPartListener2#partBroughtToTop(IWorkbenchPartReference)
199          */

200         public void partBroughtToTop(IWorkbenchPartReference ref) {
201         }
202
203         /**
204          * @see org.eclipse.ui.IPartListener2#partClosed(IWorkbenchPartReference)
205          */

206         public void partClosed(IWorkbenchPartReference ref) {
207         }
208
209         /**
210          * @see org.eclipse.ui.IPartListener2#partDeactivated(IWorkbenchPartReference)
211          */

212         public void partDeactivated(IWorkbenchPartReference ref) {
213         }
214
215         /**
216          * @see org.eclipse.ui.IPartListener2#partOpened(IWorkbenchPartReference)
217          */

218         public void partOpened(IWorkbenchPartReference ref) {
219         }
220         
221         /**
222          * @see org.eclipse.ui.IPartListener2#partInputChanged(IWorkbenchPartReference)
223          */

224         public void partInputChanged(IWorkbenchPartReference ref){
225         }
226
227     }
228     
229     /**
230      * Constructs a new debug view.
231      */

232     public AbstractDebugView() {
233         fActionMap = new HashMap JavaDoc(5);
234         fUpdateables= new ArrayList JavaDoc(3);
235     }
236     
237     /**
238      * Debug views implement the debug view adapter which
239      * provides access to a view's underlying viewer and
240      * debug model presentation for a specific debug model.
241      *
242      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
243      * @see IDebugView
244      */

245     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
246         if (adapter == IDebugView.class) {
247             return this;
248         }
249         if (adapter == IDebugModelPresentation.class) {
250             StructuredViewer viewer = getStructuredViewer();
251             if (viewer != null) {
252                 IBaseLabelProvider labelProvider = viewer.getLabelProvider();
253                 if (labelProvider instanceof IDebugModelPresentation) {
254                     return labelProvider;
255                 }
256             }
257         }
258         return super.getAdapter(adapter);
259     }
260     
261     /**
262      * A page in this view's page book that contains this
263      * view's viewer.
264      */

265     class ViewerPage extends Page {
266         /**
267          * @see IPage#createControl(Composite)
268          */

269         public void createControl(Composite parent) {
270             Viewer viewer = createViewer(parent);
271             setViewer(viewer);
272         }
273
274         /**
275          * @see IPage#getControl()
276          */

277         public Control getControl() {
278             return getDefaultControl();
279         }
280
281         /**
282          * @see IPage#setFocus()
283          */

284         public void setFocus() {
285             Viewer viewer= getViewer();
286             if (viewer != null) {
287                 Control c = viewer.getControl();
288                 if (!c.isFocusControl()) {
289                     c.setFocus();
290                 }
291             }
292         }
293
294 }
295     
296     /**
297      * Creates this view's underlying viewer and actions.
298      * Hooks a pop-up menu to the underlying viewer's control,
299      * as well as a key listener. When the delete key is pressed,
300      * the <code>REMOVE_ACTION</code> is invoked. Hooks help to
301      * this view. Subclasses must implement the following methods
302      * which are called in the following order when a view is
303      * created:<ul>
304      * <li><code>createViewer(Composite)</code> - the context
305      * menu is hooked to the viewer's control.</li>
306      * <li><code>createActions()</code></li>
307      * <li><code>configureToolBar(IToolBarManager)</code></li>
308      * <li><code>getHelpContextId()</code></li>
309      * </ul>
310      * @see IWorkbenchPart#createPartControl(Composite)
311      * @see AbstractDebugView#createPartControl(Composite)
312      * @see AbstractDebugView#createActions()
313      * @see AbstractDebugView#configureToolBar(IToolBarManager)
314      * @see AbstractDebugView#getHelpContextId()
315      * @see AbstractDebugView#fillContextMenu(IMenuManager)
316      */

317     public void createPartControl(Composite parent) {
318         registerPartListener();
319         super.createPartControl(parent);
320         createActions();
321         initializeToolBar();
322         Viewer viewer = getViewer();
323         if (viewer != null) {
324             createContextMenu(viewer.getControl());
325         }
326         String JavaDoc helpId = getHelpContextId();
327         if (helpId != null) {
328             PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, helpId);
329         }
330         if (viewer != null) {
331             getViewer().getControl().addKeyListener(new KeyAdapter() {
332                 public void keyPressed(KeyEvent e) {
333                     handleKeyPressed(e);
334                 }
335             });
336             if (getViewer() instanceof StructuredViewer) {
337                 ((StructuredViewer)getViewer()).addDoubleClickListener(this);
338             }
339         }
340         // create the message page
341
setMessagePage(new MessagePage());
342         getMessagePage().createControl(getPageBook());
343         initPage(getMessagePage());
344         
345         if (fEarlyMessage != null) { //bug 28127
346
showMessage(fEarlyMessage);
347             fEarlyMessage= null;
348         }
349     }
350     
351     /**
352      * The default page for a debug view is its viewer.
353      *
354      * @see PageBookView#createDefaultPage(PageBook)
355      */

356     protected IPage createDefaultPage(PageBook book) {
357         ViewerPage page = new ViewerPage();
358         page.createControl(book);
359         initPage(page);
360         return page;
361     }
362
363     /**
364      * Creates and returns this view's underlying viewer.
365      * The viewer's control will automatically be hooked
366      * to display a pop-up menu that other plug-ins may
367      * contribute to. Subclasses must override this method.
368      *
369      * @param parent the parent control
370      */

371     protected abstract Viewer createViewer(Composite parent);
372     
373     /**
374      * Creates this view's actions. Subclasses must
375      * override this method, which is called after
376      * <code>createViewer(Composite)</code>
377      */

378     protected abstract void createActions();
379     
380     /**
381      * Returns this view's help context id, which is hooked
382      * to this view on creation.
383      *
384      * @return help context id
385      */

386     protected abstract String JavaDoc getHelpContextId();
387     
388     /**
389      * @see IWorkbenchPart#dispose()
390      */

391     public void dispose() {
392         saveAllCheckedActionStates();
393         deregisterPartListener();
394         if (getViewer() instanceof StructuredViewer) {
395             ((StructuredViewer)getViewer()).removeDoubleClickListener(this);
396         }
397         setViewer(null);
398         fActionMap.clear();
399         super.dispose();
400     }
401     
402     /**
403      * Saves the checked state for all actions contributed to the toolbar
404      * manager that function as a toggle action. The states are saved in
405      * the Debug UI plugin's preference store.
406      *
407      * @since 2.1
408      */

409     protected void saveAllCheckedActionStates() {
410         IToolBarManager tbm= getViewSite().getActionBars().getToolBarManager();
411         IContributionItem[] items= tbm.getItems();
412         for (int i = 0; i < items.length; i++) {
413             IContributionItem iContributionItem = items[i];
414             if (iContributionItem instanceof ActionContributionItem) {
415                 ActionContributionItem item= (ActionContributionItem)iContributionItem;
416                 IAction action= item.getAction();
417                 if (action.getStyle() == IAction.AS_CHECK_BOX && action.isEnabled()) {
418                     saveCheckedActionState(action);
419                 }
420             }
421         }
422     }
423     
424     /**
425      * Save the checked state of the specified action in the Debug UI plugin's
426      * preference store. The specified action is expected to be enabled and
427      * support the style <code>IAction.AS_CHECK_BOX</code>.
428      *
429      * @param action the enabled, toggle action whose checked state will be
430      * saved in preferences
431      * @since 2.1
432      */

433     protected void saveCheckedActionState(IAction action) {
434         String JavaDoc prefKey = generatePreferenceKey(action);
435         IPreferenceStore prefStore = getPreferenceStore();
436         prefStore.setValue(prefKey, action.isChecked());
437     }
438     
439     /**
440      * Generate a String that can be used as a key into a preference store based
441      * on the specified action. The resulting String will be unique across
442      * views.
443      *
444      * @return a String suitable for use as a preference store key for the given
445      * action
446      * @since 2.1
447      */

448     protected String JavaDoc generatePreferenceKey(IAction action) {
449         return getViewSite().getId() + '+' + action.getId();
450     }
451     
452     /**
453      * Convenience method to return the preference store for the Debug UI
454      * plug-in.
455      *
456      * @return the preference store for the Debug UI plug-in
457      * @since 2.1
458      */

459     protected IPreferenceStore getPreferenceStore() {
460         return DebugUIPlugin.getDefault().getPreferenceStore();
461     }
462     
463     /**
464      * @see IDebugView#getViewer()
465      */

466     public Viewer getViewer() {
467         return fViewer;
468     }
469     
470     /**
471      * Returns this view's viewer as a structured viewer,
472      * or <code>null</code> if none.
473      *
474      * @return this view's viewer as a structured viewer
475      * or <code>null</code>
476      */

477     protected StructuredViewer getStructuredViewer() {
478         if (getViewer() instanceof StructuredViewer) {
479             return (StructuredViewer)getViewer();
480         }
481         return null;
482     }
483     
484     /**
485      * Returns this view's viewer as a text viewer,
486      * or <code>null</code> if none.
487      *
488      * @return this view's viewer as a text viewer
489      * or <code>null</code>
490      */

491     protected TextViewer getTextViewer() {
492         if (getViewer() instanceof TextViewer) {
493             return (TextViewer)getViewer();
494         }
495         return null;
496     }
497     
498     /**
499      * @see IDebugView#getPresentation(String)
500      */

501     public IDebugModelPresentation getPresentation(String JavaDoc id) {
502         if (getViewer() instanceof StructuredViewer) {
503             IBaseLabelProvider lp = ((StructuredViewer)getViewer()).getLabelProvider();
504             if (lp instanceof DelegatingModelPresentation) {
505                 return ((DelegatingModelPresentation)lp).getPresentation(id);
506             }
507             if (lp instanceof LazyModelPresentation) {
508                 if (((LazyModelPresentation)lp).getDebugModelIdentifier().equals(id)) {
509                     return (IDebugModelPresentation)lp;
510                 }
511             }
512         }
513         return null;
514     }
515     
516     /**
517      * Creates a pop-up menu on the given control. The menu
518      * is registered with this view's site, such that other
519      * plug-ins may contribute to the menu. Subclasses should
520      * call this method, specifying the menu control as the
521      * control used in their viewer (for example, tree viewer).
522      * Subclasses must implement the method
523      * <code>#fillContextMenu(IMenuManager)</code> which will
524      * be called each time the context menu is realized.
525      *
526      * @param menuControl the control with which the pop-up
527      * menu will be associated with.
528      */

529     protected void createContextMenu(Control menuControl) {
530         MenuManager menuMgr= new MenuManager("#PopUp"); //$NON-NLS-1$
531
menuMgr.setRemoveAllWhenShown(true);
532         menuMgr.addMenuListener(new IMenuListener() {
533             public void menuAboutToShow(IMenuManager mgr) {
534                 fillContextMenu(mgr);
535             }
536         });
537         Menu menu= menuMgr.createContextMenu(menuControl);
538         menuControl.setMenu(menu);
539
540         // register the context menu such that other plug-ins may contribute to it
541
if (getSite() != null) {
542             getSite().registerContextMenu(menuMgr, getViewer());
543         }
544         addContextMenuManager(menuMgr);
545     }
546     
547     /**
548      * @see IDebugView#getContextMenuManager()
549      *
550      * @deprecated @see AbstractDebugView.getContextMenuManagers()
551      */

552     public IMenuManager getContextMenuManager() {
553         if (fContextMenuManagers != null) {
554             fContextMenuManagers.get(fContextMenuManagers.size() - 1);
555         }
556         return null;
557     }
558     
559     /**
560      * Returns the context menu managers relevant to this view.
561      *
562      * @return the context menu managers relevant to this view
563      * @since 2.1
564      */

565     public List JavaDoc getContextMenuManagers() {
566         return fContextMenuManagers;
567     }
568     
569     /**
570      * Subclasses must override this method to fill the context
571      * menu each time it is realized.
572      *
573      * @param menu the context menu
574      */

575     protected abstract void fillContextMenu(IMenuManager menu);
576     
577     /**
578      * Configures this view's toolbar. Subclasses implement
579      * <code>#configureToolBar(IToolBarManager)</code> to
580      * contribute actions to the toolbar.
581      * <p>
582      * To properly initialize toggle actions that are contributed
583      * to this view, state is restored for toggle actions that have
584      * a persisted state in the Debug UI plugin's preferences. As well, any
585      * toggle actions that have an initial state of 'checked' are invoked. The
586      * actions' states are restored and the actions are invoked in a runnable,
587      * after the view is created.
588      * </p>
589      */

590     protected void initializeToolBar() {
591         final IToolBarManager tbm= getViewSite().getActionBars().getToolBarManager();
592         configureToolBar(tbm);
593         getViewSite().getActionBars().updateActionBars();
594         
595         // This is done in a runnable to be run after this view's pane
596
// is created
597
Runnable JavaDoc r = new Runnable JavaDoc() {
598             public void run() {
599                 if (!isAvailable()) {
600                     return;
601                 }
602                 IContributionItem[] items = tbm.getItems();
603                 if (items != null) {
604                     for (int i = 0; i < items.length; i++) {
605                         if (items[i] instanceof ActionContributionItem) {
606                             IAction action = ((ActionContributionItem)items[i]).getAction();
607                             if (action.getStyle() == IAction.AS_CHECK_BOX) {
608                                 initActionState(action);
609                                 if (action.isChecked()) {
610                                     action.run();
611                                 }
612                             }
613                         }
614                     }
615                     setMemento(null);
616                 }
617                 updateObjects();
618             }
619         };
620         asyncExec(r);
621     }
622     
623     /**
624      * Restores the persisted checked state of the specified action that was
625      * stored in preferences. If the action is disabled, its persisted state
626      * is not restored (because a disabled action cannot be run).
627      *
628      * @param action the action whose checked state will be restored
629      * @since 2.1
630      */

631     protected void initActionState(IAction action) {
632         String JavaDoc id = action.getId();
633         if (id != null && action.isEnabled()) {
634             String JavaDoc prefKey = generatePreferenceKey(action);
635             boolean checked = getPreferenceStore().getBoolean(prefKey);
636             action.setChecked(checked);
637         }
638     }
639
640     /**
641      * @see IViewPart#init(IViewSite, IMemento)
642      */

643     public void init(IViewSite site, IMemento memento) throws PartInitException {
644         super.init(site, memento);
645         //store the memento to be used when this view is created.
646
setMemento(memento);
647     }
648
649     /**
650      * Sets the viewer for this view.
651      *
652      * @param viewer viewer
653      * @since 3.1
654      */

655     protected void setViewer(Viewer viewer) {
656         fViewer = viewer;
657     }
658     
659     /**
660      * Subclasses implement this menu to contribute actions
661      * to the toolbar. This method is called after
662      * <code>createActions()</code>.
663      *
664      * @param tbm the tool bar manager for this view's site
665      * @see #createViewer(Composite)
666      */

667     protected abstract void configureToolBar(IToolBarManager tbm);
668     
669     /**
670      * @see IDebugView#setAction(String, IAction)
671      */

672     public void setAction(String JavaDoc actionID, IAction action) {
673         if (action == null) {
674             Object JavaDoc removedAction= fActionMap.remove(actionID);
675             fUpdateables.remove(removedAction);
676         } else {
677             fActionMap.put(actionID, action);
678             if (action instanceof IUpdate) {
679                 fUpdateables.add(action);
680             }
681         }
682         if (fgGlobalActionIds.contains(actionID)) {
683             IActionBars actionBars = getViewSite().getActionBars();
684             actionBars.setGlobalActionHandler(actionID, action);
685         }
686     }
687     
688     /**
689      * @see IDebugView#getAction(String)
690      */

691     public IAction getAction(String JavaDoc actionID) {
692         return (IAction) fActionMap.get(actionID);
693     }
694     
695     /**
696      * Updates all the registered updatables.
697      */

698     public void updateObjects() {
699         Iterator JavaDoc actions = fUpdateables.iterator();
700         while (actions.hasNext()) {
701             ((IUpdate)actions.next()).update();
702         }
703     }
704             
705     /**
706      * Handles key events in viewer. Invokes
707      * <ol>
708      * <li><code>REMOVE_ACTION</code> when the delete
709      * key is pressed</li>
710      */

711     protected void handleKeyPressed(KeyEvent event) {
712         if (event.character == SWT.DEL && event.stateMask == 0) {
713             IAction action = getAction(REMOVE_ACTION);
714             if (action != null && action.isEnabled()) {
715                 action.run();
716             }
717         }
718     }
719     
720     /**
721      * Delegate to the <code>DOUBLE_CLICK_ACTION</code>,
722      * if any.
723      *
724      * @see IDoubleClickListener#doubleClick(DoubleClickEvent)
725      */

726     public void doubleClick(DoubleClickEvent event) {
727         IAction action = getAction(DOUBLE_CLICK_ACTION);
728         if (action != null && !event.getSelection().isEmpty() && action.isEnabled()) {
729             action.run();
730         }
731     }
732     
733     /**
734      * Registers the given runnable with the display
735      * associated with this view's control, if any.
736      *
737      * @see org.eclipse.swt.widgets.Display#asyncExec(java.lang.Runnable)
738      */

739     public void asyncExec(Runnable JavaDoc r) {
740         if (isAvailable()) {
741             getControl().getDisplay().asyncExec(r);
742         }
743     }
744     
745     /**
746      * Returns the control for this view, or <code>null</code> if none.
747      *
748      * @return the control for this view, or <code>null</code> if none
749      * @since 3.0
750      */

751     protected Control getControl() {
752         return getViewer().getControl();
753     }
754     
755     /**
756      * Registers the given runnable with the display
757      * associated with this view's control, if any.
758      *
759      * @see org.eclipse.swt.widgets.Display#syncExec(java.lang.Runnable)
760      */

761     public void syncExec(Runnable JavaDoc r) {
762         if (isAvailable()) {
763             getControl().getDisplay().syncExec(r);
764         }
765     }
766     
767     /**
768      * Returns the memento that contains the persisted state of
769      * the view. May be <code>null</code>.
770      */

771     protected IMemento getMemento() {
772         return fMemento;
773     }
774
775     /**
776      * Sets the memento that contains the persisted state of the
777      * view.
778      */

779     protected void setMemento(IMemento memento) {
780         fMemento = memento;
781     }
782     
783     /**
784      * Returns the specified view in this view's page
785      * or <code>null</code> if none.
786      *
787      * @param id view identifier
788      * @return view part
789      */

790     protected IViewPart findView(String JavaDoc id) {
791         IWorkbenchPage page = getSite().getPage();
792         IViewPart view = null;
793         if (page != null) {
794             view = page.findView(id);
795         }
796         return view;
797     }
798     
799     /**
800      * @see PageBookView#isImportant(IWorkbenchPart)
801      */

802     protected boolean isImportant(IWorkbenchPart part) {
803         return false;
804     }
805
806     /**
807      * @see PageBookView#doCreatePage(IWorkbenchPart)
808      */

809     protected PageRec doCreatePage(IWorkbenchPart part) {
810         return null;
811     }
812
813     /**
814      * @see PageBookView#doDestroyPage(org.eclipse.ui.IWorkbenchPart, org.eclipse.ui.part.PageBookView.PageRec)
815      */

816     protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
817     }
818
819     /**
820      * @see PageBookView#getBootstrapPart()
821      */

822     protected IWorkbenchPart getBootstrapPart() {
823         return null;
824     }
825
826     /**
827      * Returns the default control for this view. By default,
828      * this view's viewer's control is returned. Subclasses
829      * should override if required - for example, if this
830      * view has its viewer nested inside other controls.
831      *
832      * @return this view's default control.
833      */

834     protected Control getDefaultControl() {
835         Viewer viewer = getViewer();
836         if (viewer != null) {
837             return viewer.getControl();
838         }
839         return null;
840     }
841     
842     /**
843      * Sets this view's message page
844      *
845      * @param page message page
846      */

847     private void setMessagePage(MessagePage page) {
848         fMessagePage = page;
849     }
850     
851     /**
852      * Returns this view's message page
853      *
854      * @return message page
855      */

856     protected MessagePage getMessagePage() {
857         return fMessagePage;
858     }
859     
860     /**
861      * Shows the given message in this view's message'
862      * page. Makes the message page the visible page.
863      *
864      * @param message the message to display
865      */

866     public void showMessage(String JavaDoc message) {
867         if (getPageBook().isDisposed()) {
868             return;
869         }
870         if (getMessagePage() == null) {
871             //not fully created yet
872
fEarlyMessage= message;
873             return;
874         }
875         getMessagePage().setMessage(message);
876         getPageBook().showPage(getMessagePage().getControl());
877     }
878     
879     /**
880      * Shows this view's viewer page.
881      */

882     public void showViewer() {
883         if (getPageBook().isDisposed()) {
884             return;
885         }
886         getPageBook().showPage(getDefaultPage().getControl());
887     }
888     
889     /**
890      * Returns whether this view's viewer is
891      * currently available.
892      *
893      * @return whether this view's viewer is
894      * currently available
895      */

896     public boolean isAvailable() {
897         return !(getViewer() == null || getViewer().getControl() == null || getViewer().getControl().isDisposed());
898     }
899     /**
900      * @see IDebugView#add(IUpdate)
901      */

902     public void add(IUpdate updatable) {
903         if (!fUpdateables.contains(updatable)) {
904             fUpdateables.add(updatable);
905         }
906     }
907
908     /**
909      * @see IDebugView#remove(IUpdate)
910      */

911     public void remove(IUpdate updatable) {
912         fUpdateables.remove(updatable);
913     }
914     
915     /**
916      * Adds a context menu manager that is relevant to this view.
917      * @param contextMenuManager The contextMenuManager to add
918      *
919      * @since 2.1
920      */

921     public void addContextMenuManager(IMenuManager contextMenuManager) {
922         if (fContextMenuManagers == null) {
923             fContextMenuManagers= new ArrayList JavaDoc();
924         }
925         fContextMenuManagers.add(contextMenuManager);
926     }
927     
928     /**
929      * Notification this view is now visible.
930      *
931      * @since 2.1
932      */

933     protected void becomesVisible() {
934     }
935     
936     /**
937      * Notification this view is now hidden.
938      *
939      * @since 2.1
940      */

941     protected void becomesHidden() {
942     }
943     
944     /**
945      * Returns whether this view is currently visible.
946      *
947      * @return whether this view is currently visible
948      * @since 2.1
949      */

950     public boolean isVisible() {
951         return fIsVisible;
952     }
953     
954     /**
955      * Creates and registers a part listener with this event handler's page,
956      * if one does not already exist.
957      *
958      * @since 2.1
959      */

960     protected void registerPartListener() {
961         if (fPartListener == null) {
962             fPartListener= new DebugViewPartListener();
963             getSite().getPage().addPartListener(fPartListener);
964         }
965     }
966
967     /**
968      * Unregisters and disposes this event handler's part listener.
969      *
970      * @since 2.1
971      */

972     protected void deregisterPartListener() {
973         if (fPartListener != null) {
974             getSite().getPage().removePartListener(fPartListener);
975             fPartListener = null;
976         }
977     }
978
979     /**
980      * Returns a map of the current attribute settings in the model
981      * presentation in this view associated with the given debug model.
982      *
983      * @return a map of the current attribute settings in the model
984      * presentation in this view associated with the given debug model
985      * @since 3.0
986      */

987     public Map JavaDoc getPresentationAttributes(String JavaDoc modelId) {
988         IDebugModelPresentation presentation = getPresentation(modelId);
989         if (presentation instanceof DelegatingModelPresentation) {
990             return ((DelegatingModelPresentation)presentation).getAttributeMap();
991         } else if (presentation instanceof LazyModelPresentation) {
992             return ((LazyModelPresentation)presentation).getAttributeMap();
993         }
994         return new HashMap JavaDoc();
995     }
996 }
997
998
999
Popular Tags