Search in sources :

Example 1 with DiagramDescription

use of org.eclipse.sirius.diagram.description.DiagramDescription in project sirius-components by eclipse-sirius.

the class NavigationOperationHandlerTests method testMultipleChildModelOperationWithSelection.

@Test
public void testMultipleChildModelOperationWithSelection() {
    DiagramDescription firstDiagramDescription = DescriptionFactory.eINSTANCE.createDiagramDescription();
    firstDiagramDescription.setLabel(FIRST_DIAGRAM_DESCRIPTION_ID.toString());
    Navigation firstNavigation = ToolFactory.eINSTANCE.createNavigation();
    firstNavigation.setCreateIfNotExistent(false);
    firstNavigation.setDiagramDescription(firstDiagramDescription);
    DiagramDescription secondDiagramDescription = DescriptionFactory.eINSTANCE.createDiagramDescription();
    secondDiagramDescription.setLabel(SECOND_DIAGRAM_DESCRIPTION_ID.toString());
    Navigation secondNavigation = ToolFactory.eINSTANCE.createNavigation();
    secondNavigation.setCreateIfNotExistent(false);
    secondNavigation.setDiagramDescription(secondDiagramDescription);
    IStatus status = new ChildModelOperationHandler(List.of()).handle(new IObjectService.NoOp(), this.representationMetadataSearchService, this.diagramDescriptionIdentifierProvider, new AQLInterpreter(List.of(), List.of()), Map.of(IEditingContext.EDITING_CONTEXT, new IEditingContext.NoOp()), List.of(firstNavigation, secondNavigation));
    assertThat(status).isInstanceOf(Success.class);
    Success success = (Success) status;
    Object selectionParameter = success.getParameters().get(Success.NEW_SELECTION);
    assertThat(selectionParameter).isInstanceOf(WorkbenchSelection.class);
    WorkbenchSelection selection = (WorkbenchSelection) selectionParameter;
    // @formatter:off
    assertThat(selection).isEqualTo(new WorkbenchSelection(List.of(new WorkbenchSelectionEntry(FIRST_DIAGRAM_ID, FIRST_DIAGRAM_LABEL, Diagram.KIND), new WorkbenchSelectionEntry(SECOND_DIAGRAM_ID, SECOND_DIAGRAM_LABEL, Diagram.KIND), new WorkbenchSelectionEntry(THIRD_DIAGRAM_ID, THIRD_DIAGRAM_LABEL, Diagram.KIND))));
// @formatter:on
}
Also used : IStatus(org.eclipse.sirius.components.representations.IStatus) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Navigation(org.eclipse.sirius.diagram.description.tool.Navigation) WorkbenchSelectionEntry(org.eclipse.sirius.components.core.api.WorkbenchSelectionEntry) WorkbenchSelection(org.eclipse.sirius.components.core.api.WorkbenchSelection) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) DiagramDescription(org.eclipse.sirius.diagram.description.DiagramDescription) ChildModelOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler) Success(org.eclipse.sirius.components.representations.Success) Test(org.junit.jupiter.api.Test)

Example 2 with DiagramDescription

use of org.eclipse.sirius.diagram.description.DiagramDescription in project sirius-components by eclipse-sirius.

the class ToolProvider method getToolSections.

@Override
public List<ToolSection> getToolSections(Map<UUID, NodeDescription> id2NodeDescriptions, List<EdgeDescription> edgeDescriptions, DiagramDescription siriusDiagramDescription, List<Layer> layers) {
    List<ToolSection> result = new ArrayList<>();
    // @formatter:off
    var siriusToolSections = layers.stream().flatMap(layer -> layer.getToolSections().stream()).filter(org.eclipse.sirius.diagram.description.tool.ToolSection.class::isInstance).map(org.eclipse.sirius.diagram.description.tool.ToolSection.class::cast).collect(Collectors.toList());
    // @formatter:on
    AQLInterpreter interpreter = this.interpreterFactory.create(siriusDiagramDescription);
    for (var siriusToolSection : siriusToolSections) {
        // @formatter:off
        List<ITool> tools = this.getToolDescriptions(siriusToolSection).stream().filter(this::isSupported).map(toolDescription -> this.convertTool(id2NodeDescriptions, siriusDiagramDescription, toolDescription, interpreter)).flatMap(Optional::stream).collect(Collectors.toList());
        // @formatter:on
        if (!tools.isEmpty()) {
            ToolSection toolSection = this.convertToolSection(siriusToolSection, tools);
            result.add(toolSection);
        }
    }
    return result;
}
Also used : InitialOperation(org.eclipse.sirius.viewpoint.description.tool.InitialOperation) LayerSpec(org.eclipse.sirius.diagram.business.internal.metamodel.description.spec.LayerSpec) ToolDescription(org.eclipse.sirius.viewpoint.description.tool.ToolDescription) AbstractNodeMapping(org.eclipse.sirius.diagram.description.AbstractNodeMapping) Layer(org.eclipse.sirius.diagram.description.Layer) OperationAction(org.eclipse.sirius.viewpoint.description.tool.OperationAction) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) InitialNodeCreationOperation(org.eclipse.sirius.viewpoint.description.tool.InitialNodeCreationOperation) IToolImageProviderFactory(org.eclipse.sirius.components.compatibility.api.IToolImageProviderFactory) ToolSection(org.eclipse.sirius.components.diagrams.tools.ToolSection) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IStatus(org.eclipse.sirius.components.representations.IStatus) ITool(org.eclipse.sirius.components.diagrams.tools.ITool) Map(java.util.Map) AbstractToolDescription(org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription) ContainerMapping(org.eclipse.sirius.diagram.description.ContainerMapping) AdditionalLayer(org.eclipse.sirius.diagram.description.AdditionalLayer) DiagramDescription(org.eclipse.sirius.diagram.description.DiagramDescription) NodeCreationDescription(org.eclipse.sirius.diagram.description.tool.NodeCreationDescription) ToolGroup(org.eclipse.sirius.diagram.description.tool.ToolGroup) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) Collection(java.util.Collection) UUID(java.util.UUID) SelectModelElementVariableProvider(org.eclipse.sirius.components.compatibility.services.SelectModelElementVariableProvider) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) IdentifiedElementQuery(org.eclipse.sirius.business.api.query.IdentifiedElementQuery) Objects(java.util.Objects) DeleteElementDescription(org.eclipse.sirius.diagram.description.tool.DeleteElementDescription) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) SingleClickOnTwoDiagramElementsCandidate(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsCandidate) Stream(java.util.stream.Stream) Optional(java.util.Optional) ContainerCreationDescription(org.eclipse.sirius.diagram.description.tool.ContainerCreationDescription) Node(org.eclipse.sirius.components.diagrams.Node) EdgeMapping(org.eclipse.sirius.diagram.description.EdgeMapping) Function(java.util.function.Function) InitEdgeCreationOperation(org.eclipse.sirius.viewpoint.description.tool.InitEdgeCreationOperation) ArrayList(java.util.ArrayList) SingleClickOnDiagramElementTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool) Service(org.springframework.stereotype.Service) SingleClickOnTwoDiagramElementsTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool) EdgeCreationDescription(org.eclipse.sirius.diagram.description.tool.EdgeCreationDescription) IAQLInterpreterFactory(org.eclipse.sirius.components.compatibility.api.IAQLInterpreterFactory) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) DiagramElementMapping(org.eclipse.sirius.diagram.description.DiagramElementMapping) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) ArrayList(java.util.ArrayList) ITool(org.eclipse.sirius.components.diagrams.tools.ITool) ToolSection(org.eclipse.sirius.components.diagrams.tools.ToolSection)

Example 3 with DiagramDescription

use of org.eclipse.sirius.diagram.description.DiagramDescription in project sirius-components by eclipse-sirius.

the class NavigationOperationHandler method handle.

@Override
public IStatus handle(Map<String, Object> variables) {
    Success success = new Success();
    Object editingContextVariable = variables.get(IEditingContext.EDITING_CONTEXT);
    boolean createIfNotExistent = this.navigation.isCreateIfNotExistent();
    if (!createIfNotExistent && editingContextVariable instanceof IEditingContext) {
        IEditingContext editingContext = (IEditingContext) editingContextVariable;
        DiagramDescription diagramDescription = this.navigation.getDiagramDescription();
        String diagramDescriptionIdString = this.identifierProvider.getIdentifier(diagramDescription);
        UUID diagramDescriptionId = UUID.fromString(diagramDescriptionIdString);
        Object self = variables.get(VariableManager.SELF);
        String selfId = this.objectService.getId(self);
        // @formatter:off
        List<WorkbenchSelectionEntry> entries = this.representationMetadataSearchService.findAllByTargetObjectId(editingContext, selfId).stream().filter(representationMetadata -> representationMetadata.getDescriptionId().equals(diagramDescriptionId)).map(representationMetadata -> {
            String id = representationMetadata.getId();
            String label = representationMetadata.getLabel();
            String kind = representationMetadata.getKind();
            return new WorkbenchSelectionEntry(id, label, kind);
        }).collect(Collectors.toList());
        // @formatter:on
        if (!entries.isEmpty()) {
            WorkbenchSelection newSelection = new WorkbenchSelection(entries);
            success.getParameters().put(Success.NEW_SELECTION, newSelection);
        }
    }
    return success;
}
Also used : Navigation(org.eclipse.sirius.diagram.description.tool.Navigation) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Success(org.eclipse.sirius.components.representations.Success) UUID(java.util.UUID) IModelOperationHandler(org.eclipse.sirius.components.compatibility.api.IModelOperationHandler) WorkbenchSelection(org.eclipse.sirius.components.core.api.WorkbenchSelection) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) IRepresentationMetadataSearchService(org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService) Objects(java.util.Objects) List(java.util.List) IStatus(org.eclipse.sirius.components.representations.IStatus) Map(java.util.Map) WorkbenchSelectionEntry(org.eclipse.sirius.components.core.api.WorkbenchSelectionEntry) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) DiagramDescription(org.eclipse.sirius.diagram.description.DiagramDescription) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) WorkbenchSelectionEntry(org.eclipse.sirius.components.core.api.WorkbenchSelectionEntry) WorkbenchSelection(org.eclipse.sirius.components.core.api.WorkbenchSelection) UUID(java.util.UUID) DiagramDescription(org.eclipse.sirius.diagram.description.DiagramDescription) Success(org.eclipse.sirius.components.representations.Success)

Example 4 with DiagramDescription

use of org.eclipse.sirius.diagram.description.DiagramDescription in project sirius-components by eclipse-sirius.

the class DiagramDescriptionNodeAndEdgeDescriptionsPopulator method getDropHandler.

private Function<VariableManager, IStatus> getDropHandler(DiagramDescription siriusDiagramDescription, AQLInterpreter interpreter) {
    // @formatter:off
    List<ContainerDropDescription> diagramDropTools = siriusDiagramDescription.getAllTools().stream().filter(ContainerDropDescription.class::isInstance).map(ContainerDropDescription.class::cast).collect(Collectors.toList());
    // @formatter:on
    ToolConverter toolConverter = new ToolConverter(interpreter, this.editService, this.modelOperationHandlerSwitchProvider);
    return variableManager -> {
        Optional<EObject> optionalSelf = variableManager.get(VariableManager.SELF, EObject.class);
        Optional<IEditingContext> optionalEditingContext = variableManager.get(IEditingContext.EDITING_CONTEXT, IEditingContext.class);
        Optional<Diagram> optionalDiagram = variableManager.get(IDiagramContext.DIAGRAM_CONTEXT, IDiagramContext.class).map(IDiagramContext::getDiagram);
        Optional<Node> optionalSelectedNode = variableManager.get(Node.SELECTED_NODE, Node.class);
        if (optionalSelf.isPresent() && optionalEditingContext.isPresent()) {
            EObject self = optionalSelf.get();
            IEditingContext editingContext = optionalEditingContext.get();
            VariableManager childVariableManager = variableManager.createChild();
            Optional<Object> newViewContainer = optionalSelectedNode.map(Object.class::cast).or(() -> optionalDiagram);
            // @formatter:off
            Optional<Object> newContainer = optionalSelectedNode.map(Node::getTargetObjectId).or(() -> optionalDiagram.map(Diagram::getTargetObjectId)).flatMap(targetObjectId -> this.objectService.getObject(editingContext, targetObjectId));
            if (newContainer.isPresent() && newViewContainer.isPresent()) {
                childVariableManager.put(NEW_CONTAINER, newContainer.get());
                childVariableManager.put(NEW_VIEW_CONTAINER, newViewContainer.get());
                childVariableManager.put(ToolProvider.ELEMENT, self);
                Collection<ContainerDropDescription> candidates = new ArrayList<>();
                for (ContainerDropDescription dropTool : diagramDropTools) {
                    String precondition = dropTool.getPrecondition();
                    if (precondition != null && !precondition.trim().isBlank()) {
                        boolean result = interpreter.evaluateExpression(childVariableManager.getVariables(), precondition).asBoolean().orElse(false);
                        if (result) {
                            candidates.add(dropTool);
                        }
                    } else {
                        candidates.add(dropTool);
                    }
                }
                if (!candidates.isEmpty()) {
                    ContainerDropDescription dropToolDescription = candidates.iterator().next();
                    return toolConverter.createDropToolHandler(dropToolDescription).apply(childVariableManager);
                }
            }
        }
        // $NON-NLS-1$
        return new Failure("");
    };
}
Also used : AbstractNodeMappingConverter(org.eclipse.sirius.components.compatibility.diagrams.AbstractNodeMappingConverter) Node(org.eclipse.sirius.components.diagrams.Node) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EdgeMappingConverter(org.eclipse.sirius.components.compatibility.diagrams.EdgeMappingConverter) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) HashMap(java.util.HashMap) Layer(org.eclipse.sirius.diagram.description.Layer) Function(java.util.function.Function) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ArrayList(java.util.ArrayList) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IStatus(org.eclipse.sirius.components.representations.IStatus) Service(org.springframework.stereotype.Service) Map(java.util.Map) ToolConverter(org.eclipse.sirius.components.compatibility.diagrams.ToolConverter) AdditionalLayer(org.eclipse.sirius.diagram.description.AdditionalLayer) IEditService(org.eclipse.sirius.components.core.api.IEditService) DiagramDescription(org.eclipse.sirius.diagram.description.DiagramDescription) Builder(org.eclipse.sirius.components.diagrams.description.DiagramDescription.Builder) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) LayerHelper(org.eclipse.sirius.diagram.business.internal.metamodel.helper.LayerHelper) IModelOperationHandlerSwitchProvider(org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider) ContainerDropDescription(org.eclipse.sirius.diagram.description.tool.ContainerDropDescription) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Objects(java.util.Objects) List(java.util.List) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) ContainerMappingImport(org.eclipse.sirius.diagram.description.ContainerMappingImport) VariableManager(org.eclipse.sirius.components.representations.VariableManager) Optional(java.util.Optional) Node(org.eclipse.sirius.components.diagrams.Node) ToolConverter(org.eclipse.sirius.components.compatibility.diagrams.ToolConverter) ContainerDropDescription(org.eclipse.sirius.diagram.description.tool.ContainerDropDescription) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EObject(org.eclipse.emf.ecore.EObject) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) Failure(org.eclipse.sirius.components.representations.Failure)

Example 5 with DiagramDescription

use of org.eclipse.sirius.diagram.description.DiagramDescription in project sirius-components by eclipse-sirius.

the class NavigationOperationHandlerTests method testChildModelOperationWithSelection.

@Test
public void testChildModelOperationWithSelection() {
    DiagramDescription diagramDescription = DescriptionFactory.eINSTANCE.createDiagramDescription();
    diagramDescription.setLabel(FIRST_DIAGRAM_DESCRIPTION_ID.toString());
    Navigation navigation = ToolFactory.eINSTANCE.createNavigation();
    navigation.setCreateIfNotExistent(false);
    navigation.setDiagramDescription(diagramDescription);
    IStatus status = new ChildModelOperationHandler(List.of()).handle(new IObjectService.NoOp(), this.representationMetadataSearchService, this.diagramDescriptionIdentifierProvider, new AQLInterpreter(List.of(), List.of()), Map.of(IEditingContext.EDITING_CONTEXT, new IEditingContext.NoOp()), List.of(navigation));
    assertThat(status).isInstanceOf(Success.class);
    Success success = (Success) status;
    Object selectionParameter = success.getParameters().get(Success.NEW_SELECTION);
    assertThat(selectionParameter).isInstanceOf(WorkbenchSelection.class);
    WorkbenchSelection selection = (WorkbenchSelection) selectionParameter;
    // @formatter:off
    assertThat(selection).isEqualTo(new WorkbenchSelection(List.of(new WorkbenchSelectionEntry(FIRST_DIAGRAM_ID, FIRST_DIAGRAM_LABEL, Diagram.KIND), new WorkbenchSelectionEntry(SECOND_DIAGRAM_ID, SECOND_DIAGRAM_LABEL, Diagram.KIND))));
// @formatter:on
}
Also used : IStatus(org.eclipse.sirius.components.representations.IStatus) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Navigation(org.eclipse.sirius.diagram.description.tool.Navigation) WorkbenchSelectionEntry(org.eclipse.sirius.components.core.api.WorkbenchSelectionEntry) WorkbenchSelection(org.eclipse.sirius.components.core.api.WorkbenchSelection) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) DiagramDescription(org.eclipse.sirius.diagram.description.DiagramDescription) ChildModelOperationHandler(org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler) Success(org.eclipse.sirius.components.representations.Success) Test(org.junit.jupiter.api.Test)

Aggregations

AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)5 IStatus (org.eclipse.sirius.components.representations.IStatus)5 DiagramDescription (org.eclipse.sirius.diagram.description.DiagramDescription)5 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)4 Success (org.eclipse.sirius.components.representations.Success)4 List (java.util.List)3 Map (java.util.Map)3 Objects (java.util.Objects)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 WorkbenchSelection (org.eclipse.sirius.components.core.api.WorkbenchSelection)3 WorkbenchSelectionEntry (org.eclipse.sirius.components.core.api.WorkbenchSelectionEntry)3 VariableManager (org.eclipse.sirius.components.representations.VariableManager)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 Function (java.util.function.Function)2 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)2 IIdentifierProvider (org.eclipse.sirius.components.compatibility.api.IIdentifierProvider)2 IModelOperationHandlerSwitchProvider (org.eclipse.sirius.components.compatibility.api.IModelOperationHandlerSwitchProvider)2