Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael LANOE2015-03-11 11:37:24 +0000
committerMickael LANOE2015-03-18 16:51:48 +0000
commitc595529ba732cb86e5d1d3d728c68923c9e18c74 (patch)
tree16e2331aa765accfdbfc6a169cb9ea00783cb68a
parent8d00943c05349a4825ba6f76a15803964cd5e515 (diff)
downloadorg.eclipse.sirius-c595529ba732cb86e5d1d3d728c68923c9e18c74.tar.gz
org.eclipse.sirius-c595529ba732cb86e5d1d3d728c68923c9e18c74.tar.xz
org.eclipse.sirius-c595529ba732cb86e5d1d3d728c68923c9e18c74.zip
[453437] Forbid representation creation when the container is locked
Representation creation is no disabled when the selected DRepresentationContainer is locked by using a permission authority. Update a test to check the fix. Bug: 453437 Change-Id: If2da0d72290ff67c1328512aa6015321c777a050 Signed-off-by: Mickael LANOE <mickael.lanoe@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/LockedRepresentationContainerTest.java48
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/creation/CreateRepresentationAction.java40
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/wizards/pages/RepresentationSelectionWizardPage.java99
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java34
4 files changed, 168 insertions, 53 deletions
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/LockedRepresentationContainerTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/LockedRepresentationContainerTest.java
index d604b8f9bc..82895f9448 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/LockedRepresentationContainerTest.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/LockedRepresentationContainerTest.java
@@ -116,6 +116,54 @@ public class LockedRepresentationContainerTest extends AbstractSiriusSwtBotGefTe
}
/**
+ * Ensure that the creation of a new representation is forbidden when the
+ * representation container is locked by using permission authority.
+ */
+ public void testCreateRepresentation() {
+ SWTBotTreeItem semanticPackageNode = getSelectedSemanticPackageNode();
+
+ // Before locking the representation container
+ assertTrue("The creation of new representation should be enabled", semanticPackageNode.contextMenu(NEW_REPRESENTATION).menu(REPRESENTATION_NAME).isEnabled());
+
+ // Lock the representation container
+ lockRepresentationContainer();
+
+ // After locking the representation container
+ assertFalse("The creation of new representation should be disabled when the representation container is locked", semanticPackageNode.contextMenu(NEW_REPRESENTATION).menu(REPRESENTATION_NAME)
+ .isEnabled());
+ }
+
+ /**
+ * Ensure that the creation of a new representation from the session is
+ * forbidden when the representation container is locked by using permission
+ * authority.
+ */
+ public void testCreateRepresentationFromSession() {
+ SWTBotTreeItem sessionTreeItem = localSession.getRootSessionTreeItem();
+
+ // Open the "Create Representation" Wizard from the session
+ clickContextMenu(sessionTreeItem, CREATE_REPRESENTATION);
+
+ SWTBotShell shell = bot.shell(CREATE_REPRESENTATION_WIZARD);
+ shell.activate();
+
+ // Select the representation description
+ bot.tree().expandNode(VIEWPOINT_NAME, REPRESENTATION_DESCRIPTION_NAME).select();
+ assertTrue("The representation creation should be allowed", bot.button(NEXT).isEnabled());
+
+ // Lock the representation container
+ lockRepresentationContainer();
+
+ // After locking the representation container, the node must be selected
+ // again to update the button status
+ bot.tree().expandNode(VIEWPOINT_NAME, REPRESENTATION_DESCRIPTION_NAME).select();
+ assertFalse("The representation creation should be forbidden when the representation container is locked", bot.button(NEXT).isEnabled());
+
+ // Close the wizard
+ bot.button(CANCEL).click();
+ }
+
+ /**
* Ensure that the creation of a new representation from the session is
* forbidden when the representation container is locked by using permission
* authority.
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/creation/CreateRepresentationAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/creation/CreateRepresentationAction.java
index b75365b8dc..2a266fc70b 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/creation/CreateRepresentationAction.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/actions/creation/CreateRepresentationAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 THALES GLOBAL SERVICES.
+ * Copyright (c) 2009, 2015 THALES GLOBAL SERVICES.
* 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
@@ -11,6 +11,7 @@
package org.eclipse.sirius.ui.tools.internal.actions.creation;
import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -30,15 +31,19 @@ import org.eclipse.sirius.business.api.dialect.command.CreateRepresentationComma
import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager;
import org.eclipse.sirius.business.api.query.IdentifiedElementQuery;
import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.sirius.business.internal.session.danalysis.DAnalysisSessionImpl;
import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
import org.eclipse.sirius.common.tools.api.util.StringUtil;
+import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority;
+import org.eclipse.sirius.ecore.extender.business.api.permission.PermissionAuthorityRegistry;
import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
import org.eclipse.sirius.ui.business.api.session.EditingSessionEvent;
import org.eclipse.sirius.ui.business.api.session.IEditingSession;
import org.eclipse.sirius.ui.business.api.session.SessionUIManager;
import org.eclipse.sirius.ui.tools.api.Messages;
import org.eclipse.sirius.viewpoint.DRepresentation;
+import org.eclipse.sirius.viewpoint.DRepresentationContainer;
import org.eclipse.sirius.viewpoint.description.DescriptionPackage;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
@@ -90,20 +95,40 @@ public class CreateRepresentationAction extends Action {
void updateActionLabels() {
ImageDescriptor descriptor = ImageDescriptor.getMissingImageDescriptor();
final Image descImage = labelProvider.getImage(description);
+
if (descImage != null) {
descriptor = ImageDescriptor.createFromImage(descImage);
}
+
this.setImageDescriptor(descriptor);
+
computeRepresentationName();
this.setText(name);
this.setToolTipText(description.getEndUserDocumentation());
+
+ if (session instanceof DAnalysisSessionImpl) {
+ // Disable the action in case of the representation cannot be
+ // created
+ Collection<DRepresentationContainer> containers = ((DAnalysisSessionImpl) session).getAvailableRepresentationContainers(description);
+
+ // If containers is empty, a new one will be created, so the action
+ // is enabled
+ if (!containers.isEmpty()) {
+ // Try to find one valid container candidate
+ boolean enabled = false;
+ for (DRepresentationContainer container : containers) {
+ IPermissionAuthority permissionAuthority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority(container);
+ if (permissionAuthority == null || permissionAuthority.canCreateIn(container)) {
+ enabled = true;
+ break;
+ }
+ } // for
+
+ this.setEnabled(enabled);
+ }
+ }
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.Action#run()
- */
@Override
public void run() {
super.run();
@@ -116,6 +141,7 @@ public class CreateRepresentationAction extends Action {
IRunnableWithProgress representationCreationRunnable = new IRunnableWithProgress() {
+ @Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
monitor.beginTask("Representation creation", 5);
@@ -135,6 +161,7 @@ public class CreateRepresentationAction extends Action {
};
PlatformUI.getWorkbench().getProgressService().run(true, false, representationCreationRunnable);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
+ @Override
public void run(final IProgressMonitor monitor) {
try {
monitor.beginTask("Representation opening", 1);
@@ -175,6 +202,7 @@ public class CreateRepresentationAction extends Action {
}
descriptionLabel += Messages.createRepresentationInputDialog_NewRepresentationNameLabel;
final InputDialog askSiriusName = new InputDialog(Display.getDefault().getActiveShell(), Messages.createRepresentationInputDialog_Title, descriptionLabel, name, new IInputValidator() {
+ @Override
public String isValid(final String newText) {
return null;
}
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 4038270b9a..68dec31913 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 THALES GLOBAL SERVICES.
+ * Copyright (c) 2011, 2015 THALES GLOBAL SERVICES.
* 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.ui.tools.internal.wizards.pages;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -25,9 +26,13 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.sirius.business.internal.session.danalysis.DAnalysisSessionImpl;
import org.eclipse.sirius.common.ui.tools.api.util.SWTUtil;
+import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority;
+import org.eclipse.sirius.ecore.extender.business.api.permission.PermissionAuthorityRegistry;
import org.eclipse.sirius.ui.tools.api.views.ViewHelper;
import org.eclipse.sirius.ui.tools.internal.views.common.navigator.sorter.CommonItemSorter;
+import org.eclipse.sirius.viewpoint.DRepresentationContainer;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
import org.eclipse.swt.SWT;
@@ -48,6 +53,8 @@ public class RepresentationSelectionWizardPage extends WizardPage {
private static final String SELECT_REPRESENTATIONS = "Select a representation type";
+ private static final String READ_ONLY_REPRESENTATION_CONTAINER = "The representation container is read only.\r\n Please select another representation type.";
+
/** The title of the page. */
private static final String PAGE_TITLE = "Create a new representation";
@@ -77,18 +84,42 @@ public class RepresentationSelectionWizardPage extends WizardPage {
setMessage(SELECT_REPRESENTATIONS);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage()
- */
+ @Override
public boolean canFlipToNextPage() {
+ boolean result = false;
+
+ setErrorMessage(null); // clear previous error if exists
ISelection selection = treeViewer.getSelection();
if (selection instanceof StructuredSelection && ((StructuredSelection) selection).getFirstElement() instanceof RepresentationDescription) {
- setRepresentation((RepresentationDescription) ((StructuredSelection) selection).getFirstElement());
- return true;
+ RepresentationDescription representationDescription = (RepresentationDescription) ((StructuredSelection) selection).getFirstElement();
+ result = true; // set to true before permission authority check
+
+ if (root instanceof DAnalysisSessionImpl) {
+ Collection<DRepresentationContainer> containers = ((DAnalysisSessionImpl) root).getAvailableRepresentationContainers(representationDescription);
+
+ // 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;
+ for (DRepresentationContainer container : containers) {
+ IPermissionAuthority permissionAuthority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority(container);
+ if (permissionAuthority == null || permissionAuthority.canCreateIn(container)) {
+ result = true;
+ break;
+ }
+ } // for
+ }
+ }
+
+ if (result) {
+ setRepresentation(representationDescription);
+ } else {
+ setErrorMessage(READ_ONLY_REPRESENTATION_CONTAINER);
+ }
}
- return false;
+
+ return result;
}
private void setRepresentation(RepresentationDescription firstElement) {
@@ -103,11 +134,7 @@ public class RepresentationSelectionWizardPage extends WizardPage {
this.selectionWizard = selectionWizard;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
- */
+ @Override
public void createControl(final Composite parent) {
initializeDialogUnits(parent);
@@ -131,6 +158,7 @@ public class RepresentationSelectionWizardPage extends WizardPage {
treeViewer.collapseAll();
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
public void selectionChanged(SelectionChangedEvent event) {
setPageComplete(isPageComplete());
if (selectionWizard != null) {
@@ -173,6 +201,9 @@ public class RepresentationSelectionWizardPage extends WizardPage {
return super.isCurrentPage();
}
+ /**
+ * Session content provider.
+ */
private static final class SessionContentProvider implements ITreeContentProvider {
private static Object[] empty = new Object[0];
@@ -180,16 +211,11 @@ public class RepresentationSelectionWizardPage extends WizardPage {
/**
* Create a new <code>SemanticContentProvider</code> with the specified
* session.
- *
*/
public SessionContentProvider() {
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- */
+ @Override
public Object[] getChildren(final Object parentElement) {
Object[] children = empty;
if (parentElement instanceof Session) {
@@ -197,6 +223,7 @@ public class RepresentationSelectionWizardPage extends WizardPage {
} else if (parentElement instanceof Viewpoint) {
List<RepresentationDescription> reps = Lists.newArrayList(((Viewpoint) parentElement).getOwnedRepresentations());
Collections.sort(reps, new Comparator<RepresentationDescription>() {
+ @Override
public int compare(RepresentationDescription rep1, RepresentationDescription rep2) {
return CommonItemSorter.compareRepresentationDescriptions(rep1, rep2);
};
@@ -206,50 +233,28 @@ public class RepresentationSelectionWizardPage extends WizardPage {
return children;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- */
+ @Override
public Object getParent(final Object element) {
return null;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
- */
+ @Override
public boolean hasChildren(final Object element) {
return getChildren(element).length > 0;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
- */
+ @Override
public Object[] getElements(final Object inputElement) {
return getChildren(inputElement);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
+ @Override
public void dispose() {
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
- * java.lang.Object, java.lang.Object)
- */
+ @Override
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
// empty
}
}
-
}
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java
index 6ba030c977..834123c64b 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java
@@ -51,6 +51,7 @@ import org.eclipse.emf.workspace.ResourceUndoContext;
import org.eclipse.sirius.business.api.componentization.ViewpointRegistry;
import org.eclipse.sirius.business.api.query.DAnalysisQuery;
import org.eclipse.sirius.business.api.query.FileQuery;
+import org.eclipse.sirius.business.api.query.RepresentationDescriptionQuery;
import org.eclipse.sirius.business.api.query.ResourceQuery;
import org.eclipse.sirius.business.api.query.URIQuery;
import org.eclipse.sirius.business.api.session.CustomDataConstants;
@@ -97,6 +98,7 @@ import org.eclipse.sirius.viewpoint.DRepresentationContainer;
import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.sirius.viewpoint.DView;
import org.eclipse.sirius.viewpoint.SiriusPlugin;
+import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
import org.eclipse.sirius.viewpoint.impl.DAnalysisSessionEObjectImpl;
@@ -1494,4 +1496,36 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements
}
return builder.toString();
}
+
+ /**
+ * Get collection of available {@link DRepresentationContainer} for the
+ * {@link RepresentationDescription}.
+ *
+ * @param representationDescription
+ * the representation description.
+ * @return available representation containers
+ */
+ public Collection<DRepresentationContainer> getAvailableRepresentationContainers(RepresentationDescription representationDescription) {
+ final Viewpoint viewpoint = new RepresentationDescriptionQuery(representationDescription).getParentViewpoint();
+ Collection<DAnalysis> allAnalysis = allAnalyses();
+
+ final List<DRepresentationContainer> containers = new ArrayList<DRepresentationContainer>();
+
+ for (DAnalysis analysis : allAnalysis) {
+ DRepresentationContainer container = null;
+
+ for (final DView view : analysis.getOwnedViews()) {
+ if (view instanceof DRepresentationContainer && viewpoint == view.getViewpoint() && view.eContainer() instanceof DAnalysis) {
+ container = (DRepresentationContainer) view;
+ break;
+ }
+ } // for
+
+ if (container != null) {
+ containers.add(container);
+ }
+ }
+
+ return containers;
+ }
}

Back to the top