Skip to content

Commit a6884c7

Browse files
committed
#52: User should be able to drag and drop an Identicon from the Table into the Journal window
1 parent e93332c commit a6884c7

6 files changed

Lines changed: 47 additions & 17 deletions

File tree

framework/src/main/java/dev/ikm/komet/framework/dnd/KometClipboard.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public class KometClipboard
4545
public static final DataFormat KOMET_PATTERN_VERSION_PROXY = new DataFormat("application/komet-pattern-version-proxy");
4646
public static final DataFormat KOMET_SEMANTIC_VERSION_PROXY = new DataFormat("application/komet-semantic-version-proxy");
4747

48+
/**
49+
* Drag format used when dragging a Component. Can be used anywhere a Component is in the clipboard and a Public Id is stored
50+
* in there.
51+
* */
52+
public static final DataFormat COMPONENT_DRAG_FORMAT = new DataFormat("application/x-komet-component-drag-format");
53+
4854
public static final Set<DataFormat> CONCEPT_TYPES = new HashSet<>(Arrays.asList(KOMET_CONCEPT_VERSION_PROXY, KOMET_CONCEPT_PROXY));
4955
public static final Set<DataFormat> PATTERN_TYPES = new HashSet<>(Arrays.asList(KOMET_PATTERN_VERSION_PROXY, KOMET_PATTERN_PROXY));
5056
public static final Set<DataFormat> SEMANTIC_TYPES = new HashSet<>(Arrays.asList(KOMET_SEMANTIC_VERSION_PROXY, KOMET_SEMANTIC_PROXY));

kview/src/main/java/dev/ikm/komet/kview/controls/KLConceptNavigatorTreeCell.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import javafx.scene.shape.Path;
2020

2121
import java.util.BitSet;
22-
import java.util.concurrent.Future;
2322
import java.util.function.Consumer;
2423

2524
import static dev.ikm.komet.kview.controls.ConceptNavigatorTreeItem.PS_STATE;

kview/src/main/java/dev/ikm/komet/kview/controls/skin/ComponentItemNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.function.Supplier;
2727
import java.util.stream.Collectors;
2828

29+
import static dev.ikm.komet.framework.dnd.KometClipboard.COMPONENT_DRAG_FORMAT;
30+
2931
/**
3032
* A Node used to render a Component (icon + text)
3133
*/
@@ -75,7 +77,7 @@ private void setupDragAndDrop() {
7577
String encoded = Arrays.stream(publicId.asUuidArray())
7678
.map(UUID::toString)
7779
.collect(Collectors.joining(","));
78-
content.put(KLComponentControlSkin.COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT, encoded);
80+
content.put(COMPONENT_DRAG_FORMAT, encoded);
7981
dragboard.setContent(content);
8082

8183
// Drag Image

kview/src/main/java/dev/ikm/komet/kview/controls/skin/KLComponentControlSkin.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.UUID;
4848
import java.util.function.Function;
4949

50+
import static dev.ikm.komet.framework.dnd.KometClipboard.COMPONENT_DRAG_FORMAT;
5051
import static dev.ikm.komet.kview.controls.KLConceptNavigatorTreeCell.CONCEPT_NAVIGATOR_DRAG_FORMAT;
5152

5253
/**
@@ -57,15 +58,6 @@ public class KLComponentControlSkin extends SkinBase<KLComponentControl> {
5758
private static final Logger LOG = LoggerFactory.getLogger(KLComponentControl.class);
5859
private static final String SEARCH_TEXT_VALUE = "search.text.value";
5960

60-
/**
61-
* Drag format for component drag and drop operations coming from outside of KLComponentControl.
62-
*/
63-
public static final DataFormat COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT;
64-
static {
65-
DataFormat dataFormat = DataFormat.lookupMimeType("application/x-komet-outside-component-control-format");
66-
COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT = dataFormat == null ? new DataFormat("application/x-komet-outside-component-control-format") : dataFormat;
67-
}
68-
6961
/**
7062
* Drag format for component control drag and drop operations from KLComponentControl to KLComponentControl.
7163
*/
@@ -178,7 +170,7 @@ private void setupDragNDrop() {
178170
control.setOnDragOver(event -> {
179171
if (event.getDragboard().hasContent(COMPONENT_CONTROL_DRAG_FORMAT)) {
180172
event.acceptTransferModes(TransferMode.MOVE);
181-
} else if(event.getDragboard().hasContent(COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT)) {
173+
} else if(event.getDragboard().hasContent(COMPONENT_DRAG_FORMAT)) {
182174
event.acceptTransferModes(TransferMode.COPY);
183175
} else if (event.getGestureSource() != control && event.getDragboard().hasString()) {
184176
if (isFilterAllowedWhileDragAndDropping(event)) {
@@ -195,7 +187,7 @@ private void setupDragNDrop() {
195187

196188
control.setOnDragEntered(event -> {
197189
if (event.getGestureSource() != control &&
198-
(event.getDragboard().hasString() || event.getDragboard().hasContent(COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT))) {
190+
(event.getDragboard().hasString() || event.getDragboard().hasContent(COMPONENT_DRAG_FORMAT))) {
199191
conceptContainer.setOpacity(.90);
200192
if (event.getDragboard().hasContent(COMPONENT_CONTROL_DRAG_FORMAT)) {
201193
if (hasAllowedDND(control)) {
@@ -250,8 +242,8 @@ private void setupDragNDrop() {
250242
}
251243
}
252244

253-
if (event.getDragboard().hasContent(COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT)) {
254-
String encoded = (String) event.getDragboard().getContent(COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT);
245+
if (event.getDragboard().hasContent(COMPONENT_DRAG_FORMAT)) {
246+
String encoded = (String) event.getDragboard().getContent(COMPONENT_DRAG_FORMAT);
255247
PublicId publicId = PublicIds.of(encoded.split(","));
256248

257249
EntityHandle.get(publicId).ifPresent(entity -> {
@@ -303,7 +295,7 @@ private void setupDragNDrop() {
303295
* @return Returns true if the user is allowed to drag and drop an item (source) to this control (destination).
304296
*/
305297
private boolean isFilterAllowedWhileDragAndDropping(DragEvent dragEvent) {
306-
boolean isFromOutsideControl = dragEvent.getDragboard().hasContent(COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT);
298+
boolean isFromOutsideControl = dragEvent.getDragboard().hasContent(COMPONENT_DRAG_FORMAT);
307299

308300
// Detect classic concept navigator to drag and drop concepts
309301
boolean classicConceptNavigatorDnD = isFromClassicConceptNav(dragEvent); // and the allowed filter returns true

kview/src/main/java/dev/ikm/komet/kview/controls/skin/KLWorkspaceSkin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.Comparator;
5454
import java.util.Objects;
5555

56+
import static dev.ikm.komet.framework.dnd.KometClipboard.COMPONENT_DRAG_FORMAT;
5657
import static dev.ikm.komet.framework.dnd.KometClipboard.MULTI_PARENT_GRAPH_DRAG_FORMAT;
5758
import static dev.ikm.komet.kview.controls.KLConceptNavigatorTreeCell.CONCEPT_NAVIGATOR_DRAG_FORMAT;
5859
import static dev.ikm.komet.kview.controls.KLDropRegion.Type.BOX;
@@ -401,7 +402,9 @@ private void configureDragDropHandlers(KLWorkspace workspace) {
401402
// Show drop-region if a valid item is dragged over
402403
workspace.setOnDragOver(event -> {
403404
if (event.getGestureSource() != null && (event.getDragboard().hasContent(CONCEPT_NAVIGATOR_DRAG_FORMAT)
404-
|| event.getDragboard().hasContent(MULTI_PARENT_GRAPH_DRAG_FORMAT) || event.getDragboard().hasString())) {
405+
|| event.getDragboard().hasContent(MULTI_PARENT_GRAPH_DRAG_FORMAT)
406+
|| event.getDragboard().hasContent(COMPONENT_DRAG_FORMAT)
407+
|| event.getDragboard().hasString())) {
405408
// Convert screen coordinates to local coordinates of the desktop pane
406409
final Point2D localCoords = desktopPane.screenToLocal(event.getScreenX(), event.getScreenY());
407410
final double mouseX = localCoords.getX();

kview/src/main/java/dev/ikm/komet/kview/mvvm/view/journal/JournalController.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package dev.ikm.komet.kview.mvvm.view.journal;
1717

18+
import static dev.ikm.komet.framework.dnd.KometClipboard.COMPONENT_DRAG_FORMAT;
1819
import static dev.ikm.komet.framework.dnd.KometClipboard.MULTI_PARENT_GRAPH_DRAG_FORMAT;
1920
import static dev.ikm.komet.framework.events.appevents.ProgressEvent.SUMMON;
2021
import static dev.ikm.komet.kview.controls.FilterOptionsPopup.FILTER_TYPE.JOURNAL_VIEW;
@@ -615,6 +616,9 @@ private void setupDragNDrop(Node node) {
615616
.or(() -> dragboardOpt
616617
.filter(db -> db.hasContent(MULTI_PARENT_GRAPH_DRAG_FORMAT))
617618
.map(db -> handleUuidArrayDrag(db, MULTI_PARENT_GRAPH_DRAG_FORMAT)))
619+
.or(() -> dragboardOpt
620+
.filter(db -> db.hasContent(COMPONENT_DRAG_FORMAT))
621+
.map(db -> handleComponentItemNodeDrag(db)))
618622
.or(() -> dragboardOpt
619623
.filter(Dragboard::hasString)
620624
.map(db -> handleEntityDrag(event.getGestureSource())))
@@ -627,6 +631,30 @@ private void setupDragNDrop(Node node) {
627631
});
628632
}
629633

634+
/**
635+
* Handles a drop from a {@link dev.ikm.komet.kview.controls.skin.ComponentItemNode},
636+
* which encodes a PublicId as a comma-separated list of UUID strings.
637+
*
638+
* @param dragboard the dragboard containing the encoded UUID string
639+
* @return true if a window was successfully created
640+
*/
641+
private boolean handleComponentItemNodeDrag(Dragboard dragboard) {
642+
String encoded = (String) dragboard.getContent(COMPONENT_DRAG_FORMAT);
643+
if (encoded == null || encoded.isBlank()) {
644+
return false;
645+
}
646+
try {
647+
UUID[] uuids = Arrays.stream(encoded.split(","))
648+
.map(UUID::fromString)
649+
.toArray(UUID[]::new);
650+
createWindowFromUuids(uuids);
651+
return true;
652+
} catch (IllegalArgumentException e) {
653+
LOG.error("Failed to parse UUIDs from ComponentItemNode drag: {}", encoded, e);
654+
return false;
655+
}
656+
}
657+
630658
/**
631659
* Processes drag operations containing UUID arrays from concept navigator or proxy list formats.
632660
* Extracts nested UUID arrays from the drag board content and creates corresponding windows

0 commit comments

Comments
 (0)