KickJava   Java API By Example, From Geeks To Geeks.

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


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
15 /**
16  * <p>
17  * Stores information about the non-leaf components of a location until such
18  * time as the leaf component can be created. This is used to support the order
19  * in which a legacy action-based extension is parsed.
20  * </p>
21  * <p>
22  * This class is not intended for use outside of the
23  * <code>org.eclipse.ui.workbench</code> plug-in.
24  * </p>
25  *
26  * @since 3.2
27  */

28 final class LegacyLocationInfo {
29
30     /**
31      * The part as it would appear in an instance of {@link SPart}. This value
32      * is <code>null</code> iff this location info does not represent an
33      * {@link SPart} instance.
34      */

35     private final String JavaDoc part;
36
37     /**
38      * Whether the leaf element should be converted into an instance of
39      * {@link SPopup}.
40      */

41     private final boolean popupMenu;
42
43     /**
44      * Constructs an instance of {@link LegacyLocationInfo}. This is used for
45      * {@link IRegisryConstants#ELEMENT_OBJECT_CONTRIBUTION}. This will just
46      * convert any {@link SBar} instances into {@link SPopup} instances.
47      */

48     LegacyLocationInfo() {
49         this(null, true);
50     }
51
52     /**
53      * Constructs an instance of {@link LegacyLocationInfo}. This is used for
54      * {@link IRegisryConstants#ELEMENT_VIEW_CONTRIBUTION}.
55      *
56      * @param part
57      * The part as it would appear in an instance of {@link SPart}.
58      * This value is <code>null</code> iff this location info does
59      * not represent an {@link SPart} instance.
60      */

61     LegacyLocationInfo(final String JavaDoc part) {
62         this(part, false);
63     }
64
65     /**
66      * Constructs an instance of {@link LegacyLocationInfo}. This is used for
67      * {@link IRegisryConstants#ELEMENT_VIEWER_CONTRIBUTION}.
68      *
69      * @param part
70      * The part as it would appear in an instance of {@link SPart}.
71      * This value is <code>null</code> iff this location info does
72      * not represent an {@link SPart} instance.
73      * @param popupMenu
74      * Whether the leaf element should be converted into a popup
75      * element (if it is not one already).
76      */

77     LegacyLocationInfo(final String JavaDoc part, final boolean popupMenu) {
78         this.part = part;
79         this.popupMenu = popupMenu;
80     }
81
82     /**
83      * Appends the leaf element to this location, and returns the result.
84      *
85      * @param leafElement
86      * The leaf element to append; must not be <code>null</code>.
87      * @return The location element containing the information in this instance
88      * as well as in the leaf element; never <code>null</code>.
89      */

90     final LocationElement append(final LeafLocationElement leafElement) {
91         if ((popupMenu) && (leafElement instanceof SBar)) {
92             final SBar bar = (SBar) leafElement;
93             final String JavaDoc path = bar.getPath();
94             final SPopup popup = new SPopup(null, path);
95             if (part == null) {
96                 return popup; // object contrib
97
}
98
99             return new SPart(part, SPart.TYPE_ID, popup); // viewer contrib
100
}
101
102         if (part != null) {
103             return new SPart(part, SPart.TYPE_ID, leafElement); // view contrib
104
}
105
106         return leafElement; // unknown
107
}
108 }
109
Popular Tags