|
Lines 1-7
Link Here
|
| 1 |
/** |
1 |
/** |
| 2 |
* <copyright> |
2 |
* <copyright> |
| 3 |
* |
3 |
* |
| 4 |
* Copyright (c) 2002-2006 IBM Corporation and others. |
4 |
* Copyright (c) 2002-2010 IBM Corporation and others. |
| 5 |
* All rights reserved. This program and the accompanying materials |
5 |
* All rights reserved. This program and the accompanying materials |
| 6 |
* are made available under the terms of the Eclipse Public License v1.0 |
6 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 7 |
* which accompanies this distribution, and is available at |
7 |
* which accompanies this distribution, and is available at |
|
Lines 16-25
Link Here
|
| 16 |
*/ |
16 |
*/ |
| 17 |
package org.eclipse.emf.edit.ui; |
17 |
package org.eclipse.emf.edit.ui; |
| 18 |
|
18 |
|
| 19 |
|
19 |
import org.eclipse.core.runtime.IConfigurationElement; |
|
|
20 |
import org.eclipse.core.runtime.Platform; |
| 20 |
import org.eclipse.emf.common.EMFPlugin; |
21 |
import org.eclipse.emf.common.EMFPlugin; |
| 21 |
import org.eclipse.emf.common.ui.EclipseUIPlugin; |
22 |
import org.eclipse.emf.common.ui.EclipseUIPlugin; |
| 22 |
import org.eclipse.emf.common.util.ResourceLocator; |
23 |
import org.eclipse.emf.common.util.ResourceLocator; |
|
|
24 |
import org.eclipse.emf.ecore.plugin.RegistryReader; |
| 25 |
import org.eclipse.emf.edit.ui.util.QueryDelegateTextViewer; |
| 26 |
import org.osgi.framework.Bundle; |
| 27 |
import org.osgi.framework.BundleContext; |
| 23 |
|
28 |
|
| 24 |
|
29 |
|
| 25 |
/** |
30 |
/** |
|
Lines 34-40
Link Here
|
| 34 |
* In this case, emf.edit.resources.jar must be on the CLASSPATH. |
39 |
* In this case, emf.edit.resources.jar must be on the CLASSPATH. |
| 35 |
* @see #INSTANCE |
40 |
* @see #INSTANCE |
| 36 |
*/ |
41 |
*/ |
| 37 |
public final class EMFEditUIPlugin extends EMFPlugin |
42 |
public final class EMFEditUIPlugin extends EMFPlugin |
| 38 |
{ |
43 |
{ |
| 39 |
/** |
44 |
/** |
| 40 |
* The singleton instance of the plugin. |
45 |
* The singleton instance of the plugin. |
|
Lines 46-57
Link Here
|
| 46 |
*/ |
51 |
*/ |
| 47 |
private static Implementation plugin; |
52 |
private static Implementation plugin; |
| 48 |
|
53 |
|
|
|
54 |
public static final String QUERY_DELEGATE_TEXT_VIEWER_FACTORIES_PPID = "queryDelegateTextViewerFactories"; |
| 55 |
|
| 49 |
/** |
56 |
/** |
| 50 |
* Creates the singleton instance. |
57 |
* Creates the singleton instance. |
| 51 |
*/ |
58 |
*/ |
| 52 |
private EMFEditUIPlugin() |
59 |
private EMFEditUIPlugin() |
| 53 |
{ |
60 |
{ |
| 54 |
super(new ResourceLocator[] {}); |
61 |
super(new ResourceLocator []{}); |
| 55 |
} |
62 |
} |
| 56 |
|
63 |
|
| 57 |
/* |
64 |
/* |
|
Lines 75-81
Link Here
|
| 75 |
/** |
82 |
/** |
| 76 |
* The actual implementation of the Eclipse <b>Plugin</b>. |
83 |
* The actual implementation of the Eclipse <b>Plugin</b>. |
| 77 |
*/ |
84 |
*/ |
| 78 |
public static class Implementation extends EclipseUIPlugin |
85 |
public static class Implementation extends EclipseUIPlugin |
| 79 |
{ |
86 |
{ |
| 80 |
/** |
87 |
/** |
| 81 |
* Creates an instance. |
88 |
* Creates an instance. |
|
Lines 88-92
Link Here
|
| 88 |
// |
95 |
// |
| 89 |
plugin = this; |
96 |
plugin = this; |
| 90 |
} |
97 |
} |
|
|
98 |
|
| 99 |
/** |
| 100 |
* Starts up this plugin by reading some extensions and populating the relevant registries. |
| 101 |
* <p> |
| 102 |
* @throws Exception if there is a show stopping problem. |
| 103 |
*/ |
| 104 |
@Override |
| 105 |
public void start(BundleContext context) throws Exception |
| 106 |
{ |
| 107 |
super.start(context); |
| 108 |
|
| 109 |
Bundle bundle = Platform.getBundle("org.eclipse.jface.text"); |
| 110 |
if (bundle != null && (bundle.getState() & (Bundle.ACTIVE | Bundle.STARTING | Bundle.RESOLVED)) != 0) |
| 111 |
{ |
| 112 |
new RegistryReader( |
| 113 |
Platform.getExtensionRegistry(), |
| 114 |
EMFEditUIPlugin.getPlugin().getBundle().getSymbolicName(), |
| 115 |
QUERY_DELEGATE_TEXT_VIEWER_FACTORIES_PPID) |
| 116 |
{ |
| 117 |
@Override |
| 118 |
protected boolean readElement(IConfigurationElement element, boolean add) |
| 119 |
{ |
| 120 |
if (element.getName().equals("factory")) |
| 121 |
{ |
| 122 |
String uri = element.getAttribute("uri"); |
| 123 |
if (uri == null) |
| 124 |
{ |
| 125 |
logMissingAttribute(element, "uri"); |
| 126 |
} |
| 127 |
else if (element.getAttribute("class") == null) |
| 128 |
{ |
| 129 |
logMissingAttribute(element, "class"); |
| 130 |
} |
| 131 |
|
| 132 |
class FactoryDescriptor extends PluginClassDescriptor implements QueryDelegateTextViewer.Factory.Descriptor |
| 133 |
{ |
| 134 |
protected QueryDelegateTextViewer.Factory factory; |
| 135 |
|
| 136 |
public FactoryDescriptor(IConfigurationElement e, String attrName) |
| 137 |
{ |
| 138 |
super(e, attrName); |
| 139 |
} |
| 140 |
|
| 141 |
public QueryDelegateTextViewer.Factory getFactory() |
| 142 |
{ |
| 143 |
if (factory == null) |
| 144 |
{ |
| 145 |
factory = (QueryDelegateTextViewer.Factory)createInstance(); |
| 146 |
} |
| 147 |
return factory; |
| 148 |
} |
| 149 |
|
| 150 |
public IConfigurationElement getElement() |
| 151 |
{ |
| 152 |
return element; |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
if (add) |
| 157 |
{ |
| 158 |
Object previous = QueryDelegateTextViewer.Factory.Registry.INSTANCE.put(uri, new FactoryDescriptor(element, "class")); |
| 159 |
if (previous instanceof FactoryDescriptor) |
| 160 |
{ |
| 161 |
FactoryDescriptor descriptor = (FactoryDescriptor)previous; |
| 162 |
EMFEditUIPlugin.INSTANCE.log("Both '" + descriptor.getElement().getContributor().getName() + "' and '" |
| 163 |
+ element.getContributor().getName() + "' register a query delegate text viewer factory for '" + uri + "'"); |
| 164 |
} |
| 165 |
return true; |
| 166 |
} |
| 167 |
else |
| 168 |
{ |
| 169 |
QueryDelegateTextViewer.Factory.Registry.INSTANCE.remove(uri); |
| 170 |
return true; |
| 171 |
} |
| 172 |
} |
| 173 |
return false; |
| 174 |
} |
| 175 |
}.readRegistry(); |
| 176 |
} |
| 177 |
} |
| 91 |
} |
178 |
} |
| 92 |
} |
179 |
} |