diff options
| author | cbrun | 2016-06-22 09:40:55 +0000 |
|---|---|---|
| committer | Cedric Brun | 2016-08-02 08:25:20 +0000 |
| commit | 1235c2cf25b7cd08a110b8ff580c14e9203bcd6d (patch) | |
| tree | ce1534f717c03b4a2fbf19de74a569a3e0260618 | |
| parent | 05d7fe5524093ac7cf2cf56190ccd9e473057ca0 (diff) | |
| download | org.eclipse.sirius-1235c2cf25b7cd08a110b8ff580c14e9203bcd6d.tar.gz org.eclipse.sirius-1235c2cf25b7cd08a110b8ff580c14e9203bcd6d.tar.xz org.eclipse.sirius-1235c2cf25b7cd08a110b8ff580c14e9203bcd6d.zip | |
[496532] extend IRefreshExtension to allow for overriding the refresh
Introduce an interface IRefreshOverride which can be implemented by
IRefreshExtension instances to override the refresh default
implementation.
This mechanism could have been made more general but we don't envision
many usages besides very specific or experimental contexts.
Because of this we won't expose this new possibility in the release
notes.
Bug: 496532
Change-Id: Idc1f382ad1a60e778365f8c5953eb7655695d27b
Signed-off-by: Cedric Brun <cedric.brun@obeo.fr>
3 files changed, 106 insertions, 41 deletions
diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/api/refresh/IRefreshOverride.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/api/refresh/IRefreshOverride.java new file mode 100644 index 0000000000..3a55f4e9f2 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/api/refresh/IRefreshOverride.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2016 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.business.api.refresh; + +import org.eclipse.sirius.diagram.DDiagram; + +/** + * An interface which might be implemented by a {@link IRefreshExtension} + * instance to bypass the default refresh implementation. + * + * @author Cedric Brun <cedric.brun@obeo.fr> + * + */ +public interface IRefreshOverride { + + /** + * This operation is invoked before the refresh to give a chance to external + * code to override completely the default refresh implementation. If true + * is returned by the implementer then the default implementation will not + * be triggered at all. + * + * The refresh mechanism is complex and this operation can have unintended + * consequences if you don't control all elements handled through the + * refresh. It should therefore be used with caution. + * + * @param dDiagram + * the diagram to refresh. + */ + boolean aroundRefresh(DDiagram dDiagram); + +} diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/api/refresh/RefreshExtensionService.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/api/refresh/RefreshExtensionService.java index fd3e57f0b7..b280a08fab 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/api/refresh/RefreshExtensionService.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/api/refresh/RefreshExtensionService.java @@ -29,7 +29,7 @@ import org.eclipse.sirius.diagram.business.internal.helper.refresh.RefreshExtens * * @author ymortier */ -public final class RefreshExtensionService implements IRefreshExtension { +public final class RefreshExtensionService implements IRefreshExtension, IRefreshOverride { /** Name of the extension point to parse for refresh extension providers. */ private static final String REFRESH_EXTENSION_PROVIDER_EXTENSION_POINT = "org.eclipse.sirius.refreshExtensionProvider"; //$NON-NLS-1$ @@ -109,7 +109,6 @@ public final class RefreshExtensionService implements IRefreshExtension { /** * {@inheritDoc} * - * @see org.eclipse.sirius.diagram.business.api.refresh.IRefreshExtension#beforeRefresh(DDiagram) */ public void beforeRefresh(final DDiagram viewPoint) { final ListIterator<RefreshExtensionProviderDescriptor> iterProviders = this.getProviders().listIterator(); @@ -128,7 +127,6 @@ public final class RefreshExtensionService implements IRefreshExtension { /** * {@inheritDoc} * - * @see org.eclipse.sirius.diagram.business.api.refresh.IRefreshExtension#postRefresh(DDiagram) */ public void postRefresh(final DDiagram viewPoint) { final ListIterator<RefreshExtensionProviderDescriptor> iterProviders = this.getProviders().listIterator(); @@ -145,6 +143,30 @@ public final class RefreshExtensionService implements IRefreshExtension { } /** + * {@inheritDoc} + * + */ + @Override + public boolean aroundRefresh(DDiagram dDiagram) { + final ListIterator<RefreshExtensionProviderDescriptor> iterProviders = this.getProviders().listIterator(); + + boolean oneOverride = false; + + while (iterProviders.hasNext()) { + final RefreshExtensionProviderDescriptor currentProviderDecsriptor = iterProviders.next(); + final IRefreshExtensionProvider refreshExtensionProvider = currentProviderDecsriptor.getProviderInstance(); + + if (RefreshExtensionService.safeProvides(refreshExtensionProvider, dDiagram)) { + final IRefreshExtension refreshExtension = RefreshExtensionService.safeGetRefreshExtension(refreshExtensionProvider, dDiagram); + if (refreshExtension instanceof IRefreshOverride) { + oneOverride = ((IRefreshOverride) refreshExtension).aroundRefresh(dDiagram) || oneOverride; + } + } + } + return oneOverride; + } + + /** * Get the providers. * * @return the providers diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/experimental/sync/DDiagramSynchronizer.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/experimental/sync/DDiagramSynchronizer.java index 41f917144f..1f9332d1a6 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/experimental/sync/DDiagramSynchronizer.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/experimental/sync/DDiagramSynchronizer.java @@ -384,57 +384,61 @@ public class DDiagramSynchronizer { RefreshExtensionService.getInstance().beforeRefresh(this.diagram); - final int mappingNumbers = nodeMappings.size() + edgeMappings.size() + containerMappings.size(); - monitor.beginTask(Messages.DDiagramSynchronizer_refreshMappingsMsg, mappingNumbers); + boolean override = RefreshExtensionService.getInstance().aroundRefresh(this.diagram); - /* - * compute a first time the cache with old mappings => updater - * need the cache - */ - computePreviousCandidatesCache(); - /* update mappings */ - mappingsUpdater.updateMappings(); - /* compute a second time the cache with updated mapping */ - computePreviousCandidatesCache(); + if (!override) { + final int mappingNumbers = nodeMappings.size() + edgeMappings.size() + containerMappings.size(); + monitor.beginTask(Messages.DDiagramSynchronizer_refreshMappingsMsg, mappingNumbers); - fillIgnoredElements(); + /* + * compute a first time the cache with old mappings => + * updater need the cache + */ + computePreviousCandidatesCache(); + /* update mappings */ + mappingsUpdater.updateMappings(); + /* compute a second time the cache with updated mapping */ + computePreviousCandidatesCache(); - final Set<AbstractDNodeCandidate> elementsCreated = LayerService.withoutLayersMode(description) ? null : new HashSet<AbstractDNodeCandidate>(); + fillIgnoredElements(); - /* Let's refresh the node mappings. */ - for (final NodeMapping mapping : nodeMappings) { - refreshNodeMapping(mappingsToEdgeTargets, this.diagram, mapping, elementsCreated, new SubProgressMonitor(monitor, 1)); - } + final Set<AbstractDNodeCandidate> elementsCreated = LayerService.withoutLayersMode(description) ? null : new HashSet<AbstractDNodeCandidate>(); - /* Let's refresh the container mappings */ - if (elementsCreated != null) { - elementsCreated.clear(); - } + /* Let's refresh the node mappings. */ + for (final NodeMapping mapping : nodeMappings) { + refreshNodeMapping(mappingsToEdgeTargets, this.diagram, mapping, elementsCreated, new SubProgressMonitor(monitor, 1)); + } - for (final ContainerMapping mapping : containerMappings) { - refreshContainerMapping(mappingsToEdgeTargets, this.diagram, mapping, elementsCreated, false, false, new SubProgressMonitor(monitor, 1)); - } + /* Let's refresh the container mappings */ + if (elementsCreated != null) { + elementsCreated.clear(); + } + + for (final ContainerMapping mapping : containerMappings) { + refreshContainerMapping(mappingsToEdgeTargets, this.diagram, mapping, elementsCreated, false, false, new SubProgressMonitor(monitor, 1)); + } - /* handle multiple importers . */ - handleImportersIssues(); + /* handle multiple importers . */ + handleImportersIssues(); - /* Compute the decorations. */ - computeDecorations(mappingsToEdgeTargets, edgeToSemanticBasedDecoration, edgeToMappingBasedDecoration); + /* Compute the decorations. */ + computeDecorations(mappingsToEdgeTargets, edgeToSemanticBasedDecoration, edgeToMappingBasedDecoration); - /* - * now all the nodes/containers are done and ready in the - * mappintToEdgeTarget map. - */ - edgesDones = new HashSet<DDiagramElement>(); + /* + * now all the nodes/containers are done and ready in the + * mappintToEdgeTarget map. + */ + edgesDones = new HashSet<DDiagramElement>(); - processEdgeMappingsRefresh(edgeMappings, mappingsToEdgeTargets, edgeToMappingBasedDecoration, edgeToSemanticBasedDecoration, monitor); + processEdgeMappingsRefresh(edgeMappings, mappingsToEdgeTargets, edgeToMappingBasedDecoration, edgeToSemanticBasedDecoration, monitor); - edgesDones.clear(); + edgesDones.clear(); - deleteIgnoredElementsAndDuplicates(); + deleteIgnoredElementsAndDuplicates(); - /* Garbage collect orphan computed StyleDescription. */ - removeOrphanComputedStyleDescriptions(); + /* Garbage collect orphan computed StyleDescription. */ + removeOrphanComputedStyleDescriptions(); + } RefreshExtensionService.getInstance().postRefresh(this.diagram); /* We can now clear the cache. */ |
