Search in sources :

Example 1 with TreeDescription

use of org.eclipse.sirius.components.trees.description.TreeDescription in project sirius-components by eclipse-sirius.

the class DeleteTreeItemEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, Tree tree, ITreeInput treeInput) {
    this.counter.increment();
    String message = this.messageService.invalidInput(treeInput.getClass().getSimpleName(), DeleteTreeItemInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(treeInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, treeInput.getRepresentationId(), treeInput);
    if (treeInput instanceof DeleteTreeItemInput) {
        DeleteTreeItemInput input = (DeleteTreeItemInput) treeInput;
        var optionalTreeItem = this.treeQueryService.findTreeItem(tree, input.getTreeItemId());
        if (optionalTreeItem.isPresent()) {
            TreeDescription treeDescription = this.explorerDescriptionProvider.getDescription();
            TreeItem treeItem = optionalTreeItem.get();
            VariableManager variableManager = new VariableManager();
            variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext);
            variableManager.put(TreeItem.SELECTED_TREE_ITEM, treeItem);
            var status = treeDescription.getDeleteHandler().apply(variableManager);
            if (status instanceof Success) {
                Success success = (Success) status;
                changeDescription = new ChangeDescription(success.getChangeKind(), treeInput.getRepresentationId(), treeInput, success.getParameters());
                payload = new DeleteTreeItemSuccessPayload(treeInput.getId());
            } else if (status instanceof Failure) {
                payload = new ErrorPayload(treeInput.getId(), ((Failure) status).getMessage());
            }
        }
    }
    changeDescriptionSink.tryEmitNext(changeDescription);
    payloadSink.tryEmitValue(payload);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) DeleteTreeItemInput(org.eclipse.sirius.components.collaborative.trees.dto.DeleteTreeItemInput) TreeItem(org.eclipse.sirius.components.trees.TreeItem) DeleteTreeItemSuccessPayload(org.eclipse.sirius.components.collaborative.trees.dto.DeleteTreeItemSuccessPayload) TreeDescription(org.eclipse.sirius.components.trees.description.TreeDescription) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Success(org.eclipse.sirius.components.representations.Success) Failure(org.eclipse.sirius.components.representations.Failure) IPayload(org.eclipse.sirius.components.core.api.IPayload)

Example 2 with TreeDescription

use of org.eclipse.sirius.components.trees.description.TreeDescription in project sirius-components by eclipse-sirius.

the class RenameTreeItemEventHandler method handle.

@Override
public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDescriptionSink, IEditingContext editingContext, Tree tree, ITreeInput treeInput) {
    this.counter.increment();
    String message = this.messageService.invalidInput(treeInput.getClass().getSimpleName(), DeleteTreeItemInput.class.getSimpleName());
    IPayload payload = new ErrorPayload(treeInput.getId(), message);
    ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, treeInput.getRepresentationId(), treeInput);
    if (treeInput instanceof RenameTreeItemInput) {
        RenameTreeItemInput input = (RenameTreeItemInput) treeInput;
        var optionalTreeItem = this.treeQueryService.findTreeItem(tree, input.getTreeItemId());
        if (optionalTreeItem.isPresent()) {
            TreeDescription treeDescription = this.explorerDescriptionProvider.getDescription();
            TreeItem treeItem = optionalTreeItem.get();
            VariableManager variableManager = new VariableManager();
            variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext);
            variableManager.put(TreeItem.SELECTED_TREE_ITEM, treeItem);
            var status = treeDescription.getRenameHandler().apply(variableManager, input.getNewLabel());
            if (status instanceof Success) {
                Success success = (Success) status;
                changeDescription = new ChangeDescription(success.getChangeKind(), treeInput.getRepresentationId(), treeInput, success.getParameters());
                payload = new RenameTreeItemSuccessPayload(treeInput.getId());
            } else if (status instanceof Failure) {
                payload = new ErrorPayload(treeInput.getId(), ((Failure) status).getMessage());
            }
        }
    }
    changeDescriptionSink.tryEmitNext(changeDescription);
    payloadSink.tryEmitValue(payload);
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) RenameTreeItemInput(org.eclipse.sirius.components.collaborative.trees.dto.RenameTreeItemInput) TreeItem(org.eclipse.sirius.components.trees.TreeItem) RenameTreeItemSuccessPayload(org.eclipse.sirius.components.collaborative.trees.dto.RenameTreeItemSuccessPayload) Success(org.eclipse.sirius.components.representations.Success) IPayload(org.eclipse.sirius.components.core.api.IPayload) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) DeleteTreeItemInput(org.eclipse.sirius.components.collaborative.trees.dto.DeleteTreeItemInput) TreeDescription(org.eclipse.sirius.components.trees.description.TreeDescription) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) Failure(org.eclipse.sirius.components.representations.Failure)

Example 3 with TreeDescription

use of org.eclipse.sirius.components.trees.description.TreeDescription in project sirius-components by eclipse-sirius.

the class TreeEventProcessorFactory method createRepresentationEventProcessor.

@Override
public <T extends IRepresentationEventProcessor> Optional<T> createRepresentationEventProcessor(Class<T> representationEventProcessorClass, IRepresentationConfiguration configuration, IEditingContext editingContext) {
    if (ITreeEventProcessor.class.isAssignableFrom(representationEventProcessorClass) && configuration instanceof TreeConfiguration) {
        TreeConfiguration treeConfiguration = (TreeConfiguration) configuration;
        TreeDescription treeDescription = this.explorerDescriptionProvider.getDescription();
        // @formatter:off
        TreeCreationParameters treeCreationParameters = TreeCreationParameters.newTreeCreationParameters(treeConfiguration.getId()).treeDescription(treeDescription).expanded(treeConfiguration.getExpanded()).editingContext(editingContext).build();
        // @formatter:on
        IRepresentationEventProcessor treeEventProcessor = new TreeEventProcessor(editingContext, this.treeService, treeCreationParameters, this.treeEventHandlers, this.subscriptionManagerFactory.create(), new SimpleMeterRegistry(), this.representationRefreshPolicyRegistry);
        // @formatter:off
        return Optional.of(treeEventProcessor).filter(representationEventProcessorClass::isInstance).map(representationEventProcessorClass::cast);
    // @formatter:on
    }
    return Optional.empty();
}
Also used : TreeCreationParameters(org.eclipse.sirius.components.collaborative.trees.api.TreeCreationParameters) ITreeEventProcessor(org.eclipse.sirius.components.collaborative.trees.api.ITreeEventProcessor) TreeDescription(org.eclipse.sirius.components.trees.description.TreeDescription) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ITreeEventProcessor(org.eclipse.sirius.components.collaborative.trees.api.ITreeEventProcessor) TreeConfiguration(org.eclipse.sirius.components.collaborative.trees.api.TreeConfiguration) IRepresentationEventProcessor(org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor)

Aggregations

TreeDescription (org.eclipse.sirius.components.trees.description.TreeDescription)3 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)2 DeleteTreeItemInput (org.eclipse.sirius.components.collaborative.trees.dto.DeleteTreeItemInput)2 ErrorPayload (org.eclipse.sirius.components.core.api.ErrorPayload)2 IPayload (org.eclipse.sirius.components.core.api.IPayload)2 Failure (org.eclipse.sirius.components.representations.Failure)2 Success (org.eclipse.sirius.components.representations.Success)2 VariableManager (org.eclipse.sirius.components.representations.VariableManager)2 TreeItem (org.eclipse.sirius.components.trees.TreeItem)2 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 IRepresentationEventProcessor (org.eclipse.sirius.components.collaborative.api.IRepresentationEventProcessor)1 ITreeEventProcessor (org.eclipse.sirius.components.collaborative.trees.api.ITreeEventProcessor)1 TreeConfiguration (org.eclipse.sirius.components.collaborative.trees.api.TreeConfiguration)1 TreeCreationParameters (org.eclipse.sirius.components.collaborative.trees.api.TreeCreationParameters)1 DeleteTreeItemSuccessPayload (org.eclipse.sirius.components.collaborative.trees.dto.DeleteTreeItemSuccessPayload)1 RenameTreeItemInput (org.eclipse.sirius.components.collaborative.trees.dto.RenameTreeItemInput)1 RenameTreeItemSuccessPayload (org.eclipse.sirius.components.collaborative.trees.dto.RenameTreeItemSuccessPayload)1