When I want to order extension liner points, I add a priority number, for example, int 10.
I use only the numbers 10, 20, 30, ... because you can easily add elements between them in the future. This can be used to order buttons, composites, or anything you cannot order by name.
You can add this priority to your interface, which you use to define your extension point. Or you can hold a field in the description of the extension point.
When you collect all contributions to additional points, you can request a priority and order deposits in a linked list before returning them.
String tmpExtensionPoint = "EXTENSION POINT ID";
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = registry.getConfigurationElementsFor(tmpExtensionPoint);
List references = new LinkedList();
if (elements != null && elements.length > 0) {
for (int i = 0; i < elements.length; i++) {
try {
Object obj = elements[i].createExecutableExtension("class");
references.add((IExtensionPointInterface)obj);
} catch (CoreException e) {
logger.error("Get Extension Point For " + tmpExtensionPoint, e);
}
}
}
return references;
The order code may look something like this:
Arrays.sort(references, new Comparator() {
public int compare(Object arg0, Object arg1) {
if (!(arg0 instanceof IExtensionPointInterface )) {
return -1;
}
if (!(arg1 instanceof IExtensionPointInterface )) {
return -1;
}
IExtensionPointInterface part0 = (IExtensionPointInterface)arg0;
IExtensionPointInterface part1 = (IExtensionPointInterface)arg1;
if (part0.getPriority() < part1.getPriority()) {
return -1;
}
if (part0.getPriority() > part1.getPriority()) {
return 1;
}
return 0;
}
});
source
share