Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael LANOE2015-03-24 11:36:05 +0000
committerPierre-Charles David2015-04-14 08:40:18 +0000
commite41b9ff55c5020a29ab3fcfa7b641728742b2092 (patch)
treef95bf912162662f6bef9b6d7fd10aca3f515ddd3
parent8c5caf0cf3e82e8820afa597e3f6aade21e8e9ae (diff)
downloadorg.eclipse.sirius-e41b9ff55c5020a29ab3fcfa7b641728742b2092.tar.gz
org.eclipse.sirius-e41b9ff55c5020a29ab3fcfa7b641728742b2092.tar.xz
org.eclipse.sirius-e41b9ff55c5020a29ab3fcfa7b641728742b2092.zip
[458822] Remove deep walk inside semantic model in the delete
command Clean DeletionCommandBuilder to avoid iterating inside semantic elements. The permission authority now is responsible to iterate through the contents of a semantic element if needed to allow or forbid the deletion. IPermissionAuthority.canDeleteInstance(EObject) also checks that the container can be edited, so calls to IPermissionAuthority.canEditInstance(EObject) are unnecessary. Do not add all the content of a semantic element in the list of element to destroy. The content will be automatically removed with the containing element if the action is triggered. Bug: 458822 Change-Id: Id27800daae3e58e051351245fb37c38f894fdc03 Signed-off-by: Mickael LANOE <mickael.lanoe@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DeletionCommandBuilder.java78
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/helper/task/DeleteWithoutToolTask.java60
2 files changed, 68 insertions, 70 deletions
diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DeletionCommandBuilder.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DeletionCommandBuilder.java
index bb5491fbb4..de7dc66959 100644
--- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DeletionCommandBuilder.java
+++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DeletionCommandBuilder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2014 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2009, 2015 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
@@ -42,7 +42,6 @@ import org.eclipse.sirius.diagram.description.EdgeMapping;
import org.eclipse.sirius.diagram.description.tool.DeleteElementDescription;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
-import org.eclipse.sirius.ext.emf.AllContents;
import org.eclipse.sirius.tools.api.command.DCommand;
import org.eclipse.sirius.tools.api.command.NoNullResourceCommand;
import org.eclipse.sirius.tools.api.interpreter.InterpreterUtil;
@@ -55,7 +54,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
- * .
+ * Delete command builder.
*
* @author mchauvin
*/
@@ -121,11 +120,7 @@ public class DeletionCommandBuilder extends AbstractDiagramCommandBuilder {
this.deleteFromDiagram = deleteFromDiagram;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.tools.internal.command.builders.CommandBuilder#buildCommand()
- */
+ @Override
public Command buildCommand() {
Command command = UnexecutableCommand.INSTANCE;
if (diagram != null) {
@@ -138,7 +133,7 @@ public class DeletionCommandBuilder extends AbstractDiagramCommandBuilder {
private Command buildDeleteDiagram() {
Command cmd = UnexecutableCommand.INSTANCE;
- if (permissionAuthority.canEditInstance(diagram) && permissionAuthority.canEditInstance(diagram.eContainer())) {
+ if (permissionAuthority.canDeleteInstance(diagram)) {
final DCommand vpCmd = createEnclosingCommand();
/* delete the diagram */
vpCmd.getTasks().add(new DeleteDRepresentationTask(diagram));
@@ -148,7 +143,7 @@ public class DeletionCommandBuilder extends AbstractDiagramCommandBuilder {
}
private Command buildDeleteDiagramElementFromDiagram() {
- if (permissionAuthority.canEditInstance(diagramElement) && permissionAuthority.canEditInstance(diagramElement.eContainer())) {
+ if (permissionAuthority.canDeleteInstance(diagramElement)) {
final DCommand cmd = createEnclosingCommand();
cmd.getTasks().add(new DeleteEObjectTask(diagramElement, modelAccessor));
@@ -172,22 +167,15 @@ public class DeletionCommandBuilder extends AbstractDiagramCommandBuilder {
Command cmd = UnexecutableCommand.INSTANCE;
// We first check that the permission authority allows to delete the
// given diagram element
- if (permissionAuthority.canEditInstance(diagramElement) && permissionAuthority.canEditInstance(diagramElement.eContainer())) {
+ if (permissionAuthority.canDeleteInstance(diagramElement)) {
// We also check that the underlying semantic elements can be
// deleted
- boolean semanticElementCanBeDeleted = true;
- final Set<EObject> allSemanticElements = getSemanticElementsToDestroy(diagramElement);
- for (final EObject semantic : allSemanticElements) {
- final EObject container = semantic.eContainer();
- if (!permissionAuthority.canDeleteInstance(semantic) || (container != null && !permissionAuthority.canEditInstance(container))) {
- semanticElementCanBeDeleted = false;
- }
- }
+ Set<EObject> semanticElements = getSemanticElementsToDestroy(diagramElement);
// If both graphical and semantic elements can be deleted, we build
// the command
- if (semanticElementCanBeDeleted) {
+ if (semanticElements != null) {
final DCommand result = createEnclosingCommand();
setTool();
if (tool != null) {
@@ -195,7 +183,7 @@ public class DeletionCommandBuilder extends AbstractDiagramCommandBuilder {
addRefreshTask(diagramElement, result, tool);
cmd = new NoNullResourceCommand(result, diagramElement);
} else {
- cmd = buildDeleteDiagramElementCommandWithoutTool(result, allSemanticElements);
+ cmd = buildDeleteDiagramElementCommandWithoutTool(result, semanticElements);
}
}
}
@@ -284,18 +272,18 @@ public class DeletionCommandBuilder extends AbstractDiagramCommandBuilder {
return result;
}
- private Command buildDeleteDiagramElementCommandWithoutTool(final DCommand result, final Set<EObject> allSemanticElements) {
+ private Command buildDeleteDiagramElementCommandWithoutTool(final DCommand result, final Set<EObject> semanticElements) {
Command cmd;
- if (allSemanticElements.isEmpty()) {
- // Do not return unexcutable command, actions will be deactivated
+ if (semanticElements.isEmpty()) {
+ // Do not return unexecutable command, actions will be deactivated
// when an element is not deletable, here the result needs to be
// return to handle multi-selection.
cmd = result;
} else {
// Now delete all the diagram elements corresponding to
// the semantic elements to delete
- ICommandTask deleteWithoutToolTask = new DeleteWithoutToolTask(diagramElement, allSemanticElements, modelAccessor, taskHelper) {
+ ICommandTask deleteWithoutToolTask = new DeleteWithoutToolTask(diagramElement, semanticElements, modelAccessor, taskHelper) {
@Override
protected void addDialectSpecificAdditionalDeleteSubTasks(DSemanticDecorator decorator, List<ICommandTask> subTasks) {
@@ -326,26 +314,39 @@ public class DeletionCommandBuilder extends AbstractDiagramCommandBuilder {
*/
private Set<EObject> getSemanticElementsToDestroy(final DDiagramElement currentDiagramElement) {
Set<EObject> elementsToDestroy = Sets.newLinkedHashSet();
- appendSemanticElementsToDestroy(currentDiagramElement, elementsToDestroy);
- return elementsToDestroy;
+ boolean canDelete = appendSemanticElementsToDestroy(currentDiagramElement, elementsToDestroy);
+ return canDelete ? elementsToDestroy : null;
}
- private void appendSemanticElementsToDestroy(final DDiagramElement currentDiagramElement, Set<EObject> elementsToDestroy) {
+ private boolean appendSemanticElementsToDestroy(final DDiagramElement currentDiagramElement, Set<EObject> elementsToDestroy) {
+ boolean canDelete = true;
+
for (final EObject semantic : currentDiagramElement.getSemanticElements()) {
if (semantic != null && !elementsToDestroy.contains(semantic)) {
- Iterables.addAll(elementsToDestroy, AllContents.of(semantic, true));
- }
- }
- for (final EObject child : currentDiagramElement.eContents()) {
- if (child instanceof DDiagramElement) {
- appendSemanticElementsToDestroy((DDiagramElement) child, elementsToDestroy);
+ if (!permissionAuthority.canDeleteInstance(semantic)) {
+ canDelete = false;
+ break;
+ } else {
+ elementsToDestroy.add(semantic);
+ }
}
+ } // for
+
+ if (canDelete) {
+ for (final EObject child : currentDiagramElement.eContents()) {
+ if (child instanceof DDiagramElement) {
+ if (!appendSemanticElementsToDestroy((DDiagramElement) child, elementsToDestroy)) {
+ canDelete = false;
+ break;
+ }
+ }
+ } // for
}
+
+ return canDelete;
}
- /**
- * {@inheritDoc}
- */
+ @Override
protected String getEnclosingCommandLabel() {
String commandLabel = DELETE;
if (diagram != null) {
@@ -362,9 +363,6 @@ public class DeletionCommandBuilder extends AbstractDiagramCommandBuilder {
return commandLabel;
}
- /**
- * {@inheritDoc}
- */
@Override
protected Option<DDiagram> getDDiagram() {
if (diagram == null && diagramElement != null) {
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/helper/task/DeleteWithoutToolTask.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/helper/task/DeleteWithoutToolTask.java
index b8591dc298..91373b7ab8 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/helper/task/DeleteWithoutToolTask.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/helper/task/DeleteWithoutToolTask.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014 Obeo.
+ * Copyright (c) 2014, 2015 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
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.sirius.business.internal.helper.task;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -20,12 +21,11 @@ import org.eclipse.sirius.business.api.helper.task.TaskHelper;
import org.eclipse.sirius.business.api.query.EObjectQuery;
import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor;
import org.eclipse.sirius.ext.base.Option;
-import org.eclipse.sirius.ext.emf.AllContents;
import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationElement;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
-import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@@ -38,7 +38,7 @@ public class DeleteWithoutToolTask extends AbstractCompoundTask {
private DRepresentationElement element;
- private Set<EObject> allSemanticElements;
+ private Set<EObject> semanticElements;
private ModelAccessor modelAccessor;
@@ -49,7 +49,7 @@ public class DeleteWithoutToolTask extends AbstractCompoundTask {
*
* @param element
* the current {@link DRepresentationElement} to delete.
- * @param allSemanticElements
+ * @param semanticElements
* All the precomputed semantic elements to delete.
* @param modelAccessor
* the model accessor to use for deletion
@@ -57,9 +57,9 @@ public class DeleteWithoutToolTask extends AbstractCompoundTask {
* the task helper to use to compute the DSemanticDecorator to
* delete
*/
- public DeleteWithoutToolTask(DRepresentationElement element, Set<EObject> allSemanticElements, ModelAccessor modelAccessor, TaskHelper taskHelper) {
+ public DeleteWithoutToolTask(DRepresentationElement element, Set<EObject> semanticElements, ModelAccessor modelAccessor, TaskHelper taskHelper) {
this.element = element;
- this.allSemanticElements = allSemanticElements;
+ this.semanticElements = semanticElements;
this.modelAccessor = modelAccessor;
this.taskHelper = taskHelper;
}
@@ -82,34 +82,29 @@ public class DeleteWithoutToolTask extends AbstractCompoundTask {
this.taskHelper = taskHelper;
}
- /**
- * {@inheritDoc}
- */
@Override
public String getLabel() {
return "Delete without tool";
}
- /**
- * {@inheritDoc}
- */
@Override
protected List<ICommandTask> prepareSubTasks() {
List<ICommandTask> subTasks = Lists.newArrayList();
Option<DRepresentation> parentRepresentation = new EObjectQuery(element).getRepresentation();
if (parentRepresentation.some()) {
- if (allSemanticElements == null) {
- allSemanticElements = Sets.newLinkedHashSet();
- // Get the corresponding semanticElement (and
- // their children)
- addSemanticElementsToDestroy(element, allSemanticElements);
+ if (semanticElements == null) {
+ EObject semanticElement = element.getTarget();
+ if (semanticElement == null) {
+ semanticElements = Collections.emptySet();
+ } else {
+ semanticElements = Collections.singleton(semanticElement);
+ }
}
// Now delete all the representation elements corresponding to the
- // semantic
- // elements to delete
- final Set<DSemanticDecorator> diagramElements = taskHelper.getDElementToClearFromSemanticElements(parentRepresentation.get(), allSemanticElements);
+ // semantic elements to delete
+ final Set<DSemanticDecorator> diagramElements = taskHelper.getDElementToClearFromSemanticElements(parentRepresentation.get(), getAllSemanticElements());
for (final DSemanticDecorator decorator : diagramElements) {
subTasks.add(new DeleteEObjectTask(decorator, modelAccessor));
addDialectSpecificAdditionalDeleteSubTasks(decorator, subTasks);
@@ -117,7 +112,7 @@ public class DeleteWithoutToolTask extends AbstractCompoundTask {
}
// Now delete all the semantic elements
- for (final EObject semantic : allSemanticElements) {
+ for (final EObject semantic : semanticElements) {
DeleteEObjectTask deleteSemanticElementTask = new DeleteEObjectTask(semantic, modelAccessor);
subTasks.add(deleteSemanticElementTask);
}
@@ -125,14 +120,6 @@ public class DeleteWithoutToolTask extends AbstractCompoundTask {
return subTasks;
}
- private Set<EObject> addSemanticElementsToDestroy(final DSemanticDecorator repElt, final Set<EObject> elementsToDestroy) {
- EObject semantic = repElt.getTarget();
- if (semantic != null && !elementsToDestroy.contains(semantic)) {
- Iterables.addAll(elementsToDestroy, AllContents.of(semantic, true));
- }
- return elementsToDestroy;
- }
-
/**
* This method can be overridden to add Dialect specific additional delete
* tasks. A DeleteEObjectTask for the given decorator has already been added
@@ -146,4 +133,17 @@ public class DeleteWithoutToolTask extends AbstractCompoundTask {
protected void addDialectSpecificAdditionalDeleteSubTasks(DSemanticDecorator decorator, List<ICommandTask> subTasks) {
// Nothing to add per default.
}
+
+ /**
+ * Get all semantic elements.
+ *
+ * @return all semantic elements
+ */
+ private Set<EObject> getAllSemanticElements() {
+ Set<EObject> result = Sets.newHashSet(semanticElements);
+ for (EObject sem : semanticElements) {
+ Iterators.addAll(result, sem.eAllContents());
+ }
+ return result;
+ }
}

Back to the top