Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael LANOE2015-02-25 08:32:03 +0000
committerEsteban DUGUEPEROUX2015-02-27 12:59:17 +0000
commitc9432acc8ac52333fb8fb1e333556eb093b08788 (patch)
treeb6ea7d06839fa69fb0c99ac4845282fc4d800d9c
parent987e568a7a28924dcc4da9cbbd83d3f7132c4e3d (diff)
downloadorg.eclipse.sirius-c9432acc8ac52333fb8fb1e333556eb093b08788.tar.gz
org.eclipse.sirius-c9432acc8ac52333fb8fb1e333556eb093b08788.tar.xz
org.eclipse.sirius-c9432acc8ac52333fb8fb1e333556eb093b08788.zip
[442761] Fix arrange actions enablement after permission modification
After changing permissions to forbid diagram modification, arrange actions were still available until the diagram gets the focus again that triggers actions refresh. DiagramActionContributionItem is now used to refresh the enablement of the encapsulated arrange actions when it is updated. Use a CopyOnWriteArrayList to store authority listeners in order to avoid copying the list before iterating on it. Add notifications in ReadOnlyPermissionAuthority to properly update listeners after locking or unlocking some elements. Bug: 442761 Change-Id: If7c209ad36bfd3d017f71a90bc4847b0c7a539b6 Signed-off-by: Mickael LANOE <mickael.lanoe@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/permission/EditPartAuthorityListener.java44
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/TabbarArrangeMenuManager.java26
-rw-r--r--plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java63
-rw-r--r--plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/ReadOnlyPermissionAuthority.java88
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/LockedTabBarTest.java89
5 files changed, 138 insertions, 172 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/permission/EditPartAuthorityListener.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/permission/EditPartAuthorityListener.java
index e667387e58..c66c301f86 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/permission/EditPartAuthorityListener.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/permission/EditPartAuthorityListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2014 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2007-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
@@ -53,31 +53,19 @@ public class EditPartAuthorityListener implements IAuthorityListener {
this.part = part;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IAuthorityListener#notifyIsLocked(org.eclipse.emf.ecore.EObject)
- */
+ @Override
public void notifyIsLocked(final EObject instance) {
if (shouldRefresh(instance))
refreshEditMode();
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IAuthorityListener#notifyIsReleased(org.eclipse.emf.ecore.EObject)
- */
+ @Override
public void notifyIsReleased(final EObject instance) {
if (shouldRefresh(instance))
refreshEditMode();
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IAuthorityListener#notifyIsLocked(java.util.Collection)
- */
+ @Override
public void notifyIsLocked(Collection<EObject> instances) {
for (final EObject eObject : instances) {
if (shouldRefresh(eObject)) {
@@ -87,11 +75,7 @@ public class EditPartAuthorityListener implements IAuthorityListener {
}
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IAuthorityListener#notifyIsReleased(java.util.Collection)
- */
+ @Override
public void notifyIsReleased(Collection<EObject> instances) {
for (final EObject eObject : instances) {
if (shouldRefresh(eObject)) {
@@ -102,11 +86,20 @@ public class EditPartAuthorityListener implements IAuthorityListener {
}
private boolean shouldRefresh(EObject instance) {
+ // Do not call part.resolveSemanticElement() if the part is not active
boolean shouldRefresh = instance != null && part.isActive() && part.resolveSemanticElement() instanceof DSemanticDecorator;
- boolean isConcerningEditPart = shouldRefresh && instance.equals(((DSemanticDecorator) part.resolveSemanticElement()).getTarget());
- boolean isConcerningDiagramEditPart = shouldRefresh && part.resolveSemanticElement() instanceof DDiagramElement && ((DDiagramElement) part.resolveSemanticElement()).getTarget() != null
- && instance.equals(((DDiagramElement) part.resolveSemanticElement()).getParentDiagram());
- return shouldRefresh && (isConcerningEditPart || isConcerningDiagramEditPart);
+
+ if (shouldRefresh) {
+ DSemanticDecorator semanticDecorator = (DSemanticDecorator) part.resolveSemanticElement();
+ EObject target = semanticDecorator.getTarget();
+
+ boolean isConcerningEditPart = instance.equals(target) || instance.equals(semanticDecorator);
+ boolean isConcerningDiagramEditPart = semanticDecorator instanceof DDiagramElement && target != null && instance.equals(((DDiagramElement) semanticDecorator).getParentDiagram());
+
+ shouldRefresh = isConcerningEditPart || isConcerningDiagramEditPart;
+ }
+
+ return shouldRefresh;
}
/**
@@ -138,6 +131,7 @@ public class EditPartAuthorityListener implements IAuthorityListener {
// Otherwise, we launch it asynchronously
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+ @Override
public void run() {
doRefreshEditMode(enableEditMode, diagramEditor, semanticElement);
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/TabbarArrangeMenuManager.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/TabbarArrangeMenuManager.java
index 250ffa8fe4..fd8b820ada 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/TabbarArrangeMenuManager.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/tabbar/actions/TabbarArrangeMenuManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2013, 2014 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010-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
@@ -17,6 +17,7 @@ import java.util.Iterator;
import org.eclipse.gef.RootEditPart;
import org.eclipse.gmf.runtime.common.ui.action.IDisposableAction;
import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
+import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
import org.eclipse.gmf.runtime.diagram.ui.actions.internal.ArrangeAction;
import org.eclipse.gmf.runtime.diagram.ui.actions.internal.ArrangeMenuManager;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
@@ -59,24 +60,18 @@ public class TabbarArrangeMenuManager extends ArrangeMenuManager implements ISel
EclipseUIUtil.addSelectionListener(this.representationPart, this);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.jface.action.ContributionManager#add(org.eclipse.jface.action.IAction)
- */
@Override
public void add(IAction action) {
- super.add(action);
+ if (action instanceof DiagramAction) {
+ add(new DiagramActionContributionItem((DiagramAction) action));
+ } else {
+ add(new ActionContributionItem(action));
+ }
if (action instanceof IDisposableAction) {
((IDisposableAction) action).init();
}
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.gmf.runtime.common.ui.action.ActionMenuManager#itemRemoved(org.eclipse.jface.action.IContributionItem)
- */
@Override
protected void itemRemoved(IContributionItem item) {
if (item instanceof ActionContributionItem) {
@@ -87,9 +82,6 @@ public class TabbarArrangeMenuManager extends ArrangeMenuManager implements ISel
}
}
- /**
- * {@inheritDoc}
- */
@Override
public void dispose() {
if (representationPart != null) {
@@ -145,9 +137,7 @@ public class TabbarArrangeMenuManager extends ArrangeMenuManager implements ISel
}
}
- /**
- * {@inheritDoc}
- */
+ @Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
IWorkbenchPage page = EclipseUIUtil.getActivePage();
if (page != null && representationPart != null && representationPart.equals(part)) {
diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java
index 506bba0fd8..82d1ee664c 100644
--- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java
+++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 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
@@ -10,20 +10,17 @@
*******************************************************************************/
package org.eclipse.sirius.ecore.extender.business.internal.permission;
-import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.MapMaker;
-
import org.eclipse.sirius.ecore.extender.business.api.permission.IAuthorityListener;
import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority;
+import com.google.common.collect.MapMaker;
+
/**
* A basic permission authority which will manage a list of listeners.
*
@@ -35,7 +32,7 @@ public abstract class AbstractPermissionAuthority implements IPermissionAuthorit
protected boolean listen;
/** the authority listeners. */
- protected List<IAuthorityListener> listeners = new ArrayList<IAuthorityListener>();
+ protected List<IAuthorityListener> listeners = new CopyOnWriteArrayList<IAuthorityListener>();
/** the locked objects. */
protected ConcurrentMap<Object, Object> lockedObjects = new MapMaker().concurrencyLevel(4).weakKeys().makeMap();
@@ -59,9 +56,7 @@ public abstract class AbstractPermissionAuthority implements IPermissionAuthorit
*/
protected void storeAsLockedAndNotify(final EObject eObject) {
lockedObjects.put(eObject, true);
- final Iterator<IAuthorityListener> iterator = Lists.newArrayList(listeners).iterator();
- while (iterator.hasNext()) {
- final IAuthorityListener listener = iterator.next();
+ for (IAuthorityListener listener : listeners) {
listener.notifyIsLocked(eObject);
}
}
@@ -74,18 +69,12 @@ public abstract class AbstractPermissionAuthority implements IPermissionAuthorit
*/
protected void releaseFromLockedAndNotify(final EObject eObject) {
lockedObjects.remove(eObject);
- final Iterator<IAuthorityListener> iterator = Lists.newArrayList(listeners).iterator();
- while (iterator.hasNext()) {
- final IAuthorityListener listener = iterator.next();
+ for (IAuthorityListener listener : listeners) {
listener.notifyIsReleased(eObject);
}
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#addAuthorityListener(org.eclipse.sirius.ecore.extender.business.api.permission.IAuthorityListener)
- */
+ @Override
public void addAuthorityListener(final IAuthorityListener listener) {
// The same listener cannot be added multiple times
if (!listeners.contains(listener)) {
@@ -93,11 +82,7 @@ public abstract class AbstractPermissionAuthority implements IPermissionAuthorit
}
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#dispose(org.eclipse.emf.ecore.resource.ResourceSet)
- */
+ @Override
public void dispose(final ResourceSet set) {
if (set == null) {
listeners.clear();
@@ -107,49 +92,29 @@ public abstract class AbstractPermissionAuthority implements IPermissionAuthorit
}
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#init(org.eclipse.emf.ecore.resource.ResourceSet)
- */
+ @Override
public void init(final ResourceSet set) {
if (set != null) {
// we may create a map for each resource set
}
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#removeAuthorityListener(org.eclipse.sirius.ecore.extender.business.api.permission.IAuthorityListener)
- */
+ @Override
public void removeAuthorityListener(final IAuthorityListener listener) {
listeners.remove(listener);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#setListening(boolean)
- */
+ @Override
public void setListening(final boolean shouldListen) {
listen = shouldListen;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#isChanged(org.eclipse.emf.ecore.EObject)
- */
+ @Override
public boolean isChanged(final EObject instance) {
return false;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#isNewInstance(org.eclipse.emf.ecore.EObject)
- */
+ @Override
public boolean isNewInstance(final EObject instance) {
return false;
}
diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/ReadOnlyPermissionAuthority.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/ReadOnlyPermissionAuthority.java
index e39d1bd020..354c2d24bd 100644
--- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/ReadOnlyPermissionAuthority.java
+++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/ReadOnlyPermissionAuthority.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
@@ -13,12 +13,12 @@ package org.eclipse.sirius.ecore.extender.business.internal.permission;
import java.util.Collection;
import org.eclipse.emf.ecore.EObject;
-
+import org.eclipse.sirius.ecore.extender.business.api.permission.IAuthorityListener;
import org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus;
/**
- * A permission authority which will not allow write access depending on a boolean.
- * Do not extend.
+ * A permission authority which will not allow write access depending on a
+ * boolean. Do not extend.
*
* @author mchauvin
*/
@@ -69,92 +69,60 @@ public class ReadOnlyPermissionAuthority extends AbstractPermissionAuthority {
return approval;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.internal.permission.DummyPermissionAuthority#canCreateIn(org.eclipse.emf.ecore.EObject)
- */
+ @Override
public boolean canCreateIn(final EObject obj) {
return checkApproval(obj);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.internal.permission.DummyPermissionAuthority#canDeleteInstance(org.eclipse.emf.ecore.EObject)
- */
+ @Override
public boolean canDeleteInstance(final EObject target) {
return checkApproval(target);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.internal.permission.DummyPermissionAuthority#canEditFeature(org.eclipse.emf.ecore.EObject,
- * java.lang.String)
- */
+ @Override
public boolean canEditFeature(final EObject obj, final String featureName) {
return checkApproval(obj);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.internal.permission.DummyPermissionAuthority#canEditInstance(org.eclipse.emf.ecore.EObject)
- */
+ @Override
public boolean canEditInstance(final EObject obj) {
return checkApproval(obj);
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#setReportIssues(boolean)
- */
+ @Override
public void setReportIssues(final boolean report) {
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#notifyInstanceChange(org.eclipse.emf.ecore.EObject)
- */
+ @Override
public void notifyInstanceChange(final EObject instance) {
+
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#notifyInstanceDeletion(org.eclipse.emf.ecore.EObject)
- */
+ @Override
public void notifyInstanceDeletion(final EObject instance) {
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#notifyNewInstanceCreation(org.eclipse.emf.ecore.EObject)
- */
+ @Override
public void notifyNewInstanceCreation(final EObject instance) {
}
- /**
- * {@inheritDoc}
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#notifyLock(java.util.Collection)
- */
- public void notifyLock(Collection<? extends EObject> elements) {
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public void notifyLock(Collection<? extends EObject> elements) {
+ for (IAuthorityListener listener : listeners) {
+ listener.notifyIsLocked((Collection<EObject>) elements);
+ }
+ }
- /**
- * {@inheritDoc}
- * @see org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority#notifyUnlock(java.util.Collection)
- */
- public void notifyUnlock(Collection<? extends EObject> elements) {
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public void notifyUnlock(Collection<? extends EObject> elements) {
+ for (IAuthorityListener listener : listeners) {
+ listener.notifyIsReleased((Collection<EObject>) elements);
+ }
+ }
- /**
- * {@inheritDoc}
- */
+ @Override
public LockStatus getLockStatus(EObject element) {
return canEditInstance(element) ? LockStatus.NOT_LOCKED : LockStatus.LOCKED_BY_OTHER;
}
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/LockedTabBarTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/LockedTabBarTest.java
index f3325acf7f..df02684b88 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/LockedTabBarTest.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/LockedTabBarTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES.
+ * Copyright (c) 2010-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,12 +11,18 @@
package org.eclipse.sirius.tests.swtbot.tabbar;
import java.util.Collection;
+import java.util.Collections;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramContainerEditPart;
import org.eclipse.sirius.diagram.ui.edit.api.part.IDDiagramEditPart;
+import org.eclipse.sirius.ecore.extender.business.api.accessor.ExtenderConstants;
+import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionProvider;
import org.eclipse.sirius.ecore.extender.business.api.permission.PermissionAuthorityRegistry;
+import org.eclipse.sirius.ecore.extender.business.internal.permission.DefaultPermissionProvider;
+import org.eclipse.sirius.ecore.extender.business.internal.permission.PermissionService;
import org.eclipse.sirius.ecore.extender.business.internal.permission.ReadOnlyPermissionAuthority;
+import org.eclipse.sirius.ecore.extender.business.internal.permission.descriptors.StandalonePermissionProviderDescriptor;
import org.eclipse.sirius.tests.swtbot.Activator;
import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase;
import org.eclipse.sirius.tests.swtbot.support.api.business.UILocalSession;
@@ -25,6 +31,7 @@ import org.eclipse.sirius.tests.swtbot.support.api.condition.CheckSelectedCondit
import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusDiagramEditor;
import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotUtils;
import org.eclipse.sirius.ui.business.api.dialect.DialectEditor;
+import org.eclipse.sirius.viewpoint.DRepresentation;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
@@ -95,6 +102,8 @@ public class LockedTabBarTest extends AbstractSiriusSwtBotGefTestCase {
@Override
protected void onSetUpAfterOpeningDesignerPerspective() throws Exception {
+ initCustomPermissionAuthority();
+
sessionAirdResource = new UIResource(designerProject, FILE_DIR, SESSION_FILE);
localSession = designerPerspective.openSessionFromFile(sessionAirdResource);
@@ -115,11 +124,8 @@ public class LockedTabBarTest extends AbstractSiriusSwtBotGefTestCase {
selectPackageElement();
checkEnabledWithSelectedElement(true);
- // activate the ReadOnlyPermission Authority on the representation
- DialectEditor dialectEditor = (DialectEditor) editor.getReference().getEditor(false);
- ((ReadOnlyPermissionAuthority) PermissionAuthorityRegistry.getDefault().getPermissionAuthority(dialectEditor.getRepresentation())).activate();
-
- looseAndRetrieveTheFocus();
+ // lock the diagram
+ lockDiagram();
// check that tested buttons are disabled for the diagram
selectDiagram();
@@ -131,6 +137,63 @@ public class LockedTabBarTest extends AbstractSiriusSwtBotGefTestCase {
}
/**
+ * Check that tabbar actions are enabled or disabled for the diagram
+ * depending on the permission authority
+ */
+ public void testTabbarActionsEnablementForDiagram() {
+ selectDiagram();
+
+ // check that tested buttons are enabled for the diagram
+ checkEnabled(true);
+
+ // lock the diagram
+ lockDiagram();
+
+ // check that tested buttons are disabled for the diagram
+ checkEnabled(false);
+ }
+
+ /**
+ * Check that tabbar actions are enabled or disabled for a selection
+ * depending on the permission authority
+ */
+ public void testTabbarActionsEnablementForSelection() {
+ selectPackageElement();
+
+ // check that tested buttons are enabled for the selected package
+ checkEnabledWithSelectedElement(true);
+
+ // lock the diagram
+ lockDiagram();
+
+ // check that tested buttons are disable for the selected package
+ checkEnabledWithSelectedElement(false);
+ }
+
+ /**
+ * Lock the diagram
+ */
+ private void lockDiagram() {
+ // activate the ReadOnlyPermission Authority on the representation
+ DialectEditor dialectEditor = (DialectEditor) editor.getReference().getEditor(false);
+ DRepresentation representation = dialectEditor.getRepresentation();
+ ReadOnlyPermissionAuthority permissionAuthority = (ReadOnlyPermissionAuthority) PermissionAuthorityRegistry.getDefault().getPermissionAuthority(representation);
+ permissionAuthority.activate();
+ permissionAuthority.notifyLock(Collections.singleton(representation));
+ }
+
+ /**
+ * Init Sirius with a {@link ReadOnlyPermissionAuthority}.
+ */
+ private void initCustomPermissionAuthority() {
+ ReadOnlyPermissionAuthority readOnlyPermissionAuthority = new ReadOnlyPermissionAuthority();
+ IPermissionProvider permissionProvider = new DefaultPermissionProvider(readOnlyPermissionAuthority);
+ StandalonePermissionProviderDescriptor permissionProviderDescriptor = new StandalonePermissionProviderDescriptor("org.eclipse.sirius.tree.tests.forbiddenPermissionAuthorityProvider",
+ ExtenderConstants.HIGHEST_PRIORITY, permissionProvider);
+ PermissionService.addExtension(permissionProviderDescriptor);
+ }
+
+ /**
* Asserts that the widget is enabled or not depending on the parameter.
*
* @param widget
@@ -147,20 +210,6 @@ public class LockedTabBarTest extends AbstractSiriusSwtBotGefTestCase {
}
/**
- * Loose and retrieve the focus
- */
- private void looseAndRetrieveTheFocus() {
- // loose the focus (set focus to the session brower)
- localSession.getLocalSessionBrowser().getTreeItem().setFocus();
- SWTBotUtils.waitAllUiEvents();
-
- // retrieve the focus
- editor.setFocus();
- editor.click(300, 300);
- SWTBotUtils.waitAllUiEvents();
- }
-
- /**
* Check that widgets should be enabled depending on the parameter. Theses
* widgets are available when the diagram is selected.
*

Back to the top