Skip to content

Commit

Permalink
klighd, klighd.standalone: allow to register more extensions via
Browse files Browse the repository at this point in the history
ServiceLoader.

During startup as a non-Eclipse-application KLighD now will also load
the registrations for the IViewerProvider, IUpdateStragety, IAction, and
IStyleModifier via ServiceLoader.
  • Loading branch information
NiklasRentzCAU committed Jul 16, 2020
1 parent 4da94d0 commit 307c8f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Require-Bundle: org.eclipse.emf.ecore.xmi,
de.cau.cs.kieler.klighd.piccolo,
org.eclipse.elk.alg.common;resolution:=optional,
org.eclipse.elk.alg.force;resolution:=optional,
org.eclipse.elk.alg.graphviz.dot,
org.eclipse.elk.alg.graphviz.layouter;resolution:=optional,
org.eclipse.elk.alg.layered;resolution:=optional,
org.eclipse.elk.alg.mrtree;resolution:=optional,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public void doInitialize() {
);

KlighdDataManager.getInstance()
.registerUpdateStrategy(SimpleUpdateStrategy.ID, new SimpleUpdateStrategy())
.registerViewer(PiccoloViewer.ID, new PiccoloViewer.Provider())
.registerOffscreenRenderer(BitmapOffscreenRenderer.ID, new BitmapOffscreenRenderer(),
IOffscreenRenderer.BMP, IOffscreenRenderer.JPEG, IOffscreenRenderer.PNG)
.registerOffscreenRenderer(SVGOffscreenRenderer.ID, new SVGOffscreenRenderer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private KlighdDataManager() {

} else {
loadDiagramSynthesesViaServiceLoader(id2Synthesis, type2Syntheses);
loadKlighdExtensionsViaServiceLoader();
}

this.idSynthesisMapping = id2Synthesis;
Expand Down Expand Up @@ -323,6 +324,32 @@ private void loadKlighdExtensionsViaExtensionPoint() {
}
}

/**
* Loads the registered {@link IViewerProvider}, {@link IUpdateStrategy}, {@link IAction},
* and {@link IStyleModifier} via Java {@link ServiceLoader}.
* This does not load the extensions for exporters via {@link IConfigurationElement}, {@link IExportBranding},
* and {@link IOffscreenRenderer}, as they need further information for registration other than the class and an ID.
* They need to be registered manually when extension points are not used.
*/
private void loadKlighdExtensionsViaServiceLoader() {
for (IViewerProvider viewerProvider : ServiceLoader.load(IViewerProvider.class,
KlighdDataManager.class.getClassLoader())) {
registerViewer(viewerProvider.getClass().getName(), viewerProvider);
}
for (IUpdateStrategy updateStrategy : ServiceLoader.load(IUpdateStrategy.class,
KlighdDataManager.class.getClassLoader())) {
registerUpdateStrategy(updateStrategy.getClass().getName(), updateStrategy);
}
for (IStyleModifier styleModifier : ServiceLoader.load(IStyleModifier.class,
KlighdDataManager.class.getClassLoader())) {
registerStyleModifier(styleModifier.getClass().getName(), styleModifier);
}
for (IAction action : ServiceLoader.load(IAction.class,
KlighdDataManager.class.getClassLoader())) {
registerAction(action.getClass().getName(), action);
}
}

private <T> void doRegisterExtension(final IConfigurationElement element,
final Class<T> type, final Consumer<T> registration) {
try {
Expand Down

0 comments on commit 307c8f6

Please sign in to comment.