When i want to order the extension point contributions, i add a priority number, like int 10.
I only use numbers of 10, 20 , 30,... because you can easily put elements between in the future. This you can use for ordering Buttons, Composites, or everything which you can not order by name.
You can add this priority into your interface you are using to define your extension point. Or you can spend a field in the extension point description.
When you collect all extension point contrubutions you can ask for the priority and order the contributions in a linked list before returnin them.
String tmpExtensionPoint = "EXTENSION POINT ID"; //$NON-NLS-1$
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); //$NON-NLS-1$
} catch (CoreException e) {
logger.error("Get Extension Point For " + tmpExtensionPoint, e);
}
}
}
//...
//ORDER here
return references;
the order code could by something like
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;
}
});