Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2581] Add a new API to provide a reference position handler for cust…
…om tool Bug: #2581 Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
- Loading branch information
1 parent
12e1e10
commit aae6c6d
Showing
9 changed files
with
147 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../sirius/components/collaborative/diagrams/api/IDiagramInputReferencePositionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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.components.collaborative.diagrams.api; | ||
|
||
import org.eclipse.sirius.components.collaborative.diagrams.dto.ReferencePosition; | ||
import org.eclipse.sirius.components.core.api.IInput; | ||
|
||
/** | ||
* Provides diagram input reference position for a diagram. | ||
* | ||
* @author frouene | ||
*/ | ||
public interface IDiagramInputReferencePositionProvider { | ||
|
||
boolean canHandle(IInput diagramInput); | ||
|
||
ReferencePosition getReferencePosition(IInput diagramInput, IDiagramContext diagramContext); | ||
} |
54 changes: 54 additions & 0 deletions
54
...ponents/collaborative/diagrams/providers/GenericDiagramToolReferencePositionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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.components.collaborative.diagrams.providers; | ||
|
||
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext; | ||
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInputReferencePositionProvider; | ||
import org.eclipse.sirius.components.collaborative.diagrams.dto.DropNodeInput; | ||
import org.eclipse.sirius.components.collaborative.diagrams.dto.DropOnDiagramInput; | ||
import org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolInput; | ||
import org.eclipse.sirius.components.collaborative.diagrams.dto.ReferencePosition; | ||
import org.eclipse.sirius.components.core.api.IInput; | ||
import org.eclipse.sirius.components.diagrams.layoutdata.Position; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Provider use to retrieve the reference position for InvokeSingleClickOnDiagramElementToolInput, DropNodeInput and DropOnDiagramInput input. | ||
* | ||
* @author frouene | ||
*/ | ||
@Service | ||
public class GenericDiagramToolReferencePositionProvider implements IDiagramInputReferencePositionProvider { | ||
|
||
@Override | ||
public boolean canHandle(IInput diagramInput) { | ||
return diagramInput instanceof InvokeSingleClickOnDiagramElementToolInput || diagramInput instanceof DropNodeInput || diagramInput instanceof DropOnDiagramInput; | ||
} | ||
|
||
@Override | ||
public ReferencePosition getReferencePosition(IInput diagramInput, IDiagramContext diagramContext) { | ||
ReferencePosition referencePosition = null; | ||
if (diagramInput instanceof InvokeSingleClickOnDiagramElementToolInput input) { | ||
String parentId = null; | ||
if (!diagramContext.getDiagram().getId().equals(input.diagramElementId())) { | ||
parentId = input.diagramElementId(); | ||
} | ||
referencePosition = new ReferencePosition(parentId, new Position(input.startingPositionX(), input.startingPositionY())); | ||
} else if (diagramInput instanceof DropNodeInput input) { | ||
referencePosition = new ReferencePosition(input.targetElementId(), new Position(input.x(), input.y())); | ||
} else if (diagramInput instanceof DropOnDiagramInput input) { | ||
referencePosition = new ReferencePosition(null, new Position(input.startingPositionX(), input.startingPositionY())); | ||
} | ||
return referencePosition; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters