KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > context > BooleanRequestMonitor


1 /*******************************************************************************
2  * Copyright (c) 2006 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.context;
12
13 import org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor;
14 import org.eclipse.jface.action.IAction;
15
16 /**
17  * Boolean request monitor that collects boolean results from a number of voters.
18  * Request is cancelled when one voter votes false.
19  *
20  * @since 3.2
21  *
22  */

23 public class BooleanRequestMonitor extends AbstractRequestMonitor implements IBooleanRequestMonitor {
24     
25     private IAction fAction;
26     private int fNumVoters;
27     private int fNumOfVotes = 0;
28     
29     BooleanRequestMonitor(IAction action, int numVoters) {
30         fAction = action;
31         fNumVoters = numVoters;
32     }
33
34     /* (non-Javadoc)
35      * @see org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor#setResult(boolean)
36      */

37     public void setResult(boolean result) {
38         fNumOfVotes++;
39         if (!isCanceled()) {
40             if (!result) {
41                 setCanceled(true);
42             }
43         }
44     }
45
46     /* (non-Javadoc)
47      * @see org.eclipse.core.runtime.IProgressMonitor#done()
48      */

49     public void done() {
50         if (isCanceled()) {
51             fAction.setEnabled(false);
52         } else {
53             fAction.setEnabled(fNumOfVotes == fNumVoters);
54         }
55     }
56
57 }
58
Popular Tags