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);
}
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);
}
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("");
}
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("");
}
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("");
}
Aggregations