Search in sources :

Example 1 with WorkbenchSelection

use of org.eclipse.sirius.components.core.api.WorkbenchSelection 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 WorkbenchSelection

use of org.eclipse.sirius.components.core.api.WorkbenchSelection in project sirius-components by eclipse-sirius.

the class InvokeSingleClickOnDiagramElementToolEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDiagramContext diagramContext, IDiagramInput diagramInput) {
    this.counter.increment();
    String message = this.messageService.invalidInput(diagramInput.getClass().getSimpleName(), InvokeSingleClickOnDiagramElementToolInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(diagramInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, diagramInput.getRepresentationId(), diagramInput);
    if (diagramInput instanceof InvokeSingleClickOnDiagramElementToolInput) {
        InvokeSingleClickOnDiagramElementToolInput input = (InvokeSingleClickOnDiagramElementToolInput) diagramInput;
        Diagram diagram = diagramContext.getDiagram();
        // @formatter:off
        var optionalTool = this.toolService.findToolById(editingContext, diagram, input.getToolId()).filter(SingleClickOnDiagramElementTool.class::isInstance).map(SingleClickOnDiagramElementTool.class::cast);
        // @formatter:on
        if (optionalTool.isPresent()) {
            IStatus status = this.executeTool(editingContext, diagramContext, input.getDiagramElementId(), optionalTool.get(), input.getStartingPositionX(), input.getStartingPositionY(), input.getSelectedObjectId());
            if (status instanceof Success) {
                WorkbenchSelection newSelection = null;
                Object newSelectionParameter = ((Success) status).getParameters().get(Success.NEW_SELECTION);
                if (newSelectionParameter instanceof WorkbenchSelection) {
                    newSelection = (WorkbenchSelection) newSelectionParameter;
                }
                payload = new InvokeSingleClickOnDiagramElementToolSuccessPayload(diagramInput.getId(), newSelection);
                changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, diagramInput.getRepresentationId(), diagramInput);
            } else if (status instanceof Failure) {
                payload = new ErrorPayload(diagramInput.getId(), ((Failure) status).getMessage());
            }
        }
    }
    payloadSink.tryEmitValue(payload);
    changeDescriptionSink.tryEmitNext(changeDescription);
}
Also used : InvokeSingleClickOnDiagramElementToolInput(org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolInput) IStatus(org.eclipse.sirius.components.representations.IStatus) WorkbenchSelection(org.eclipse.sirius.components.core.api.WorkbenchSelection) Success(org.eclipse.sirius.components.representations.Success) IPayload(org.eclipse.sirius.components.core.api.IPayload) Diagram(org.eclipse.sirius.components.diagrams.Diagram) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) SingleClickOnDiagramElementTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Failure(org.eclipse.sirius.components.representations.Failure) InvokeSingleClickOnDiagramElementToolSuccessPayload(org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolSuccessPayload)

Example 3 with WorkbenchSelection

use of org.eclipse.sirius.components.core.api.WorkbenchSelection in project sirius-components by eclipse-sirius.

the class ChildModelOperationHandler method handle.

public IStatus handle(IObjectService objectService, IRepresentationMetadataSearchService representationMetadataSearchService, IIdentifierProvider identifierProvider, AQLInterpreter interpreter, Map<String, Object> variables, List<ModelOperation> modelOperations) {
    Success success = new Success();
    boolean hasBeenSuccessfullyExecuted = true;
    ModelOperationHandlerSwitch modelOperationHandlerSwitch = new ModelOperationHandlerSwitch(objectService, representationMetadataSearchService, identifierProvider, this.externalJavaActionProviders, interpreter);
    for (ModelOperation modelOperation : modelOperations) {
        Optional<IModelOperationHandler> optionalModelOperationHandler = modelOperationHandlerSwitch.apply(modelOperation);
        IStatus status = optionalModelOperationHandler.map(handler -> {
            return handler.handle(variables);
        }).orElse(// $NON-NLS-1$
        new Failure(""));
        hasBeenSuccessfullyExecuted = hasBeenSuccessfullyExecuted && status instanceof Success;
        if (hasBeenSuccessfullyExecuted) {
            // @formatter:off
            var optionalChildModelOperationNewSelection = Optional.of(status).filter(Success.class::isInstance).map(Success.class::cast).map(result -> result.getParameters().get(Success.NEW_SELECTION)).filter(WorkbenchSelection.class::isInstance).map(WorkbenchSelection.class::cast);
            if (optionalChildModelOperationNewSelection.isPresent()) {
                WorkbenchSelection childWorkbenchSelection = optionalChildModelOperationNewSelection.get();
                Object newSelection = success.getParameters().get(Success.NEW_SELECTION);
                if (newSelection instanceof WorkbenchSelection) {
                    ((WorkbenchSelection) newSelection).getEntries().addAll(childWorkbenchSelection.getEntries());
                } else if (newSelection == null) {
                    success.getParameters().put(Success.NEW_SELECTION, new WorkbenchSelection(childWorkbenchSelection.getEntries()));
                }
            }
        }
    }
    if (hasBeenSuccessfullyExecuted) {
        return success;
    }
    // $NON-NLS-1$
    return new Failure("");
}
Also used : Failure(org.eclipse.sirius.components.representations.Failure) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) Success(org.eclipse.sirius.components.representations.Success) IModelOperationHandler(org.eclipse.sirius.components.compatibility.api.IModelOperationHandler) WorkbenchSelection(org.eclipse.sirius.components.core.api.WorkbenchSelection) 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) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) Map(java.util.Map) Optional(java.util.Optional) IExternalJavaActionProvider(org.eclipse.sirius.components.emf.compatibility.api.IExternalJavaActionProvider) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) IModelOperationHandler(org.eclipse.sirius.components.compatibility.api.IModelOperationHandler) IStatus(org.eclipse.sirius.components.representations.IStatus) ModelOperation(org.eclipse.sirius.viewpoint.description.tool.ModelOperation) WorkbenchSelection(org.eclipse.sirius.components.core.api.WorkbenchSelection) Success(org.eclipse.sirius.components.representations.Success) Failure(org.eclipse.sirius.components.representations.Failure)

Example 4 with WorkbenchSelection

use of org.eclipse.sirius.components.core.api.WorkbenchSelection in project sirius-components by eclipse-sirius.

the class InvokeSingleClickOnTwoDiagramElementsToolEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, IDiagramContext diagramContext, IDiagramInput diagramInput) {
    this.counter.increment();
    String message = this.messageService.invalidInput(diagramInput.getClass().getSimpleName(), InvokeSingleClickOnTwoDiagramElementsToolInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(diagramInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, diagramInput.getRepresentationId(), diagramInput);
    if (diagramInput instanceof InvokeSingleClickOnTwoDiagramElementsToolInput) {
        InvokeSingleClickOnTwoDiagramElementsToolInput input = (InvokeSingleClickOnTwoDiagramElementsToolInput) diagramInput;
        Diagram diagram = diagramContext.getDiagram();
        // @formatter:off
        var optionalTool = this.toolService.findToolById(editingContext, diagram, input.getToolId()).filter(SingleClickOnTwoDiagramElementsTool.class::isInstance).map(SingleClickOnTwoDiagramElementsTool.class::cast);
        // @formatter:on
        if (optionalTool.isPresent()) {
            Position sourcePosition = Position.at(input.getSourcePositionX(), input.getSourcePositionY());
            Position targetPosition = Position.at(input.getTargetPositionX(), input.getTargetPositionY());
            IStatus status = this.executeTool(editingContext, diagramContext, input.getDiagramSourceElementId(), input.getDiagramTargetElementId(), optionalTool.get(), sourcePosition, targetPosition);
            if (status instanceof Success) {
                WorkbenchSelection newSelection = null;
                Object newSelectionParameter = ((Success) status).getParameters().get(Success.NEW_SELECTION);
                if (newSelectionParameter instanceof WorkbenchSelection) {
                    newSelection = (WorkbenchSelection) newSelectionParameter;
                }
                payload = new InvokeSingleClickOnTwoDiagramElementsToolSuccessPayload(diagramInput.getId(), newSelection);
                changeDescription = new ChangeDescription(ChangeKind.SEMANTIC_CHANGE, diagramInput.getRepresentationId(), diagramInput);
            } else if (status instanceof Failure) {
                payload = new ErrorPayload(diagramInput.getId(), ((Failure) status).getMessage());
            }
        }
    }
    payloadSink.tryEmitValue(payload);
    changeDescriptionSink.tryEmitNext(changeDescription);
}
Also used : IStatus(org.eclipse.sirius.components.representations.IStatus) Position(org.eclipse.sirius.components.diagrams.Position) SingleClickOnTwoDiagramElementsTool(org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool) InvokeSingleClickOnTwoDiagramElementsToolInput(org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnTwoDiagramElementsToolInput) WorkbenchSelection(org.eclipse.sirius.components.core.api.WorkbenchSelection) InvokeSingleClickOnTwoDiagramElementsToolSuccessPayload(org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnTwoDiagramElementsToolSuccessPayload) Success(org.eclipse.sirius.components.representations.Success) IPayload(org.eclipse.sirius.components.core.api.IPayload) Diagram(org.eclipse.sirius.components.diagrams.Diagram) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Failure(org.eclipse.sirius.components.representations.Failure)

Example 5 with WorkbenchSelection

use of org.eclipse.sirius.components.core.api.WorkbenchSelection 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)

Aggregations

WorkbenchSelection (org.eclipse.sirius.components.core.api.WorkbenchSelection)6 IStatus (org.eclipse.sirius.components.representations.IStatus)6 Success (org.eclipse.sirius.components.representations.Success)6 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)4 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)4 WorkbenchSelectionEntry (org.eclipse.sirius.components.core.api.WorkbenchSelectionEntry)3 Failure (org.eclipse.sirius.components.representations.Failure)3 DiagramDescription (org.eclipse.sirius.diagram.description.DiagramDescription)3 Navigation (org.eclipse.sirius.diagram.description.tool.Navigation)3 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)2 IIdentifierProvider (org.eclipse.sirius.components.compatibility.api.IIdentifierProvider)2 IModelOperationHandler (org.eclipse.sirius.components.compatibility.api.IModelOperationHandler)2 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)2 IPayload (org.eclipse.sirius.components.core.api.IPayload)2 IRepresentationMetadataSearchService (org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService)2 Diagram (org.eclipse.sirius.components.diagrams.Diagram)2 ChildModelOperationHandler (org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler)2