88import dev .ikm .komet .kview .controls .KLComponentControl ;
99import dev .ikm .komet .kview .controls .KLComponentCollectionControl ;
1010import dev .ikm .komet .kview .mvvm .model .DragAndDropInfo ;
11+ import dev .ikm .tinkar .common .id .PublicId ;
12+ import dev .ikm .tinkar .common .id .PublicIds ;
1113import dev .ikm .tinkar .coordinate .stamp .calculator .LatestVersionSearchResult ;
1214import dev .ikm .tinkar .entity .Entity ;
15+ import dev .ikm .tinkar .entity .EntityHandle ;
1316import dev .ikm .tinkar .entity .EntityService ;
1417import dev .ikm .tinkar .terms .EntityFacade ;
1518import dev .ikm .tinkar .terms .EntityProxy ;
@@ -53,11 +56,24 @@ public class KLComponentControlSkin extends SkinBase<KLComponentControl> {
5356
5457 private static final Logger LOG = LoggerFactory .getLogger (KLComponentControl .class );
5558 private static final String SEARCH_TEXT_VALUE = "search.text.value" ;
59+
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+
69+ /**
70+ * Drag format for component control drag and drop operations from KLComponentControl to KLComponentControl.
71+ */
5672 public static final DataFormat COMPONENT_CONTROL_DRAG_FORMAT ;
5773
5874 static {
59- DataFormat dataFormat = DataFormat .lookupMimeType ("text/concept -control-format" );
60- COMPONENT_CONTROL_DRAG_FORMAT = dataFormat == null ? new DataFormat ("text/concept -control-format" ) : dataFormat ;
75+ DataFormat dataFormat = DataFormat .lookupMimeType ("application/x-komet-component -control-format" );
76+ COMPONENT_CONTROL_DRAG_FORMAT = dataFormat == null ? new DataFormat ("application/x-komet-component -control-format" ) : dataFormat ;
6177 }
6278
6379 private final Label titleLabel ;
@@ -162,6 +178,8 @@ private void setupDragNDrop() {
162178 control .setOnDragOver (event -> {
163179 if (event .getDragboard ().hasContent (COMPONENT_CONTROL_DRAG_FORMAT )) {
164180 event .acceptTransferModes (TransferMode .MOVE );
181+ } else if (event .getDragboard ().hasContent (COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT )) {
182+ event .acceptTransferModes (TransferMode .COPY );
165183 } else if (event .getGestureSource () != control && event .getDragboard ().hasString ()) {
166184 if (isFilterAllowedWhileDragAndDropping (event )) {
167185 event .acceptTransferModes (TransferMode .COPY_OR_MOVE );
@@ -176,7 +194,8 @@ private void setupDragNDrop() {
176194 });
177195
178196 control .setOnDragEntered (event -> {
179- if (event .getGestureSource () != control && event .getDragboard ().hasString ()) {
197+ if (event .getGestureSource () != control &&
198+ (event .getDragboard ().hasString () || event .getDragboard ().hasContent (COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT ))) {
180199 conceptContainer .setOpacity (.90 );
181200 if (event .getDragboard ().hasContent (COMPONENT_CONTROL_DRAG_FORMAT )) {
182201 if (hasAllowedDND (control )) {
@@ -205,7 +224,7 @@ private void setupDragNDrop() {
205224 if (hasAllowedDND (control )) {
206225 Dragboard dragboard = control .startDragAndDrop (TransferMode .MOVE );
207226 ClipboardContent clipboardContent = new ClipboardContent ();
208- clipboardContent .put (COMPONENT_CONTROL_DRAG_FORMAT , "concept -control" );
227+ clipboardContent .put (COMPONENT_CONTROL_DRAG_FORMAT , "component -control" );
209228 control .setUserData (control .getEntity ().publicId ());
210229 clipboardContent .putString (control .getEntity ().toString ());
211230 dragboard .setContent (clipboardContent );
@@ -231,6 +250,20 @@ private void setupDragNDrop() {
231250 }
232251 }
233252
253+ if (event .getDragboard ().hasContent (COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT )) {
254+ String encoded = (String ) event .getDragboard ().getContent (COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT );
255+ PublicId publicId = PublicIds .of (encoded .split ("," ));
256+
257+ EntityHandle .get (publicId ).ifPresent (entity -> {
258+ control .setEntity (entity .toProxy ());
259+ addConceptNode (entity .toProxy (), control .getComponentNameRenderer ());
260+
261+ event .setDropCompleted (true );
262+ event .consume ();
263+ return ;
264+ });
265+ }
266+
234267 if (event .getDragboard ().hasContent (CONCEPT_NAVIGATOR_DRAG_FORMAT ) ) {
235268 List list = (List ) event .getDragboard ().getContent (CONCEPT_NAVIGATOR_DRAG_FORMAT );
236269 if (!list .isEmpty () && list .get (0 ) instanceof List ) {
@@ -270,6 +303,8 @@ private void setupDragNDrop() {
270303 * @return Returns true if the user is allowed to drag and drop an item (source) to this control (destination).
271304 */
272305 private boolean isFilterAllowedWhileDragAndDropping (DragEvent dragEvent ) {
306+ boolean isFromOutsideControl = dragEvent .getDragboard ().hasContent (COMPONENT_OUTSIDE_COMPONENT_CONTROL_DRAG_FORMAT );
307+
273308 // Detect classic concept navigator to drag and drop concepts
274309 boolean classicConceptNavigatorDnD = isFromClassicConceptNav (dragEvent ); // and the allowed filter returns true
275310
@@ -282,7 +317,7 @@ private boolean isFilterAllowedWhileDragAndDropping(DragEvent dragEvent) {
282317 // Existing checks for next gen search navigator items to drag.
283318 boolean nextGenSearchDnD = isADragAndDropInfo (dragEvent );
284319
285- return classicConceptNavigatorDnD || classicSearchDnD || nextGenConceptNavigatorDnD || nextGenSearchDnD ;
320+ return classicConceptNavigatorDnD || classicSearchDnD || nextGenConceptNavigatorDnD || nextGenSearchDnD || isFromOutsideControl ;
286321 }
287322
288323 /**
0 commit comments