KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > breakpoints > 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.breakpoints;
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.debug.internal.ui.actions.ActionMessages;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.swt.widgets.Event;
23 import org.eclipse.ui.IActionDelegate2;
24 import org.eclipse.ui.IObjectActionDelegate;
25 import org.eclipse.ui.IWorkbenchPart;
26
27 /**
28  * Action that modifies a watchpoint's access/modification attributes
29  */

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

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

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

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

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

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

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

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

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

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