From 2aab1f72b5fc83c5425b714032f2e10966041384 Mon Sep 17 00:00:00 2001 From: Gwendal Daniel Date: Wed, 11 Dec 2024 16:57:23 +0100 Subject: [PATCH] [4286] Make default explorer DnD work only for the default explorer Bug: https://github.com/eclipse-sirius/sirius-web/issues/4286 Signed-off-by: Gwendal Daniel --- CHANGELOG.adoc | 2 + .../DomainDropTreeItemHandler.java | 54 +++++++++++++++++++ .../services/ExplorerDropTreeItemHandler.java | 5 +- .../trees/api/IDropTreeItemHandler.java | 2 +- .../handlers/DropTreeItemEventHandler.java | 2 +- 5 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/studio/services/representations/DomainDropTreeItemHandler.java diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 1579e3149a9..863f692338c 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -103,6 +103,8 @@ This is now fixed. - https://github.com/eclipse-sirius/sirius-web/issues/4234[#4234] [table] Make table's row resizable - https://github.com/eclipse-sirius/sirius-web/issues/4254[#4254] [sirius-web] Make explorer services reusable - https://github.com/eclipse-sirius/sirius-web/issues/4264[#4264] [table] Reset all custom rows height +- https://github.com/eclipse-sirius/sirius-web/issues/4286[#4286] [sirius-web] Make default explorer drag and drop work only for the default explorer +Downstream applications with a custom explorer that relies on `ExplorerDropTreeItemHandler` now need to provide their own `IDropTreeItemHandler` to support drag and drop in their explorer. == v2024.11.0 diff --git a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/studio/services/representations/DomainDropTreeItemHandler.java b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/studio/services/representations/DomainDropTreeItemHandler.java new file mode 100644 index 00000000000..f2b6ea72e0b --- /dev/null +++ b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/studio/services/representations/DomainDropTreeItemHandler.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2024 Obeo. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.web.application.studio.services.representations; + +import org.eclipse.sirius.components.collaborative.trees.api.IDropTreeItemHandler; +import org.eclipse.sirius.components.core.api.IEditingContext; +import org.eclipse.sirius.components.core.api.IObjectService; +import org.eclipse.sirius.components.trees.Tree; +import org.eclipse.sirius.components.view.emf.IRepresentationDescriptionIdProvider; +import org.eclipse.sirius.components.view.emf.IViewRepresentationDescriptionSearchService; +import org.eclipse.sirius.web.application.views.explorer.services.ExplorerDescriptionProvider; +import org.eclipse.sirius.web.application.views.explorer.services.ExplorerDropTreeItemHandler; +import org.eclipse.sirius.web.domain.services.api.IMessageService; +import org.springframework.stereotype.Service; + +/** + * Provides the drop tree item tool for the Domain explorer by DSL explorer. + * + * @author gdaniel + */ +@Service +public class DomainDropTreeItemHandler extends ExplorerDropTreeItemHandler implements IDropTreeItemHandler { + + private final IViewRepresentationDescriptionSearchService viewRepresentationDescriptionSearchService; + + public DomainDropTreeItemHandler(IObjectService objectService, IMessageService messageService, IViewRepresentationDescriptionSearchService viewRepresentationDescriptionSearchService) { + super(objectService, messageService); + this.viewRepresentationDescriptionSearchService = viewRepresentationDescriptionSearchService; + } + + @Override + public boolean canHandle(IEditingContext editingContext, Tree tree) { + boolean result = false; + if (tree.getId().startsWith(ExplorerDescriptionProvider.PREFIX) + && tree.getDescriptionId().startsWith(IRepresentationDescriptionIdProvider.PREFIX)) { + var optionalViewTreeDescription = this.viewRepresentationDescriptionSearchService.findById(editingContext, tree.getDescriptionId()); + if (optionalViewTreeDescription.isPresent()) { + result = optionalViewTreeDescription.get().getName().equals(DomainViewTreeDescriptionProvider.DOMAIN_EXPLORER_DESCRIPTION_NAME); + } + } + return result; + } + +} diff --git a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/ExplorerDropTreeItemHandler.java b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/ExplorerDropTreeItemHandler.java index 4c939080f88..547d91ccbab 100644 --- a/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/ExplorerDropTreeItemHandler.java +++ b/packages/sirius-web/backend/sirius-web-application/src/main/java/org/eclipse/sirius/web/application/views/explorer/services/ExplorerDropTreeItemHandler.java @@ -54,8 +54,9 @@ public ExplorerDropTreeItemHandler(IObjectService objectService, IMessageService } @Override - public boolean canHandle(Tree tree) { - return tree.getId().startsWith(ExplorerDescriptionProvider.PREFIX); + public boolean canHandle(IEditingContext editingContext, Tree tree) { + return tree.getId().startsWith(ExplorerDescriptionProvider.PREFIX) + && Objects.equals(tree.getDescriptionId(), ExplorerDescriptionProvider.DESCRIPTION_ID); } @Override diff --git a/packages/trees/backend/sirius-components-collaborative-trees/src/main/java/org/eclipse/sirius/components/collaborative/trees/api/IDropTreeItemHandler.java b/packages/trees/backend/sirius-components-collaborative-trees/src/main/java/org/eclipse/sirius/components/collaborative/trees/api/IDropTreeItemHandler.java index 21f97080131..5a5724e6905 100644 --- a/packages/trees/backend/sirius-components-collaborative-trees/src/main/java/org/eclipse/sirius/components/collaborative/trees/api/IDropTreeItemHandler.java +++ b/packages/trees/backend/sirius-components-collaborative-trees/src/main/java/org/eclipse/sirius/components/collaborative/trees/api/IDropTreeItemHandler.java @@ -24,7 +24,7 @@ */ public interface IDropTreeItemHandler { - boolean canHandle(Tree tree); + boolean canHandle(IEditingContext editingContext, Tree tree); IStatus handle(IEditingContext editingContext, Tree tree, DropTreeItemInput input); diff --git a/packages/trees/backend/sirius-components-collaborative-trees/src/main/java/org/eclipse/sirius/components/collaborative/trees/handlers/DropTreeItemEventHandler.java b/packages/trees/backend/sirius-components-collaborative-trees/src/main/java/org/eclipse/sirius/components/collaborative/trees/handlers/DropTreeItemEventHandler.java index 227657dc856..acde8c35f4e 100644 --- a/packages/trees/backend/sirius-components-collaborative-trees/src/main/java/org/eclipse/sirius/components/collaborative/trees/handlers/DropTreeItemEventHandler.java +++ b/packages/trees/backend/sirius-components-collaborative-trees/src/main/java/org/eclipse/sirius/components/collaborative/trees/handlers/DropTreeItemEventHandler.java @@ -74,7 +74,7 @@ public void handle(One payloadSink, Many changeDesc ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, treeInput.representationId(), treeInput); if (treeInput instanceof DropTreeItemInput input) { - var optionalDropHandler = this.dropTreeItemHandlers.stream().filter(provider -> provider.canHandle(tree)).findFirst(); + var optionalDropHandler = this.dropTreeItemHandlers.stream().filter(provider -> provider.canHandle(editingContext, tree)).findFirst(); var status = optionalDropHandler .map(provider -> provider.handle(editingContext, tree, input))