Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Barbin2019-03-04 08:08:23 -0500
committerFlorian Barbin2019-03-05 09:10:23 -0500
commit7f3a84a511a17ef856c769519b751591168ec4f8 (patch)
treebc9da72d0554e94fe38c8ca1b5cbebfcda5d9533
parent8f7dd3427baa56cd34df20134fa4a7feb72f85b6 (diff)
downloadorg.eclipse.sirius-7f3a84a511a17ef856c769519b751591168ec4f8.tar.gz
org.eclipse.sirius-7f3a84a511a17ef856c769519b751591168ec4f8.tar.xz
org.eclipse.sirius-7f3a84a511a17ef856c769519b751591168ec4f8.zip
[543252] Makes Hide/Reveal actions more consistent between each othersv6.2.0rc3v6.2.0
* The Show/Hide elements actions are now available if at least one element is Hidden/Visible. * The Show/Hide labels actions are now checking the authorization from the permission authority. Bug: 543252 Cherry-picked-from Bug: 543540 Change-Id: I01eb2a88562f8aecb75c12b383527196a326d586 Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/plugin.xml4
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/HideDDiagramElementAction.java2
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/HideDDiagramElementLabelAction.java17
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/RevealElementsAction.java35
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/TabbarRevealLabelsAction.java17
5 files changed, 50 insertions, 25 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml
index 8e70b51698..4dfaf6ff52 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml
+++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml
@@ -1283,7 +1283,7 @@
<with
variable="activeMenuSelection">
<iterate
- operator="and">
+ operator="or">
<instanceof
value="org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart">
</instanceof>
@@ -1304,7 +1304,7 @@
<with
variable="activeMenuSelection">
<iterate
- operator="and">
+ operator="or">
<instanceof
value="org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart">
</instanceof>
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/HideDDiagramElementAction.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/HideDDiagramElementAction.java
index 70244b33e8..8f02f9cdd4 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/HideDDiagramElementAction.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/HideDDiagramElementAction.java
@@ -154,7 +154,7 @@ public class HideDDiagramElementAction extends Action implements IObjectActionDe
DDiagram parentDiagram = ddes.iterator().next().getParentDiagram();
Predicate<DDiagramElement> allowsHideReveal = allowsHideReveal(parentDiagram);
Predicate<DDiagramElement> notDirectlyHidden = dde -> dde.isVisible();
- return Iterables.all(ddes, Predicates.and(allowsHideReveal, notDirectlyHidden));
+ return Iterables.any(ddes, Predicates.and(allowsHideReveal, notDirectlyHidden));
}
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/HideDDiagramElementLabelAction.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/HideDDiagramElementLabelAction.java
index 278946a6fa..7cf976ccbb 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/HideDDiagramElementLabelAction.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/HideDDiagramElementLabelAction.java
@@ -21,6 +21,7 @@ import java.util.Set;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
@@ -33,6 +34,7 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery;
import org.eclipse.sirius.diagram.tools.api.command.IDiagramCommandFactory;
@@ -42,6 +44,8 @@ import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin;
import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor;
import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath;
import org.eclipse.sirius.diagram.ui.tools.internal.editor.DiagramOutlinePage;
+import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority;
+import org.eclipse.sirius.ecore.extender.business.api.permission.PermissionAuthorityRegistry;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
@@ -139,8 +143,19 @@ public class HideDDiagramElementLabelAction extends Action implements IObjectAct
}
private static boolean isEnabled(DDiagramElement diagramElement) {
+ DDiagram dDiagram = diagramElement.getParentDiagram();
DDiagramElementQuery query = new DDiagramElementQuery(diagramElement);
- return query.canHideLabel() && !query.isLabelHidden();
+ return (dDiagram != null && isEditable(dDiagram)) && query.canHideLabel() && !query.isLabelHidden();
+ }
+
+ private static boolean isEditable(DDiagram diagram) {
+ boolean isEditable = false;
+ Resource resource = diagram.eResource();
+ if (resource != null) {
+ IPermissionAuthority permissionAuthority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority(resource.getResourceSet());
+ isEditable = permissionAuthority.canEditInstance(diagram);
+ }
+ return isEditable;
}
/**
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/RevealElementsAction.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/RevealElementsAction.java
index dd6353d76c..c9ef58d25d 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/RevealElementsAction.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/RevealElementsAction.java
@@ -45,7 +45,7 @@ public class RevealElementsAction extends AbstractRevealElementsAction<Object> {
public RevealElementsAction() {
super(Messages.RevealOutlineElementsAction_label);
}
-
+
/**
* Constructor.
*
@@ -75,29 +75,22 @@ public class RevealElementsAction extends AbstractRevealElementsAction<Object> {
}
/**
- * Tests whether this action should be active. The action is active if the the given selection contains only hidden
- * diagram graphical element.
+ * Tests whether this action should be active. The action is active if the given selection contains at least one
+ * hidden diagram graphical element.
*
* @param selectedElements
* The current selection
* @return true if all selected elements are hidden.
*/
public static boolean isActive(IStructuredSelection selectedElements) {
- boolean result = true;
final Iterator<?> iterator = selectedElements.iterator();
-
- if (!iterator.hasNext()) {
- result = false;
- }
while (iterator.hasNext()) {
final Object selectedElement = iterator.next();
- if (selectedElement instanceof IDiagramElementEditPart) {
- result = result && isActive((IDiagramElementEditPart) selectedElement);
- } else {
- result = false;
+ if (selectedElement instanceof IDiagramElementEditPart && isActive((IDiagramElementEditPart) selectedElement)) {
+ return true;
}
}
- return result;
+ return false;
}
/**
@@ -124,13 +117,15 @@ public class RevealElementsAction extends AbstractRevealElementsAction<Object> {
final DDiagramEditor diagramEditor = (DDiagramEditor) wrapper.getViewer().getProperty(DDiagramEditor.EDITOR_ID);
runRevealCommand(root, diagramEditor, (DDiagramElement) vpe);
} else if (vpe instanceof IDiagramElementEditPart) {
- Optional<DDiagramElement> optionalDiagramElement = Optional.of((IGraphicalEditPart) vpe).map(IGraphicalEditPart::resolveSemanticElement).filter(DDiagramElement.class::isInstance)
- .map(DDiagramElement.class::cast);
- if (optionalDiagramElement.isPresent()) {
- IDiagramElementEditPart diagramElementEditPart = (IDiagramElementEditPart) vpe;
- SelectionRequest request = new SelectionRequest();
- request.setType(RequestConstants.REQ_OPEN);
- diagramElementEditPart.performRequest(request);
+ if (isActive((IDiagramElementEditPart) vpe)) {
+ Optional<DDiagramElement> optionalDiagramElement = Optional.of((IGraphicalEditPart) vpe).map(IGraphicalEditPart::resolveSemanticElement).filter(DDiagramElement.class::isInstance)
+ .map(DDiagramElement.class::cast);
+ if (optionalDiagramElement.isPresent()) {
+ IDiagramElementEditPart diagramElementEditPart = (IDiagramElementEditPart) vpe;
+ SelectionRequest request = new SelectionRequest();
+ request.setType(RequestConstants.REQ_OPEN);
+ diagramElementEditPart.performRequest(request);
+ }
}
}
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/TabbarRevealLabelsAction.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/TabbarRevealLabelsAction.java
index 8e4c80960e..0735c701be 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/TabbarRevealLabelsAction.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/visibility/TabbarRevealLabelsAction.java
@@ -14,12 +14,14 @@ package org.eclipse.sirius.diagram.ui.tools.internal.actions.visibility;
import java.util.Collection;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.gef.Disposable;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery;
import org.eclipse.sirius.diagram.ui.business.api.provider.AbstractDDiagramElementLabelItemProvider;
@@ -27,6 +29,8 @@ import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin;
import org.eclipse.sirius.diagram.ui.provider.Messages;
import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath;
import org.eclipse.sirius.diagram.ui.tools.internal.editor.DiagramOutlinePage;
+import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority;
+import org.eclipse.sirius.ecore.extender.business.api.permission.PermissionAuthorityRegistry;
import org.eclipse.sirius.ext.base.Option;
import com.google.common.base.Predicate;
@@ -143,8 +147,19 @@ public class TabbarRevealLabelsAction extends RevealOutlineLabelsAction implemen
}
private static boolean isEnabled(DDiagramElement diagramElement) {
+ DDiagram dDiagram = diagramElement.getParentDiagram();
DDiagramElementQuery query = new DDiagramElementQuery(diagramElement);
- return query.isLabelHidden();
+ return (dDiagram != null && isEditable(dDiagram)) && query.isLabelHidden();
+ }
+
+ private static boolean isEditable(DDiagram diagram) {
+ boolean isEditable = false;
+ Resource resource = diagram.eResource();
+ if (resource != null) {
+ IPermissionAuthority permissionAuthority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority(resource.getResourceSet());
+ isEditable = permissionAuthority.canEditInstance(diagram);
+ }
+ return isEditable;
}
/**

Back to the top