KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > expressions > EnableWatchExpressionAction


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.expressions;
12
13 import java.util.Iterator JavaDoc;
14
15 import org.eclipse.debug.core.DebugEvent;
16 import org.eclipse.debug.core.DebugPlugin;
17 import org.eclipse.debug.core.model.IWatchExpression;
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.ui.IObjectActionDelegate;
22 import org.eclipse.ui.IWorkbenchPart;
23
24 /**
25  *
26  */

27 public class EnableWatchExpressionAction implements IObjectActionDelegate {
28
29     private ISelection fSelection;
30     protected boolean fEnable= true;
31
32     /**
33      * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
34      */

35     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
36     }
37
38     /**
39      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
40      */

41     public void run(IAction action) {
42         if (fSelection instanceof IStructuredSelection) {
43             Iterator JavaDoc iter= ((IStructuredSelection) fSelection).iterator();
44             IWatchExpression expression;
45             while (iter.hasNext()) {
46                 expression= ((IWatchExpression) iter.next());
47                 expression.setEnabled(fEnable);
48                 fireWatchExpressionChanged(expression);
49             }
50         } else if (fSelection instanceof IWatchExpression) {
51             IWatchExpression expression= ((IWatchExpression) fSelection);
52             expression.setEnabled(fEnable);
53             fireWatchExpressionChanged(expression);
54         }
55     }
56
57     /**
58      * @param expression
59      */

60     private void fireWatchExpressionChanged(IWatchExpression expression) {
61         DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {new DebugEvent(expression, DebugEvent.CHANGE)});
62     }
63
64     /**
65      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
66      */

67     public void selectionChanged(IAction action, ISelection selection) {
68         fSelection= selection;
69         if (fSelection instanceof IStructuredSelection) {
70             boolean enabled= false;
71             Iterator JavaDoc iter= ((IStructuredSelection) selection).iterator();
72             while (iter.hasNext()) {
73                 IWatchExpression expression = (IWatchExpression) iter.next();
74                 if (expression.isEnabled() != fEnable) {
75                     enabled= true;
76                     break;
77                 }
78             }
79             action.setEnabled(enabled);
80         } else if (fSelection instanceof IWatchExpression) {
81             action.setEnabled(((IWatchExpression) fSelection).isEnabled() != fEnable);
82         } else {
83             action.setEnabled(false);
84         }
85     }
86
87 }
88
Popular Tags