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
}
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;
}
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
}
Aggregations