The name field is now protected (PHPVarDeclaration needs)
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / actions / CompositeActionGroup.java
1 /*******************************************************************************
2  * Copyright (c) 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
12
13 import org.eclipse.jface.action.IMenuManager;
14 import org.eclipse.jface.util.Assert;
15
16 import org.eclipse.ui.IActionBars;
17 import org.eclipse.ui.actions.ActionContext;
18 import org.eclipse.ui.actions.ActionGroup;
19
20 public class CompositeActionGroup extends ActionGroup {
21
22         private ActionGroup[] fGroups;
23         
24         public CompositeActionGroup() {
25         }
26         
27         public CompositeActionGroup(ActionGroup[] groups) {
28                 setGroups(groups);
29         }
30
31         protected void setGroups(ActionGroup[] groups) {
32                 Assert.isTrue(fGroups == null);
33                 Assert.isNotNull(groups);
34                 fGroups= groups;                
35         }
36                 
37         public ActionGroup get(int index) {
38                 if (fGroups == null)
39                         return null;
40                 return fGroups[index];
41         }
42         
43         public void addGroup(ActionGroup group) {
44                 if (fGroups == null) {
45                         fGroups= new ActionGroup[] { group };
46                 } else {
47                         ActionGroup[] newGroups= new ActionGroup[fGroups.length + 1];
48                         System.arraycopy(fGroups, 0, newGroups, 0, fGroups.length);
49                         newGroups[fGroups.length]= group;
50                         fGroups= newGroups;
51                 }
52         }
53         
54         public void dispose() {
55                 super.dispose();
56                 if (fGroups == null)
57                         return;
58                 for (int i= 0; i < fGroups.length; i++) {
59                         fGroups[i].dispose();
60                 }
61         }
62
63         public void fillActionBars(IActionBars actionBars) {
64                 super.fillActionBars(actionBars);
65                 if (fGroups == null)
66                         return;
67                 for (int i= 0; i < fGroups.length; i++) {
68                         fGroups[i].fillActionBars(actionBars);
69                 }
70         }
71
72         public void fillContextMenu(IMenuManager menu) {
73                 super.fillContextMenu(menu);
74                 if (fGroups == null)
75                         return;
76                 for (int i= 0; i < fGroups.length; i++) {
77                         fGroups[i].fillContextMenu(menu);
78                 }
79         }
80
81         public void setContext(ActionContext context) {
82                 super.setContext(context);
83                 if (fGroups == null)
84                         return;
85                 for (int i= 0; i < fGroups.length; i++) {
86                         fGroups[i].setContext(context);
87                 }
88         }
89
90         public void updateActionBars() {
91                 super.updateActionBars();
92                 if (fGroups == null)
93                         return;
94                 for (int i= 0; i < fGroups.length; i++) {
95                         fGroups[i].updateActionBars();
96                 }
97         }
98 }