diff options
author | Pierre-Charles David | 2017-01-02 10:31:43 +0000 |
---|---|---|
committer | Maxime Porhel | 2017-01-16 15:46:43 +0000 |
commit | 10c6f5118405e0b0d124cfb8249ac28b92183616 (patch) | |
tree | 226e10a6cc86bdaccde270d2035e84c4b179bd01 | |
parent | 23326dce2a54d56b0ad9c52c445144753061ed8f (diff) | |
download | org.eclipse.sirius-10c6f5118405e0b0d124cfb8249ac28b92183616.tar.gz org.eclipse.sirius-10c6f5118405e0b0d124cfb8249ac28b92183616.tar.xz org.eclipse.sirius-10c6f5118405e0b0d124cfb8249ac28b92183616.zip |
Bug: 510520
Cherry-picked-from: 509519
Change-Id: I90a595a251b1a846493d935072aaa9367e42fd30
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
6 files changed, 103 insertions, 18 deletions
diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/RefreshAction.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/RefreshAction.java index 3f4a9d250a..ab7c1e882f 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/RefreshAction.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/actions/RefreshAction.java @@ -30,6 +30,7 @@ import org.eclipse.sirius.business.api.query.EObjectQuery; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.tree.DTreeItem; import org.eclipse.sirius.tree.business.api.command.DTreeItemLocalRefreshCommand; +import org.eclipse.sirius.tree.business.internal.dialect.common.tree.TreeRefreshContext; import org.eclipse.sirius.tree.business.internal.dialect.common.viewpoint.GlobalContext; import org.eclipse.sirius.tree.ui.provider.Messages; import org.eclipse.sirius.tree.ui.tools.internal.editor.DTreeEditor; @@ -111,7 +112,7 @@ public class RefreshAction extends Action implements IObjectActionDelegate { public void run(final IProgressMonitor monitor) { Session session = new EObjectQuery(treeEditor.getRepresentation()).getSession(); if (session != null) { - GlobalContext globalContext = new GlobalContext(session.getModelAccessor(), session.getInterpreter(), session.getSemanticResources()); + GlobalContext globalContext = new TreeRefreshContext(session.getModelAccessor(), session.getInterpreter(), session.getSemanticResources(), session.getTransactionalEditingDomain()); TransactionalEditingDomain domain = treeEditor.getEditingDomain(); Command localRefreshCmd = new DTreeItemLocalRefreshCommand(domain, globalContext, dTreeItems, false); domain.getCommandStack().execute(localRefreshCmd); diff --git a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/listeners/ExpandDTreeItemRunnableWithProgress.java b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/listeners/ExpandDTreeItemRunnableWithProgress.java index f6d8028b62..6cbbccedca 100644 --- a/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/listeners/ExpandDTreeItemRunnableWithProgress.java +++ b/plugins/org.eclipse.sirius.tree.ui/src/org/eclipse/sirius/tree/ui/tools/internal/editor/listeners/ExpandDTreeItemRunnableWithProgress.java @@ -25,6 +25,7 @@ import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.tools.api.command.SiriusCommand; import org.eclipse.sirius.tree.DTreeItem; import org.eclipse.sirius.tree.business.api.command.DTreeItemExpansionChangeCommand; +import org.eclipse.sirius.tree.business.internal.dialect.common.tree.TreeRefreshContext; import org.eclipse.sirius.tree.business.internal.dialect.common.viewpoint.GlobalContext; import org.eclipse.sirius.tree.business.internal.helper.RefreshTreeElementTask; import org.eclipse.sirius.tree.ui.provider.Messages; @@ -74,7 +75,7 @@ public class ExpandDTreeItemRunnableWithProgress implements IRunnableWithProgres try { TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); CommandStack commandStack = domain.getCommandStack(); - GlobalContext globalContext = new GlobalContext(session.getModelAccessor(), session.getInterpreter(), session.getSemanticResources()); + GlobalContext globalContext = new TreeRefreshContext(session.getModelAccessor(), session.getInterpreter(), session.getSemanticResources(), session.getTransactionalEditingDomain()); if (expand) { monitor.beginTask(Messages.ExpandDTreeItemRunnableWithProgress_treeItemExpanding, 1); CompoundCommand expandDTreeItemCmd = new CompoundCommand(MessageFormat.format(Messages.ExpandDTreeItemRunnableWithProgress_expandTreeItem, dTreeItem.getName())); diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/TreeDialectServices.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/TreeDialectServices.java index aae92e7422..e3280ef687 100644 --- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/TreeDialectServices.java +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/TreeDialectServices.java @@ -45,7 +45,7 @@ import org.eclipse.sirius.tree.DTreeElementSynchronizer; import org.eclipse.sirius.tree.DTreeItem; import org.eclipse.sirius.tree.TreeFactory; import org.eclipse.sirius.tree.business.api.interaction.DTreeUserInteraction; -import org.eclipse.sirius.tree.business.internal.dialect.common.viewpoint.GlobalContext; +import org.eclipse.sirius.tree.business.internal.dialect.common.tree.TreeRefreshContext; import org.eclipse.sirius.tree.business.internal.dialect.description.TreeInterpretedExpressionQuery; import org.eclipse.sirius.tree.business.internal.refresh.DTreeElementSynchronizerSpec; import org.eclipse.sirius.tree.description.TreeDescription; @@ -213,7 +213,7 @@ public class TreeDialectServices extends AbstractRepresentationDialectServices { InterpreterRegistry.prepareImportsFromSession(interpreter, session); ModelAccessor accessor = SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(tree.getTarget()); - DTreeUserInteraction interaction = new DTreeUserInteraction(tree, new GlobalContext(accessor, session.getInterpreter(), session.getSemanticResources())); + DTreeUserInteraction interaction = new DTreeUserInteraction(tree, new TreeRefreshContext(accessor, session.getInterpreter(), session.getSemanticResources(), session.getTransactionalEditingDomain())); interaction.refreshContent(fullRefresh, new SubProgressMonitor(monitor, 1)); } diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/AbstractCreatedDTreeItemContainer.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/AbstractCreatedDTreeItemContainer.java index 58d81a1b6d..2c893ffb3f 100644 --- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/AbstractCreatedDTreeItemContainer.java +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/AbstractCreatedDTreeItemContainer.java @@ -20,7 +20,7 @@ import org.eclipse.sirius.tree.business.internal.dialect.common.viewpoint.Global */ abstract class AbstractCreatedDTreeItemContainer implements CreatedOutput { - private GlobalContext ctx; + protected GlobalContext ctx; /** * A default constructor. diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/CreatedTreeItem.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/CreatedTreeItem.java index f719005086..2a2c446cff 100644 --- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/CreatedTreeItem.java +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/CreatedTreeItem.java @@ -11,6 +11,7 @@ package org.eclipse.sirius.tree.business.internal.dialect.common.tree; import java.util.Collection; +import java.util.Collections; import java.util.List; import org.eclipse.emf.ecore.EObject; @@ -132,22 +133,31 @@ class CreatedTreeItem extends AbstractCreatedDTreeItemContainer { * work only from Eclipse Mars. See Bug 460206. */ private boolean willBeExpandedOnSelection(RefreshPlan refreshPlan) { - boolean willBeExpandedOnSelection = false; - TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(tItem); - if (domain instanceof InternalTransactionalEditingDomain) { - InternalTransaction transaction = ((InternalTransactionalEditingDomain) domain).getActiveTransaction().getRoot(); - TransactionChangeDescription changeDescription = transaction.getChangeDescription(); - if (changeDescription != null) { - Collection<EObject> createdObjects = changeDescription.getObjectsToDetach(); - for (OutputDescriptor descriptorToCreate : refreshPlan.getDescriptorsToCreate()) { - if (EcoreUtil.isAncestor(createdObjects, descriptorToCreate.getSourceElement())) { - willBeExpandedOnSelection = true; - break; - } + Collection<EObject> createdObjects = getCreatedObjects(this); + for (OutputDescriptor descriptorToCreate : refreshPlan.getDescriptorsToCreate()) { + if (EcoreUtil.isAncestor(createdObjects, descriptorToCreate.getSourceElement())) { + return true; + } + } + return false; + } + + private static Collection<EObject> getCreatedObjects(CreatedTreeItem item) { + GlobalContext ctx = item.getGlobalContext(); + if (ctx instanceof TreeRefreshContext) { + return ((TreeRefreshContext) ctx).getCreatedObjects(); + } else { + Collection<EObject> result = Collections.emptySet(); + TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(item.tItem); + if (domain instanceof InternalTransactionalEditingDomain) { + InternalTransaction transaction = ((InternalTransactionalEditingDomain) domain).getActiveTransaction().getRoot(); + TransactionChangeDescription changeDescription = transaction.getChangeDescription(); + if (changeDescription != null) { + result = changeDescription.getObjectsToDetach(); } } + return result; } - return willBeExpandedOnSelection; } @Override diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/TreeRefreshContext.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/TreeRefreshContext.java new file mode 100644 index 0000000000..86f1ae3a94 --- /dev/null +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/common/tree/TreeRefreshContext.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * 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.tree.business.internal.dialect.common.tree; + +import java.util.Collection; +import java.util.Collections; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.transaction.TransactionChangeDescription; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.emf.transaction.impl.InternalTransaction; +import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain; +import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; +import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor; +import org.eclipse.sirius.tree.business.internal.dialect.common.viewpoint.GlobalContext; + +import com.google.common.base.Objects; + +/** + * Custom refresh context for tree refresh, which caches costly information + * about the global result of the refresh that will be needed in all individual + * {@link CreatedTreeItem}. + * + * @author pcdavid + */ +public class TreeRefreshContext extends GlobalContext { + private final InternalTransactionalEditingDomain domain; + + private Collection<EObject> createdObjects; + + /** + * Constructor. + * + * @param accessor + * the model accessor. + * @param interpreter + * the interpreter. + * @param semanticResources + * the semantic resources. + * @param ted + * the editing domain. + */ + public TreeRefreshContext(ModelAccessor accessor, IInterpreter interpreter, Collection<Resource> semanticResources, TransactionalEditingDomain ted) { + super(accessor, interpreter, semanticResources); + this.domain = (InternalTransactionalEditingDomain) ted; + } + + /** + * Returns the root elements newly created and attached to the model during + * the transaction in which the refresh was performed. + * + * @return the newly created root objects. + */ + public Collection<EObject> getCreatedObjects() { + if (createdObjects == null) { + InternalTransaction transaction = domain.getActiveTransaction().getRoot(); + TransactionChangeDescription changeDescription = transaction.getChangeDescription(); + if (changeDescription != null) { + createdObjects = changeDescription.getObjectsToDetach(); + } + } + return Objects.firstNonNull(createdObjects, Collections.<EObject> emptySet()); + } +} |