Debian Codegraph @

plugins/org.eclipse.emf.edit.ui/src/org/eclipse/emf/edit/ui/EMFEditUIPlugin.java

raw
1 /**
2 * Copyright (c) 2002-2010 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 v2.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v20.html
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 */
11 package org.eclipse.emf.edit.ui;
12
13 import org.eclipse.core.runtime.IConfigurationElement;
14 import org.eclipse.core.runtime.Platform;
15 import org.eclipse.emf.common.EMFPlugin;
16 import org.eclipse.emf.common.ui.EclipseUIPlugin;
17 import org.eclipse.emf.common.util.ResourceLocator;
18 import org.eclipse.emf.ecore.plugin.RegistryReader;
19 import org.eclipse.emf.edit.ui.util.QueryDelegateTextViewer;
20 import org.osgi.framework.Bundle;
21 import org.osgi.framework.BundleContext;
22
23
24 /**
25 * The <b>Plugin</b> for the model EMF.Edit.UI library.
26 * EMF must run
27 * within an Eclipse workbench,
28 * within a headless Eclipse workspace,
29 * or just stand-alone as part of some other application.
30 * To support this, all resource access should be directed to the resource locator,
31 * which can redirect the service as appropriate to the runtime.
32 * @see #INSTANCE
33 */
34 public final class EMFEditUIPlugin extends EMFPlugin
35 {
36 /**
37 * The singleton instance of the plugin.
38 */
39 public static final EMFEditUIPlugin INSTANCE = new EMFEditUIPlugin();
40
41 /**
42 * The one instance of this class.
43 */
44 private static Implementation plugin;
45
46 public static final String QUERY_DELEGATE_TEXT_VIEWER_FACTORIES_PPID = "queryDelegateTextViewerFactories";
47
48 /**
49 * Creates the singleton instance.
50 */
51 private EMFEditUIPlugin()
52 {
53 super(new ResourceLocator []{});
54 }
55
56 /*
57 * Javadoc copied from base class.
58 */
59 @Override
60 public ResourceLocator getPluginResourceLocator()
61 {
62 return plugin;
63 }
64
65 /**
66 * Returns the singleton instance of the Eclipse plugin.
67 * @return the singleton instance.
68 */
69 public static Implementation getPlugin()
70 {
71 return plugin;
72 }
73
74 /**
75 * The actual implementation of the Eclipse <b>Plugin</b>.
76 */
77 public static class Implementation extends EclipseUIPlugin
78 {
79 /**
80 * Creates an instance.
81 */
82 public Implementation()
83 {
84 super();
85
86 // Remember the static instance.
87 //
88 plugin = this;
89 }
90
91 /**
92 * Starts up this plugin by reading some extensions and populating the relevant registries.
93 * <p>
94 * @throws Exception if there is a show stopping problem.
95 */
96 @Override
97 public void start(BundleContext context) throws Exception
98 {
99 super.start(context);
100
101 Bundle bundle = Platform.getBundle("org.eclipse.jface.text");
102 if (bundle != null && (bundle.getState() & (Bundle.ACTIVE | Bundle.STARTING | Bundle.RESOLVED)) != 0)
103 {
104 new RegistryReader(
105 Platform.getExtensionRegistry(),
106 EMFEditUIPlugin.getPlugin().getBundle().getSymbolicName(),
107 QUERY_DELEGATE_TEXT_VIEWER_FACTORIES_PPID)
108 {
109 @Override
110 protected boolean readElement(IConfigurationElement element, boolean add)
111 {
112 if (element.getName().equals("factory"))
113 {
114 String uri = element.getAttribute("uri");
115 if (uri == null)
116 {
117 logMissingAttribute(element, "uri");
118 }
119 else if (element.getAttribute("class") == null)
120 {
121 logMissingAttribute(element, "class");
122 }
123
124 class FactoryDescriptor extends PluginClassDescriptor implements QueryDelegateTextViewer.Factory.Descriptor
125 {
126 protected QueryDelegateTextViewer.Factory factory;
127
128 public FactoryDescriptor(IConfigurationElement e, String attrName)
129 {
130 super(e, attrName);
131 }
132
133 public QueryDelegateTextViewer.Factory getFactory()
134 {
135 if (factory == null)
136 {
137 factory = (QueryDelegateTextViewer.Factory)createInstance();
138 }
139 return factory;
140 }
141
142 public IConfigurationElement getElement()
143 {
144 return element;
145 }
146 }
147
148 if (add)
149 {
150 Object previous = QueryDelegateTextViewer.Factory.Registry.INSTANCE.put(uri, new FactoryDescriptor(element, "class"));
151 if (previous instanceof FactoryDescriptor)
152 {
153 FactoryDescriptor descriptor = (FactoryDescriptor)previous;
154 EMFEditUIPlugin.INSTANCE.log("Both '" + descriptor.getElement().getContributor().getName() + "' and '"
155 + element.getContributor().getName() + "' register a query delegate text viewer factory for '" + uri + "'");
156 }
157 return true;
158 }
159 else
160 {
161 QueryDelegateTextViewer.Factory.Registry.INSTANCE.remove(uri);
162 return true;
163 }
164 }
165 return false;
166 }
167 }.readRegistry();
168 }
169 }
170 }
171 }