diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings index d56df62c9fec9d011ee8f826ae89d373ff499a0d..862569d009873d084a246055796410c2d0322cd6 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings @@ -1,8 +1,8 @@ DynamicTreeContentProviderBase.java e801da995a1b6e5a1b757247c1638bafb6073e6d GREEN DynamicTreeItem.java 75dc5534b119ffdb3c10a65810c2a0f330b7955e GREEN -DynamicTreeTableUIProviderBase.java 7bfc1395283d3dc10026aff5e2e65df88d25f3a7 GREEN -DynamicTreeTableViewer.java 43757359b3071192ae79710bcbc0e9577bb6f62d GREEN -DynamicTreeUIProviderBase.java 13b5f54f5a9c19a6c53a5856824fa64bf7460605 YELLOW -DynamicTreeViewer.java 59da052c7c34ad526d3f81db9939676fd6050964 YELLOW +DynamicTreeTableUIProviderBase.java 75ddf3e91c08fd6a5853ab261593040d1039d774 YELLOW +DynamicTreeTableViewer.java 7d35586715715a2b2b29bac37913480b18ca00d2 YELLOW +DynamicTreeUIProviderBase.java e9b68607683de279d0cb8712a28dc131c5c33ece YELLOW +DynamicTreeViewer.java ff43fff033e81c7eded44baab16e5a5a05b26213 YELLOW DynamicTreeViewerBase.java 47124c847de322a0ae26eb7a114f85ce4bd02d7e GREEN IDoubleClickHandler.java 447f7769dead9a106b3ea3139ef0da51eb0b9a89 GREEN diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java index 7bfc1395283d3dc10026aff5e2e65df88d25f3a7..75ddf3e91c08fd6a5853ab261593040d1039d774 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableUIProviderBase.java @@ -19,6 +19,7 @@ import javafx.scene.Node; import javafx.scene.control.ContextMenu; import javafx.scene.control.TreeTableCell; import javafx.scene.control.TreeTableColumn; +import javafx.scene.input.Dragboard; import javafx.util.Callback; /** @@ -59,6 +60,28 @@ public abstract class DynamicTreeTableUIProviderBase<T> { return null; } + /** + * @param item + * the tree element currently targeted by the drag location + * @param dragboard + * the current {@link Dragboard} + * @return whether the drag-over event succeeds (i.e. should be consumed). + */ + public boolean dragOver(T item, Dragboard dragboard) { + return false; + } + + /** + * @param element + * the element the content is dropped on + * @param dragboard + * the current {@link Dragboard} + * @return whether the drop event completed (i.e. should be consumed). + */ + public boolean dropClipboardContent(T element, Dragboard dragboard) { + return false; + } + /** * Returns whether the given column is editable. * diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java index 43757359b3071192ae79710bcbc0e9577bb6f62d..7d35586715715a2b2b29bac37913480b18ca00d2 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java @@ -19,8 +19,11 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.scene.control.SelectionMode; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeTableColumn; +import javafx.scene.control.TreeTableRow; import javafx.scene.control.TreeTableView; import javafx.scene.control.TreeTableView.TreeTableViewSelectionModel; +import javafx.scene.input.TransferMode; +import javafx.util.Callback; /** * A JavaFX {@link TreeTableView} based on an {@link DynamicTreeContentProviderBase} and @@ -51,6 +54,28 @@ public final class DynamicTreeTableViewer<T> extends DynamicTreeViewerBase<T> { view.setRoot(rootItem); view.setShowRoot(showRoot); view.setEditable(true); + view.setRowFactory(new Callback<TreeTableView<T>, TreeTableRow<T>>() { + @Override + public TreeTableRow<T> call(TreeTableView<T> param) { + final TreeTableRow<T> row = new TreeTableRow<T>(); + row.setOnDragOver(evt -> { + T item = row.getItem(); + if(uiProvider.dragOver(item, evt.getDragboard())) { + evt.acceptTransferModes(TransferMode.ANY); + evt.consume(); + } + }); + row.setOnDragDropped(evt -> { + T item = row.getItem(); + if(uiProvider.dropClipboardContent(item, evt.getDragboard())) { + evt.setDropCompleted(true); + evt.consume(); + } + }); + return row; + } + }); + TreeTableViewSelectionModel<T> selectionModel = view.getSelectionModel(); selectionModel.setSelectionMode(SelectionMode.MULTIPLE); selectionModel.selectedItemProperty().addListener((obs, oVal, nVal) -> { @@ -98,8 +123,8 @@ public final class DynamicTreeTableViewer<T> extends DynamicTreeViewerBase<T> { public TreeTableColumn<T, String> addColumn(String headerLabel, int prefWidth) { int num = view.getColumns().size(); TreeTableColumn<T, String> column = new TreeTableColumn<>(headerLabel); - column.setPrefWidth(prefWidth); + column.setCellValueFactory(param -> { T data = param.getValue().getValue(); return new SimpleObjectProperty<String>(uiProvider.getLabel(data, num)); diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeUIProviderBase.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeUIProviderBase.java index 13b5f54f5a9c19a6c53a5856824fa64bf7460605..e9b68607683de279d0cb8712a28dc131c5c33ece 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeUIProviderBase.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeUIProviderBase.java @@ -15,6 +15,8 @@ package org.fortiss.tooling.common.ui.javafx.control.treetableview; import javafx.scene.Node; import javafx.scene.control.ContextMenu; +import javafx.scene.input.ClipboardContent; +import javafx.scene.input.Dragboard; /** * This UI provider is responsible to return the label, the icon, and the context menu for each cell @@ -53,7 +55,29 @@ public abstract class DynamicTreeUIProviderBase<T> { * the tree element, which was dragged * @return the content of the clipboard or {@code null} if the drag should be ignored. */ - public Object getDragClipboardContent(T element) { + public ClipboardContent getDragClipboardContent(T element) { return null; } + + /** + * @param item + * the tree element currently targeted by the drag location + * @param dragboard + * the current {@link Dragboard} + * @return whether the drag-over event succeeds (i.e. should be consumed). + */ + public boolean dragOver(T item, Dragboard dragboard) { + return false; + } + + /** + * @param element + * the element the content is dropped on + * @param dragboard + * the current {@link Dragboard} + * @return whether the drop event completed (i.e. should be consumed). + */ + public boolean dropClipboardContent(T element, Dragboard dragboard) { + return false; + } } diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeViewer.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeViewer.java index 59da052c7c34ad526d3f81db9939676fd6050964..ff43fff033e81c7eded44baab16e5a5a05b26213 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeViewer.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeViewer.java @@ -24,7 +24,6 @@ import javafx.scene.control.TreeCell; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeView; import javafx.scene.input.ClipboardContent; -import javafx.scene.input.DataFormat; import javafx.scene.input.DragEvent; import javafx.scene.input.Dragboard; import javafx.scene.input.MouseButton; @@ -147,11 +146,15 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> { dragDetected(evt, this, item); }); this.setOnDragOver(evt -> { + System.out.println("Over " + item.toString()); dragOver(evt, item); }); this.setOnDragDropped(evt -> { dragDropped(evt, item); }); + this.setOnDragExited(evt -> { + System.out.println("Exited " + item.toString()); + }); } else { this.setText(null); this.setGraphic(null); @@ -165,22 +168,24 @@ public final class DynamicTreeViewer<T> extends DynamicTreeViewerBase<T> { /** Called when an item in the tree is dragged. */ private void dragDetected(MouseEvent evt, TreeCell<T> cell, T item) { - Object cbContent = uiProvider.getDragClipboardContent(item); + ClipboardContent cbContent = uiProvider.getDragClipboardContent(item); if(cbContent != null) { - Dragboard db = cell.startDragAndDrop(TransferMode.MOVE); - ClipboardContent content = new ClipboardContent(); - content.put(new DataFormat("JAVA_OBJECT"), cbContent); - db.setContent(content); + Dragboard db = cell.startDragAndDrop(TransferMode.ANY); + db.setContent(cbContent); evt.consume(); } } + /** Gives the current drag-over event to the UI provider. */ private void dragOver(DragEvent evt, T item) { - + if(uiProvider.dragOver(item, evt.getDragboard())) { + evt.consume(); + } } + /** Gives the completed drop gesture to the UI provider. */ private void dragDropped(DragEvent evt, T item) { - + uiProvider.dropClipboardContent(item, evt.getDragboard()); } /** Expands the tree to the given item. */ diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/.ratings b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/.ratings index 98884b1f9f16da0c374a25039c59d6d5886b7d06..777d1178a73f07e0f9d912bded67e983b02aa42b 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/.ratings +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/.ratings @@ -5,7 +5,7 @@ LibraryViewDragSourceAdapter.java 56ef61b214ef5d6cb5b751791a92158bda0391ec GREEN LinkWithEditorPartListener.java c5ab74424378e7b158a805c4dd14fc03c8abeded GREEN MarkerViewContentProvider.java 4cb1192baebe21bca951c439c163d0c171512515 GREEN MarkerViewPart.java cbb650271b6877af205421b7cb11f930440a7ef9 GREEN -ModelElementsViewFX.java 77b4a234b4d2bd37f532373265ee7618f7dbafaa YELLOW +ModelElementsViewFX.java 5e1b3217eaa69c6d54c4300cdd1c744e36b3495b YELLOW NavigatorNewMenu.java a35e391960d1dacbe7f77982e53e1891e9382d5a GREEN NavigatorTreeContentComparator.java d9f1354cfdff78b104b28887d2397e5ca0e9755b GREEN NavigatorTreeContentProvider.java 1fbe97bebf3805cc1af190cecd784fc1cfd12306 GREEN diff --git a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/ModelElementsViewFX.java b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/ModelElementsViewFX.java index 77b4a234b4d2bd37f532373265ee7618f7dbafaa..5e1b3217eaa69c6d54c4300cdd1c744e36b3495b 100644 --- a/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/ModelElementsViewFX.java +++ b/org.fortiss.tooling.kernel.ui/src/org/fortiss/tooling/kernel/ui/internal/views/ModelElementsViewFX.java @@ -17,6 +17,7 @@ package org.fortiss.tooling.kernel.ui.internal.views; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; +import static org.fortiss.tooling.kernel.service.IPrototypeService.PROTOTYPE_DATA_FORMAT; import static org.fortiss.tooling.kernel.utils.EcoreUtils.filterOutInstanceOf; import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement; @@ -47,6 +48,7 @@ import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.TextField; +import javafx.scene.input.ClipboardContent; import javafx.scene.layout.BorderPane; /** @@ -241,10 +243,15 @@ public final class ModelElementsViewFX extends FXViewPart { /** {@inheritDoc} */ @Override - public Object getDragClipboardContent(Object element) { + public ClipboardContent getDragClipboardContent(Object element) { if(element instanceof Prototype) { Prototype proto = (Prototype)element; - return IPrototypeService.getInstance().getUniquePrototypeID(proto); + String uid = IPrototypeService.getInstance().getUniquePrototypeID(proto); + if(uid != null) { + ClipboardContent cbContent = new ClipboardContent(); + cbContent.put(PROTOTYPE_DATA_FORMAT, uid); + return cbContent; + } } return null; } diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IPrototypeService.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IPrototypeService.java index 3f11fc887f729ab739736081af9e663d67d3131f..d2b66742bea8bd6d394157985def6f8ea39c8d20 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IPrototypeService.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/IPrototypeService.java @@ -24,6 +24,8 @@ import org.fortiss.tooling.kernel.extension.data.Prototype; import org.fortiss.tooling.kernel.extension.data.PrototypeCategory; import org.fortiss.tooling.kernel.internal.PrototypeService; +import javafx.scene.input.DataFormat; + /** * The prototype service provides registration and access to model element * prototypes. It distinguishes between two types of prototypes. Primary @@ -37,6 +39,10 @@ import org.fortiss.tooling.kernel.internal.PrototypeService; * @author hoelzl */ public interface IPrototypeService { + /** The DataFormat used to transfer prototypes via drag-and-drop. */ + public static final DataFormat PROTOTYPE_DATA_FORMAT = + new DataFormat(IPrototypeService.class.getName()); + /** Returns the service instance. */ public static IPrototypeService getInstance() { return PrototypeService.getInstance();