diff options
| author | Pierre Guilet | 2018-03-05 10:27:10 +0000 |
|---|---|---|
| committer | Pierre Guilet | 2018-03-05 17:10:40 +0000 |
| commit | 4088ca72db02c58e87641fd3d58016ce4cb8758a (patch) | |
| tree | 73bc6d5c067fbaa0f2174cac29492347e49d5429 | |
| parent | afb5a7953a93e2f9b207f7aca7c8cfecde0f255a (diff) | |
| download | org.eclipse.sirius-4088ca72db02c58e87641fd3d58016ce4cb8758a.tar.gz org.eclipse.sirius-4088ca72db02c58e87641fd3d58016ce4cb8758a.tar.xz org.eclipse.sirius-4088ca72db02c58e87641fd3d58016ce4cb8758a.zip | |
[509070] Add an extension point to provide custom layout algorithms
A new extension point
"org.eclipse.sirius.diagram.ui.customLayoutAlgorithmProvider" has been
created and should be use by custom layout algorithm providers to be
sure to be available in VSM editor.
Bug: 509070
Change-Id: Ic8c796f68808b42ced53fb8bd6cb930d2c3865f1
Signed-off-by: Pierre Guilet <pierre.guilet@obeo.fr>
16 files changed, 593 insertions, 125 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.elk/plugin.xml b/plugins/org.eclipse.sirius.diagram.elk/plugin.xml index 523c6fff2b..05984629a6 100644 --- a/plugins/org.eclipse.sirius.diagram.elk/plugin.xml +++ b/plugins/org.eclipse.sirius.diagram.elk/plugin.xml @@ -16,4 +16,10 @@ </Priority> </editpolicyProvider> </extension> + <extension + point="org.eclipse.sirius.diagram.ui.customLayoutAlgorithmProvider"> + <customLayoutProvider + class="org.eclipse.sirius.diagram.elk.ELKAlgorithmProvider"> + </customLayoutProvider> + </extension> </plugin> diff --git a/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/DiagramElkPlugin.java b/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/DiagramElkPlugin.java index 7c9ee89132..8c5b9d28a1 100644 --- a/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/DiagramElkPlugin.java +++ b/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/DiagramElkPlugin.java @@ -10,21 +10,6 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.elk; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.elk.core.data.LayoutAlgorithmData; -import org.eclipse.elk.core.data.LayoutMetaDataService; -import org.eclipse.elk.core.data.LayoutOptionData; -import org.eclipse.elk.core.data.LayoutOptionData.Target; -import org.eclipse.elk.core.data.LayoutOptionData.Type; -import org.eclipse.elk.core.data.LayoutOptionData.Visibility; -import org.eclipse.elk.core.options.CoreOptions; -import org.eclipse.sirius.diagram.description.LayoutOption; -import org.eclipse.sirius.diagram.ui.api.layout.EnumChoice; -import org.eclipse.sirius.diagram.ui.api.layout.LayoutOptionFactory; -import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -45,62 +30,6 @@ public class DiagramElkPlugin extends AbstractUIPlugin { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; - - // we fill the Sirius layout algorithm registry with all ELK algorithms. - Collection<LayoutAlgorithmData> algorithmData = LayoutMetaDataService.getInstance().getAlgorithmData(); - for (LayoutAlgorithmData layoutAlgorithmData : algorithmData) { - - List<LayoutOptionData> optionDatas = LayoutMetaDataService.getInstance().getOptionData(layoutAlgorithmData, Target.PARENTS); - List<LayoutOption> layoutOptions = new ArrayList<>(); - LayoutOptionFactory layoutOptionFactory = new LayoutOptionFactory(); - for (LayoutOptionData layoutOptionData : optionDatas) { - if (!CoreOptions.ALGORITHM.getId().equals(layoutOptionData.getId()) && !layoutOptionData.getVisibility().equals(Visibility.HIDDEN)) { - switch (layoutOptionData.getType()) { - case STRING: - layoutOptions.add(layoutOptionFactory.createStringOption((String) layoutOptionData.getDefault(), layoutOptionData.getId(), layoutOptionData.getDescription(), - layoutOptionData.getName())); - break; - case BOOLEAN: - layoutOptions.add(layoutOptionFactory.createBooleanOption((Boolean) layoutOptionData.getDefault(), layoutOptionData.getId(), layoutOptionData.getDescription(), - layoutOptionData.getName())); - break; - case INT: - layoutOptions.add(layoutOptionFactory.createIntegerOption((Integer) layoutOptionData.getDefault(), layoutOptionData.getId(), layoutOptionData.getDescription(), - layoutOptionData.getName())); - break; - case DOUBLE: - layoutOptions.add(layoutOptionFactory.createDoubleOption((Double) layoutOptionData.getDefault(), layoutOptionData.getId(), layoutOptionData.getDescription(), - layoutOptionData.getName())); - break; - case ENUMSET: - case ENUM: - - String[] choices = layoutOptionData.getChoices(); - List<EnumChoice> choicesList = new ArrayList<>(); - for (int i = 0; i < choices.length; i++) { - String choiceId = choices[i]; - choicesList.add(new EnumChoice(choiceId, "")); - - } - String defaultValue = null; - Object defaultObject = layoutOptionData.getDefaultDefault(); - if (defaultObject instanceof Enum) { - defaultValue = ((Enum<?>) defaultObject).name(); - } - if (layoutOptionData.getType() == Type.ENUM) { - layoutOptions.add(layoutOptionFactory.createEnumOption(choicesList, layoutOptionData.getId(), layoutOptionData.getDescription(), layoutOptionData.getName(), defaultValue)); - } else { - layoutOptions.add(layoutOptionFactory.createEnumSetOption(choicesList, layoutOptionData.getId(), layoutOptionData.getDescription(), layoutOptionData.getName())); - } - - break; - default: - break; - } - } - } - DiagramUIPlugin.getPlugin().addLayoutProvider(layoutAlgorithmData.getId(), layoutAlgorithmData.getName(), () -> new ELKLayoutNodeProvider(), layoutOptions); - } } @Override diff --git a/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/ELKAlgorithmProvider.java b/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/ELKAlgorithmProvider.java new file mode 100644 index 0000000000..3e3b9aebee --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.elk/src/org/eclipse/sirius/diagram/elk/ELKAlgorithmProvider.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2018 Obeo + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +/** +* +*/ +package org.eclipse.sirius.diagram.elk; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.elk.core.data.LayoutAlgorithmData; +import org.eclipse.elk.core.data.LayoutMetaDataService; +import org.eclipse.elk.core.data.LayoutOptionData; +import org.eclipse.elk.core.data.LayoutOptionData.Target; +import org.eclipse.elk.core.data.LayoutOptionData.Type; +import org.eclipse.elk.core.data.LayoutOptionData.Visibility; +import org.eclipse.elk.core.options.CoreOptions; +import org.eclipse.sirius.diagram.description.LayoutOption; +import org.eclipse.sirius.diagram.ui.api.layout.CustomLayoutAlgorithm; +import org.eclipse.sirius.diagram.ui.api.layout.CustomLayoutAlgorithmProvider; +import org.eclipse.sirius.diagram.ui.api.layout.EnumChoice; +import org.eclipse.sirius.diagram.ui.api.layout.LayoutOptionFactory; + +/** + * @author <a href=mailto:pierre.guilet@obeo.fr>Pierre Guilet</a> + * + */ +public class ELKAlgorithmProvider implements CustomLayoutAlgorithmProvider { + + @Override + public List<CustomLayoutAlgorithm> getCustomLayoutAlgorithms() { + List<CustomLayoutAlgorithm> layoutAlgorithms = new ArrayList<>(); + // we fill the Sirius layout algorithm registry with all ELK algorithms. + Collection<LayoutAlgorithmData> algorithmData = LayoutMetaDataService.getInstance().getAlgorithmData(); + for (LayoutAlgorithmData layoutAlgorithmData : algorithmData) { + + List<LayoutOptionData> optionDatas = LayoutMetaDataService.getInstance().getOptionData(layoutAlgorithmData, Target.PARENTS); + Map<String, LayoutOption> layoutOptions = new HashMap<>(); + LayoutOptionFactory layoutOptionFactory = new LayoutOptionFactory(); + for (LayoutOptionData layoutOptionData : optionDatas) { + if (!CoreOptions.ALGORITHM.getId().equals(layoutOptionData.getId()) && !layoutOptionData.getVisibility().equals(Visibility.HIDDEN)) { + switch (layoutOptionData.getType()) { + case STRING: + layoutOptions.put(layoutOptionData.getId(), layoutOptionFactory.createStringOption((String) layoutOptionData.getDefault(), layoutOptionData.getId(), + layoutOptionData.getDescription(), layoutOptionData.getName())); + break; + case BOOLEAN: + layoutOptions.put(layoutOptionData.getId(), layoutOptionFactory.createBooleanOption((Boolean) layoutOptionData.getDefault(), layoutOptionData.getId(), + layoutOptionData.getDescription(), layoutOptionData.getName())); + break; + case INT: + layoutOptions.put(layoutOptionData.getId(), layoutOptionFactory.createIntegerOption((Integer) layoutOptionData.getDefault(), layoutOptionData.getId(), + layoutOptionData.getDescription(), layoutOptionData.getName())); + break; + case DOUBLE: + layoutOptions.put(layoutOptionData.getId(), layoutOptionFactory.createDoubleOption((Double) layoutOptionData.getDefault(), layoutOptionData.getId(), + layoutOptionData.getDescription(), layoutOptionData.getName())); + break; + case ENUMSET: + case ENUM: + + String[] choices = layoutOptionData.getChoices(); + List<EnumChoice> choicesList = new ArrayList<>(); + for (int i = 0; i < choices.length; i++) { + String choiceId = choices[i]; + choicesList.add(new EnumChoice(choiceId, "")); + + } + String defaultValue = null; + Object defaultObject = layoutOptionData.getDefaultDefault(); + if (defaultObject instanceof Enum) { + defaultValue = ((Enum<?>) defaultObject).name(); + } + if (layoutOptionData.getType() == Type.ENUM) { + layoutOptions.put(layoutOptionData.getId(), + layoutOptionFactory.createEnumOption(choicesList, layoutOptionData.getId(), layoutOptionData.getDescription(), layoutOptionData.getName(), defaultValue)); + } else { + layoutOptions.put(layoutOptionData.getId(), + layoutOptionFactory.createEnumSetOption(choicesList, layoutOptionData.getId(), layoutOptionData.getDescription(), layoutOptionData.getName())); + } + + break; + default: + break; + } + } + } + layoutAlgorithms.add(new CustomLayoutAlgorithm(layoutAlgorithmData.getId(), layoutAlgorithmData.getName(), () -> new ELKLayoutNodeProvider(), layoutOptions)); + } + return layoutAlgorithms; + } + +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties index b913fcb756..ea641e6f85 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties @@ -92,6 +92,7 @@ extension-point.styleConfigurationProvider..name = org.eclipse.sirius.diagram.ui extension-point.viewOrderingProvider.name = org.eclipse.sirius.diagram.ui.viewOrderingProvider extension-point.tabbarContributor.name = Tabbar Contributor Extension extension.diagramProblems.name = Sirius diagram editor Plugin problems +extension-point.customLayoutAlgorithmProvider.name = org.eclipse.sirius.diagram.ui.api.layout.customLayoutAlgorithmProvider menu.find.label = Find menu.showHide.label = Show/Hide @@ -1029,6 +1030,8 @@ PinnedElementsHandler_notMovableMsg = Pinned elements can not move PinnedElementsHandler_remainOverlapsMsg = solvable but unsolved overlaps remain PinnedElementsHandler_unknownDirection = Unknown direction PinnedElementsSelectionCommand_dialogMessage = Pinned diagram elements are checked. +LayoutAlgorithmProviderRegistry_classInitialization=The PageProvider class ''{0}'' could not be initialized. +LayoutAlgorithmProviderRegistry_badClassType=The class ''{0}'' provided by the extension to extension point ''org.eclipse.sirius.ui.editor.airdEditoPageProvider'' is not an instance of ''org.eclipse.sirius.ui.editor.api.pages.PageProvider'' PopupMenuContribution_storeMouseLocationCmdLabel = Store mouse location RefreshDiagramAction_cancelled = Cancelled RefreshDiagramAction_error = Error diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml index 1bd4ab6af8..08a947814a 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml @@ -20,6 +20,7 @@ <extension-point id="formatDataManager" name="%extension-point.formatDataManager.name" schema="schema/formatDataManager.exsd"/> <extension-point id="imageSelector" name="%extension-point.imageSelector.name" schema="schema/imageSelector.exsd"/> <extension-point id="tabbarContributor" name="%extension-point.tabbarContributor.name" schema="schema/tabbarContributor.exsd"/> + <extension-point id="customLayoutAlgorithmProvider" name="%extension-point.customLayoutAlgorithmProvider.name" schema="schema/customLayoutAlgorithmProvider.exsd"/> <extension point="org.eclipse.ui.elementFactories"> <factory diff --git a/plugins/org.eclipse.sirius.diagram.ui/schema/customLayoutAlgorithmProvider.exsd b/plugins/org.eclipse.sirius.diagram.ui/schema/customLayoutAlgorithmProvider.exsd new file mode 100644 index 0000000000..f8c5bc9238 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/schema/customLayoutAlgorithmProvider.exsd @@ -0,0 +1,97 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.sirius.diagram.ui" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="org.eclipse.sirius.diagram.ui" id="customLayoutAlgorithmProvider" name="%extension-point.customLayoutAlgorithmProvider.name"/> + </appInfo> + <documentation> + This extension allows to provide custom layout algorithms by registering a layout algorithm provider. These algorithms are made visible in Sirius VSM editor so that the specifier can specify one of these to be used by the arrange all action of a Sirius diagram editor for a particular diagram kind. + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <sequence> + <element ref="customLayoutProvider"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="customLayoutProvider"> + <annotation> + <documentation> + A layout provider that will be usable by Sirius specifiers. + +It allows them to define the provided layout algorithm as the algorithm to use when doing an arrange all in a Sirius diagram editor. + </documentation> + </annotation> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + The layout algorithm provider class . + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":org.eclipse.sirius.diagram.ui.api.layout.CustomAlgorithmProvider"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + 6.0.0 + </documentation> + </annotation> + + + + + <annotation> + <appInfo> + <meta.section type="copyright"/> + </appInfo> + <documentation> + Copyright (c) 2018 Obeo<br> +All rights reserved. This program and the accompanying materials +are made available under the terms of the Eclipse Public License v1.0 +which accompanies this distribution, and is available at +<a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> + </documentation> + </annotation> + +</schema> diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/CustomLayoutConfigurationItemProviderSpec.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/CustomLayoutConfigurationItemProviderSpec.java index c587485034..1fb5302a44 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/CustomLayoutConfigurationItemProviderSpec.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/CustomLayoutConfigurationItemProviderSpec.java @@ -19,7 +19,7 @@ import org.eclipse.sirius.diagram.description.CustomLayoutConfiguration; import org.eclipse.sirius.diagram.description.EnumOption; import org.eclipse.sirius.diagram.description.LayoutOption; import org.eclipse.sirius.diagram.description.provider.CustomLayoutConfigurationItemProvider; -import org.eclipse.sirius.diagram.ui.internal.layout.GenericLayoutProviderSupplier; +import org.eclipse.sirius.diagram.ui.api.layout.CustomLayoutAlgorithm; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; /** @@ -49,10 +49,10 @@ public class CustomLayoutConfigurationItemProviderSpec extends CustomLayoutConfi @Override protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { - Map<String, GenericLayoutProviderSupplier> layoutProviderRegistry = DiagramUIPlugin.getPlugin().getLayoutProviderRegistry(); + Map<String, CustomLayoutAlgorithm> layoutProviderRegistry = DiagramUIPlugin.getPlugin().getLayoutAlgorithms(); CustomLayoutConfiguration layout = (CustomLayoutConfiguration) object; - GenericLayoutProviderSupplier genericLayoutProviderSupplier = layoutProviderRegistry.get(layout.getId()); + CustomLayoutAlgorithm genericLayoutProviderSupplier = layoutProviderRegistry.get(layout.getId()); Map<String, LayoutOption> layoutOptions = genericLayoutProviderSupplier.getLayoutOptions(); for (LayoutOption layoutOption : layoutOptions.values()) { LayoutOption copy = EcoreUtil.copy(layoutOption); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/EnumLayoutOptionItemProviderSpec.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/EnumLayoutOptionItemProviderSpec.java index eec6e228f6..db0e6b0eb9 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/EnumLayoutOptionItemProviderSpec.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/EnumLayoutOptionItemProviderSpec.java @@ -21,7 +21,7 @@ import org.eclipse.sirius.diagram.description.EnumLayoutOption; import org.eclipse.sirius.diagram.description.EnumLayoutValue; import org.eclipse.sirius.diagram.description.LayoutOption; import org.eclipse.sirius.diagram.description.provider.EnumLayoutOptionItemProvider; -import org.eclipse.sirius.diagram.ui.internal.layout.GenericLayoutProviderSupplier; +import org.eclipse.sirius.diagram.ui.api.layout.CustomLayoutAlgorithm; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; /** @@ -51,10 +51,10 @@ public class EnumLayoutOptionItemProviderSpec extends EnumLayoutOptionItemProvid @Override protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { - Map<String, GenericLayoutProviderSupplier> layoutProviderRegistry = DiagramUIPlugin.getPlugin().getLayoutProviderRegistry(); + Map<String, CustomLayoutAlgorithm> layoutProviderRegistry = DiagramUIPlugin.getPlugin().getLayoutAlgorithms(); EnumLayoutOption layoutOption = (EnumLayoutOption) object; CustomLayoutConfiguration layout = (CustomLayoutConfiguration) layoutOption.eContainer(); - GenericLayoutProviderSupplier genericLayoutProviderSupplier = layoutProviderRegistry.get(layout.getId()); + CustomLayoutAlgorithm genericLayoutProviderSupplier = layoutProviderRegistry.get(layout.getId()); Map<String, LayoutOption> layoutOptions = genericLayoutProviderSupplier.getLayoutOptions(); EnumLayoutOption layoutOptionTemplate = (EnumLayoutOption) layoutOptions.get(layoutOption.getId()); EList<EnumLayoutValue> choices = layoutOptionTemplate.getChoices(); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/EnumSetLayoutOptionItemProviderSpec.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/EnumSetLayoutOptionItemProviderSpec.java index 93a05916d0..4b34a289c7 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/EnumSetLayoutOptionItemProviderSpec.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/EnumSetLayoutOptionItemProviderSpec.java @@ -22,7 +22,7 @@ import org.eclipse.sirius.diagram.description.EnumLayoutValue; import org.eclipse.sirius.diagram.description.EnumSetLayoutOption; import org.eclipse.sirius.diagram.description.LayoutOption; import org.eclipse.sirius.diagram.description.provider.EnumSetLayoutOptionItemProvider; -import org.eclipse.sirius.diagram.ui.internal.layout.GenericLayoutProviderSupplier; +import org.eclipse.sirius.diagram.ui.api.layout.CustomLayoutAlgorithm; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; /** @@ -52,10 +52,10 @@ public class EnumSetLayoutOptionItemProviderSpec extends EnumSetLayoutOptionItem @Override protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { - Map<String, GenericLayoutProviderSupplier> layoutProviderRegistry = DiagramUIPlugin.getPlugin().getLayoutProviderRegistry(); + Map<String, CustomLayoutAlgorithm> layoutProviderRegistry = DiagramUIPlugin.getPlugin().getLayoutAlgorithms(); EnumSetLayoutOption layoutOption = (EnumSetLayoutOption) object; CustomLayoutConfiguration layout = (CustomLayoutConfiguration) layoutOption.eContainer(); - GenericLayoutProviderSupplier genericLayoutProviderSupplier = layoutProviderRegistry.get(layout.getId()); + CustomLayoutAlgorithm genericLayoutProviderSupplier = layoutProviderRegistry.get(layout.getId()); Map<String, LayoutOption> layoutOptions = genericLayoutProviderSupplier.getLayoutOptions(); EnumSetLayoutOption layoutOptionTemplate = (EnumSetLayoutOption) layoutOptions.get(layoutOption.getId()); EList<EnumLayoutValue> choices = layoutOptionTemplate.getChoices(); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/provider/DiagramDescriptionItemProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/provider/DiagramDescriptionItemProvider.java index c1999d0dde..38054f3c42 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/provider/DiagramDescriptionItemProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/provider/DiagramDescriptionItemProvider.java @@ -35,7 +35,7 @@ import org.eclipse.sirius.diagram.description.Layer; import org.eclipse.sirius.diagram.description.concern.ConcernFactory; import org.eclipse.sirius.diagram.description.concern.ConcernSet; import org.eclipse.sirius.diagram.description.filter.FilterFactory; -import org.eclipse.sirius.diagram.ui.internal.layout.GenericLayoutProviderSupplier; +import org.eclipse.sirius.diagram.ui.api.layout.CustomLayoutAlgorithm; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; import org.eclipse.sirius.diagram.ui.provider.Messages; import org.eclipse.sirius.viewpoint.description.DescriptionPackage; @@ -655,9 +655,9 @@ public class DiagramDescriptionItemProvider extends DragAndDropTargetDescription * the child descriptor collection where to add new child descriptors. */ private void addAllCustomLayoutChildDescriptors(Collection<Object> newChildDescriptors) { - Map<String, GenericLayoutProviderSupplier> layoutProviderRegistry = DiagramUIPlugin.getPlugin().getLayoutProviderRegistry(); - Set<Entry<String, GenericLayoutProviderSupplier>> layoutProviders = layoutProviderRegistry.entrySet(); - for (Entry<String, GenericLayoutProviderSupplier> layoutProviderEntry : layoutProviders) { + Map<String, CustomLayoutAlgorithm> layoutProviderRegistry = DiagramUIPlugin.getPlugin().getLayoutAlgorithms(); + Set<Entry<String, CustomLayoutAlgorithm>> layoutProviders = layoutProviderRegistry.entrySet(); + for (Entry<String, CustomLayoutAlgorithm> layoutProviderEntry : layoutProviders) { CustomLayoutConfiguration customConfiguration = DescriptionFactory.eINSTANCE.createCustomLayoutConfiguration(); customConfiguration.setId(layoutProviderEntry.getKey()); customConfiguration.setLabel(layoutProviderEntry.getValue().getLabel()); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/ui/provider/DiagramUIPlugin.java b/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/ui/provider/DiagramUIPlugin.java index 6b3cfd7138..7db23aca22 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/ui/provider/DiagramUIPlugin.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/ui/provider/DiagramUIPlugin.java @@ -18,10 +18,13 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.function.Supplier; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.emf.common.EMFPlugin; import org.eclipse.emf.common.notify.AdapterFactory; @@ -44,16 +47,15 @@ import org.eclipse.jface.viewers.DecorationOverlayIcon; import org.eclipse.jface.viewers.IDecoration; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.sirius.common.ui.tools.internal.preference.DynamicConfigurationHelper; -import org.eclipse.sirius.diagram.description.LayoutOption; import org.eclipse.sirius.diagram.description.concern.provider.ConcernItemProviderAdapterFactory; import org.eclipse.sirius.diagram.description.filter.provider.FilterItemProviderAdapterFactory; import org.eclipse.sirius.diagram.provider.DiagramItemProviderAdapterFactory; +import org.eclipse.sirius.diagram.ui.api.layout.CustomLayoutAlgorithm; import org.eclipse.sirius.diagram.ui.business.internal.image.ImageSelectorDescriptorRegistryListener; import org.eclipse.sirius.diagram.ui.business.internal.image.refresh.WorkspaceImageFigureRefresher; -import org.eclipse.sirius.diagram.ui.internal.layout.GenericLayoutProviderSupplier; +import org.eclipse.sirius.diagram.ui.internal.layout.CustomLayoutAlgorithmProviderRegistry; import org.eclipse.sirius.diagram.ui.internal.refresh.listeners.WorkspaceFileResourceChangeListener; import org.eclipse.sirius.diagram.ui.tools.api.decoration.SiriusDecorationProviderRegistry; -import org.eclipse.sirius.diagram.ui.tools.api.layout.provider.DefaultLayoutProvider; import org.eclipse.sirius.diagram.ui.tools.api.preferences.SiriusDiagramUiPreferencesKeys; import org.eclipse.sirius.diagram.ui.tools.internal.decoration.DescribedDecorationDescriptorProvider; import org.eclipse.sirius.diagram.ui.tools.internal.decoration.EditModeDecorationDescriptorProvider; @@ -160,7 +162,12 @@ public final class DiagramUIPlugin extends EMFPlugin { * A registry containing all layout providers that can be specified directly in the VSM. A layout provider * provides a layout algorithm that can be used when doing an arrange all on a Sirius diagram. */ - private Map<String, GenericLayoutProviderSupplier> layoutProviderRegistry; + private Map<String, CustomLayoutAlgorithm> layoutAlgorithmsRegistry; + + /** + * A registry updating the {@link Implementation#layoutAlgorithmsRegistry} from extension point declarations. + */ + private CustomLayoutAlgorithmProviderRegistry layoutAlgorithmProviderRegistry; /** * Creates an instance. <!-- begin-user-doc --> <!-- end-user-doc --> @@ -176,42 +183,54 @@ public final class DiagramUIPlugin extends EMFPlugin { } /** - * Add a new layout provider to the registry. + * Add a new custom layout algorithm to the registry. * - * @param providerId - * the id of the layout provider to register. - * @param providerLabel - * the label of the layout provider to register. - * @param layoutSupplier - * the {@link DefaultLayoutProvider} instances supplier. - * @param layoutOptions - */ - public void addLayoutProvider(String providerId, String providerLabel, Supplier<DefaultLayoutProvider> layoutSupplier, List<LayoutOption> layoutOptions) { - Map<String, LayoutOption> optionsMap = new HashMap<String, LayoutOption>(); - for (LayoutOption layoutOption : layoutOptions) { - optionsMap.put(layoutOption.getId(), layoutOption); - } - layoutProviderRegistry.put(providerId, new GenericLayoutProviderSupplier(providerLabel, layoutSupplier, optionsMap)); + * @param customLayoutAlgorithm + * the layout algorithm to add. + */ + public void addLayoutAlgorithm(CustomLayoutAlgorithm customLayoutAlgorithm) { + layoutAlgorithmsRegistry.put(customLayoutAlgorithm.getId(), customLayoutAlgorithm); } /** - * Remove the layout provider identified by the given id from the registry. + * Remove the layout algorithm identified by the given id from the registry. * * @param layoutProviderId - * the id of the layout provider to remove from the registry. - * @return the layout provider removed if such element exists. + * the id of the layout algorithm to remove from the registry. + * @return the layout algorithm removed if such element exists. */ - public GenericLayoutProviderSupplier removeLayoutProvider(String layoutProviderId) { - return layoutProviderRegistry.remove(layoutProviderId); + public CustomLayoutAlgorithm removeLayoutAlgorithm(String layoutProviderId) { + return layoutAlgorithmsRegistry.remove(layoutProviderId); } /** * Returns the unmodifiable registry containing all layout providers that can be specified directly in the VSM. * - * @return an unmodifiable map of layout providers suppliers associated to their ids. + * @return an unmodifiable map of CustomLayoutAlgorithm associated to their id. + */ + public Map<String, CustomLayoutAlgorithm> getLayoutAlgorithms() { + return Collections.unmodifiableMap(layoutAlgorithmsRegistry); + } + + /** + * Logs an error in the error log. + * + * @param message + * the message to log (optional). + * @param e + * the exception (optional). */ - public Map<String, GenericLayoutProviderSupplier> getLayoutProviderRegistry() { - return Collections.unmodifiableMap(layoutProviderRegistry); + public void error(final String message, final Exception e) { + String msgToDisplay = message; + if (message == null && e != null) { + msgToDisplay = e.getMessage(); + } + if (e instanceof CoreException) { + this.getLog().log(((CoreException) e).getStatus()); + } else { + final IStatus status = new Status(IStatus.ERROR, this.getBundle().getSymbolicName(), msgToDisplay, e); + this.getLog().log(status); + } } /** @@ -239,7 +258,10 @@ public final class DiagramUIPlugin extends EMFPlugin { layoutDataManagerRegistryListener = new LayoutDataManagerRegistryListener(); layoutDataManagerRegistryListener.init(); - layoutProviderRegistry = new HashMap<String, GenericLayoutProviderSupplier>(); + layoutAlgorithmsRegistry = new HashMap<String, CustomLayoutAlgorithm>(); + + layoutAlgorithmProviderRegistry = new CustomLayoutAlgorithmProviderRegistry(layoutAlgorithmsRegistry); + Platform.getExtensionRegistry().addListener(layoutAlgorithmProviderRegistry, CustomLayoutAlgorithmProviderRegistry.LAYOUT_ALGORITHM_PROVIDER_EXTENSION_POINT_ID); registerCoreDecorationProviders(); } @@ -272,7 +294,7 @@ public final class DiagramUIPlugin extends EMFPlugin { // can occur when using CDO (if the view is // closed when transactions have been closed) } - layoutProviderRegistry = null; + layoutAlgorithmsRegistry = null; formatDataManagerRegistryListener.dispose(); formatDataManagerRegistryListener = null; @@ -284,6 +306,9 @@ public final class DiagramUIPlugin extends EMFPlugin { imageSelectorDescriptorRegistryListener.dispose(); imageSelectorDescriptorRegistryListener = null; + + layoutAlgorithmProviderRegistry = null; + layoutAlgorithmsRegistry = null; /* * Disposing the images */ diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/api/layout/CustomLayoutAlgorithm.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/api/layout/CustomLayoutAlgorithm.java new file mode 100644 index 0000000000..0c14be079f --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/api/layout/CustomLayoutAlgorithm.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2018 Obeo + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.api.layout; + +import java.util.Map; +import java.util.function.Supplier; + +import org.eclipse.sirius.diagram.description.LayoutOption; +import org.eclipse.sirius.diagram.ui.tools.api.layout.provider.DefaultLayoutProvider; + +/** + * A component providing all needed information to provide a custom layout algorithm that can be used to layout Sirius + * diagrams. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class CustomLayoutAlgorithm { + + /** + * The algorithm's id. + */ + private String id; + + /** + * The algorithm's label that should be used in UI to present it. + */ + private String label; + + /** + * A supplier of {@link DefaultLayoutProvider} that contains the layout algorithm. + */ + private Supplier<DefaultLayoutProvider> layoutSupplier; + + /** + * The options allowing to configure the layout algorithm behavior indexed by their name. Use the factory + * {@link LayoutOptionFactory} to create it. + */ + private Map<String, LayoutOption> layoutOptions; + + /** + * Initialize the custom layout algorithm with given information. + * + * @param id + * the algorithm's id. + * @param label + * the algorithm's label that should be used in UI to present it. + * @param layoutSupplier + * a supplier of {@link DefaultLayoutProvider} that contains the layout algorithm. + * @param layoutOptions + * the options allowing to configure the layout algorithm behavior. Use the factory + * {@link LayoutOptionFactory} to create it. + */ + public CustomLayoutAlgorithm(String id, String label, Supplier<DefaultLayoutProvider> layoutSupplier, Map<String, LayoutOption> layoutOptions) { + super(); + this.id = id; + this.label = label; + this.layoutSupplier = layoutSupplier; + this.layoutOptions = layoutOptions; + } + + /** + * Returns the algorithm's id. + * + * @return the algorithm's id. + */ + public String getId() { + return id; + } + + /** + * Returns the algorithm's label that should be used in UI to present it. + * + * @return the algorithm's label that should be used in UI to present it. + */ + public String getLabel() { + return label; + } + + /** + * Returns the options allowing to configure the layout algorithm behavior indexed by their names. + * + * @return the options allowing to configure the layout algorithm behavior indexed by their names. + */ + public Map<String, LayoutOption> getLayoutOptions() { + return layoutOptions; + } + + /** + * Returns an instance of {@link DefaultLayoutProvider} that contains the layout algorithm. + * + * @return an instance of {@link DefaultLayoutProvider} that contains the layout algorithm. + */ + public DefaultLayoutProvider getLayoutAlgorithmInstance() { + return layoutSupplier.get(); + } +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/api/layout/CustomLayoutAlgorithmProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/api/layout/CustomLayoutAlgorithmProvider.java new file mode 100644 index 0000000000..6ff3b72bb0 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/api/layout/CustomLayoutAlgorithmProvider.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2018 Obeo + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.api.layout; + +import java.util.List; + +/** + * The purpose of this component is to provide custom layout algorithms to Sirius that can be used by VSM specifiers. + * The specifiers will then be able to select the custom layout algorithms to use when arranging a Sirius diagram. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public interface CustomLayoutAlgorithmProvider { + + /** + * Returns the custom layout algorithms that should be available to VSM specifiers to specify the kind of layouting + * that will be done when arranging a particular diagram kind. + * + * @return the custom layout algorithms. + */ + List<CustomLayoutAlgorithm> getCustomLayoutAlgorithms(); +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/internal/layout/CustomLayoutAlgorithmProviderRegistry.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/internal/layout/CustomLayoutAlgorithmProviderRegistry.java new file mode 100644 index 0000000000..f9b8b9d84a --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/internal/layout/CustomLayoutAlgorithmProviderRegistry.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2018 Obeo + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.internal.layout; + +import java.text.MessageFormat; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IRegistryEventListener; +import org.eclipse.core.runtime.Platform; +import org.eclipse.sirius.diagram.ui.api.layout.CustomLayoutAlgorithm; +import org.eclipse.sirius.diagram.ui.api.layout.CustomLayoutAlgorithmProvider; +import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; +import org.eclipse.sirius.diagram.ui.provider.Messages; + +/** + * This registry dynamically update providers in the given custom layout algorithm registry when plugins providing some + * are activated/deactivated. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class CustomLayoutAlgorithmProviderRegistry implements IRegistryEventListener { + /** + * Custom layout algorithm provider extension point's id. + */ + public static final String LAYOUT_ALGORITHM_PROVIDER_EXTENSION_POINT_ID = "org.eclipse.sirius.diagram.ui.customLayoutAlgorithmProvider"; //$NON-NLS-1$ + + /** + * Page provider element's name. + */ + private static final String LAYOUT_ALGORITHM_PROVIDER_ELEMENT_NAME = "customLayoutProvider"; //$NON-NLS-1$ + + /** + * Page provider's class attribute's name. + */ + private static final String LAYOUT_ALGORITHM_PROVIDER_CLASS_ATTRIBUTE_NAME = "class"; //$NON-NLS-1$ + + /** + * A map of {@link IExtension} currently provided by plugins to the {@link CustomLayoutAlgorithmProvider} they + * provide. + */ + private Map<IExtension, CustomLayoutAlgorithmProvider> extensionToLayoutAlgorithmProvider; + + /** + * A registry containing all layout providers that can be specified directly in the VSM. A layout provider provides + * a layout algorithm that can be used when doing an arrange all on a Sirius diagram. + */ + private Map<String, CustomLayoutAlgorithm> layoutProviderRegistry; + + /** + * Initialize this registry with a {@link PageProviderRegistry}. + * + * @param thePageRegistry + * the page registry providing pages from registered {@link CustomLayoutAlgorithmProvider}. + */ + public CustomLayoutAlgorithmProviderRegistry(Map<String, CustomLayoutAlgorithm> layoutProviderRegistry) { + this.layoutProviderRegistry = layoutProviderRegistry; + extensionToLayoutAlgorithmProvider = new HashMap<>(); + final IExtensionRegistry registry = Platform.getExtensionRegistry(); + + for (IExtension extension : registry.getExtensionPoint(LAYOUT_ALGORITHM_PROVIDER_EXTENSION_POINT_ID).getExtensions()) { + parseExtension(extension); + } + } + + @Override + public void added(IExtension[] extensions) { + for (IExtension extension : extensions) { + parseExtension(extension); + } + } + + /** + * Parse extension. If the extension corresponds to the extension point identified by + * {@link CustomLayoutAlgorithmProviderRegistry#LAYOUT_ALGORITHM_PROVIDER_EXTENSION_POINT_ID}, then all + * {@link CustomLayoutAlgorithmProvider} it provides are registered to the layout provider registry instance. + * + * @param extension + * the extension to parse. + */ + private void parseExtension(IExtension extension) { + CustomLayoutAlgorithmProvider layoutAlgorithmProvider = extensionToLayoutAlgorithmProvider.get(extension); + if (layoutAlgorithmProvider == null) { + + IConfigurationElement[] configurationElements = extension.getConfigurationElements(); + for (IConfigurationElement configurationElement : configurationElements) { + if (LAYOUT_ALGORITHM_PROVIDER_ELEMENT_NAME.equals(configurationElement.getName())) { + try { + Object newInstance = configurationElement.createExecutableExtension(LAYOUT_ALGORITHM_PROVIDER_CLASS_ATTRIBUTE_NAME); + if (CustomLayoutAlgorithmProvider.class.isAssignableFrom(newInstance.getClass())) { + CustomLayoutAlgorithmProvider CustomAlgorithmProvider = (CustomLayoutAlgorithmProvider) newInstance; + List<CustomLayoutAlgorithm> customLayoutAlgorithms = CustomAlgorithmProvider.getCustomLayoutAlgorithms(); + for (CustomLayoutAlgorithm customLayoutAlgorithm : customLayoutAlgorithms) { + layoutProviderRegistry.put(customLayoutAlgorithm.getId(), customLayoutAlgorithm); + } + } else { + DiagramUIPlugin.getPlugin().error(MessageFormat.format(Messages.LayoutAlgorithmProviderRegistry_badClassType, newInstance.getClass().getName()), null); + } + } catch (CoreException e) { + DiagramUIPlugin.getPlugin().error(MessageFormat.format(Messages.LayoutAlgorithmProviderRegistry_classInitialization, configurationElement.getName()), e); + } + } + } + } + } + + @Override + public void removed(IExtension[] extensions) { + for (IExtension extension : extensions) { + CustomLayoutAlgorithmProvider layoutAlgorithmProvider = extensionToLayoutAlgorithmProvider.get(extension); + + if (layoutAlgorithmProvider != null) { + List<CustomLayoutAlgorithm> customLayoutAlgorithms = layoutAlgorithmProvider.getCustomLayoutAlgorithms(); + for (CustomLayoutAlgorithm customLayoutAlgorithm : customLayoutAlgorithms) { + layoutProviderRegistry.remove(customLayoutAlgorithm.getId()); + } + } + extensionToLayoutAlgorithmProvider.remove(extension); + } + + } + + @Override + public void added(IExtensionPoint[] extensionPoints) { + + } + + @Override + public void removed(IExtensionPoint[] extensionPoints) { + + } + +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/internal/layout/GenericLayoutProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/internal/layout/GenericLayoutProvider.java index fe543cdf35..fd2b5293e5 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/internal/layout/GenericLayoutProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/internal/layout/GenericLayoutProvider.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.internal.layout; -import java.util.function.Supplier; - import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.services.layout.AbstractLayoutEditPartProvider; @@ -36,10 +34,9 @@ public class GenericLayoutProvider implements LayoutProvider { @Override public AbstractLayoutEditPartProvider getLayoutNodeProvider(final IGraphicalEditPart container) { - Supplier<DefaultLayoutProvider> layoutProvider = getGenericLayoutProvider(container); + DefaultLayoutProvider layoutProvider = getGenericLayoutProvider(container); if (layoutProvider != null) { - - return new ArrangeSelectionLayoutProvider(layoutProvider.get()); + return new ArrangeSelectionLayoutProvider(layoutProvider); } return null; } @@ -55,14 +52,14 @@ public class GenericLayoutProvider implements LayoutProvider { } /** - * Returns the generic layout provider associated to the description of the {@link DDiagram} related to the given - * part. + * Returns the {@link CustomLayoutConfiguration} associated to the description of the {@link DDiagram} related to + * the given part. * * @param container - * @return the generic layout provider associated to the description of the {@link DDiagram} related to the given - * part. Null if no such element exists. + * @return the {@link CustomLayoutConfiguration} associated to the description of the {@link DDiagram} related to + * the given part. Null if no such element exists. */ - private Supplier<DefaultLayoutProvider> getGenericLayoutProvider(final IGraphicalEditPart container) { + private CustomLayoutConfiguration getCustomLayoutConfiguration(final IGraphicalEditPart container) { final View view = container.getNotationView(); final EObject modelElement = view.getElement(); if (view instanceof Diagram && modelElement instanceof DDiagram) { @@ -71,11 +68,27 @@ public class GenericLayoutProvider implements LayoutProvider { if (desc != null) { final Layout layout = desc.getLayout(); if (layout instanceof CustomLayoutConfiguration) { - return DiagramUIPlugin.getPlugin().getLayoutProviderRegistry().get(((CustomLayoutConfiguration) layout).getId()).getLayoutProviderSupplier(); + return (CustomLayoutConfiguration) layout; } } } return null; } + /** + * Returns the generic layout provider associated to the description of the {@link DDiagram} related to the given + * part. + * + * @param container + * @return the generic layout provider associated to the description of the {@link DDiagram} related to the given + * part. Null if no such element exists. + */ + private DefaultLayoutProvider getGenericLayoutProvider(final IGraphicalEditPart container) { + CustomLayoutConfiguration customLayoutConfiguration = getCustomLayoutConfiguration(container); + if (customLayoutConfiguration != null) { + return DiagramUIPlugin.getPlugin().getLayoutAlgorithms().get(customLayoutConfiguration.getId()).getLayoutAlgorithmInstance(); + } + return null; + } + } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java index 226476793c..e7adbabe2b 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java @@ -1511,6 +1511,12 @@ public final class Messages { @TranslatableMessage public static String ResetToDefaultFiltersAction_tooltip; + @TranslatableMessage + public static String LayoutAlgorithmProviderRegistry_badClassType; + + @TranslatableMessage + public static String LayoutAlgorithmProviderRegistry_classInitialization; + // CHECKSTYLE:ON private Messages() { |
