diff options
| author | Pierre Guilet | 2018-02-27 14:27:36 +0000 |
|---|---|---|
| committer | Pierre Guilet | 2018-02-28 13:15:31 +0000 |
| commit | dea99f00f9234993dbe89cccc9cf0fb4a5b88287 (patch) | |
| tree | d95a7e208e790e7ba2c9615a691ea22d41a054d3 | |
| parent | ca5a79711048c86fd7d0dfe05c98b036660fd6c1 (diff) | |
| download | org.eclipse.sirius-dea99f00f9234993dbe89cccc9cf0fb4a5b88287.tar.gz org.eclipse.sirius-dea99f00f9234993dbe89cccc9cf0fb4a5b88287.tar.xz org.eclipse.sirius-dea99f00f9234993dbe89cccc9cf0fb4a5b88287.zip | |
[509070] Add generic layout algorithm selection on VSM editor
All layout algorithm providers registered to Sirius registry are now
proposed in the context menu of a diagram description in the VSM editor.
Bug: 509070
Change-Id: I7375ff28ec1f722c69baf5f5a3376c2c28f97d33
Signed-off-by: pguilet <pierre.guilet@obeo.fr>
7 files changed, 154 insertions, 13 deletions
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 4f1c903585..5e293d8061 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 @@ -38,9 +38,8 @@ public class DiagramElkPlugin extends AbstractUIPlugin { Collection<LayoutAlgorithmData> algorithmData = LayoutMetaDataService.getInstance().getAlgorithmData(); for (LayoutAlgorithmData layoutAlgorithmData : algorithmData) { - DiagramUIPlugin.getPlugin().addLayoutProvider(layoutAlgorithmData.getId(), () -> new ELKLayoutNodeProvider()); + DiagramUIPlugin.getPlugin().addLayoutProvider(layoutAlgorithmData.getId(), layoutAlgorithmData.getName(), () -> new ELKLayoutNodeProvider()); } - } @Override 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 new file mode 100644 index 0000000000..1140595c25 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/internal/description/provider/CustomLayoutConfigurationItemProviderSpec.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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.internal.description.provider; + +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.sirius.diagram.description.GenericLayout; +import org.eclipse.sirius.diagram.description.provider.CustomLayoutConfigurationItemProvider; + +/** + * Customize the label of {@link GenericLayout} items in VSM editor. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class CustomLayoutConfigurationItemProviderSpec extends CustomLayoutConfigurationItemProvider { + + /** + * Default constructor. + * + * @param adapterFactory + * factory to use. + */ + public CustomLayoutConfigurationItemProviderSpec(AdapterFactory adapterFactory) { + super(adapterFactory); + } + + /* + * (non-Javadoc) + * @see org.eclipse.sirius.diagram.description.provider.GenericLayoutItemProvider#getText(java.lang.Object) + */ + @Override + public String getText(Object object) { + GenericLayout layout = (GenericLayout) object; + return layout.getLabel(); + } + +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/provider/DescriptionItemProviderAdapterFactory.java b/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/provider/DescriptionItemProviderAdapterFactory.java index 35a1614db4..94d3e7a4a4 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/provider/DescriptionItemProviderAdapterFactory.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/provider/DescriptionItemProviderAdapterFactory.java @@ -38,6 +38,7 @@ import org.eclipse.sirius.diagram.description.DescriptionFactory; import org.eclipse.sirius.diagram.description.DiagramDescription; import org.eclipse.sirius.diagram.description.Layer; import org.eclipse.sirius.diagram.description.util.DescriptionAdapterFactory; +import org.eclipse.sirius.diagram.internal.description.provider.CustomLayoutConfigurationItemProviderSpec; import org.eclipse.sirius.diagram.internal.description.provider.DiagramDescriptionItemProviderSpec; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; import org.eclipse.sirius.diagram.ui.provider.Messages; @@ -435,12 +436,12 @@ public class DescriptionItemProviderAdapterFactory extends DescriptionAdapterFac * This creates an adapter for a {@link org.eclipse.sirius.diagram.description.CustomLayoutConfiguration}. <!-- * begin-user-doc --> <!-- end-user-doc --> * - * @generated + * @generated NOT */ @Override public Adapter createCustomLayoutConfigurationAdapter() { if (customLayoutConfigurationItemProvider == null) { - customLayoutConfigurationItemProvider = new CustomLayoutConfigurationItemProvider(this); + customLayoutConfigurationItemProvider = new CustomLayoutConfigurationItemProviderSpec(this); } return customLayoutConfigurationItemProvider; 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 c36b7f55e7..fe406b46a1 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 @@ -13,6 +13,7 @@ package org.eclipse.sirius.diagram.description.provider; import java.util.Collection; import java.util.List; +import java.util.Map; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification; @@ -24,13 +25,17 @@ import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; import org.eclipse.emf.edit.provider.ViewerNotification; import org.eclipse.sirius.business.api.query.IdentifiedElementQuery; import org.eclipse.sirius.diagram.description.AdditionalLayer; +import org.eclipse.sirius.diagram.description.CustomLayoutConfiguration; import org.eclipse.sirius.diagram.description.DescriptionFactory; import org.eclipse.sirius.diagram.description.DiagramDescription; import org.eclipse.sirius.diagram.description.EdgeMapping; +import org.eclipse.sirius.diagram.description.GenericLayout; 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.provider.DiagramUIPlugin; import org.eclipse.sirius.diagram.ui.provider.Messages; import org.eclipse.sirius.viewpoint.description.DescriptionPackage; import org.eclipse.sirius.viewpoint.description.IdentifiedElement; @@ -536,14 +541,16 @@ public class DiagramDescriptionItemProvider extends DragAndDropTargetDescription ConcernSet concernSet = ConcernFactory.eINSTANCE.createConcernSet(); concernSet.getOwnedConcernDescriptions().add(ConcernFactory.eINSTANCE.createConcernDescription()); newChildDescriptors.add(createChildParameter(org.eclipse.sirius.diagram.description.DescriptionPackage.Literals.DIAGRAM_DESCRIPTION__CONCERNS, concernSet)); + newChildDescriptors.add( createChildParameter(org.eclipse.sirius.diagram.description.DescriptionPackage.Literals.DIAGRAM_DESCRIPTION__LAYOUT, DescriptionFactory.eINSTANCE.createCustomLayoutConfiguration())); + addAllCustomLayoutChildDescriptors(newChildDescriptors); newChildDescriptors .add(createChildParameter(org.eclipse.sirius.diagram.description.DescriptionPackage.Literals.DIAGRAM_DESCRIPTION__LAYOUT, DescriptionFactory.eINSTANCE.createOrderedTreeLayout())); newChildDescriptors .add(createChildParameter(org.eclipse.sirius.diagram.description.DescriptionPackage.Literals.DIAGRAM_DESCRIPTION__LAYOUT, DescriptionFactory.eINSTANCE.createCompositeLayout())); - + addAllCustomLayoutChildDescriptors(newChildDescriptors); newChildDescriptors.add( createChildParameter(org.eclipse.sirius.diagram.description.DescriptionPackage.Literals.DIAGRAM_DESCRIPTION__DIAGRAM_INITIALISATION, ToolFactory.eINSTANCE.createInitialOperation())); @@ -608,6 +615,7 @@ public class DiagramDescriptionItemProvider extends DragAndDropTargetDescription newChildDescriptors.add( createChildParameter(org.eclipse.sirius.diagram.description.DescriptionPackage.Literals.DIAGRAM_DESCRIPTION__LAYOUT, DescriptionFactory.eINSTANCE.createCustomLayoutConfiguration())); + addAllCustomLayoutChildDescriptors(newChildDescriptors); newChildDescriptors.add( createChildParameter(org.eclipse.sirius.diagram.description.DescriptionPackage.Literals.DIAGRAM_DESCRIPTION__DIAGRAM_INITIALISATION, ToolFactory.eINSTANCE.createInitialOperation())); @@ -644,6 +652,22 @@ public class DiagramDescriptionItemProvider extends DragAndDropTargetDescription } /** + * Add all registered generic layout providers as child descriptor. + * + * @param newChildDescriptors + * the child descriptor collection where to add new child descriptors. + */ + private void addAllCustomLayoutChildDescriptors(Collection<Object> newChildDescriptors) { + Map<String, GenericLayoutProviderSupplier> layoutProviderRegistry = DiagramUIPlugin.getPlugin().getLayoutProviderRegistry(); + layoutProviderRegistry.forEach((key, value) -> { + CustomLayoutConfiguration customConfiguration = DescriptionFactory.eINSTANCE.createCustomLayoutConfiguration(); + customConfiguration.setId(key); + customConfiguration.setLabel(value.getLabel()); + newChildDescriptors.add(createChildParameter(org.eclipse.sirius.diagram.description.DescriptionPackage.Literals.DIAGRAM_DESCRIPTION__LAYOUT, customConfiguration)); + }); + } + + /** * This returns the label text for {@link org.eclipse.emf.edit.command.CreateChildCommand}. <!-- begin-user-doc --> * <!-- end-user-doc --> * @@ -658,6 +682,8 @@ public class DiagramDescriptionItemProvider extends DragAndDropTargetDescription // child type currently available for is Layer (see // collectNewChildDescriptors). return getString("_UI_CreateChild_text2", new Object[] { getTypeText(child), "Default", getTypeText(owner) }); //$NON-NLS-1$ //$NON-NLS-2$ + } else if (child instanceof GenericLayout) { + return ((GenericLayout) child).getLabel(); } String createChildText = super.getCreateChildText(owner, feature, child, selection); if (child != null && isNormalEdgeMapping(child)) { 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 d6e4e8a2ff..78efd4cbe2 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 @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, 2017 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2018 THALES GLOBAL SERVICES and others. * 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 @@ -49,6 +49,7 @@ import org.eclipse.sirius.diagram.description.filter.provider.FilterItemProvider import org.eclipse.sirius.diagram.provider.DiagramItemProviderAdapterFactory; 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.refresh.listeners.WorkspaceFileResourceChangeListener; import org.eclipse.sirius.diagram.ui.tools.api.decoration.SiriusDecorationProviderRegistry; import org.eclipse.sirius.diagram.ui.tools.api.layout.provider.DefaultLayoutProvider; @@ -157,7 +158,7 @@ public final class DiagramUIPlugin extends EMFPlugin { /** * A registry containing all layout providers that can be specified directly in the VSM. */ - private Map<String, Supplier<DefaultLayoutProvider>> layoutProviderRegistry; + private Map<String, GenericLayoutProviderSupplier> layoutProviderRegistry; /** * Creates an instance. <!-- begin-user-doc --> <!-- end-user-doc --> @@ -176,11 +177,14 @@ public final class DiagramUIPlugin extends EMFPlugin { * * @param providerId * the id of the layout provider to add in the registry. + * + * @param providerLabel + * the label of the layout provider to register. * @param layoutSupplier - * the layout provider that should be used and that should extend {@link DefaultLayoutProvider}. + * the {@link DefaultLayoutProvider} instances supplier. */ - public void addLayoutProvider(String providerId, Supplier<DefaultLayoutProvider> layoutSupplier) { - layoutProviderRegistry.put(providerId, layoutSupplier); + public void addLayoutProvider(String providerId, String providerLabel, Supplier<DefaultLayoutProvider> layoutSupplier) { + layoutProviderRegistry.put(providerId, new GenericLayoutProviderSupplier(providerLabel, layoutSupplier)); } /** @@ -190,7 +194,7 @@ public final class DiagramUIPlugin extends EMFPlugin { * the id of the layout provider to remove from the registry. * @return the layout provider removed if such element exists. */ - public Supplier<DefaultLayoutProvider> removeLayoutProvider(String layoutProviderId) { + public GenericLayoutProviderSupplier removeLayoutProvider(String layoutProviderId) { return layoutProviderRegistry.remove(layoutProviderId); } @@ -199,7 +203,7 @@ public final class DiagramUIPlugin extends EMFPlugin { * * @return an unmodifiable map of layout providers suppliers associated to their ids. */ - public Map<String, Supplier<DefaultLayoutProvider>> getLayoutProviderRegistry() { + public Map<String, GenericLayoutProviderSupplier> getLayoutProviderRegistry() { return Collections.unmodifiableMap(layoutProviderRegistry); } 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 b2e272ca02..ed89f9eab2 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 @@ -71,7 +71,7 @@ public class GenericLayoutProvider implements LayoutProvider { if (desc != null) { final Layout layout = desc.getLayout(); if (layout instanceof GenericLayout) { - return DiagramUIPlugin.getPlugin().getLayoutProviderRegistry().get(((GenericLayout) layout).getID()); + return DiagramUIPlugin.getPlugin().getLayoutProviderRegistry().get(((GenericLayout) layout).getID()).getLayoutProviderSupplier(); } } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/internal/layout/GenericLayoutProviderSupplier.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/internal/layout/GenericLayoutProviderSupplier.java new file mode 100644 index 0000000000..4962b06b68 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/internal/layout/GenericLayoutProviderSupplier.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * 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.util.function.Supplier; + +import org.eclipse.sirius.diagram.ui.tools.api.layout.provider.DefaultLayoutProvider; + +/** + * Component providing instances of {@link DefaultLayoutProvider} and associated label to use in UI. + * + * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a> + * + */ +public class GenericLayoutProviderSupplier { + /** + * Label to use in Sirius UI to represent this layout algorithm provider. + */ + private String label; + + /** + * Provide instances of {@link DefaultLayoutProvider}. + */ + private Supplier<DefaultLayoutProvider> layoutProviderSupplier; + + /** + * Initialize the component. + * + * @param label + * Label to use in Sirius UI to represent this layout algorithm provider. + * @param layoutProviderSupplier + * Provide instances of {@link DefaultLayoutProvider}. + */ + public GenericLayoutProviderSupplier(String label, Supplier<DefaultLayoutProvider> layoutProviderSupplier) { + super(); + this.label = label; + this.layoutProviderSupplier = layoutProviderSupplier; + } + + /** + * Returns the supplier providing {@link DefaultLayoutProvider} instances. + * + * @return the supplier providing {@link DefaultLayoutProvider} instances. + */ + public Supplier<DefaultLayoutProvider> getLayoutProviderSupplier() { + return layoutProviderSupplier; + } + + /** + * Returns the label to use in Sirius UI to represent this layout algorithm provider. + * + * @return the label to use in Sirius UI to represent this layout algorithm provider. + */ + public String getLabel() { + return label; + } + +} |
