KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.debug.internal.ui.actions;
12
13 import java.util.Iterator JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.debug.core.model.IWatchpoint;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.swt.widgets.Event;
22 import org.eclipse.ui.IActionDelegate2;
23 import org.eclipse.ui.IObjectActionDelegate;
24 import org.eclipse.ui.IWorkbenchPart;
25
26 /**
27  * Action that modifies a watchpoint's access/modification attributes
28  */

29 public abstract class ModifyWatchpointAction implements IObjectActionDelegate, IActionDelegate2 {
30     
31     private IStructuredSelection fWatchpoints = null;
32
33     /* (non-Javadoc)
34      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
35      */

36     public void run(IAction action) {
37         try {
38             if (fWatchpoints != null) {
39                 Iterator JavaDoc iterator = fWatchpoints.iterator();
40                 while (iterator.hasNext()) {
41                     IWatchpoint watchpoint = (IWatchpoint)iterator.next();
42                     toggleWatchpoint(watchpoint, action.isChecked());
43                 }
44             }
45         } catch (CoreException e) {
46             DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), ActionMessages.ModifyWatchpointAction_0, ActionMessages.ModifyWatchpointAction_1, e.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
47
}
48
49     }
50     
51     /**
52      * Toggles the watch point attribute to the given value.
53      *
54      * @param watchpoint
55      * @param b on or off
56      */

57     protected abstract void toggleWatchpoint(IWatchpoint watchpoint, boolean b) throws CoreException;
58     
59     /* (non-Javadoc)
60      * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
61      */

62     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
67      */

68     public void selectionChanged(IAction action, ISelection selection) {
69         if (selection instanceof IStructuredSelection) {
70             fWatchpoints = (IStructuredSelection) selection;
71             if (!selection.isEmpty()) {
72                 Iterator JavaDoc iterator = fWatchpoints.iterator();
73                 while (iterator.hasNext()) {
74                     Object JavaDoc next = iterator.next();
75                     if (next instanceof IWatchpoint) {
76                         IWatchpoint watchpoint = (IWatchpoint) next;
77                         action.setChecked(isChecked(watchpoint));
78                         if (!isEnabled(watchpoint)) {
79                             action.setEnabled(false);
80                             return;
81                         }
82                     }
83                 }
84                 action.setEnabled(true);
85                 return;
86             }
87         }
88         action.setEnabled(false);
89     }
90
91     /**
92      * Returns whether the action should be checke for the current selection
93      *
94      * @param watchpoint selected watchpoint
95      * @return whether the action should be checke for the current selection
96      */

97     protected abstract boolean isChecked(IWatchpoint watchpoint);
98
99     /**
100      * Returns whether this action is enabled for the given watchpoint.
101      *
102      * @param watchpoint
103      * @return whether this action is enabled for the given watchpoint
104      */

105     protected abstract boolean isEnabled(IWatchpoint watchpoint);
106
107     /* (non-Javadoc)
108      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
109      */

110     public void init(IAction action) {
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.ui.IActionDelegate2#dispose()
115      */

116     public void dispose() {
117         fWatchpoints = null;
118     }
119
120     /* (non-Javadoc)
121      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
122      */

123     public void runWithEvent(IAction action, Event event) {
124         run(action);
125     }
126 }
127
Popular Tags