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