KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > AbstractListenerActionDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  * Pawel Piech - Bug 75183
11  *******************************************************************************/

12 package org.eclipse.debug.internal.ui.actions;
13
14  
15 import org.eclipse.debug.core.DebugEvent;
16 import org.eclipse.debug.core.DebugPlugin;
17 import org.eclipse.debug.core.IDebugEventSetListener;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.swt.widgets.Event;
20 import org.eclipse.swt.widgets.Shell;
21 import org.eclipse.ui.IActionDelegate2;
22 import org.eclipse.ui.IViewPart;
23 import org.eclipse.ui.IWorkbenchWindow;
24
25 public abstract class AbstractListenerActionDelegate extends AbstractDebugActionDelegate implements IDebugEventSetListener, IActionDelegate2 {
26
27     private boolean fDisposed = false;
28     
29     /**
30      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
31      * @see org.eclipse.ui.IActionDelegate2#dispose()
32      */

33     public synchronized void dispose() {
34         super.dispose();
35         DebugPlugin.getDefault().removeDebugEventListener(this);
36         fDisposed = true;
37     }
38     
39     /**
40      * @see IDebugEventSetListener#handleDebugEvents(DebugEvent[])
41      */

42     public void handleDebugEvents(final DebugEvent[] events) {
43         if (getWindow() == null || getAction() == null) {
44             return;
45         }
46         Shell shell= getWindow().getShell();
47         if (shell == null || shell.isDisposed()) {
48             return;
49         }
50         synchronized (this) {
51             if (fDisposed) {
52                 return;
53             }
54         }
55         for (int i = 0; i < events.length; i++) {
56             if (events[i].getSource() != null) {
57                 doHandleDebugEvent(events[i]);
58             }
59         }
60     }
61     
62     /**
63      * Default implementation to update on specific debug events.
64      * Subclasses should override to handle events differently.
65      */

66     protected void doHandleDebugEvent(DebugEvent event) {
67         switch (event.getKind()) {
68             case DebugEvent.TERMINATE :
69                 update(getAction(), getSelection());
70                 break;
71             case DebugEvent.RESUME :
72                 if (!event.isEvaluation() || !((event.getDetail() & DebugEvent.EVALUATION_IMPLICIT) != 0)) {
73                     update(getAction(), getSelection());
74                 }
75                 break;
76             case DebugEvent.SUSPEND :
77                 // Update on suspend events (even for evaluations), in case the user changed
78
// the selection during an implicit evaluation.
79
update(getAction(), getSelection());
80                 break;
81             case DebugEvent.CHANGE :
82                 // Implementations can use this event for debugger state
83
// changes other than just suspend/resume. This may or
84
// may not affect the enable state of run/suspend/step
85
// actions.
86
update(getAction(), getSelection());
87                 break;
88         }
89     }
90
91     /**
92      * @see IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
93      */

94     public void init(IWorkbenchWindow window){
95         super.init(window);
96         DebugPlugin.getDefault().addDebugEventListener(this);
97     }
98
99     /**
100      * @see IViewActionDelegate#init(IViewPart)
101      */

102     public void init(IViewPart view) {
103         super.init(view);
104         DebugPlugin.getDefault().addDebugEventListener(this);
105         setWindow(view.getViewSite().getWorkbenchWindow());
106     }
107
108     /**
109      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
110      */

111     public void init(IAction action) {
112     }
113
114     /**
115      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
116      */

117     public void runWithEvent(IAction action, Event event) {
118         run(action);
119     }
120 }
121
Popular Tags