diff options
| author | Laurent Redor | 2017-09-07 14:21:18 +0000 |
|---|---|---|
| committer | Laurent Redor | 2017-09-11 15:02:41 +0000 |
| commit | 800d5cb892245801ff00f8423e3c248d67c123cd (patch) | |
| tree | d729e71c575210a04eae065191c4737ca9285120 | |
| parent | bd1d82c356db9ada41d4bbe29b128ce912149349 (diff) | |
| download | org.eclipse.sirius-800d5cb892245801ff00f8423e3c248d67c123cd.tar.gz org.eclipse.sirius-800d5cb892245801ff00f8423e3c248d67c123cd.tar.xz org.eclipse.sirius-800d5cb892245801ff00f8423e3c248d67c123cd.zip | |
[522007] Activate Hide label even if selection contains invalid elements
* Change plugin.xml to make the contextual menu visible if at least one
element is OK in the selection. This is the case for diagram selection
or for selected elements in the tree of Outline view.
* Change the action HideDDiagramElementLabelAction to correctly enable
it in tabbar if at least one element is OK in the selection
* Change the UndoRedoCapableEMFCommandFactory.buildHideLabelCommand to
apply the command only on elements for which the label can be hidden.
Bug: 522007
Change-Id: I02e7ff19777e2b496c71f0f50d2b52fd645b98a1
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
3 files changed, 46 insertions, 50 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml index e682e91a52..a082461f0c 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml @@ -1230,15 +1230,7 @@ checkEnabled="false"> <with variable="activeMenuSelection"> - <iterate - operator="and"> - <instanceof - value="org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart"> - </instanceof> - <test - property="org.eclipse.sirius.diagram.ui.canHideLabel"> - </test> - </iterate> + <reference definitionId="canHideLabel" /> </with> </visibleWhen> </command> @@ -1760,7 +1752,7 @@ </iterate> </definition> <definition id="canHideLabel"> - <iterate operator="and"> + <iterate operator="or"> <and> <reference definitionId="isInstanceOfIDiagramElementEditPart"> 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 b11888933f..ea72307db8 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2014 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2017 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 @@ -45,6 +45,9 @@ import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PlatformUI; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + /** * Hide the label of a {@link DDiagramElement}. * @@ -53,6 +56,24 @@ import org.eclipse.ui.PlatformUI; */ public class HideDDiagramElementLabelAction extends Action implements IObjectActionDelegate, Disposable { + private static Predicate<Object> isEnabledPredicate = new Predicate<Object>() { + @Override + public boolean apply(Object input) { + boolean result = false; + if (input instanceof IGraphicalEditPart) { + result = HideDDiagramElementLabelAction.isEnabled((IGraphicalEditPart) input); + } else if (input instanceof DDiagramElement) { + result = HideDDiagramElementLabelAction.isEnabled((DDiagramElement) input); + } else if (input instanceof AbstractDDiagramElementLabelItemProvider) { + Option<DDiagramElement> optionTarget = ((AbstractDDiagramElementLabelItemProvider) input).getDiagramElementTarget(); + if (optionTarget.some()) { + result = HideDDiagramElementLabelAction.isEnabled(optionTarget.get()); + } + } + return result; + } + }; + /** The selection. */ private ISelection selection; @@ -87,25 +108,15 @@ public class HideDDiagramElementLabelAction extends Action implements IObjectAct } /** - * Check if all the elements have a label that can be hide. + * Check if at least on element has a label that can be hide. * * @param elementsToCheck * The elements to check. - * @return true if all the elements have a label that can be hide, false + * @return true if at least on element has a label that can be hide, false * otherwise */ public static boolean isEnabled(Collection<?> elementsToCheck) { - boolean canHideLabel = true; - for (Object selectedElement : elementsToCheck) { - if (selectedElement instanceof IGraphicalEditPart) { - canHideLabel = canHideLabel & HideDDiagramElementLabelAction.isEnabled((IGraphicalEditPart) selectedElement); - } else if (selectedElement instanceof DDiagramElement) { - canHideLabel = canHideLabel & HideDDiagramElementLabelAction.isEnabled((DDiagramElement) selectedElement); - } else { - canHideLabel = false; - } - } - return canHideLabel; + return Iterables.any(elementsToCheck, isEnabledPredicate); } private static boolean isEnabled(IGraphicalEditPart graphicalEditPart) { @@ -165,12 +176,14 @@ public class HideDDiagramElementLabelAction extends Action implements IObjectAct final Iterator<Object> it = minimizedSelection.iterator(); while (it.hasNext()) { final Object obj = it.next(); - if (obj instanceof EObject) { - eObjectSelection.add((EObject) obj); - } else if (obj instanceof AbstractDDiagramElementLabelItemProvider) { - Option<DDiagramElement> optionTarget = ((AbstractDDiagramElementLabelItemProvider) obj).getDiagramElementTarget(); - if (optionTarget.some()) { - eObjectSelection.add(optionTarget.get()); + if (isEnabledPredicate.apply(obj)) { + if (obj instanceof EObject) { + eObjectSelection.add((EObject) obj); + } else if (obj instanceof AbstractDDiagramElementLabelItemProvider) { + Option<DDiagramElement> optionTarget = ((AbstractDDiagramElementLabelItemProvider) obj).getDiagramElementTarget(); + if (optionTarget.some()) { + eObjectSelection.add(optionTarget.get()); + } } } } @@ -241,7 +254,7 @@ public class HideDDiagramElementLabelAction extends Action implements IObjectAct // Action of the outline this.setEnabled(HideDDiagramElementLabelAction.isEnabled(((DiagramOutlinePage.TreeSelectionWrapper) s).toList())); } else if (s instanceof IStructuredSelection) { - // Action of the tabber or + // Action of the tabbar or of the contextual menu this.setEnabled(HideDDiagramElementLabelAction.isEnabled(((IStructuredSelection) s).toList())); } } diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/UndoRedoCapableEMFCommandFactory.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/UndoRedoCapableEMFCommandFactory.java index 406fb05730..ac6f27d84d 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/UndoRedoCapableEMFCommandFactory.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/UndoRedoCapableEMFCommandFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2008, 2017 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.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.common.command.Command; @@ -525,25 +526,15 @@ public class UndoRedoCapableEMFCommandFactory extends AbstractCommandFactory imp */ @Override public Command buildHideLabelCommand(Set<EObject> elementsToHide) { - final Set<EObject> filteredSet = new HashSet<EObject>(); - final Iterator<EObject> it = elementsToHide.iterator(); - while (it.hasNext()) { - final EObject eObj = it.next(); - if (getPermissionAuthority().canEditInstance(eObj)) { - filteredSet.add(eObj); - } - } - boolean canHideLabel = true; - for (Object selectedElement : filteredSet) { - if (selectedElement instanceof DDiagramElement) { - canHideLabel = canHideLabel & new DDiagramElementQuery((DDiagramElement) selectedElement).canHideLabel(); - } + Set<DDiagramElement> ddeWithLabelToHide = elementsToHide.stream().filter(input -> { + return input instanceof DDiagramElement && new DDiagramElementQuery((DDiagramElement) input).canHideLabel() && getPermissionAuthority().canEditInstance(input); + }).map(DDiagramElement.class::cast).collect(Collectors.toSet()); + + if (ddeWithLabelToHide.isEmpty()) { + return UnexecutableCommand.INSTANCE; + } else { + return new HideDDiagramElementLabel(domain, ddeWithLabelToHide); } - if (canHideLabel) { - return new HideDDiagramElementLabel(domain, filteredSet); - } - - return UnexecutableCommand.INSTANCE; } /** |
