diff options
| author | Jessy Mallet | 2015-03-24 09:51:42 +0000 |
|---|---|---|
| committer | Laurent Redor | 2015-03-29 08:49:24 +0000 |
| commit | 42b9bff908ed51210a7a2a18b271612c53b5581a (patch) | |
| tree | 3d85092d043bf9b9e662a9a5a2f46c73fe047a4a | |
| parent | 15e2fa2d7ea8c45017e7d8cfc2fba49873947792 (diff) | |
| download | org.eclipse.sirius-42b9bff908ed51210a7a2a18b271612c53b5581a.tar.gz org.eclipse.sirius-42b9bff908ed51210a7a2a18b271612c53b5581a.tar.xz org.eclipse.sirius-42b9bff908ed51210a7a2a18b271612c53b5581a.zip | |
[461991] Use Precondition for directEdit and doubleClick tool.
Preconditions did not work for Double Click and Direct Edit tools. So
they are now evaluated before the activation of the direct edit and in
the DoubleClick command.
Bug: 461991
Change-Id: I97b7f628a5f2c4aa63633d2593bf9e6bc14f2ca3
Signed-off-by: Jessy Mallet <jessy.mallet@obeo.fr>
9 files changed, 380 insertions, 32 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramNameEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramNameEditPart.java index a129716697..d003f9ee0e 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramNameEditPart.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/api/part/AbstractDiagramNameEditPart.java @@ -31,6 +31,8 @@ import org.eclipse.sirius.diagram.DEdge; import org.eclipse.sirius.diagram.DNode; import org.eclipse.sirius.diagram.DNodeContainer; import org.eclipse.sirius.diagram.DNodeList; +import org.eclipse.sirius.diagram.description.tool.DirectEditLabel; +import org.eclipse.sirius.diagram.tools.internal.command.builders.DirectEditCommandBuilder; import org.eclipse.sirius.diagram.ui.edit.internal.part.DiagramElementEditPartOperation; import org.eclipse.sirius.diagram.ui.graphical.edit.policies.LabelDeletionEditPolicy; import org.eclipse.sirius.diagram.ui.graphical.edit.policies.LabelSemanticEditPolicy; @@ -245,10 +247,10 @@ public abstract class AbstractDiagramNameEditPart extends LabelEditPart implemen final DMappingBased mappingBasedObject = (DMappingBased) eObj; if (mappingBasedObject.getMapping() != null && mappingBasedObject instanceof DDiagramElement && ((DDiagramElement) mappingBasedObject).getDiagramElementMapping().getLabelDirectEdit() != null) { - // Layouting mode on diagrams - // if the ddiagram is in LayoutingMode, we do not allow - // direct edit - directEditEnabled = !isInLayoutingModeDiagram((DDiagramElement) mappingBasedObject); + // check precondition + DirectEditLabel labelDirectEdit = ((DDiagramElement) mappingBasedObject).getDiagramElementMapping().getLabelDirectEdit(); + final DirectEditCommandBuilder builder = new DirectEditCommandBuilder((DDiagramElement) mappingBasedObject, labelDirectEdit, null); + directEditEnabled = builder.canDirectEdit(); } } return directEditEnabled; diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DirectEditCommandBuilder.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DirectEditCommandBuilder.java index 6ea9d2c473..0f28994aff 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DirectEditCommandBuilder.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DirectEditCommandBuilder.java @@ -58,9 +58,7 @@ public class DirectEditCommandBuilder extends AbstractDiagramCommandBuilder { * @see org.eclipse.sirius.tools.internal.command.builders.CommandBuilder#buildCommand() */ public Command buildCommand() { - // Layouting mode on diagrams, if the ddiagram is in - // LayoutingMode, we do not allow direct edit. - if (this.permissionAuthority.canEditInstance(labeled) && !isInLayoutingModeDiagram(labeled)) { + if (this.permissionAuthority.canEditInstance(labeled) && canDirectEdit()) { final DCommand result = createEnclosingCommand(); /* * First we need to init the mask variables. @@ -85,6 +83,19 @@ public class DirectEditCommandBuilder extends AbstractDiagramCommandBuilder { } /** + * Indicates if the label to edit can be directly editable. + * + * @return true if the label can be direct edited, false otherwise + */ + public boolean canDirectEdit() { + // Layouting mode on diagrams, if the diagram is in + // LayoutingMode, we do not allow direct edit. + boolean valid = !isInLayoutingModeDiagram(labeled); + valid = valid && checkPrecondition((DDiagramElement) labeled, directEditTool); + return valid; + } + + /** * Add tasks to execute after model operations. * * @param command diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DoubleClickCommandBuilder.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DoubleClickCommandBuilder.java index faef937daf..b0a8dddce8 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DoubleClickCommandBuilder.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/builders/DoubleClickCommandBuilder.java @@ -60,30 +60,34 @@ public class DoubleClickCommandBuilder extends AbstractDiagramCommandBuilder { * @see org.eclipse.sirius.tools.internal.command.builders.CommandBuilder#buildCommand() */ public Command buildCommand() { - // Layouting mode on diagrams - // if the dDiagram is in layoutMode - if (isInLayoutingModeDiagram(dDiagramElement)) { - // We disable this double click, unless the tool is only containing - // Navigation descriptions - if (!(tool.getInitialOperation().getFirstModelOperations() instanceof Navigation)) { - return UnexecutableCommand.INSTANCE; - } - } - final Map<AbstractVariable, Object> variables = new HashMap<AbstractVariable, Object>(); - variables.put(tool.getElement(), dDiagramElement.getTarget()); - variables.put(tool.getElementView(), dDiagramElement); + if (canDoubleClick()) { + final Map<AbstractVariable, Object> variables = new HashMap<AbstractVariable, Object>(); + variables.put(tool.getElement(), dDiagramElement.getTarget()); + variables.put(tool.getElementView(), dDiagramElement); - final DCommand cmd = createEnclosingCommand(); - IInterpreter interpreter = InterpreterUtil.getInterpreter(dDiagramElement); - cmd.getTasks().add(new InitInterpreterVariablesTask(variables, interpreter, uiCallback)); + final DCommand cmd = createEnclosingCommand(); + IInterpreter interpreter = InterpreterUtil.getInterpreter(dDiagramElement); + cmd.getTasks().add(new InitInterpreterVariablesTask(variables, interpreter, uiCallback)); - Option<DDiagram> parentDiagram = getDDiagram(); - if (tool.getInitialOperation() != null && tool.getInitialOperation().getFirstModelOperations() != null) { - cmd.getTasks().add(taskHelper.buildTaskFromModelOperation(parentDiagram.get(), dDiagramElement, tool.getInitialOperation().getFirstModelOperations())); - addPostOperationTasks(cmd, interpreter); + Option<DDiagram> parentDiagram = getDDiagram(); + if (tool.getInitialOperation() != null && tool.getInitialOperation().getFirstModelOperations() != null) { + cmd.getTasks().add(taskHelper.buildTaskFromModelOperation(parentDiagram.get(), dDiagramElement, tool.getInitialOperation().getFirstModelOperations())); + addPostOperationTasks(cmd, interpreter); + } + + return cmd; } + return UnexecutableCommand.INSTANCE; + } - return cmd; + private boolean canDoubleClick() { + // Layouting mode on diagrams + // if the dDiagram is in layoutMode + // We disable this double click, unless the tool is only containing + // Navigation descriptions + boolean valid = !(isInLayoutingModeDiagram(dDiagramElement) && !(tool.getInitialOperation().getFirstModelOperations() instanceof Navigation)); + valid = valid && checkPrecondition(dDiagramElement, tool); + return valid; } /** diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/doubleClick/bug461991/461991.aird b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/doubleClick/bug461991/461991.aird new file mode 100644 index 0000000000..cab9e91127 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/doubleClick/bug461991/461991.aird @@ -0,0 +1,154 @@ +<?xml version="1.0" encoding="UTF-8"?> +<viewpoint:DAnalysis xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:diagram="http://www.eclipse.org/sirius/diagram/1.1.0" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" xsi:schemaLocation="http://www.eclipse.org/sirius/description/1.1.0 http://www.eclipse.org/sirius/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/style/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description/style" xmi:id="_8BGnkX0KEeKifZQ-ejpKMg" selectedViews="_YS1wEM8YEeS6WYAqfUzz6A" version="10.0.10.201502231700"> + <models xmi:type="ecore:EPackage" href="461991.ecore#/"/> + <ownedViews xmi:type="viewpoint:DRepresentationContainer" xmi:id="_8pOXgH0KEeKifZQ-ejpKMg" initialized="true"> + <ownedRepresentations xmi:type="diagram:DSemanticDiagram" xmi:id="__Al3gH0KEeKifZQ-ejpKMg" name="new desc"> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="__A6noH0KEeKifZQ-ejpKMg" source="GMF_DIAGRAMS"> + <data xmi:type="notation:Diagram" xmi:id="__A6noX0KEeKifZQ-ejpKMg" type="Sirius" element="__Al3gH0KEeKifZQ-ejpKMg" measurementUnit="Pixel"> + <children xmi:type="notation:Node" xmi:id="_XNGFcM8XEeS6WYAqfUzz6A" type="2002" element="_XMoLYM8XEeS6WYAqfUzz6A"> + <children xmi:type="notation:Node" xmi:id="_XNREkM8XEeS6WYAqfUzz6A" type="5006"/> + <children xmi:type="notation:Node" xmi:id="_XNTg0M8XEeS6WYAqfUzz6A" type="7001"> + <styles xmi:type="notation:SortingStyle" xmi:id="_XNTg0c8XEeS6WYAqfUzz6A"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_XNTg0s8XEeS6WYAqfUzz6A"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_XNGFcc8XEeS6WYAqfUzz6A" fontName="Segoe UI" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_XNGFcs8XEeS6WYAqfUzz6A"/> + </children> + <styles xmi:type="notation:DiagramStyle" xmi:id="__A6non0KEeKifZQ-ejpKMg"/> + </data> + </ownedAnnotationEntries> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_Q3U2MM8XEeS6WYAqfUzz6A" source="DANNOTATION_CUSTOMIZATION_KEY"> + <data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_Q3U2Mc8XEeS6WYAqfUzz6A"/> + </ownedAnnotationEntries> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_XMoLYM8XEeS6WYAqfUzz6A" name="C1"> + <target xmi:type="ecore:EClass" href="My.ecore#//C1"/> + <semanticElements xmi:type="ecore:EClass" href="My.ecore#//C1"/> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_XMrOsM8XEeS6WYAqfUzz6A"> + <description xmi:type="style:FlatContainerStyleDescription" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer/@containerMappings[name='EClassMapping']/@style"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer/@containerMappings[name='EClassMapping']"/> + </ownedDiagramElements> + <description xmi:type="description_1:DiagramDescription" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']"/> + <filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="__Al3gX0KEeKifZQ-ejpKMg"/> + <activatedLayers xmi:type="description_1:Layer" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer"/> + <target xmi:type="ecore:EPackage" href="My.ecore#/"/> + </ownedRepresentations> + <ownedRepresentations xmi:type="diagram:DSemanticDiagram" xmi:id="_pKCzMM8XEeS6WYAqfUzz6A" name="new desc"> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_pKCzMc8XEeS6WYAqfUzz6A" source="DANNOTATION_CUSTOMIZATION_KEY"> + <data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_pKCzMs8XEeS6WYAqfUzz6A"/> + </ownedAnnotationEntries> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_pKISwM8XEeS6WYAqfUzz6A" source="GMF_DIAGRAMS"> + <data xmi:type="notation:Diagram" xmi:id="_pKISwc8XEeS6WYAqfUzz6A" type="Sirius" element="_pKCzMM8XEeS6WYAqfUzz6A" measurementUnit="Pixel"> + <children xmi:type="notation:Node" xmi:id="_pKISw88XEeS6WYAqfUzz6A" type="2002" element="_pKCzM88XEeS6WYAqfUzz6A"> + <children xmi:type="notation:Node" xmi:id="_pKI50M8XEeS6WYAqfUzz6A" type="5006"/> + <children xmi:type="notation:Node" xmi:id="_pKI50c8XEeS6WYAqfUzz6A" type="7001"> + <styles xmi:type="notation:SortingStyle" xmi:id="_pKI50s8XEeS6WYAqfUzz6A"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_pKI5088XEeS6WYAqfUzz6A"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_pKISxM8XEeS6WYAqfUzz6A" fontName="Segoe UI" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_pKISxc8XEeS6WYAqfUzz6A"/> + </children> + <styles xmi:type="notation:DiagramStyle" xmi:id="_pKISws8XEeS6WYAqfUzz6A"/> + </data> + </ownedAnnotationEntries> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_pKCzM88XEeS6WYAqfUzz6A" name="C1"> + <target xmi:type="ecore:EClass" href="My.ecore#//C1"/> + <semanticElements xmi:type="ecore:EClass" href="My.ecore#//C1"/> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_pKCzNM8XEeS6WYAqfUzz6A"> + <description xmi:type="style:FlatContainerStyleDescription" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer/@containerMappings[name='EClassMapping']/@style"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer/@containerMappings[name='EClassMapping']"/> + </ownedDiagramElements> + <description xmi:type="description_1:DiagramDescription" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']"/> + <filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="_pKCzNc8XEeS6WYAqfUzz6A"/> + <activatedLayers xmi:type="description_1:Layer" href="My.odesign#//@ownedViewpoints[name='vp3507']/@ownedRepresentations[name='desc']/@defaultLayer"/> + <target xmi:type="ecore:EPackage" href="My.ecore#/"/> + </ownedRepresentations> + <viewpoint xmi:type="description:Viewpoint" href="My.odesign#//@ownedViewpoints[name='vp3507']"/> + </ownedViews> + <ownedViews xmi:type="viewpoint:DRepresentationContainer" xmi:id="_2ublQM8XEeS6WYAqfUzz6A" initialized="true"> + <ownedRepresentations xmi:type="diagram:DSemanticDiagram" xmi:id="_3gjlwM8XEeS6WYAqfUzz6A" name="new bug461991"> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_3gjlwc8XEeS6WYAqfUzz6A" source="DANNOTATION_CUSTOMIZATION_KEY"> + <data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_3gjlws8XEeS6WYAqfUzz6A"/> + </ownedAnnotationEntries> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_3gkM0M8XEeS6WYAqfUzz6A" source="GMF_DIAGRAMS"> + <data xmi:type="notation:Diagram" xmi:id="_3gkM0c8XEeS6WYAqfUzz6A" type="Sirius" element="_3gjlwM8XEeS6WYAqfUzz6A" measurementUnit="Pixel"> + <children xmi:type="notation:Node" xmi:id="_3gkM088XEeS6WYAqfUzz6A" type="2002" element="_3gjlw88XEeS6WYAqfUzz6A"> + <children xmi:type="notation:Node" xmi:id="_3gkM1s8XEeS6WYAqfUzz6A" type="5006"/> + <children xmi:type="notation:Node" xmi:id="_3gkM188XEeS6WYAqfUzz6A" type="7001"> + <styles xmi:type="notation:SortingStyle" xmi:id="_3gkM2M8XEeS6WYAqfUzz6A"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_3gkM2c8XEeS6WYAqfUzz6A"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_3gkM1M8XEeS6WYAqfUzz6A" fontName="Segoe UI" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_3gkM1c8XEeS6WYAqfUzz6A"/> + </children> + <styles xmi:type="notation:DiagramStyle" xmi:id="_3gkM0s8XEeS6WYAqfUzz6A"/> + </data> + </ownedAnnotationEntries> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_3gjlw88XEeS6WYAqfUzz6A" name="C1"> + <target xmi:type="ecore:EClass" href="My.ecore#//C1"/> + <semanticElements xmi:type="ecore:EClass" href="My.ecore#//C1"/> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_3gjlxM8XEeS6WYAqfUzz6A"> + <description xmi:type="style:FlatContainerStyleDescription" href="My.odesign#//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@containerMappings[name='EClassMapping']/@style"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="My.odesign#//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@containerMappings[name='EClassMapping']"/> + </ownedDiagramElements> + <description xmi:type="description_1:DiagramDescription" href="My.odesign#//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']"/> + <filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="_3gjlxc8XEeS6WYAqfUzz6A"/> + <activatedLayers xmi:type="description_1:Layer" href="My.odesign#//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer"/> + <target xmi:type="ecore:EPackage" href="My.ecore#/"/> + </ownedRepresentations> + <viewpoint xmi:type="description:Viewpoint" href="My.odesign#//@ownedViewpoints[name='bug461991']"/> + </ownedViews> + <ownedViews xmi:type="viewpoint:DRepresentationContainer" xmi:id="_YS1wEM8YEeS6WYAqfUzz6A" initialized="true"> + <ownedRepresentations xmi:type="diagram:DSemanticDiagram" xmi:id="_G9aqcM8aEeS6WYAqfUzz6A" name="new bug461991"> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_G9aqcc8aEeS6WYAqfUzz6A" source="DANNOTATION_CUSTOMIZATION_KEY"> + <data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_G9aqcs8aEeS6WYAqfUzz6A"/> + </ownedAnnotationEntries> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_G9bRgM8aEeS6WYAqfUzz6A" source="GMF_DIAGRAMS"> + <data xmi:type="notation:Diagram" xmi:id="_G9bRgc8aEeS6WYAqfUzz6A" type="Sirius" element="_G9aqcM8aEeS6WYAqfUzz6A" measurementUnit="Pixel"> + <children xmi:type="notation:Node" xmi:id="_G9bRg88aEeS6WYAqfUzz6A" type="2002" element="_G9aqc88aEeS6WYAqfUzz6A"> + <children xmi:type="notation:Node" xmi:id="_G90TEM8aEeS6WYAqfUzz6A" type="5006"/> + <children xmi:type="notation:Node" xmi:id="_G90TEc8aEeS6WYAqfUzz6A" type="7001"> + <styles xmi:type="notation:SortingStyle" xmi:id="_G90TEs8aEeS6WYAqfUzz6A"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_G90TE88aEeS6WYAqfUzz6A"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_G9bRhM8aEeS6WYAqfUzz6A" fontColor="7490599" fontName="Segoe UI" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_G9bRhc8aEeS6WYAqfUzz6A"/> + </children> + <children xmi:type="notation:Node" xmi:id="_G90TFM8aEeS6WYAqfUzz6A" type="2002" element="_G9aqd88aEeS6WYAqfUzz6A"> + <children xmi:type="notation:Node" xmi:id="_G906IM8aEeS6WYAqfUzz6A" type="5006"/> + <children xmi:type="notation:Node" xmi:id="_G906Ic8aEeS6WYAqfUzz6A" type="7001"> + <styles xmi:type="notation:SortingStyle" xmi:id="_G906Is8aEeS6WYAqfUzz6A"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_G906I88aEeS6WYAqfUzz6A"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_G90TFc8aEeS6WYAqfUzz6A" fontColor="1533850" fontName="Segoe UI" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_G90TFs8aEeS6WYAqfUzz6A" x="255"/> + </children> + <styles xmi:type="notation:DiagramStyle" xmi:id="_G9bRgs8aEeS6WYAqfUzz6A"/> + </data> + </ownedAnnotationEntries> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_G9aqc88aEeS6WYAqfUzz6A" name="P1"> + <target xmi:type="ecore:EPackage" href="461991.ecore#//P1"/> + <semanticElements xmi:type="ecore:EPackage" href="461991.ecore#//P1"/> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_G9aqdM8aEeS6WYAqfUzz6A" labelColor="39,76,114" borderColor="39,76,114" foregroundColor="194,239,255"> + <description xmi:type="style:FlatContainerStyleDescription" href="461991.odesign#//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@containerMappings[name='EPackage']/@style"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="461991.odesign#//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@containerMappings[name='EPackage']"/> + </ownedDiagramElements> + <ownedDiagramElements xmi:type="diagram:DNodeContainer" xmi:id="_G9aqd88aEeS6WYAqfUzz6A" name="C1"> + <target xmi:type="ecore:EClass" href="461991.ecore#//C1"/> + <semanticElements xmi:type="ecore:EClass" href="461991.ecore#//C1"/> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_G9aqeM8aEeS6WYAqfUzz6A" labelColor="154,103,23" foregroundColor="217,196,215"> + <description xmi:type="style:FlatContainerStyleDescription" href="461991.odesign#//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@containerMappings[name='EClass']/@style"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="461991.odesign#//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@containerMappings[name='EClass']"/> + </ownedDiagramElements> + <description xmi:type="description_1:DiagramDescription" href="461991.odesign#//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']"/> + <filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="_G9aqec8aEeS6WYAqfUzz6A"/> + <activatedLayers xmi:type="description_1:Layer" href="461991.odesign#//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer"/> + <target xmi:type="ecore:EPackage" href="461991.ecore#/"/> + </ownedRepresentations> + <viewpoint xmi:type="description:Viewpoint" href="461991.odesign#//@ownedViewpoints[name='bug461991']"/> + </ownedViews> +</viewpoint:DAnalysis> diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/doubleClick/bug461991/461991.ecore b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/doubleClick/bug461991/461991.ecore new file mode 100644 index 0000000000..12eb4e4342 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/doubleClick/bug461991/461991.ecore @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="p"> + <eClassifiers xsi:type="ecore:EClass" name="C1"/> + <eSubpackages name="P1"/> +</ecore:EPackage> diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/doubleClick/bug461991/461991.odesign b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/doubleClick/bug461991/461991.odesign new file mode 100644 index 0000000000..5aba56ff2b --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/doubleClick/bug461991/461991.odesign @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:tool="http://www.eclipse.org/sirius/diagram/description/tool/1.1.0" xmlns:tool_1="http://www.eclipse.org/sirius/description/tool/1.1.0" name="bug461991" version="10.0.0.201411061000"> + <ownedViewpoints name="bug461991" modelFileExtension="ecore"> + <ownedRepresentations xsi:type="description_1:DiagramDescription" name="bug461991" domainClass="EPackage"> + <defaultLayer name="Default"> + <containerMappings name="EPackage" semanticCandidatesExpression="[eContents()/]" doubleClickDescription="//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@toolSections.0/@ownedTools[name='Double%20click%20EPackage']" domainClass="EPackage" reusedContainerMappings="//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@containerMappings[name='EPackage']"> + <style xsi:type="style:FlatContainerStyleDescription"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='dark_blue']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='dark_blue']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_blue']"/> + </style> + </containerMappings> + <containerMappings name="EClass" doubleClickDescription="//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@toolSections.0/@ownedTools[name='Double%20click%20EClass']" domainClass="EClass"> + <style xsi:type="style:FlatContainerStyleDescription"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='dark_chocolate']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_purple']"/> + </style> + </containerMappings> + <toolSections> + <ownedTools xsi:type="tool:DoubleClickDescription" name="Double click EPackage" precondition="[false/]" mappings="//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@containerMappings[name='EPackage']"> + <element name="element"/> + <elementView name="elementView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="[element/]"> + <subModelOperations xsi:type="tool_1:RemoveElement"/> + </firstModelOperations> + </initialOperation> + </ownedTools> + <ownedTools xsi:type="tool:DoubleClickDescription" name="Double click EClass" mappings="//@ownedViewpoints[name='bug461991']/@ownedRepresentations[name='bug461991']/@defaultLayer/@containerMappings[name='EClass']"> + <element name="element"/> + <elementView name="elementView"/> + <initialOperation> + <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="[element/]"> + <subModelOperations xsi:type="tool_1:RemoveElement"/> + </firstModelOperations> + </initialOperation> + </ownedTools> + </toolSections> + </defaultLayer> + </ownedRepresentations> + </ownedViewpoints> +</description:Group> diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DirectEditLabelTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DirectEditLabelTest.java index cc0ca103c0..daaef52a11 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DirectEditLabelTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DirectEditLabelTest.java @@ -99,12 +99,32 @@ public class DirectEditLabelTest extends AbstractSiriusSwtBotGefTestCase { DiagramDescription diagramDescription = dDiagram.getDescription(); // we create a new direct edit tool in VSM while the diagram is open - addDirectEditToolToVSM(diagramDescription); + String precondition = null; + addDirectEditToolToVSM(diagramDescription, precondition); - checkDirectEditLabel(); + checkDirectEditLabel(precondition); } - private void checkDirectEditLabel() { + /** + * Tests that the direct edit tool is not available if the tool has false + * precondition. + * + * @throws Exception + * thrown to fail + */ + public void testDirectEditToolWithPrecondition() throws Exception { + + DDiagram dDiagram = (DDiagram) getRepresentationWithName(localSession.getOpenedSession(), REPRESENTATION_DESCRIPTION_NAME, REPRESENTATION_NAME); + DiagramDescription diagramDescription = dDiagram.getDescription(); + + // we create a new direct edit tool in VSM while the diagram is open + String precondition = "[false/]"; + addDirectEditToolToVSM(diagramDescription, precondition); + + checkDirectEditLabel(precondition); + } + + private void checkDirectEditLabel(String precondition) { // Click a first time on the edit part to select it. editor.click(CLASS_NAME, AbstractDiagramContainerEditPart.class); SWTBotUtils.waitAllUiEvents(); @@ -113,7 +133,12 @@ public class DirectEditLabelTest extends AbstractSiriusSwtBotGefTestCase { SWTBotUtils.waitAllUiEvents(); /* wait until text widget appears */ - editor.bot().text(); + try { + editor.bot().text(); + } catch (Exception e) { + assertTrue("The direct edit mode is not accessible while there is no precondition.", "[false/]".equals(precondition)); + return; + } /* Find the text widget and check its label now. */ List<Text> controls = editor.bot().getFinder().findControls(editor.getWidget(), new IsInstanceOf<Text>(Text.class), true); if (controls.size() == 1) { @@ -132,7 +157,7 @@ public class DirectEditLabelTest extends AbstractSiriusSwtBotGefTestCase { editor.getEditPart("newLabel", AbstractDiagramContainerEditPart.class); } - private void addDirectEditToolToVSM(DiagramDescription diagramDescription) throws Exception { + private void addDirectEditToolToVSM(DiagramDescription diagramDescription, String precondition) throws Exception { ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("odesign", new DescriptionResourceFactoryImpl()); Resource odesignResource = resourceSet.getResource(diagramDescription.eResource().getURI(), true); @@ -148,6 +173,9 @@ public class DirectEditLabelTest extends AbstractSiriusSwtBotGefTestCase { DirectEditLabel directEditLabel = ToolFactory.eINSTANCE.createDirectEditLabel(); section.getOwnedTools().add(directEditLabel); directEditLabel.setName(DIRECT_EDIT_NAME); + if (precondition != null) { + directEditLabel.setPrecondition(precondition); + } containerMapping.setLabelDirectEdit(directEditLabel); InitialOperation initialOperation = directEditLabel.getInitialOperation(); diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DoubleClickToolWithPreconditionTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DoubleClickToolWithPreconditionTest.java new file mode 100644 index 0000000000..5127d8086f --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/DoubleClickToolWithPreconditionTest.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.swtbot; + +import java.util.List; + +import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.DDiagramElement; +import org.eclipse.sirius.diagram.DSemanticDiagram; +import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase; +import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource; +import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusDiagramEditor; +import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotUtils; +import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart; + +/** + * Test class that check if precondition is working for double click tool. + * + * See OD-883. + * + * @author @author <a href="mailto:jessy.mallet@obeo.fr">Jessy Mallet</a> + */ +public class DoubleClickToolWithPreconditionTest extends AbstractSiriusSwtBotGefTestCase { + + private static final String PACKAGE_NAME = "P1"; + + private static final String AIRD = "461991.aird"; + + private static final String REPRESENTATION_DESCRIPTION_NAME = "bug461991"; + + private static final String REPRESENTATION_NAME = "new bug461991"; + + private static final String PATH = "/data/unit/doubleClick/bug461991/"; + + private static final String ODESIGN = "461991.odesign"; + + private static final String SEMANTIC = "461991.ecore"; + + private static final String FILE_DIR = "/"; + + /** + * {@inheritDoc} + */ + @Override + protected void onSetUpBeforeClosingWelcomePage() throws Exception { + copyFileToTestProject(Activator.PLUGIN_ID, PATH, SEMANTIC, AIRD, ODESIGN); + } + + /** + * {@inheritDoc} + */ + @Override + protected void onSetUpAfterOpeningDesignerPerspective() { + sessionAirdResource = new UIResource(designerProject, FILE_DIR, AIRD); + localSession = designerPerspective.openSessionFromFile(sessionAirdResource, true); + sessionAirdResource = new UIResource(designerProject, FILE_DIR, AIRD); + + } + + /** + * Tests that the precondition of the double click tool works. + */ + public void testDoubleClickWithPrecondition() { + editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_DESCRIPTION_NAME, REPRESENTATION_NAME, DDiagram.class); + checkDoubleClickRemoveAction(); + } + + private void checkDoubleClickRemoveAction() { + // Double click on P1 + editor.getEditPart(PACKAGE_NAME, AbstractBorderedShapeEditPart.class).select(); + editor.doubleClick(PACKAGE_NAME); + SWTBotUtils.waitAllUiEvents(); + // Recover semantic model + SWTBotGefEditPart diagramBot = editor.rootEditPart().children().iterator().next(); + DSemanticDiagram semanticDiagram = (DSemanticDiagram) ((Diagram) diagramBot.part().getModel()).getElement(); + List<DDiagramElement> diagramElements = semanticDiagram.getOwnedDiagramElements(); + // Check that P1 Package exists + boolean isPresent = false; + for (DDiagramElement element : diagramElements) { + if (PACKAGE_NAME.equals(element.getName())) { + isPresent = true; + } + } + assertTrue("The P1 package has been deleted while the false precondition does not allow this.", isPresent); + } + +} diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java index 10bf5585a5..ff64c4ecab 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java @@ -252,6 +252,7 @@ public class AllTestSuite extends TestCase { suite.addTestSuite(SpecificLayoutBendpointsOnReopeningTest.class); suite.addTestSuite(TreeFoldingTest.class); suite.addTestSuite(DoubleClickToolNavigationOperationTest.class); + suite.addTestSuite(DoubleClickToolNavigationOperationTest.class); suite.addTestSuite(BackgroundColorFigureUpdateTests.class); suite.addTestSuite(BackgroundStyleUpdateTest.class); suite.addTestSuite(BorderSizeComputationExpressionTest.class); |
