Search in sources :

Example 1 with SelectionDescription

use of org.eclipse.sirius.components.selection.description.SelectionDescription in project sirius-components by eclipse-sirius.

the class SelectionEventProcessorFactory method createRepresentationEventProcessor.

@Override
public <T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration, IEditingContext editingContext) {
    if (ISelectionEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof SelectionConfiguration) {
        SelectionConfiguration selectionConfiguration = (SelectionConfiguration) configuration;
        // @formatter:off
        Optional<SelectionDescription> optionalSelectionDescription = this.representationDescriptionSearchService.findById(editingContext, selectionConfiguration.getSelectionId()).filter(SelectionDescription.class::isInstance).map(SelectionDescription.class::cast);
        // @formatter:on
        Optional<Object> optionalObject = this.objectService.getObject(editingContext, selectionConfiguration.getTargetObjectId());
        if (optionalSelectionDescription.isPresent() && optionalObject.isPresent()) {
            SelectionDescription selectionDescription = optionalSelectionDescription.get();
            Object object = optionalObject.get();
            IRepresentationEventProcessor selectionEventProcessor = new SelectionEventProcessor(editingContext, selectionDescription, selectionConfiguration.getId(), object, this.subscriptionManagerFactory.create(), this.representationRefreshPolicyRegistry);
            // @formatter:off
            return Optional.of(selectionEventProcessor).filter(representationEventProcessorClass::isInstance).map(representationEventProcessorClass::cast);
        // @formatter:on
        }
    }
    return Optional.empty();
}
Also used : ISelectionEventProcessor(org.eclipse.sirius.components.collaborative.selection.api.ISelectionEventProcessor) SelectionDescription(org.eclipse.sirius.components.selection.description.SelectionDescription) SelectionConfiguration(org.eclipse.sirius.components.collaborative.selection.api.SelectionConfiguration) ISelectionEventProcessor(org.eclipse.sirius.components.collaborative.selection.api.ISelectionEventProcessor) IRepresentationEventProcessor(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor)

Example 2 with SelectionDescription

use of org.eclipse.sirius.components.selection.description.SelectionDescription in project sirius-components by eclipse-sirius.

the class SelectModelElementVariableConverter method convert.

@Override
public SelectionDescription convert(SelectModelElementVariable selectModelElementVariable, org.eclipse.sirius.diagram.description.DiagramDescription diagramDescription) {
    AQLInterpreter interpreter = this.interpreterFactory.create(diagramDescription);
    // @formatter:off
    SelectionDescription selectionDescription = SelectionDescription.newSelectionDescription(UUID.fromString(this.identifierProvider.getIdentifier(selectModelElementVariable))).objectsProvider(variableManager -> {
        Result result = interpreter.evaluateExpression(variableManager.getVariables(), selectModelElementVariable.getCandidatesExpression());
        return result.asObjects().orElse(List.of()).stream().filter(Objects::nonNull).collect(Collectors.toList());
    }).messageProvider(variableManager -> {
        String message = selectModelElementVariable.getMessage();
        if (message == null) {
            // $NON-NLS-1$
            message = "";
        }
        return message;
    }).idProvider(new GetOrCreateRandomIdProvider()).labelProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getLabel).orElse(null)).iconURLProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getImagePath).orElse(null)).targetObjectIdProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getId).orElse(null)).selectionObjectsIdProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getId).orElse(null)).label(// $NON-NLS-1$
    "Selection Description").canCreatePredicate(variableManager -> false).build();
    // @formatter:on
    return selectionDescription;
}
Also used : IObjectService(org.eclipse.sirius.components.core.api.IObjectService) SelectModelElementVariable(org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable) Result(org.eclipse.sirius.components.interpreter.Result) SelectionDescription(org.eclipse.sirius.components.selection.description.SelectionDescription) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Objects(java.util.Objects) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) Service(org.springframework.stereotype.Service) ISelectModelElementVariableConverter(org.eclipse.sirius.components.compatibility.services.selection.api.ISelectModelElementVariableConverter) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IIdentifierProvider(org.eclipse.sirius.components.compatibility.api.IIdentifierProvider) IAQLInterpreterFactory(org.eclipse.sirius.components.compatibility.api.IAQLInterpreterFactory) SelectionDescription(org.eclipse.sirius.components.selection.description.SelectionDescription) AQLInterpreter(org.eclipse.sirius.components.interpreter.AQLInterpreter) Objects(java.util.Objects) Result(org.eclipse.sirius.components.interpreter.Result) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider)

Aggregations

SelectionDescription (org.eclipse.sirius.components.selection.description.SelectionDescription)2 List (java.util.List)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 IRepresentationEventProcessor (org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor)1 ISelectionEventProcessor (org.eclipse.sirius.components.collaborative.selection.api.ISelectionEventProcessor)1 SelectionConfiguration (org.eclipse.sirius.components.collaborative.selection.api.SelectionConfiguration)1 IAQLInterpreterFactory (org.eclipse.sirius.components.compatibility.api.IAQLInterpreterFactory)1 IIdentifierProvider (org.eclipse.sirius.components.compatibility.api.IIdentifierProvider)1 ISelectModelElementVariableConverter (org.eclipse.sirius.components.compatibility.services.selection.api.ISelectModelElementVariableConverter)1 IObjectService (org.eclipse.sirius.components.core.api.IObjectService)1 AQLInterpreter (org.eclipse.sirius.components.interpreter.AQLInterpreter)1 Result (org.eclipse.sirius.components.interpreter.Result)1 GetOrCreateRandomIdProvider (org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider)1 VariableManager (org.eclipse.sirius.components.representations.VariableManager)1 SelectModelElementVariable (org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable)1 Service (org.springframework.stereotype.Service)1