Skip to content

Commit

Permalink
[2254] Add precondition on diagram tools
Browse files Browse the repository at this point in the history
Bug: #2329
Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
  • Loading branch information
frouene committed Sep 4, 2023
1 parent 10dc4d1 commit e08ba13
Show file tree
Hide file tree
Showing 27 changed files with 514 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -58,6 +58,7 @@ As a result the development of applications consuming Sirius Components packages
- https://github.com/eclipse-sirius/sirius-web/issues/2117[#2117] [form] Add a modal to select new values for multi-valued references
- https://github.com/eclipse-sirius/sirius-web/issues/2118[#2118] [form] Add a modal to create new objects on a widget reference
- https://github.com/eclipse-sirius/sirius-web/issues/2253[#2253] [diagram] Add the possibility of organizing palette tools into sections
- https://github.com/eclipse-sirius/sirius-web/issues/2254[#2254] [diagram] Add the possibility to specify precondition on diagram tools

=== Improvements

Expand Down
47 changes: 47 additions & 0 deletions integration-tests/cypress/e2e/project/edit/studio.cy.js
Expand Up @@ -111,4 +111,51 @@ describe('/projects/:projectId/edit - Studio', () => {
cy.get('[data-value="Source Edge End Reconnection Tool"]').should('not.exist');
cy.get('[data-value="Target Edge End Reconnection Tool"]').should('not.exist');
});

it('Check the precondition on tools', () => {
cy.getByTestId('ViewNewModel').dblclick();
cy.getByTestId('View').dblclick();
cy.get('[data-testid$=" Diagram Description"]').dblclick();
cy.getByTestId('DiagramPalette-more').click();
cy.getByTestId('new-object').click();
cy.getByTestId('childCreationDescription').children('[role="button"]').invoke('text').should('have.length.gt', 1);
cy.getByTestId('childCreationDescription').click();
cy.getByTestId('childCreationDescription').get('[data-value="Node Tool"]').should('exist').click();
cy.getByTestId('create-object').click();
cy.getByTestId('Precondition Expression').should('exist');
cy.getByTestId('Precondition Expression').type('aql:self.eAllContents()->size()>0');
cy.getByTestId('Name').clear();
cy.getByTestId('Name').type('TestTool');

cy.get('[title="Back to the homepage"]').click();
// Check the diagram representation

cy.getByTestId('create').click();
cy.getByTestId('name').type('Instance');
cy.getByTestId('create-project').click();
cy.getByTestId('empty').click();
cy.getByTestId('Others...-more').click();
cy.getByTestId('new-object').click();
cy.getByTestId('domain').children('[role="button"]').invoke('text').should('have.length.gt', 1);
cy.getByTestId('domain').click();
cy.getByTestId('domain').get('[data-value^="domain://"]').should('exist').click();
cy.getByTestId('create-object').click();

cy.getByTestId('Root-more').click();
cy.getByTestId('treeitem-contextmenu').findByTestId('new-representation').click();
cy.getByTestId('representationDescription').children('[role="button"]').invoke('text').should('have.length.gt', 1);
cy.getByTestId('representationDescription').click();
cy.get('[data-testid$=" Diagram Description"]').should('exist').click();
cy.getByTestId('create-representation').click();

cy.getByTestId('Diagram').click();
cy.getByTestId('New Entity1 - Tool').should('exist');
cy.getByTestId('New Entity2 - Tool').should('exist');
cy.getByTestId('TestTool - Tool').should('not.exist');
cy.getByTestId('New Entity1 - Tool').click();
cy.getByTestId('Diagram').click();
cy.getByTestId('New Entity1 - Tool').should('exist');
cy.getByTestId('New Entity2 - Tool').should('exist');
cy.getByTestId('TestTool - Tool').should('exist');
});
});
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.sirius.components.compatibility.api.IIdentifierProvider;
import org.eclipse.sirius.components.compatibility.services.api.IODesignRegistry;
import org.eclipse.sirius.components.core.api.Environment;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.diagrams.Edge;
import org.eclipse.sirius.components.diagrams.Node;
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
Expand Down Expand Up @@ -84,7 +85,7 @@ public boolean canHandle(DiagramDescription diagramDescription) {
}

@Override
public Palette handle(Object targetElement, Object diagramElement, Object diagramElementDescription, DiagramDescription diagramDescription) {
public Palette handle(Object targetElement, Object diagramElement, Object diagramElementDescription, DiagramDescription diagramDescription, IEditingContext editingContext) {
var optionalVsmElementId = this.identifierProvider.findVsmElementId(diagramDescription.getId());

var optionalSiriusDiagramDescription = this.odesignRegistry.getODesigns().stream()
Expand Down
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.sirius.components.collaborative.diagrams.api;

import org.eclipse.sirius.components.collaborative.diagrams.dto.Palette;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;


Expand All @@ -25,5 +26,5 @@ public interface IPaletteProvider {

boolean canHandle(DiagramDescription diagramDescription);

Palette handle(Object targetElement, Object diagramElement, Object diagramElementDescription, DiagramDescription diagramDescription);
Palette handle(Object targetElement, Object diagramElement, Object diagramElementDescription, DiagramDescription diagramDescription, IEditingContext editingContext);
}
Expand Up @@ -110,7 +110,7 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
if (optionalToolSectionsProvider.isPresent() && optionalTargetElement.isPresent() && optionalDiagramElementDescription.isPresent()) {
IPaletteProvider toolSectionsProvider = optionalToolSectionsProvider.get();
palette = toolSectionsProvider.handle(optionalTargetElement.get(), optionalDiagramElement.orElse(null), optionalDiagramElementDescription.get(),
diagramDescription);
diagramDescription, editingContext);
}
}
}
Expand Down
Expand Up @@ -1096,12 +1096,14 @@ export const DiagramRepresentation = ({
diagramServer.actionDispatcher.dispatch(sourceElementAction);
}
}
const setDefaultToolEvent: SetDefaultToolEvent = {
type: 'SET_DEFAULT_TOOL',
defaultTool: tool,
toolSection: toolSection,
};
dispatch(setDefaultToolEvent);
if (toolSection) {
const setDefaultToolEvent: SetDefaultToolEvent = {
type: 'SET_DEFAULT_TOOL',
defaultTool: tool,
toolSection: toolSection,
};
dispatch(setDefaultToolEvent);
}
};
const invokeConnectorToolFromContextualPalette = (palette: GQLPalette) => {
resetTools();
Expand Down
Expand Up @@ -51,6 +51,16 @@ public DeleteToolBuilder name(java.lang.String value) {
this.getDeleteTool().setName(value);
return this;
}
/**
* Setter for PreconditionExpression.
*
* @generated
*/
public DeleteToolBuilder preconditionExpression(java.lang.String value) {
this.getDeleteTool().setPreconditionExpression(value);
return this;
}

/**
* Setter for Body.
*
Expand Down
Expand Up @@ -51,6 +51,16 @@ public DropToolBuilder name(java.lang.String value) {
this.getDropTool().setName(value);
return this;
}
/**
* Setter for PreconditionExpression.
*
* @generated
*/
public DropToolBuilder preconditionExpression(java.lang.String value) {
this.getDropTool().setPreconditionExpression(value);
return this;
}

/**
* Setter for Body.
*
Expand Down
Expand Up @@ -35,6 +35,16 @@ public EdgeReconnectionToolBuilder name(java.lang.String value) {
this.getEdgeReconnectionTool().setName(value);
return this;
}
/**
* Setter for PreconditionExpression.
*
* @generated
*/
public EdgeReconnectionToolBuilder preconditionExpression(java.lang.String value) {
this.getEdgeReconnectionTool().setPreconditionExpression(value);
return this;
}

/**
* Setter for Body.
*
Expand Down
Expand Up @@ -51,6 +51,16 @@ public EdgeToolBuilder name(java.lang.String value) {
this.getEdgeTool().setName(value);
return this;
}
/**
* Setter for PreconditionExpression.
*
* @generated
*/
public EdgeToolBuilder preconditionExpression(java.lang.String value) {
this.getEdgeTool().setPreconditionExpression(value);
return this;
}

/**
* Setter for Body.
*
Expand Down
Expand Up @@ -51,6 +51,16 @@ public LabelEditToolBuilder name(java.lang.String value) {
this.getLabelEditTool().setName(value);
return this;
}
/**
* Setter for PreconditionExpression.
*
* @generated
*/
public LabelEditToolBuilder preconditionExpression(java.lang.String value) {
this.getLabelEditTool().setPreconditionExpression(value);
return this;
}

/**
* Setter for Body.
*
Expand Down
Expand Up @@ -51,6 +51,16 @@ public NodeToolBuilder name(java.lang.String value) {
this.getNodeTool().setName(value);
return this;
}
/**
* Setter for PreconditionExpression.
*
* @generated
*/
public NodeToolBuilder preconditionExpression(java.lang.String value) {
this.getNodeTool().setPreconditionExpression(value);
return this;
}

/**
* Setter for Body.
*
Expand Down
Expand Up @@ -51,6 +51,16 @@ public SourceEdgeEndReconnectionToolBuilder name(java.lang.String value) {
this.getSourceEdgeEndReconnectionTool().setName(value);
return this;
}
/**
* Setter for PreconditionExpression.
*
* @generated
*/
public SourceEdgeEndReconnectionToolBuilder preconditionExpression(java.lang.String value) {
this.getSourceEdgeEndReconnectionTool().setPreconditionExpression(value);
return this;
}

/**
* Setter for Body.
*
Expand Down
Expand Up @@ -51,6 +51,16 @@ public TargetEdgeEndReconnectionToolBuilder name(java.lang.String value) {
this.getTargetEdgeEndReconnectionTool().setName(value);
return this;
}
/**
* Setter for PreconditionExpression.
*
* @generated
*/
public TargetEdgeEndReconnectionToolBuilder preconditionExpression(java.lang.String value) {
this.getTargetEdgeEndReconnectionTool().setPreconditionExpression(value);
return this;
}

/**
* Setter for Body.
*
Expand Down
Expand Up @@ -35,6 +35,16 @@ public ToolBuilder name(java.lang.String value) {
this.getTool().setName(value);
return this;
}
/**
* Setter for PreconditionExpression.
*
* @generated
*/
public ToolBuilder preconditionExpression(java.lang.String value) {
this.getTool().setPreconditionExpression(value);
return this;
}

/**
* Setter for Body.
*
Expand Down
Expand Up @@ -61,6 +61,7 @@ public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
super.getPropertyDescriptors(object);

this.addNamePropertyDescriptor(object);
this.addPreconditionExpressionPropertyDescriptor(object);
}
return this.itemPropertyDescriptors;
}
Expand All @@ -76,6 +77,18 @@ protected void addNamePropertyDescriptor(Object object) {
false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}

/**
* This adds a property descriptor for the Precondition Expression feature. <!-- begin-user-doc --> <!--
* end-user-doc -->
*
* @generated
*/
protected void addPreconditionExpressionPropertyDescriptor(Object object) {
this.itemPropertyDescriptors.add(this.createItemPropertyDescriptor(((ComposeableAdapterFactory) this.adapterFactory).getRootAdapterFactory(), this.getResourceLocator(),
this.getString("_UI_Tool_preconditionExpression_feature"), this.getString("_UI_PropertyDescriptor_description", "_UI_Tool_preconditionExpression_feature", "_UI_Tool_type"),
DiagramPackage.Literals.TOOL__PRECONDITION_EXPRESSION, true, false, false, ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, null, null));
}

/**
* This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
* {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
Expand Down Expand Up @@ -140,6 +153,7 @@ public void notifyChanged(Notification notification) {

switch (notification.getFeatureID(Tool.class)) {
case DiagramPackage.TOOL__NAME:
case DiagramPackage.TOOL__PRECONDITION_EXPRESSION:
this.fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
return;
case DiagramPackage.TOOL__BODY:
Expand Down
Expand Up @@ -119,6 +119,7 @@ _UI_EdgePalette_nodeTools_feature = Node Tools
_UI_EdgePalette_edgeReconnectionTools_feature = Edge Reconnection Tools
_UI_EdgePalette_toolSections_feature = Tool Sections
_UI_Tool_name_feature = Name
_UI_Tool_preconditionExpression_feature = Precondition Expression
_UI_Tool_body_feature = Body
_UI_EdgeTool_targetElementDescriptions_feature = Target Element Descriptions
_UI_LabelEditTool_initialDirectEditLabelExpression_feature = Initial Direct Edit Label Expression
Expand Down

0 comments on commit e08ba13

Please sign in to comment.