KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > menus > MenuContainer


1 /*******************************************************************************
2  * Copyright (c) 2005, 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
12 package org.eclipse.ui.internal.menus;
13
14 import org.eclipse.core.commands.common.NotDefinedException;
15 import org.eclipse.jface.util.PropertyChangeEvent;
16 import org.eclipse.jface.util.Util;
17
18 /**
19  * <p>
20  * A menu container is a menu element that can contain other elements. This
21  * means that it can optionally have a class the will control the appearance of
22  * elements on a dynamic basis.
23  * </p>
24  * <p>
25  * Clients must not implement or extend.
26  * </p>
27  * <p>
28  * <strong>PROVISIONAL</strong>. This class or interface has been added as
29  * part of a work in progress. There is a guarantee neither that this API will
30  * work nor that it will remain the same. Please do not use this API without
31  * consulting with the Platform/UI team.
32  * </p>
33  * <p>
34  * This class will eventually exist in <code>org.eclipse.jface.menus</code>.
35  * </p>
36  *
37  * @since 3.2
38  * @see org.eclipse.ui.internal.menus.SMenu
39  * @see org.eclipse.ui.internal.menus.SGroup
40  */

41 public abstract class MenuContainer extends MenuElement {
42
43     /**
44      * The property for a property change event indicating that the dynamic
45      * class for this menu container has changed.
46      */

47     public static final String JavaDoc PROPERTY_DYNAMIC = "DYNAMIC"; //$NON-NLS-1$
48

49     /**
50      * The class providing dynamic menu elements to this menu container. If this
51      * value is <code>null</code>, then there are no dynamic elements.
52      */

53     protected IDynamicMenu dynamic;
54
55     /**
56      * Constructs a new instance of <code>MenuCollection</code>.
57      *
58      * @param id
59      * The identifier of the container to create; must not be
60      * <code>null</code>.
61      */

62     protected MenuContainer(final String JavaDoc id) {
63         super(id);
64     }
65
66     /**
67      * Returns the class generating dynamic menu elements for this menu
68      * container.
69      *
70      * @return The class generating dynamic menu elements for this menu
71      * container; never <code>null</code>.
72      * @throws NotDefinedException
73      * If the handle is not currently defined.
74      */

75     public final IDynamicMenu getDynamic() throws NotDefinedException {
76         if (!isDefined()) {
77             throw new NotDefinedException(
78                     "Cannot get the dynamic class from an undefined menu container"); //$NON-NLS-1$
79
}
80
81         return dynamic;
82     }
83
84     protected final void setDynamic(final IDynamicMenu dynamic) {
85         if (!Util.equals(this.dynamic, dynamic)) {
86             PropertyChangeEvent event = null;
87             if (isListenerAttached()) {
88                 event = new PropertyChangeEvent(this, PROPERTY_DYNAMIC,
89                         this.dynamic, dynamic);
90             }
91             this.dynamic = dynamic;
92             firePropertyChangeEvent(event);
93         }
94     }
95 }
96
Popular Tags