Skip to content

Commit

Permalink
[4286] Make default explorer DnD work only for the default explorer
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#4286
Signed-off-by: Gwendal Daniel <[email protected]>
  • Loading branch information
gdaniel committed Dec 11, 2024
1 parent f262449 commit 2aab1f7
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> 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))
Expand Down

0 comments on commit 2aab1f7

Please sign in to comment.