Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpguilet2017-06-21 14:29:26 +0000
committerpguilet2017-06-23 13:04:24 +0000
commit5c38f146d07050375cc8771a2cf5f56d1a1f29d9 (patch)
tree192297f1aba9812ff58ee373c06c85255d9b57d4
parent8cf04acad92e8646077e69a5c869923168c30f54 (diff)
downloadorg.eclipse.sirius-5c38f146d07050375cc8771a2cf5f56d1a1f29d9.tar.gz
org.eclipse.sirius-5c38f146d07050375cc8771a2cf5f56d1a1f29d9.tar.xz
org.eclipse.sirius-5c38f146d07050375cc8771a2cf5f56d1a1f29d9.zip
[517049] Remove models functionality now provides more feedback
The "Remove models" functionality is now always usable. If the action cannot be completed because of the context, the reason is given to the user as an error message provided in a dialog. Removal cannot be done in the following situations: - resource is controlled - resource has a representation from a viewpoint activated or not - resource is in the same project as the aird and this project has modeling nature. Bug: 517049 Change-Id: Iadf0e01fffacaa682d7b5bd8a80dacd36d189022 Signed-off-by: pguilet <pierre.guilet@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java127
-rw-r--r--plugins/org.eclipse.sirius.ui/plugin.properties4
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/analysis/RemoveSemanticResourceAction.java184
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java12
4 files changed, 196 insertions, 131 deletions
diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java
index 9adb3bfd92..ff13c62b7e 100644
--- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java
+++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java
@@ -18,11 +18,11 @@ import java.util.EventObject;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
@@ -58,27 +58,25 @@ import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.sirius.business.api.dialect.DialectManager;
-import org.eclipse.sirius.business.api.modelingproject.ModelingProject;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.api.session.SessionListener;
import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.business.api.session.SessionManagerListener;
+import org.eclipse.sirius.business.api.session.resource.AirdResource;
import org.eclipse.sirius.ui.editor.Messages;
import org.eclipse.sirius.ui.editor.SessionEditorPlugin;
import org.eclipse.sirius.ui.tools.api.views.common.item.ProjectDependenciesItem;
import org.eclipse.sirius.ui.tools.internal.actions.analysis.AddModelDependencyAction;
import org.eclipse.sirius.ui.tools.internal.actions.analysis.RemoveSemanticResourceAction;
+import org.eclipse.sirius.ui.tools.internal.views.common.action.DeleteRepresentationAction;
import org.eclipse.sirius.ui.tools.internal.views.common.item.NoDynamicProjectDependencies;
import org.eclipse.sirius.ui.tools.internal.views.common.item.ViewpointsFolderItemImpl;
import org.eclipse.sirius.ui.tools.internal.views.common.navigator.ManageSessionActionProvider;
@@ -89,10 +87,7 @@ import org.eclipse.sirius.ui.tools.internal.views.modelexplorer.DeleteActionHand
import org.eclipse.sirius.ui.tools.internal.views.modelexplorer.RenameActionHandler;
import org.eclipse.sirius.ui.tools.internal.wizards.newmodel.CreateEMFModelWizard;
import org.eclipse.sirius.viewpoint.DAnalysis;
-import org.eclipse.sirius.viewpoint.DAnalysisSessionEObject;
-import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
-import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
import org.eclipse.swt.SWT;
@@ -119,9 +114,6 @@ import org.eclipse.ui.navigator.INavigatorContentService;
import org.eclipse.ui.navigator.INavigatorFilterService;
import org.eclipse.ui.navigator.NavigatorContentServiceFactory;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
/**
* This graphical component provides a {@link CommonViewer} from CNF showing all
* semantic models loaded in the given session and that can be associated to a
@@ -245,12 +237,6 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM
private IWorkbenchSite site;
/**
- * A listener reacting to selection changes. It updates activation status of
- * remove button.
- */
- private ISelectionChangedListener selectionChangeListener;
-
- /**
* Initialize the component with the given session.
*
* @param theSession
@@ -329,13 +315,22 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM
final IStructuredSelection selection = (IStructuredSelection) theTreeViewer.getSelection();
Collection<?> selectedObjects = selection.toList();
if (!selectedObjects.isEmpty()) {
- RemoveSemanticResourceAction removeSemanticResourceAction = new RemoveSemanticResourceAction(getSemanticResources(selectedObjects), session);
- removeSemanticResourceAction.run();
+ Collection<Resource> semanticResources = getSemanticResources(selectedObjects);
+ if (!semanticResources.isEmpty()) {
+ RemoveSemanticResourceAction removeSemanticResourceAction = new RemoveSemanticResourceAction(semanticResources, session);
+ removeSemanticResourceAction.run();
+ }
+
+ Set<DRepresentationDescriptor> repToDelete = selectedObjects.stream().filter(DRepresentationDescriptor.class::isInstance).map(DRepresentationDescriptor.class::cast)
+ .collect(Collectors.toSet());
+ if (!repToDelete.isEmpty()) {
+ DeleteRepresentationAction deleteRepresentationAction = new DeleteRepresentationAction(repToDelete);
+ deleteRepresentationAction.run();
+ }
}
theTreeViewer.refresh();
}
});
- removeSemanticModelOrRepresentationButton.setEnabled(false);
}
/**
@@ -366,38 +361,6 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM
}
/**
- * Return true if the resources can be deleted. I.e it is not a controlled
- * resource and no representation are based on a semantic element of the
- * resources.
- *
- * @param toRemove
- * all semantic resources to remove.
- * @return true if the resources can be deleted. I.e it is not a controlled
- * resource and no representation are based on a semantic element of
- * the resources. False otherwise.
- */
- private boolean checkResources(Collection<Resource> toRemove) {
- boolean okForRemove = true;
- if (session instanceof DAnalysisSessionEObject) {
- // Controlled resource should be removed with uncontrol command
- okForRemove = !Iterables.removeAll(toRemove, ((DAnalysisSessionEObject) session).getControlledResources());
- }
-
- if (okForRemove) {
- for (final DRepresentation representation : DialectManager.INSTANCE.getAllRepresentations(session)) {
- if (representation instanceof DSemanticDecorator) {
- final DSemanticDecorator decorator = (DSemanticDecorator) representation;
- if (decorator.getTarget() != null && toRemove.contains(decorator.getTarget().eResource())) {
- okForRemove = false;
- break;
- }
- }
- }
- }
- return okForRemove;
- }
-
- /**
* Create Model explorer navigator.
*
* @param parent
@@ -447,28 +410,6 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM
manageSessionActionProvider.initFromViewer(treeViewer);
treeViewer.getControl().setMenu(menu);
- selectionChangeListener = (event) -> {
- if (event.getSelection().isEmpty()) {
- removeSemanticModelOrRepresentationButton.setEnabled(false);
- } else if (session != null && session.getSessionResource() != null) {
- TreeSelection selection = (TreeSelection) event.getSelection();
- Object firstElement = selection.getFirstElement();
- IFile airdFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(session.getSessionResource().getURI().toPlatformString(true)));
- if (airdFile != null) {
- IProject project = airdFile.getProject();
- boolean enableAction = (firstElement instanceof EObject || firstElement instanceof Resource) && !ModelingProject.hasModelingProjectNature(project);
- enableAction = enableAction || (isExternalDependency(firstElement, selection));
- enableAction = enableAction && checkResources(getSemanticResources(Lists.newArrayList(firstElement)));
- if (enableAction) {
- removeSemanticModelOrRepresentationButton.setEnabled(true);
- } else {
- removeSemanticModelOrRepresentationButton.setEnabled(false);
- }
- }
- }
- };
- treeViewer.addSelectionChangedListener(selectionChangeListener);
-
commandStackListener = new CommandStackListener() {
@Override
public void commandStackChanged(final EventObject event) {
@@ -486,7 +427,9 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM
} else {
Tree tree = treeViewer.getTree();
if (!tree.isDisposed() && tree.getItems().length > 0 && !tree.getItem(0).isDisposed()) {
- setSelectionToViewer(Lists.newArrayList(tree.getItem(0).getData()));
+ List<Object> selectionCollection = new ArrayList<Object>();
+ selectionCollection.add(tree.getItem(0).getData());
+ setSelectionToViewer(selectionCollection);
}
}
actionBars.updateActionBars();
@@ -912,33 +855,6 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM
}
/**
- * Returns true if the given element is an external dependency of the
- * session.
- *
- * @param element
- * the element from which we want to know if it is an external
- * dependency.
- * @param selection
- * the selection from which we want to know if it is an external
- * dependency.
- * @return true if the given element is an external dependency of the
- * session. False otherwise.
- */
- private boolean isExternalDependency(Object element, TreeSelection selection) {
- if (!(element instanceof ProjectDependenciesItem) && !(element instanceof DRepresentationDescriptor)) {
- TreePath pathsForSelection = selection.getPathsFor(element)[0];
- int segmentCount = pathsForSelection.getSegmentCount();
- for (int i = 0; i < segmentCount; i++) {
- Object segment = pathsForSelection.getSegment(i);
- if (segment instanceof ProjectDependenciesItem) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
* Update the semantic models viewer with the models currently loaded in the
* session.
*/
@@ -980,7 +896,7 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM
} else if (object instanceof EObject) {
EObject eObject = (EObject) object;
Resource eResource = eObject.eResource();
- if (eResource != null) {
+ if (eResource != null && !(eResource instanceof AirdResource)) {
semanticResources.add(eResource);
}
}
@@ -1034,9 +950,8 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM
public void dispose() {
if (siriusCommonContentModelProvider != null) {
siriusCommonContentModelProvider.dispose();
+ siriusCommonContentModelProvider = null;
}
- siriusCommonContentModelProvider = null;
- treeViewer.removeSelectionChangedListener(selectionChangeListener);
SessionManager.INSTANCE.removeSessionsListener(this);
if (session != null && session.getTransactionalEditingDomain() != null) {
session.getTransactionalEditingDomain().getCommandStack().removeCommandStackListener(commandStackListener);
@@ -1048,8 +963,8 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM
manageSessionActionProvider = null;
if (menuManager != null) {
menuManager.dispose();
+ menuManager = null;
}
- menuManager = null;
toolkit = null;
ecoreActionsHandler = null;
diff --git a/plugins/org.eclipse.sirius.ui/plugin.properties b/plugins/org.eclipse.sirius.ui/plugin.properties
index 14c63eb95e..4097ff01fd 100644
--- a/plugins/org.eclipse.sirius.ui/plugin.properties
+++ b/plugins/org.eclipse.sirius.ui/plugin.properties
@@ -241,6 +241,10 @@ RemoveRepresentationResourceAction_name = Remove from representations file
RemoveRepresentationResourceAction_saveDialogTitle = Save representations file before removing the resource?
RemoveSemanticResourceAction_name = Remove Model
RenameRepresentationAction_name = Rename
+RemoveSemanticResourceAction_Active_Representation_Message=The following resources could not be removed because one of their elements contains at least one representation:\n\n{0}\n\n If you want to remove it, you must delete all representations from viewpoints activated and deactivated that are associated to this model elements .
+RemoveSemanticResourceAction_Error_Removal_Title=Impossible to Remove Resource
+RemoveSemanticResourceAction_Controlled_Resources_Message=The following resources could not be removed because they are controlled:\n\n{0}\n\n Use control action instead.
+RemoveSemanticResourceAction_Not_External_Dependency_Message=The following resources could not be removed because they are on the same project with modeling nature as the aird edited:\n\n{0}\n\n If you want to remove this resources, you must remove the modeling nature of the parent project.
RepresentationFilesRepairAction_repairError = Repair error
RepresentationFilesRepairAction_repairFailed = Could not run repair process.
RepresentationFilesRepairAction_repairInterrupted = Repair interrupted
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/analysis/RemoveSemanticResourceAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/analysis/RemoveSemanticResourceAction.java
index 644337edfd..e9cfa1f0d2 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/analysis/RemoveSemanticResourceAction.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/analysis/RemoveSemanticResourceAction.java
@@ -10,23 +10,36 @@
*******************************************************************************/
package org.eclipse.sirius.ui.tools.internal.actions.analysis;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.command.CompoundCommand;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.action.Action;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.sirius.business.api.dialect.DialectManager;
+import org.eclipse.sirius.business.api.modelingproject.ModelingProject;
import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.sirius.business.api.session.resource.AirdResource;
import org.eclipse.sirius.tools.api.command.semantic.RemoveSemanticResourceCommand;
import org.eclipse.sirius.viewpoint.DAnalysisSessionEObject;
-import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.sirius.viewpoint.provider.Messages;
-
-import com.google.common.collect.Iterables;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
/**
* Action to remove semantic resources from a session.
@@ -35,6 +48,42 @@ import com.google.common.collect.Iterables;
*/
public class RemoveSemanticResourceAction extends Action {
+ private static final String DELIMITER = ", "; //$NON-NLS-1$
+
+ /**
+ * Enum use to categorize errors that can happen when launching this action.
+ *
+ * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a>
+ *
+ */
+ private enum ErrorKind {
+
+ /**
+ * A semantic resource loaded in session and controlled cannot be remove.
+ */
+ CONTROLLED_RESOURCE(Messages.RemoveSemanticResourceAction_Controlled_Resources_Message),
+ /**
+ * A semantic resource loaded in a session and belonging to the same project that has modeling nature cannot be
+ * removed.
+ */
+ NOT_EXTERNAL_DEPENDENCY_FOR_MODELING_PROJECT(Messages.RemoveSemanticResourceAction_Not_External_Dependency_Message),
+ /**
+ * A semantic resource with one of its element containing a representation instance active cannot be remove.
+ */
+ ACTIVE_REPRESENTATION(Messages.RemoveSemanticResourceAction_Active_Representation_Message);
+
+ private String message;
+
+ ErrorKind(String theMessage) {
+ this.message = theMessage;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ }
+
/** The session to change. */
private Session session;
@@ -60,41 +109,126 @@ public class RemoveSemanticResourceAction extends Action {
boolean res = super.isEnabled();
res = res && this.session != null;
res = res && !this.toRemove.isEmpty();
- res = res && this.checkResources();
return res;
}
+ /**
+ * Returns true if the given element is an external dependency of the session.
+ *
+ * @param resource
+ * the element from which we want to know if it is an external dependency.
+ * @param sourceProject
+ * @return true if the given element is an external dependency of the session. False otherwise.
+ */
+ private boolean isExternalDependency(Resource resource, IProject sourceProject) {
+ String platformString = resource.getURI().toPlatformString(true);
+ if (platformString != null) {
+ IProject resourceProject = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformString)).getProject();
+ return !sourceProject.equals(resourceProject);
+ }
+ return true;
+ }
+
@Override
public void run() {
- if (!isEnabled() || !checkResources()) {
- return;
- }
- final TransactionalEditingDomain transDomain = session.getTransactionalEditingDomain();
- CompoundCommand compoundCommand = new CompoundCommand();
- for (Resource semanticResourceToRemove : toRemove) {
- compoundCommand.append(new RemoveSemanticResourceCommand(session, semanticResourceToRemove, new NullProgressMonitor(), true));
+ Map<ErrorKind, Set<Resource>> errorKindToResource = checkAllResourcesAreRemovable();
+
+ if (errorKindToResource.isEmpty()) {
+ CompoundCommand compoundCommand = new CompoundCommand();
+ for (Resource semanticResourceToRemove : toRemove) {
+ compoundCommand.append(new RemoveSemanticResourceCommand(session, semanticResourceToRemove, new NullProgressMonitor(), true));
+ }
+ final TransactionalEditingDomain transDomain = session.getTransactionalEditingDomain();
+ transDomain.getCommandStack().execute(compoundCommand);
+ } else {
+ Set<Entry<ErrorKind, Set<Resource>>> errorKindToResourceEntrySet = errorKindToResource.entrySet();
+ String errorMessage = ""; //$NON-NLS-1$
+ for (Entry<ErrorKind, Set<Resource>> errorKindToResourceEntry : errorKindToResourceEntrySet) {
+ switch (errorKindToResourceEntry.getKey()) {
+ case NOT_EXTERNAL_DEPENDENCY_FOR_MODELING_PROJECT:
+ errorMessage = getErrorString(errorMessage, ErrorKind.NOT_EXTERNAL_DEPENDENCY_FOR_MODELING_PROJECT.getMessage(), errorKindToResourceEntry);
+ break;
+ case ACTIVE_REPRESENTATION:
+ errorMessage = getErrorString(errorMessage, ErrorKind.ACTIVE_REPRESENTATION.getMessage(), errorKindToResourceEntry);
+ break;
+ case CONTROLLED_RESOURCE:
+ errorMessage = getErrorString(errorMessage, ErrorKind.CONTROLLED_RESOURCE.getMessage(), errorKindToResourceEntry);
+ break;
+ default:
+ break;
+ }
+ }
+ final String finalErrorMessage = errorMessage;
+ Display.getDefault().asyncExec(() -> {
+ MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.RemoveSemanticResourceAction_Error_Removal_Title, finalErrorMessage);
+ });
}
- transDomain.getCommandStack().execute(compoundCommand);
}
- private boolean checkResources() {
- boolean okForRemove = true;
- if (session instanceof DAnalysisSessionEObject) {
- // Controlled resource should be removed with uncontrol command
- okForRemove = !Iterables.removeAll(toRemove, ((DAnalysisSessionEObject) session).getControlledResources());
+ /**
+ * Returns the error message corresponding to the given elements concatenated to the current one.
+ *
+ * @param errorMessage
+ * the current error message to be concatenated with new messages.
+ * @param sourceMessage
+ * the source error message not formated with {@link MessageFormat}.
+ * @param errorKindToResourceEntry
+ * the values to use when formating the source message.
+ * @return the error message corresponding to the given elements concatenated to the current one.
+ */
+ private String getErrorString(String errorMessage, String sourceMessage, Entry<ErrorKind, Set<Resource>> errorKindToResourceEntry) {
+ String resultMessage = errorMessage;
+ if (!resultMessage.isEmpty()) {
+ resultMessage += "\n\n"; //$NON-NLS-1$
}
+ resultMessage += MessageFormat.format(sourceMessage, errorKindToResourceEntry.getValue().stream().map(r -> r.getURI().lastSegment()).collect(Collectors.joining(DELIMITER)));
+ return resultMessage;
+ }
- if (okForRemove) {
- for (final DRepresentation representation : DialectManager.INSTANCE.getAllRepresentations(session)) {
- if (representation instanceof DSemanticDecorator) {
- final DSemanticDecorator decorator = (DSemanticDecorator) representation;
- if (decorator.getTarget() != null && this.toRemove.contains(decorator.getTarget().eResource())) {
- okForRemove = false;
- break;
+ /**
+ * Checks that all selection resources are removable. If not, all resources not removable are put in a map that is
+ * returned.
+ *
+ * @return a map with all resources not removable.
+ */
+ private Map<ErrorKind, Set<Resource>> checkAllResourcesAreRemovable() {
+ Map<ErrorKind, Set<Resource>> errorKindToResource = new HashMap<>();
+ Set<Resource> dSemanticDecoratorsEResources = DialectManager.INSTANCE.getAllRepresentations(session).stream().filter(rep -> rep instanceof DSemanticDecorator)
+ .map(rep -> ((DSemanticDecorator) rep).getTarget() == null ? null : ((DSemanticDecorator) rep).getTarget().eResource()).collect(Collectors.toSet());
+
+ for (Resource semanticResourceToRemove : toRemove) {
+ IFile airdFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(session.getSessionResource().getURI().toPlatformString(true)));
+ if (airdFile != null) {
+ IProject project = airdFile.getProject();
+ boolean executeRemoval = !ModelingProject.hasModelingProjectNature(project) || (semanticResourceToRemove instanceof AirdResource);
+ executeRemoval = executeRemoval || isExternalDependency(semanticResourceToRemove, airdFile.getProject());
+ if (!executeRemoval) {
+ Set<Resource> notExternalResource = errorKindToResource.get(ErrorKind.NOT_EXTERNAL_DEPENDENCY_FOR_MODELING_PROJECT);
+ if (notExternalResource == null) {
+ notExternalResource = new HashSet<>();
+ errorKindToResource.put(ErrorKind.NOT_EXTERNAL_DEPENDENCY_FOR_MODELING_PROJECT, notExternalResource);
}
+ notExternalResource.add(semanticResourceToRemove);
}
}
+ if (!(semanticResourceToRemove instanceof AirdResource) && ((DAnalysisSessionEObject) session).getControlledResources().contains(semanticResourceToRemove)) {
+ Set<Resource> controlledResources = errorKindToResource.get(ErrorKind.CONTROLLED_RESOURCE);
+ if (controlledResources == null) {
+ controlledResources = new HashSet<>();
+ errorKindToResource.put(ErrorKind.CONTROLLED_RESOURCE, controlledResources);
+ }
+ controlledResources.add(semanticResourceToRemove);
+ }
+ if (!(semanticResourceToRemove instanceof AirdResource) && dSemanticDecoratorsEResources.contains(semanticResourceToRemove)) {
+ Set<Resource> resourcesWithActiveRepresentations = errorKindToResource.get(ErrorKind.ACTIVE_REPRESENTATION);
+ if (resourcesWithActiveRepresentations == null) {
+ resourcesWithActiveRepresentations = new HashSet<>();
+ errorKindToResource.put(ErrorKind.ACTIVE_REPRESENTATION, resourcesWithActiveRepresentations);
+ }
+ resourcesWithActiveRepresentations.add(semanticResourceToRemove);
+ }
}
- return okForRemove;
+ return errorKindToResource;
}
+
}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java
index 87e3acd071..d20310d6df 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java
@@ -1167,6 +1167,18 @@ public final class Messages {
@TranslatableMessage
public static String GraphicalRepresentationHandler_checkBoxShowDisabledViewpoints_label;
+ @TranslatableMessage
+ public static String RemoveSemanticResourceAction_Active_Representation_Message;
+
+ @TranslatableMessage
+ public static String RemoveSemanticResourceAction_Controlled_Resources_Message;
+
+ @TranslatableMessage
+ public static String RemoveSemanticResourceAction_Not_External_Dependency_Message;
+
+ @TranslatableMessage
+ public static String RemoveSemanticResourceAction_Error_Removal_Title;
+
// CHECKSTYLE:ON
private Messages() {

Back to the top