ab643ef5cdcb1ded675708a31282922284921a1d
[phpeclipse.git] /
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 import org.eclipse.ui.IActionBars;
16 import org.eclipse.ui.actions.ActionContext;
17 import org.eclipse.ui.actions.ActionGroup;
18
19 public class CompositeActionGroup extends ActionGroup {
20
21         private ActionGroup[] fGroups;
22
23         public CompositeActionGroup() {
24         }
25
26         public CompositeActionGroup(ActionGroup[] groups) {
27                 setGroups(groups);
28         }
29
30         protected void setGroups(ActionGroup[] groups) {
31                 Assert.isTrue(fGroups == null);
32                 Assert.isNotNull(groups);
33                 fGroups = groups;
34         }
35
36         public ActionGroup get(int index) {
37                 if (fGroups == null)
38                         return null;
39                 return fGroups[index];
40         }
41
42         public void addGroup(ActionGroup group) {
43                 if (fGroups == null) {
44                         fGroups = new ActionGroup[] { group };
45                 } else {
46                         ActionGroup[] newGroups = new ActionGroup[fGroups.length + 1];
47                         System.arraycopy(fGroups, 0, newGroups, 0, fGroups.length);
48                         newGroups[fGroups.length] = group;
49                         fGroups = newGroups;
50                 }
51         }
52
53         public void dispose() {
54                 super.dispose();
55                 if (fGroups == null)
56                         return;
57                 for (int i = 0; i < fGroups.length; i++) {
58                         fGroups[i].dispose();
59                 }
60         }
61
62         public void fillActionBars(IActionBars actionBars) {
63                 super.fillActionBars(actionBars);
64                 if (fGroups == null)
65                         return;
66                 for (int i = 0; i < fGroups.length; i++) {
67                         fGroups[i].fillActionBars(actionBars);
68                 }
69         }
70
71         public void fillContextMenu(IMenuManager menu) {
72                 super.fillContextMenu(menu);
73                 if (fGroups == null)
74                         return;
75                 for (int i = 0; i < fGroups.length; i++) {
76                         fGroups[i].fillContextMenu(menu);
77                 }
78         }
79
80         public void setContext(ActionContext context) {
81                 super.setContext(context);
82                 if (fGroups == null)
83                         return;
84                 for (int i = 0; i < fGroups.length; i++) {
85                         fGroups[i].setContext(context);
86                 }
87         }
88
89         public void updateActionBars() {
90                 super.updateActionBars();
91                 if (fGroups == null)
92                         return;
93                 for (int i = 0; i < fGroups.length; i++) {
94                         fGroups[i].updateActionBars();
95                 }
96         }
97 }