Search in sources :

Example 1 with WorkbenchSelectionEntry

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

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

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

IObjectService (org.eclipse.sirius.components.core.api.IObjectService)3 WorkbenchSelection (org.eclipse.sirius.components.core.api.WorkbenchSelection)3 WorkbenchSelectionEntry (org.eclipse.sirius.components.core.api.WorkbenchSelectionEntry)3 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)3 IStatus (org.eclipse.sirius.components.representations.IStatus)3 Success (org.eclipse.sirius.components.representations.Success)3 DiagramDescription (org.eclipse.sirius.diagram.description.DiagramDescription)3 Navigation (org.eclipse.sirius.diagram.description.tool.Navigation)3 ChildModelOperationHandler (org.eclipse.sirius.components.emf.compatibility.modeloperations.ChildModelOperationHandler)2 Test (org.junit.jupiter.api.Test)2 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 IIdentifierProvider (org.eclipse.sirius.components.compatibility.api.IIdentifierProvider)1 IModelOperationHandler (org.eclipse.sirius.components.compatibility.api.IModelOperationHandler)1 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)1 IRepresentationMetadataSearchService (org.eclipse.sirius.components.core.api.IRepresentationMetadataSearchService)1 VariableManager (org.eclipse.sirius.components.representations.VariableManager)1