diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableConfig.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableConfig.java index f679f5871..43a42c643 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableConfig.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableConfig.java @@ -68,6 +68,7 @@ public class TableConfig private String minWidth; private Consumer> onRowEditHandler = (tableRow) -> {}; + private Consumer> onRowFinishEditHandler = (tableRow) -> {}; private final ColumnConfig pluginUtilityColumn = ColumnConfig.create("plugin-utility-column") @@ -582,6 +583,26 @@ Consumer> getOnRowEditHandler() { return onRowEditHandler; } + /** + * Use this to set a handler that will be called when ever a row editing finished. + * + * @param handler The handler to be called. + * @return same TableConfig instance. + */ + public TableConfig setOnRowFinishEditHandler(Consumer> handler) { + if (isNull(handler)) { + this.onRowFinishEditHandler = tableRow -> {}; + } else { + this.onRowFinishEditHandler = handler; + } + return this; + } + + /** @return the handler to be called when a row editing finished. */ + Consumer> getOnRowFinishEditHandler() { + return onRowFinishEditHandler; + } + /** A functional interface defining the behavior for appending rows. */ @FunctionalInterface public interface RowAppender { diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableRow.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableRow.java index c002422f9..a168631b8 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableRow.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/TableRow.java @@ -65,6 +65,7 @@ public class TableRow extends BaseDominoElement dataTable, ColumnConfig column) { */ @Override public void onRowAdded(DataTable dataTable, TableRow tableRow) { - dragSource.addDraggable(Draggable.of(tableRow)); + Draggable> draggable = Draggable.of(tableRow); + draggable.setConfig(tableRow::isDraggable); + dragSource.addDraggable(draggable); dropZone.addDropTarget( tableRow, draggableId -> moveItem(dataTable, tableRow.getRecord(), draggableId)); } diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/dnd/Draggable.java b/domino-ui/src/main/java/org/dominokit/domino/ui/dnd/Draggable.java index ac8a653ed..a1840fc04 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/dnd/Draggable.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/dnd/Draggable.java @@ -15,7 +15,7 @@ */ package org.dominokit.domino.ui.dnd; -import static org.dominokit.domino.ui.utils.Domino.*; +import static java.util.Objects.nonNull; import static org.dominokit.domino.ui.utils.ElementsFactory.elements; import elemental2.dom.*; @@ -44,6 +44,7 @@ public class Draggable> { private final E element; private final EventListener eventListener; private final Consumer dragStartListener; + private DraggableConfig config = () -> true; /** * Creates a draggable instance for the specified element. @@ -119,11 +120,33 @@ public static > Draggable of( } private void onDragStart(Event evt, E draggable, String id) { - DragEvent e = (DragEvent) evt; - e.dataTransfer.setData("draggable_id", id); - e.dataTransfer.dropEffect = "move"; - draggable.element().classList.add(DragSource.DRAGGING); - dragStartListener.accept(draggable); + if (config.isEnabled()) { + DragEvent e = (DragEvent) evt; + e.dataTransfer.setData("draggable_id", id); + e.dataTransfer.dropEffect = "move"; + draggable.element().classList.add(DragSource.DRAGGING); + dragStartListener.accept(draggable); + } else { + evt.preventDefault(); + } + } + + /** @return Draggble item DraggableConfig */ + public DraggableConfig getConfig() { + return config; + } + + /** + * Sets the configuration for the draggble item, if null use a default config + * + * @param config DraggableConfig + */ + public void setConfig(DraggableConfig config) { + if (nonNull(config)) { + this.config = config; + } else { + this.config = () -> true; + } } /** Detaches the draggable feature from the element. */ @@ -140,4 +163,8 @@ public void detach() { public String getId() { return id; } + + public interface DraggableConfig { + boolean isEnabled(); + } }