01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.core.runtime.IConfigurationElement;
13: import org.eclipse.core.runtime.IExtensionRegistry;
14: import org.eclipse.core.runtime.Platform;
15: import org.eclipse.ui.PlatformUI;
16: import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
17: import org.eclipse.ui.internal.registry.RegistryReader;
18:
19: /**
20: * This reader loads the popup menu manager with all the
21: * popup menu contributors found in the workbench registry.
22: */
23: public class ObjectActionContributorReader extends RegistryReader {
24:
25: private ObjectActionContributorManager manager;
26:
27: /**
28: * Creates popup menu contributor from this element.
29: */
30: protected void processObjectContribution(
31: IConfigurationElement element) {
32: String objectClassName = element
33: .getAttribute(IWorkbenchRegistryConstants.ATT_OBJECTCLASS);
34: if (objectClassName == null) {
35: logMissingAttribute(element,
36: IWorkbenchRegistryConstants.ATT_OBJECTCLASS);
37: return;
38: }
39:
40: IObjectContributor contributor = new ObjectActionContributor(
41: element);
42: manager.registerContributor(contributor, objectClassName);
43: }
44:
45: /**
46: * Implements abstract method to handle configuration elements.
47: */
48: protected boolean readElement(IConfigurationElement element) {
49: String tagName = element.getName();
50: if (tagName
51: .equals(IWorkbenchRegistryConstants.TAG_OBJECT_CONTRIBUTION)) {
52: processObjectContribution(element);
53: return true;
54: }
55: if (tagName
56: .equals(IWorkbenchRegistryConstants.TAG_VIEWER_CONTRIBUTION)) {
57: return true;
58: }
59:
60: return false;
61: }
62:
63: /**
64: * Reads the registry and registers popup menu contributors
65: * found there.
66: *
67: * @param mng the manager to read into
68: */
69: public void readPopupContributors(ObjectActionContributorManager mng) {
70: setManager(mng);
71: IExtensionRegistry registry = Platform.getExtensionRegistry();
72: readRegistry(registry, PlatformUI.PLUGIN_ID,
73: IWorkbenchRegistryConstants.PL_POPUP_MENU);
74: }
75:
76: /**
77: * Set the manager to read into.
78: *
79: * @param mng the manager
80: */
81: public void setManager(ObjectActionContributorManager mng) {
82: manager = mng;
83: }
84: }
|