Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpguilet2017-05-17 13:39:02 +0000
committerPierre Guilet2017-05-18 13:56:22 +0000
commit85a8e052f9f8c165c1ade6c7ca971b89fd25967a (patch)
tree5b62253d776d63a24ebf4ecd0b1ad49c55b36517 /plugins
parent0a81ed04920bd4f51a8e2bc0c7c23f73380468b3 (diff)
downloadorg.eclipse.sirius-85a8e052f9f8c165c1ade6c7ca971b89fd25967a.tar.gz
org.eclipse.sirius-85a8e052f9f8c165c1ade6c7ca971b89fd25967a.tar.xz
org.eclipse.sirius-85a8e052f9f8c165c1ade6c7ca971b89fd25967a.zip
[510040] Fix create representation wizard permission not working
Now the user is warned if he cannot create a new representation because he has no write access on any DView containing the representation description from which a representation instance must be created. If no DView contains a representation descriptor pointing at the representation description used to create the representation instance, then creation is allowed (this situation happens when the viewpoint containing the description has never been activated yet in the session). Bug: 510040 Change-Id: Ifdfd025ad497aade46afb14ecabc066fe7872e9e Signed-off-by: pguilet <pierre.guilet@obeo.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/wizards/pages/RepresentationSelectionWizardPage.java48
1 files changed, 37 insertions, 11 deletions
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/wizards/pages/RepresentationSelectionWizardPage.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/wizards/pages/RepresentationSelectionWizardPage.java
index af27ef7f80..123325fa97 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/wizards/pages/RepresentationSelectionWizardPage.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/wizards/pages/RepresentationSelectionWizardPage.java
@@ -13,6 +13,7 @@ package org.eclipse.sirius.ui.tools.internal.wizards.pages;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Optional;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ISelection;
@@ -36,6 +37,7 @@ import org.eclipse.sirius.ui.tools.internal.graphicalcomponents.GraphicalReprese
import org.eclipse.sirius.ui.tools.internal.viewpoint.ViewpointHelper;
import org.eclipse.sirius.ui.tools.internal.views.common.item.RepresentationDescriptionItemImpl;
import org.eclipse.sirius.ui.tools.internal.views.common.item.ViewpointItemImpl;
+import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.DView;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
@@ -169,31 +171,55 @@ public class RepresentationSelectionWizardPage extends WizardPage {
.getWrappedObject();
result = true; // set to true before permission authority check
- if (session instanceof DAnalysisSessionImpl) {
- Collection<DView> containers = ((DAnalysisSessionImpl) session).getAvailableRepresentationContainers(representationDescription);
+ result = hasPermissionToCreateRepresentation(session, representation);
+ if (result) {
+ representation = representationDescription;
+ viewpoint = ((RepresentationDescriptionItemImpl) ((StructuredSelection) selection).getFirstElement()).getViewpoint();
+ } else {
+ setErrorMessage(Messages.RepresentationSelectionWizardPage_errorReadonlyContainer);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns true if we have permission to create a new representation instance from the given description. False
+ * otherwise.
+ *
+ * @param theSession
+ * the session from which we check creation permission.
+ * @param theRepresentationDescription
+ * the description from which we check if a representation can created. I.e we have write permission on
+ * it if it exists in the session.
+ * @return true if we have permission to create a new representation instance from the given description. False
+ * otherwise.
+ */
+ private boolean hasPermissionToCreateRepresentation(Session theSession, RepresentationDescription theRepresentationDescription) {
+ boolean hasPermission = true;
+ if (session instanceof DAnalysisSessionImpl) {
+ // we retrieve the first descriptor pointing at the given description if such element exists.
+ Optional<DRepresentationDescriptor> loadedInSessionDescriptor = DialectManager.INSTANCE.getAllRepresentationDescriptors(session).stream()
+ .filter(rep -> EqualityHelper.areEquals(rep.getDescription(), getRepresentation())).findFirst();
+ if (loadedInSessionDescriptor.isPresent()) {
+ // Then we check it is not contained by a container we does not have permission to write into.
+ Collection<DView> containers = ((DAnalysisSessionImpl) session).getAvailableRepresentationContainers(loadedInSessionDescriptor.get().getDescription());
// If containers is empty, a new one will be created, so the
// wizard is available
if (!containers.isEmpty()) {
// Try to find one valid container candidate
- result = false;
+ hasPermission = false;
for (DView container : containers) {
IPermissionAuthority permissionAuthority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority(container);
if (permissionAuthority == null || permissionAuthority.canCreateIn(container)) {
- result = true;
+ hasPermission = true;
break;
}
} // for
}
}
- if (result) {
- representation = representationDescription;
- viewpoint = ((RepresentationDescriptionItemImpl) ((StructuredSelection) selection).getFirstElement()).getViewpoint();
- } else {
- setErrorMessage(Messages.RepresentationSelectionWizardPage_errorReadonlyContainer);
- }
}
- return result;
+ return hasPermission;
}
public RepresentationDescription getRepresentation() {

Back to the top