KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > SubActionBars2


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ui;
12
13 import org.eclipse.jface.action.ICoolBarManager;
14 import org.eclipse.jface.action.SubCoolBarManager;
15 import org.eclipse.ui.services.IServiceLocator;
16
17 /**
18  * A implementation of the extended <code>IActionBars2</code> interface. This
19  * sub class provides a sub cool bar manager for plugins to contribute multiple
20  * cool items.
21  *
22  * @since 3.0
23  */

24 public class SubActionBars2 extends SubActionBars implements IActionBars2 {
25     private SubCoolBarManager coolBarMgr = null;
26
27     /**
28      * Constucts a sub action bars object using an IActionBars2 parent.
29      *
30      * @param parent
31      * the action bars to virtualize; must not be <code>null</code>.
32      */

33     public SubActionBars2(final IActionBars2 parent) {
34         this(parent, parent.getServiceLocator());
35     }
36
37     /**
38      * Constucts a sub action bars object using an IActionBars2 parent.
39      *
40      * @param parent
41      * the action bars to virtualize; must not be <code>null</code>.
42      * @param serviceLocator
43      * The service locator for this action bar; must not be
44      * <code>null</code>.
45      *
46      * @since 3.2
47      */

48     public SubActionBars2(final IActionBars2 parent,
49             final IServiceLocator serviceLocator) {
50         super(parent, serviceLocator);
51     }
52
53     /**
54      * Returns the casted parent of the sub action bars. This method can return
55      * an IActionBars2 since it can only accept IActionBars2 in the constructor.
56      *
57      * @return the casted parent.
58      */

59     protected IActionBars2 getCastedParent() {
60         return (IActionBars2) getParent();
61     }
62
63     /**
64      * Returns a new sub coolbar manager.
65      *
66      * @param parent
67      * the parent coolbar manager
68      * @return the cool bar manager
69      */

70     protected SubCoolBarManager createSubCoolBarManager(ICoolBarManager parent) {
71         return new SubCoolBarManager(parent);
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see org.eclipse.ui.IActionBars2#getCoolBarManager()
78      */

79     public ICoolBarManager getCoolBarManager() {
80         if (coolBarMgr == null) {
81             coolBarMgr = createSubCoolBarManager(getCastedParent()
82                     .getCoolBarManager());
83             coolBarMgr.setVisible(getActive());
84         }
85         return coolBarMgr;
86     }
87
88     /*
89      * (non-Javadoc)
90      *
91      * @see org.eclipse.ui.SubActionBars#setActive(boolean)
92      */

93     protected void setActive(boolean value) {
94         super.setActive(value);
95         if (coolBarMgr != null) {
96             coolBarMgr.setVisible(value);
97         }
98     }
99
100     /*
101      * (non-Javadoc)
102      *
103      * @see org.eclipse.ui.SubActionBars#dispose()
104      */

105     public void dispose() {
106         super.dispose();
107         if (coolBarMgr != null) {
108             coolBarMgr.removeAll();
109         }
110     }
111 }
112
Popular Tags