This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new bed1ca7d2d Keep the pipeline canvas usable while output rows are
opened (#9428)
bed1ca7d2d is described below
commit bed1ca7d2df214772741d6f731afab1d4098bed1
Author: William Evan Lomanto <[email protected]>
AuthorDate: Fri Nov 13 18:32:50 2026 +0700
Keep the pipeline canvas usable while output rows are opened (#9428)
---
.../HopGuiPipelineGraphClickContractTest.java | 6 +-
.../HopGuiPipelineGraphOutputDataTest.java | 97 +++++++++-
.../hopgui/file/pipeline/HopGuiPipelineGraph.java | 206 +++++++++++++--------
3 files changed, 228 insertions(+), 81 deletions(-)
diff --git
a/rcp/src/test/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraphClickContractTest.java
b/rcp/src/test/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraphClickContractTest.java
index 0053dc29f7..41ac0664dd 100644
---
a/rcp/src/test/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraphClickContractTest.java
+++
b/rcp/src/test/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraphClickContractTest.java
@@ -25,6 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Stream;
@@ -371,10 +372,13 @@ class HopGuiPipelineGraphClickContractTest extends
GraphCanvasTestBase {
idle.put("iconDragStartScreen", null);
idle.put("iconDragCommitted", false);
idle.put("outputDataPressed", false);
- idle.put("showingOutputRows", false);
idle.put("avoidContextDialog", false);
idle.put("lastButton", 0);
assertGraphState(graph, idle);
+ assertEquals(
+ Set.of(),
+ privateField(graph, "openOutputRowsBuffers"),
+ "a closed output-rows window must not stay marked as open");
}
// ------------------------------------------------------------------ scene
diff --git
a/rcp/src/test/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraphOutputDataTest.java
b/rcp/src/test/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraphOutputDataTest.java
index 876068b023..2a7ab8693b 100644
---
a/rcp/src/test/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraphOutputDataTest.java
+++
b/rcp/src/test/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraphOutputDataTest.java
@@ -17,6 +17,7 @@
package org.apache.hop.ui.hopgui.file.pipeline;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -99,6 +100,97 @@ class HopGuiPipelineGraphOutputDataTest extends
GraphCanvasTestBase {
});
}
+ /**
+ * Every window runs its own event loop, so the rows of a second transform
open from inside the
+ * first one's loop. That must be a new window, not another click on the
open one, and the first
+ * window must stay up.
+ */
+ @Test
+ void rowsOfASecondTransformOpenWhileTheFirstWindowIsUp() {
+ onCanvas(
+ scene -> {
+ Shell first = openRows(scene, scene.source);
+ assertNotNull(first, "the first badge opens its rows");
+ assertEquals(scene.transformRowsTitle, titleOf(first));
+
+ Shell second = openRows(scene, scene.target);
+ assertNotNull(second, "a second badge opens a second window while
the first is up");
+ assertEquals(rowsTitle(TARGET_TRANSFORM), titleOf(second));
+ assertFalse(first.isDisposed(), "opening the second window leaves
the first one up");
+
+ // Newest first, so each nested loop can return to the one below it.
+ closeShell(scene.bot, second);
+ closeShell(scene.bot, first);
+ assertIdle(scene.graph);
+ assertTrue(swallowed.isEmpty(), "the canvas must not throw, but got
" + swallowed);
+ });
+ }
+
+ @Test
+ void closingAWindowFreesItsBadgeWhileAnotherWindowIsUp() {
+ onCanvas(
+ scene -> {
+ Shell first = openRows(scene, scene.source);
+ assertNotNull(first, "the first badge opens its rows");
+ Shell second = openRows(scene, scene.target);
+ assertNotNull(second, "the second badge opens its rows");
+
+ // Close the first window while the second one is still up.
+ closeShell(scene.bot, first);
+
+ Shell reopened = openRows(scene, scene.source);
+ assertNotNull(
+ reopened, "closing a window must free its badge while another
window is still up");
+ assertEquals(scene.transformRowsTitle, titleOf(reopened));
+
+ // Newest first, so each nested loop can return to the one below it.
+ closeShell(scene.bot, reopened);
+ closeShell(scene.bot, second);
+ assertIdle(scene.graph);
+ assertTrue(swallowed.isEmpty(), "the canvas must not throw, but got
" + swallowed);
+ });
+ }
+
+ /** The canvas stays usable while a window is up: a transform can still be
dragged. */
+ @Test
+ void draggingATransformWorksWhileAWindowIsOpen() {
+ onCanvas(
+ scene -> {
+ Shell rows = openRows(scene, scene.target);
+ assertNotNull(rows, "the badge opens its rows");
+
+ Point before = scene.locationOf(scene.source);
+ Point icon = scene.icon(scene.source);
+ Point drop = new Point(icon.x, icon.y + DRAG_Y);
+
+ fire(scene.canvas, SWT.MouseDown, scene.scale, icon, 1, SWT.NONE);
+ fire(scene.canvas, SWT.MouseMove, scene.scale, drop, 0, SWT.BUTTON1);
+ List<String> dialogs = release(scene, drop);
+
+ assertTrue(dialogs.isEmpty(), "the release of the drag opens no
window");
+ assertFalse(rows.isDisposed(), "the open window stays up during the
drag");
+ assertTrue(
+ scene.locationOf(scene.source).y - before.y > 100,
+ "the transform moves while the rows of another one are on
screen");
+
+ closeShell(scene.bot, rows);
+ assertIdle(scene.graph);
+ assertTrue(swallowed.isEmpty(), "the canvas must not throw, but got
" + swallowed);
+ });
+ }
+
+ /**
+ * Clicks a badge without waiting - the release opens a window and a nested
event loop - and
+ * returns the window it opened.
+ */
+ private Shell openRows(Scene scene, TransformMeta transform) {
+ Set<Shell> before = openShells();
+ Point badge = scene.outputBadge(transform);
+ fireAsync(scene.canvas, SWT.MouseDown, scene.scale, badge, 1, SWT.NONE);
+ fireAsync(scene.canvas, SWT.MouseUp, scene.scale, badge, 1, SWT.BUTTON1);
+ return awaitNewShell(scene.bot, before);
+ }
+
@Test
void releasingADragOnTheBadgeDoesNotOpenTheRows() {
onCanvas(
@@ -208,11 +300,14 @@ class HopGuiPipelineGraphOutputDataTest extends
GraphCanvasTestBase {
idle.put("iconDragStartScreen", null);
idle.put("iconDragCommitted", false);
idle.put("outputDataPressed", false);
- idle.put("showingOutputRows", false);
idle.put("avoidContextDialog", false);
idle.put("lastButton", 0);
idle.put("clickedPipelineHop", null);
assertGraphState(graph, idle);
+ assertEquals(
+ Set.of(),
+ privateField(graph, "openOutputRowsBuffers"),
+ "a closed output-rows window must not stay marked as open");
}
private void onCanvas(Consumer<Scene> test) {
diff --git
a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java
b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java
index 107373b44e..a7cbf87d85 100644
---
a/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java
+++
b/ui/src/main/java/org/apache/hop/ui/hopgui/file/pipeline/HopGuiPipelineGraph.java
@@ -29,6 +29,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -36,6 +37,7 @@ import java.util.Set;
import java.util.Timer;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
@@ -426,10 +428,21 @@ public class HopGuiPipelineGraph extends
HopGuiAbstractGraph
private int debugDiscardGeneration;
/**
- * The output-rows dialog is on screen. It runs its own event loop, which
delivers any click made
- * while it is up; that click must not move transforms or open a second copy
of the dialog.
+ * Row buffers whose "Output of" window is currently on screen.
+ *
+ * <p>Opening a preview runs a nested event loop, so the canvas keeps
handling clicks while the
+ * window is up. The user can still move a transform or open the rows of
another transform; a
+ * second click on a window that is already open is refused.
+ *
+ * <p>An entry is removed when its own window is disposed, not when the
opening call returns: with
+ * several windows the first call only returns once the newest window has
closed, see {@link
+ * #showOutputDataDialog}.
+ *
+ * <p>Buffers are tracked by identity rather than with a single boolean
flag, because windows for
+ * several transforms can be open at once. {@link RowBuffer#equals} compares
row values.
*/
- private boolean showingOutputRows;
+ private final Set<RowBuffer> openOutputRowsBuffers =
+ Collections.newSetFromMap(new IdentityHashMap<>());
/**
* Display filters used while placing a transform dragged from the context
dialog (issue #3111).
@@ -814,10 +827,6 @@ public class HopGuiPipelineGraph extends
HopGuiAbstractGraph
@Override
public void mouseDoubleClick(MouseEvent event) {
- if (showingOutputRows) {
- return;
- }
-
if (!PropsUi.getInstance().useDoubleClick()) {
return;
}
@@ -882,9 +891,6 @@ public class HopGuiPipelineGraph extends HopGuiAbstractGraph
@Override
public void mouseDown(MouseEvent event) {
- if (showingOutputRows) {
- return;
- }
if (EnvironmentUtils.getInstance().isWeb()) {
// RAP does not support certain mouse events.
mouseHover(event);
@@ -1273,9 +1279,6 @@ public class HopGuiPipelineGraph extends
HopGuiAbstractGraph
@Override
public void mouseUp(MouseEvent e) {
- if (showingOutputRows) {
- return;
- }
// A preview badge opens its rows only for the press that landed on it.
Cleared before any
// return below, including the ones that finish a drag.
boolean previewPress = outputDataPressed && e.button == 1;
@@ -1796,78 +1799,129 @@ public class HopGuiPipelineGraph extends
HopGuiAbstractGraph
if (rowBuffer == null) {
return false;
}
- // Already inside this dialog's event loop: the click that got us here is
not another preview.
- if (showingOutputRows) {
+ // Already inside this buffer's dialog event loop: the click that got us
here is not another
+ // preview of the same rows. A preview of another transform is a new
request, and does open.
+ if (openOutputRowsBuffers.contains(rowBuffer)) {
return true;
}
+ // A running pipeline appends its sampled rows to this list from its own
threads, under the
+ // list's lock. Copy the rows inside that lock and release it before the
window opens.
+ final IRowMeta rowMeta;
+ final List<Object[]> rows;
synchronized (rowBuffer.getBuffer()) {
- if (!rowBuffer.isEmpty()) {
- showingOutputRows = true;
- try {
- String title =
- BaseMessages.getString(
- PKG, "PipelineGraph.ViewOutput.OutputDialog.Header",
titleName);
- String message =
- BaseMessages.getString(
- PKG,
"PipelineGraph.ViewOutput.OutputDialog.OutputRows.Text", messageName);
- String prefix = "";
-
- if (pipeline != null && pipeline.getPipelineRunConfiguration() !=
null) {
- PipelineRunConfiguration pipelineRunConfiguration =
- pipeline.getPipelineRunConfiguration();
- if (pipelineRunConfiguration.getEngineRunConfiguration()
- instanceof LocalPipelineRunConfiguration
localPipelineRunConfiguration) {
- String sampleTypeInGui =
localPipelineRunConfiguration.getSampleTypeInGui();
- if (StringUtils.isNotEmpty(sampleTypeInGui)) {
- try {
- SampleType sampleType = SampleType.valueOf(sampleTypeInGui);
- switch (sampleType) {
- case None:
- break;
- case First:
- prefix =
- BaseMessages.getString(
- PKG,
"PipelineGraph.ViewOutput.OutputDialog.First.Text");
- break;
- case Last:
- prefix =
- BaseMessages.getString(
- PKG,
"PipelineGraph.ViewOutput.OutputDialog.Last.Text");
- break;
- case Random:
- prefix +=
- BaseMessages.getString(
- PKG,
"PipelineGraph.ViewOutput.OutputDialog.Random.Text");
- break;
- default:
- break;
- }
- } catch (Exception ex) {
- LogChannel.UI.logError("Unknown sample type: " +
sampleTypeInGui);
- }
+ if (rowBuffer.isEmpty()) {
+ return true;
+ }
+ rowMeta = rowBuffer.getRowMeta();
+ rows = new ArrayList<>(rowBuffer.getBuffer());
+ }
+
+ openOutputRowsBuffers.add(rowBuffer);
+ // Every window runs its own event loop, so a window opened from within
the first one's loop
+ // nests inside it: open() returns when the newest window closes, not when
this one does.
+ // Releasing the buffer from this window's own dispose event keeps the
mark tied to the window
+ // on screen. The flag makes the release happen once, so a late return
cannot clear a window
+ // that was reopened in the meantime.
+ final AtomicBoolean released = new AtomicBoolean();
+ final Runnable release =
+ () -> {
+ if (released.compareAndSet(false, true)) {
+ openOutputRowsBuffers.remove(rowBuffer);
+ }
+ };
+ try {
+ String title =
+ BaseMessages.getString(PKG,
"PipelineGraph.ViewOutput.OutputDialog.Header", titleName);
+ String message =
+ BaseMessages.getString(
+ PKG, "PipelineGraph.ViewOutput.OutputDialog.OutputRows.Text",
messageName);
+ String prefix = "";
+
+ if (pipeline != null && pipeline.getPipelineRunConfiguration() != null) {
+ PipelineRunConfiguration pipelineRunConfiguration =
pipeline.getPipelineRunConfiguration();
+ if (pipelineRunConfiguration.getEngineRunConfiguration()
+ instanceof LocalPipelineRunConfiguration
localPipelineRunConfiguration) {
+ String sampleTypeInGui =
localPipelineRunConfiguration.getSampleTypeInGui();
+ if (StringUtils.isNotEmpty(sampleTypeInGui)) {
+ try {
+ SampleType sampleType = SampleType.valueOf(sampleTypeInGui);
+ switch (sampleType) {
+ case None:
+ break;
+ case First:
+ prefix =
+ BaseMessages.getString(
+ PKG,
"PipelineGraph.ViewOutput.OutputDialog.First.Text");
+ break;
+ case Last:
+ prefix =
+ BaseMessages.getString(
+ PKG,
"PipelineGraph.ViewOutput.OutputDialog.Last.Text");
+ break;
+ case Random:
+ prefix +=
+ BaseMessages.getString(
+ PKG,
"PipelineGraph.ViewOutput.OutputDialog.Random.Text");
+ break;
+ default:
+ break;
}
+ } catch (Exception ex) {
+ LogChannel.UI.logError("Unknown sample type: " +
sampleTypeInGui);
}
}
-
- new ShowRowsDialog(
- hopGui.getActiveShell(),
- variables,
- title,
- prefix + message,
- rowBuffer.getRowMeta(),
- rowBuffer.getBuffer())
- .open();
- } catch (Exception ex) {
- new ErrorDialog(
- hopGui.getActiveShell(), CONST_ERROR, "Error showing output rows
dialog", ex);
- } finally {
- showingOutputRows = false;
}
}
+
+ watchOutputRowsShell(title, release);
+ new ShowRowsDialog(hopGui.getActiveShell(), variables, title, prefix +
message, rowMeta, rows)
+ .open();
+ } catch (Exception ex) {
+ new ErrorDialog(hopGui.getActiveShell(), CONST_ERROR, "Error showing
output rows dialog", ex);
+ } finally {
+ release.run();
}
return true;
}
+ /**
+ * Calls {@code onDisposed} when the window {@link ShowRowsDialog} is about
to open is disposed,
+ * and brings that window to the front.
+ *
+ * <p>The window creates its shell privately, and {@code open()} does not
return until a nested
+ * event loop ends - which, with several windows stacked, is when the newest
one closes. So the
+ * shell is found once it exists: the shell is built before its loop starts,
and the runnable
+ * posted here is the first thing that loop dispatches. It is identified by
its title among the
+ * shells that did not exist before.
+ *
+ * <p>A window opened while another one runs the event loop is not activated
by the platform, and
+ * both size themselves from the same saved position, so without raising it
here the new window
+ * appears behind the one that still has the focus.
+ *
+ * <p>This lookup relies on {@link ShowRowsDialog} setting the title as the
shell text.
+ */
+ private void watchOutputRowsShell(String title, Runnable onDisposed) {
+ Shell parent = hopGui.getActiveShell();
+ Display display = parent == null ? null : parent.getDisplay();
+ if (display == null) {
+ return;
+ }
+ Set<Shell> shellsBefore = new
HashSet<>(Arrays.asList(display.getShells()));
+ display.asyncExec(
+ () -> {
+ for (Shell candidate : display.getShells()) {
+ if (!shellsBefore.contains(candidate)
+ && !candidate.isDisposed()
+ && title.equals(candidate.getText())) {
+ candidate.addDisposeListener(e -> onDisposed.run());
+ candidate.setActive();
+ candidate.forceActive();
+ return;
+ }
+ }
+ });
+ }
+
/**
* What a click or a context-menu request landed on, and so which context
dialog it gets: the
* pipeline itself, a transform, a note or a hop. A hop reached through one
of its badges is
@@ -1998,9 +2052,6 @@ public class HopGuiPipelineGraph extends
HopGuiAbstractGraph
private void menuDetect(Event event) {
// No SWT menu hangs off the canvas, and in Hop Web the browser's own menu
is unwanted.
event.doit = false;
- if (showingOutputRows) {
- return;
- }
if (!PropsUi.getInstance().useRightClickForContextDialog()) {
return;
}
@@ -2688,9 +2739,6 @@ public class HopGuiPipelineGraph extends
HopGuiAbstractGraph
@Override
public void mouseMove(MouseEvent event) {
- if (showingOutputRows) {
- return;
- }
boolean shift = (event.stateMask & SWT.SHIFT) != 0;
boolean doRedraw = false;