KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > commands > actions > ActionsUpdater


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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.commands.actions;
12
13 import org.eclipse.jface.action.IAction;
14
15 /**
16  * Collects votes from handler update requests.
17  *
18  * @since 3.3
19  *
20  */

21 public class ActionsUpdater {
22     
23     private IAction[] fActions;
24     private int fNumVoters;
25     private int fNumOfVotes = 0;
26     private boolean fDone = false;
27     private boolean fEnabled = true;
28     
29     public ActionsUpdater(IAction[] actions, int numVoters) {
30         fActions = actions;
31         fNumVoters = numVoters;
32     }
33
34     public synchronized void setEnabled(boolean result) {
35         fNumOfVotes++;
36         if (fEnabled) {
37             fEnabled = result;
38         }
39         done();
40     }
41
42     private synchronized void done() {
43         if (!fDone) {
44             if (!fEnabled || fNumOfVotes == fNumVoters) {
45                 fDone = true;
46                 for (int i = 0; i < fActions.length; i++) {
47                     fActions[i].setEnabled(fEnabled);
48                 }
49             }
50         }
51     }
52
53 }
54
Popular Tags