Search in sources :

Example 1 with TreeItem

use of org.eclipse.sirius.components.trees.TreeItem 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 TreeItem

use of org.eclipse.sirius.components.trees.TreeItem 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 TreeItem

use of org.eclipse.sirius.components.trees.TreeItem in project sirius-web by eclipse-sirius.

the class DeleteDocumentTreeItemEventHandler method handle.

@Override
public IStatus handle(IEditingContext editingContext, TreeItem treeItem) {
    // @formatter:off
    var optionalEditingDomain = Optional.of(editingContext).filter(EditingContext.class::isInstance).map(EditingContext.class::cast).map(EditingContext::getDomain);
    // @formatter:on
    var optionalDocumentEntity = new IDParser().parse(treeItem.getId()).flatMap(this.documentRepository::findById);
    if (optionalEditingDomain.isPresent() && optionalDocumentEntity.isPresent()) {
        AdapterFactoryEditingDomain editingDomain = optionalEditingDomain.get();
        DocumentEntity documentEntity = optionalDocumentEntity.get();
        ResourceSet resourceSet = editingDomain.getResourceSet();
        URI uri = URI.createURI(documentEntity.getId().toString());
        // @formatter:off
        List<Resource> resourcesToDelete = resourceSet.getResources().stream().filter(resource -> resource.getURI().equals(uri)).collect(Collectors.toUnmodifiableList());
        resourcesToDelete.stream().forEach(resourceSet.getResources()::remove);
        // @formatter:on
        this.documentRepository.delete(documentEntity);
        return new Success(ChangeKind.SEMANTIC_CHANGE, Map.of());
    }
    // $NON-NLS-1$
    return new Failure("");
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) URI(org.eclipse.emf.common.util.URI) Failure(org.eclipse.sirius.components.representations.Failure) IDParser(org.eclipse.sirius.web.services.api.id.IDParser) Success(org.eclipse.sirius.components.representations.Success) TreeItem(org.eclipse.sirius.components.trees.TreeItem) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Objects(java.util.Objects) List(java.util.List) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IStatus(org.eclipse.sirius.components.representations.IStatus) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) IDeleteTreeItemHandler(org.eclipse.sirius.web.services.explorer.api.IDeleteTreeItemHandler) Service(org.springframework.stereotype.Service) Map(java.util.Map) Resource(org.eclipse.emf.ecore.resource.Resource) Optional(java.util.Optional) AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IDParser(org.eclipse.sirius.web.services.api.id.IDParser) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) Success(org.eclipse.sirius.components.representations.Success) Failure(org.eclipse.sirius.components.representations.Failure)

Example 4 with TreeItem

use of org.eclipse.sirius.components.trees.TreeItem in project sirius-web by eclipse-sirius.

the class ExplorerDescriptionProvider method getDeleteHandler.

private IStatus getDeleteHandler(VariableManager variableManager) {
    var optionalEditingContext = variableManager.get(IEditingContext.EDITING_CONTEXT, IEditingContext.class);
    var optionalTreeItem = variableManager.get(TreeItem.SELECTED_TREE_ITEM, TreeItem.class);
    if (optionalEditingContext.isPresent() && optionalTreeItem.isPresent()) {
        IEditingContext editingContext = optionalEditingContext.get();
        TreeItem treeItem = optionalTreeItem.get();
        // @formatter:off
        var optionalHandler = this.deleteTreeItemHandlers.stream().filter(handler -> handler.canHandle(editingContext, treeItem)).findFirst();
        if (optionalHandler.isPresent()) {
            IDeleteTreeItemHandler deleteTreeItemHandler = optionalHandler.get();
            return deleteTreeItemHandler.handle(editingContext, treeItem);
        }
    }
    // $NON-NLS-1$
    return new Failure("");
}
Also used : IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) IRenameTreeItemHandler(org.eclipse.sirius.web.services.explorer.api.IRenameTreeItemHandler) IKindParser(org.eclipse.sirius.components.core.api.IKindParser) TreeRenderer(org.eclipse.sirius.components.trees.renderer.TreeRenderer) ArrayList(java.util.ArrayList) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) IExplorerDescriptionProvider(org.eclipse.sirius.components.collaborative.trees.api.IExplorerDescriptionProvider) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IStatus(org.eclipse.sirius.components.representations.IStatus) IDeleteTreeItemHandler(org.eclipse.sirius.web.services.explorer.api.IDeleteTreeItemHandler) Service(org.springframework.stereotype.Service) RepresentationMetadata(org.eclipse.sirius.components.core.RepresentationMetadata) TreeDescription(org.eclipse.sirius.components.trees.description.TreeDescription) SemanticKindConstants(org.eclipse.sirius.components.core.api.SemanticKindConstants) Failure(org.eclipse.sirius.components.representations.Failure) Predicate(java.util.function.Predicate) EObject(org.eclipse.emf.ecore.EObject) TreeItem(org.eclipse.sirius.components.trees.TreeItem) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IRepresentationService(org.eclipse.sirius.web.services.api.representations.IRepresentationService) Objects(java.util.Objects) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) Resource(org.eclipse.emf.ecore.resource.Resource) ImageConstants(org.eclipse.sirius.components.compatibility.services.ImageConstants) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IRepresentationImageProvider(org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) TreeItem(org.eclipse.sirius.components.trees.TreeItem) IDeleteTreeItemHandler(org.eclipse.sirius.web.services.explorer.api.IDeleteTreeItemHandler) Failure(org.eclipse.sirius.components.representations.Failure)

Example 5 with TreeItem

use of org.eclipse.sirius.components.trees.TreeItem in project sirius-web by eclipse-sirius.

the class ExplorerDescriptionProvider method getRenameHandler.

private IStatus getRenameHandler(VariableManager variableManager, String newLabel) {
    var optionalEditingContext = variableManager.get(IEditingContext.EDITING_CONTEXT, IEditingContext.class);
    var optionalTreeItem = variableManager.get(TreeItem.SELECTED_TREE_ITEM, TreeItem.class);
    if (optionalEditingContext.isPresent() && optionalTreeItem.isPresent()) {
        IEditingContext editingContext = optionalEditingContext.get();
        TreeItem treeItem = optionalTreeItem.get();
        // @formatter:off
        var optionalHandler = this.renameTreeItemHandlers.stream().filter(handler -> handler.canHandle(editingContext, treeItem, newLabel)).findFirst();
        if (optionalHandler.isPresent()) {
            IRenameTreeItemHandler renameTreeItemHandler = optionalHandler.get();
            return renameTreeItemHandler.handle(editingContext, treeItem, newLabel);
        }
    }
    // $NON-NLS-1$
    return new Failure("");
}
Also used : IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) IRenameTreeItemHandler(org.eclipse.sirius.web.services.explorer.api.IRenameTreeItemHandler) IKindParser(org.eclipse.sirius.components.core.api.IKindParser) TreeRenderer(org.eclipse.sirius.components.trees.renderer.TreeRenderer) ArrayList(java.util.ArrayList) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) IExplorerDescriptionProvider(org.eclipse.sirius.components.collaborative.trees.api.IExplorerDescriptionProvider) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IStatus(org.eclipse.sirius.components.representations.IStatus) IDeleteTreeItemHandler(org.eclipse.sirius.web.services.explorer.api.IDeleteTreeItemHandler) Service(org.springframework.stereotype.Service) RepresentationMetadata(org.eclipse.sirius.components.core.RepresentationMetadata) TreeDescription(org.eclipse.sirius.components.trees.description.TreeDescription) SemanticKindConstants(org.eclipse.sirius.components.core.api.SemanticKindConstants) Failure(org.eclipse.sirius.components.representations.Failure) Predicate(java.util.function.Predicate) EObject(org.eclipse.emf.ecore.EObject) TreeItem(org.eclipse.sirius.components.trees.TreeItem) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IRepresentationService(org.eclipse.sirius.web.services.api.representations.IRepresentationService) Objects(java.util.Objects) List(java.util.List) GetOrCreateRandomIdProvider(org.eclipse.sirius.components.representations.GetOrCreateRandomIdProvider) Resource(org.eclipse.emf.ecore.resource.Resource) ImageConstants(org.eclipse.sirius.components.compatibility.services.ImageConstants) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IRepresentationImageProvider(org.eclipse.sirius.components.collaborative.api.IRepresentationImageProvider) IRenameTreeItemHandler(org.eclipse.sirius.web.services.explorer.api.IRenameTreeItemHandler) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) TreeItem(org.eclipse.sirius.components.trees.TreeItem) Failure(org.eclipse.sirius.components.representations.Failure)

Aggregations

TreeItem (org.eclipse.sirius.components.trees.TreeItem)7 VariableManager (org.eclipse.sirius.components.representations.VariableManager)6 Failure (org.eclipse.sirius.components.representations.Failure)5 ArrayList (java.util.ArrayList)4 TreeDescription (org.eclipse.sirius.components.trees.description.TreeDescription)4 List (java.util.List)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)3 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)3 IStatus (org.eclipse.sirius.components.representations.IStatus)3 Success (org.eclipse.sirius.components.representations.Success)3 IDeleteTreeItemHandler (org.eclipse.sirius.web.services.explorer.api.IDeleteTreeItemHandler)3 Service (org.springframework.stereotype.Service)3 UUID (java.util.UUID)2 Predicate (java.util.function.Predicate)2 EObject (org.eclipse.emf.ecore.EObject)2 EditingDomain (org.eclipse.emf.edit.domain.EditingDomain)2