From fc6387c3f4320f56f741e88493c88d082c6f7126 Mon Sep 17 00:00:00 2001 From: Nicolas Adment <39568358+nadment@users.noreply.github.com> Date: Sat, 23 Nov 2024 22:57:10 +0100 Subject: [PATCH] Enhance the navigation thumbnail #4617 A little code clean-up --- .../org/apache/hop/core/gui/BasePainter.java | 18 ++++--- .../org/apache/hop/pipeline/PipelineMeta.java | 12 ++--- .../apache/hop/pipeline/PipelinePainter.java | 33 +++++-------- .../apache/hop/workflow/WorkflowPainter.java | 25 ++++------ .../file/pipeline/HopGuiPipelineGraph.java | 14 +++--- .../file/workflow/HopGuiWorkflowGraph.java | 48 ++++++++----------- .../dataorch/HopGuiAbstractGraph.java | 4 +- .../execution/DragViewZoomBase.java | 19 ++++---- 8 files changed, 75 insertions(+), 98 deletions(-) diff --git a/engine/src/main/java/org/apache/hop/core/gui/BasePainter.java b/engine/src/main/java/org/apache/hop/core/gui/BasePainter.java index 86bb064f66f..54ec378c739 100644 --- a/engine/src/main/java/org/apache/hop/core/gui/BasePainter.java +++ b/engine/src/main/java/org/apache/hop/core/gui/BasePainter.java @@ -464,16 +464,20 @@ protected void drawNavigationView() { int areaHeight = (int) (area.y / magnification); // We want to show a rectangle depicting the total area of the pipeline/workflow graph. - // As such the area needs to be a certain percentage its size. - // Let's take 25%. + // This area must be adjusted to a maximum of 200 if it is too large. // - double graphWidth = 25.0 * maximum.x / 100.0; - double graphHeight = 25.0 * maximum.y / 100.0; + double graphWidth = maximum.x; + double graphHeight = maximum.y; + if (graphWidth > 200 || graphHeight > 200) { + double coefficient = 200 / Math.max(graphWidth, graphHeight); + graphWidth *= coefficient; + graphHeight *= coefficient; + } // Position it in the bottom right corner of the screen // - double graphX = area.x - graphWidth - 20.0; - double graphY = area.y - graphHeight - 20.0; + double graphX = area.x - graphWidth - 10.0; + double graphY = area.y - graphHeight - 10.0; int alpha = gc.getAlpha(); gc.setAlpha(75); @@ -486,7 +490,7 @@ protected void drawNavigationView() { // Now draw a darker area inside showing the size of the view-screen in relation to the graph // surface. The view size is a fraction of the total graph area outlined above. // - double viewWidth = (graphWidth * (double) areaWidth) / Math.max(areaWidth, maximum.x); + double viewWidth = (graphWidth * areaWidth) / Math.max(areaWidth, maximum.x); double viewHeight = (graphHeight * areaHeight) / Math.max(areaHeight, maximum.y); // The offset is a part of the screen size. The maximum offset is the graph size minus the area diff --git a/engine/src/main/java/org/apache/hop/pipeline/PipelineMeta.java b/engine/src/main/java/org/apache/hop/pipeline/PipelineMeta.java index 4d0377c737f..0746b6c42c4 100644 --- a/engine/src/main/java/org/apache/hop/pipeline/PipelineMeta.java +++ b/engine/src/main/java/org/apache/hop/pipeline/PipelineMeta.java @@ -2310,8 +2310,7 @@ public int[] getTransformIndexes(List transforms) { public Point getMaximum() { int maxx = 0; int maxy = 0; - for (int i = 0; i < nrTransforms(); i++) { - TransformMeta transformMeta = getTransform(i); + for (TransformMeta transformMeta : getTransforms()) { Point loc = transformMeta.getLocation(); if (loc.x > maxx) { maxx = loc.x; @@ -2320,8 +2319,7 @@ public Point getMaximum() { maxy = loc.y; } } - for (int i = 0; i < nrNotes(); i++) { - NotePadMeta notePadMeta = getNote(i); + for (NotePadMeta notePadMeta : getNotes()) { Point loc = notePadMeta.getLocation(); if (loc.x + notePadMeta.width > maxx) { maxx = loc.x + notePadMeta.width; @@ -2342,8 +2340,7 @@ public Point getMaximum() { public Point getMinimum() { int minx = Integer.MAX_VALUE; int miny = Integer.MAX_VALUE; - for (int i = 0; i < nrTransforms(); i++) { - TransformMeta transformMeta = getTransform(i); + for (TransformMeta transformMeta : getTransforms()) { Point loc = transformMeta.getLocation(); if (loc.x < minx) { minx = loc.x; @@ -2352,8 +2349,7 @@ public Point getMinimum() { miny = loc.y; } } - for (int i = 0; i < nrNotes(); i++) { - NotePadMeta notePadMeta = getNote(i); + for (NotePadMeta notePadMeta : getNotes()) { Point loc = notePadMeta.getLocation(); if (loc.x < minx) { minx = loc.x; diff --git a/engine/src/main/java/org/apache/hop/pipeline/PipelinePainter.java b/engine/src/main/java/org/apache/hop/pipeline/PipelinePainter.java index 20108c4377a..d7d7886cb96 100644 --- a/engine/src/main/java/org/apache/hop/pipeline/PipelinePainter.java +++ b/engine/src/main/java/org/apache/hop/pipeline/PipelinePainter.java @@ -223,20 +223,16 @@ private void drawPipeline() throws HopException { LogChannel.GENERAL.logError("Error in PipelinePainterStart extension point", e); } - gc.setFont(EFont.NOTE); - // First the notes - for (int i = 0; i < pipelineMeta.nrNotes(); i++) { - NotePadMeta ni = pipelineMeta.getNote(i); - drawNote(ni); + gc.setFont(EFont.NOTE); + for (NotePadMeta notePad : pipelineMeta.getNotes()) { + drawNote(notePad); } + // Second draw the hops on top of it... gc.setFont(EFont.GRAPH); - gc.setBackground(EColor.BACKGROUND); - - for (int i = 0; i < pipelineMeta.nrPipelineHops(); i++) { - PipelineHopMeta hi = pipelineMeta.getPipelineHop(i); - drawHop(hi); + for (PipelineHopMeta hop : pipelineMeta.getPipelineHops()) { + drawHop(hop); } EImage arrow; @@ -295,24 +291,19 @@ private void drawPipeline() throws HopException { } // Draw regular transform appearance - for (int i = 0; i < pipelineMeta.nrTransforms(); i++) { - TransformMeta transformMeta = pipelineMeta.getTransform(i); + for (TransformMeta transformMeta : pipelineMeta.getTransforms()) { drawTransform(transformMeta); } if (slowTransformIndicatorEnabled) { - // Highlight possible bottlenecks - for (int i = 0; i < pipelineMeta.nrTransforms(); i++) { - TransformMeta transformMeta = pipelineMeta.getTransform(i); + for (TransformMeta transformMeta : pipelineMeta.getTransforms()) { checkDrawSlowTransformIndicator(transformMeta); } } // Display after slow transform indicator - for (int i = 0; i < pipelineMeta.nrTransforms(); i++) { - TransformMeta transformMeta = pipelineMeta.getTransform(i); - + for (TransformMeta transformMeta : pipelineMeta.getTransforms()) { // Draw transform information icon if description is available drawTransformInformationIndicator(transformMeta); @@ -322,15 +313,13 @@ private void drawPipeline() throws HopException { // Draw data grid indicators (output data available) if (outputRowsMap != null && !outputRowsMap.isEmpty()) { - for (int i = 0; i < pipelineMeta.nrTransforms(); i++) { - TransformMeta transformMeta = pipelineMeta.getTransform(i); + for (TransformMeta transformMeta : pipelineMeta.getTransforms()) { drawTransformOutputIndicator(transformMeta); } } // Draw performance table for selected transform(s) - for (int i = 0; i < pipelineMeta.nrTransforms(); i++) { - TransformMeta transformMeta = pipelineMeta.getTransform(i); + for (TransformMeta transformMeta : pipelineMeta.getTransforms()) { drawTransformPerformanceTable(transformMeta); } diff --git a/engine/src/main/java/org/apache/hop/workflow/WorkflowPainter.java b/engine/src/main/java/org/apache/hop/workflow/WorkflowPainter.java index 6033b4e4576..f0e4becf3af 100644 --- a/engine/src/main/java/org/apache/hop/workflow/WorkflowPainter.java +++ b/engine/src/main/java/org/apache/hop/workflow/WorkflowPainter.java @@ -120,23 +120,19 @@ private void drawActions() throws HopException { ExtensionPointHandler.callExtensionPoint( LogChannel.GENERAL, variables, HopExtensionPoint.WorkflowPainterStart.id, this); } catch (HopException e) { - LogChannel.GENERAL.logError("Error in JobPainterStart extension point", e); + LogChannel.GENERAL.logError("Error in WorkflowPainterStart extension point", e); } // First draw the notes... gc.setFont(EFont.NOTE); - - for (int i = 0; i < workflowMeta.nrNotes(); i++) { - NotePadMeta ni = workflowMeta.getNote(i); - drawNote(ni); + for (NotePadMeta notePad : workflowMeta.getNotes()) { + drawNote(notePad); } + // Second draw the hops on top of it... gc.setFont(EFont.GRAPH); - - // ... and then the rest on top of it... - for (int i = 0; i < workflowMeta.nrWorkflowHops(); i++) { - WorkflowHopMeta hi = workflowMeta.getWorkflowHop(i); - drawWorkflowHop(hi, false); + for (WorkflowHopMeta hop : workflowMeta.getWorkflowHops()) { + drawWorkflowHop(hop, false); } EImage arrow; @@ -194,12 +190,11 @@ private void drawActions() throws HopException { } } - for (int j = 0; j < workflowMeta.nrActions(); j++) { - ActionMeta je = workflowMeta.getAction(j); - drawAction(je); + for (ActionMeta actionMeta : workflowMeta.getActions()) { + drawAction(actionMeta); } - // Display an icon on the indicated location signaling to the user that the transform in + // Display an icon on the indicated location signaling to the user that the action in // question does not accept input // if (noInputAction != null) { @@ -222,7 +217,7 @@ private void drawActions() throws HopException { ExtensionPointHandler.callExtensionPoint( LogChannel.GENERAL, variables, HopExtensionPoint.WorkflowPainterEnd.id, this); } catch (HopException e) { - LogChannel.GENERAL.logError("Error in JobPainterEnd extension point", e); + LogChannel.GENERAL.logError("Error in WorkflowPainterEnd extension point", e); } drawRect(selectionRectangle); 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 537abc29729..c6d5832053d 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 @@ -339,7 +339,7 @@ public class HopGuiPipelineGraph extends HopGuiAbstractGraph protected int currentMouseY = 0; - protected NotePadMeta ni = null; + protected NotePadMeta currentNotePad = null; protected TransformMeta currentTransform; @@ -399,11 +399,11 @@ public class HopGuiPipelineGraph extends HopGuiAbstractGraph private boolean avoidContextDialog; public void setCurrentNote(NotePadMeta ni) { - this.ni = ni; + this.currentNotePad = ni; } public NotePadMeta getCurrentNote() { - return ni; + return currentNotePad; } public TransformMeta getCurrentTransform() { @@ -747,10 +747,10 @@ public void mouseDown(MouseEvent e) { break; case NOTE: - ni = (NotePadMeta) areaOwner.getOwner(); + currentNotePad = (NotePadMeta) areaOwner.getOwner(); selectedNotes = pipelineMeta.getSelectedNotes(); - selectedNote = ni; - Point loc = ni.getLocation(); + selectedNote = currentNotePad; + Point loc = currentNotePad.getLocation(); previousNoteLocations = pipelineMeta.getSelectedNoteLocations(); @@ -1504,7 +1504,7 @@ public void mouseMove(MouseEvent event) { transformMeta.getLocation().y + dy); } } - // Adjust location of selected hops... + // Adjust location of selected notes... if (selectedNotes != null) { for (int i = 0; i < selectedNotes.size(); i++) { NotePadMeta ni = selectedNotes.get(i); diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java b/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java index 370b70a6fa1..9956d2afc88 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/file/workflow/HopGuiWorkflowGraph.java @@ -299,7 +299,7 @@ public class HopGuiWorkflowGraph extends HopGuiAbstractGraph protected int currentMouseY = 0; - protected NotePadMeta ni = null; + private NotePadMeta currentNotePad = null; private SashForm sashForm; @@ -601,10 +601,10 @@ public void mouseDown(MouseEvent event) { break; case NOTE: - ni = (NotePadMeta) areaOwner.getOwner(); + currentNotePad = (NotePadMeta) areaOwner.getOwner(); selectedNotes = workflowMeta.getSelectedNotes(); - selectedNote = ni; - Point loc = ni.getLocation(); + selectedNote = currentNotePad; + Point loc = currentNotePad.getLocation(); previousNoteLocations = workflowMeta.getSelectedNoteLocations(); @@ -1126,7 +1126,7 @@ public void mouseMove(MouseEvent event) { hop = findWorkflowHop(real.x, real.y); } - // Mouse over the name of the transform + // Mouse over the name of the action // if (!PropsUi.getInstance().useDoubleClick()) { if (areaOwner != null && areaOwner.getAreaType() == AreaOwner.AreaType.ACTION_NAME) { @@ -1207,19 +1207,16 @@ public void mouseMove(MouseEvent event) { selectedNotes = workflowMeta.getSelectedNotes(); selectedActions = workflowMeta.getSelectedActions(); - // Adjust location of selected transforms... + // Adjust location of selected actions... if (selectedActions != null) { - for (int i = 0; i < selectedActions.size(); i++) { - ActionMeta actionCopy = selectedActions.get(i); - PropsUi.setLocation( - actionCopy, actionCopy.getLocation().x + dx, actionCopy.getLocation().y + dy); + for (ActionMeta action : selectedActions) { + PropsUi.setLocation(action, action.getLocation().x + dx, action.getLocation().y + dy); } } - // Adjust location of selected hops... + // Adjust location of selected notes... if (selectedNotes != null) { - for (int i = 0; i < selectedNotes.size(); i++) { - NotePadMeta ni = selectedNotes.get(i); - PropsUi.setLocation(ni, ni.getLocation().x + dx, ni.getLocation().y + dy); + for (NotePadMeta notePad : selectedNotes) { + PropsUi.setLocation(notePad, notePad.getLocation().x + dx, notePad.getLocation().y + dy); } } @@ -1267,7 +1264,7 @@ public void mouseMove(MouseEvent event) { } } - // Move around notes & transforms + // Move around notes & actions // if (selectedNote != null && lastButton == 1 && !shift) { /* @@ -1281,19 +1278,16 @@ public void mouseMove(MouseEvent event) { selectedNotes = workflowMeta.getSelectedNotes(); selectedActions = workflowMeta.getSelectedActions(); - // Adjust location of selected transforms... + // Adjust location of selected actions... if (selectedActions != null) { - for (int i = 0; i < selectedActions.size(); i++) { - ActionMeta actionCopy = selectedActions.get(i); - PropsUi.setLocation( - actionCopy, actionCopy.getLocation().x + dx, actionCopy.getLocation().y + dy); + for (ActionMeta action : selectedActions) { + PropsUi.setLocation(action, action.getLocation().x + dx, action.getLocation().y + dy); } } - // Adjust location of selected hops... + // Adjust location of selected notes... if (selectedNotes != null) { - for (int i = 0; i < selectedNotes.size(); i++) { - NotePadMeta ni = selectedNotes.get(i); - PropsUi.setLocation(ni, ni.getLocation().x + dx, ni.getLocation().y + dy); + for (NotePadMeta notePad : selectedNotes) { + PropsUi.setLocation(notePad, notePad.getLocation().x + dx, notePad.getLocation().y + dy); } } @@ -2100,12 +2094,12 @@ public void newNote(HopGuiWorkflowContext context) { } } - public void setCurrentNote(NotePadMeta ni) { - this.ni = ni; + public void setCurrentNote(NotePadMeta notePad) { + this.currentNotePad = notePad; } public NotePadMeta getCurrentNote() { - return ni; + return currentNotePad; } @GuiContextAction( diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/dataorch/HopGuiAbstractGraph.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/dataorch/HopGuiAbstractGraph.java index beacd883675..496f88a3ee2 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/dataorch/HopGuiAbstractGraph.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/dataorch/HopGuiAbstractGraph.java @@ -44,8 +44,8 @@ import org.eclipse.swt.widgets.ToolTip; /** - * The beginnings of a common graph object, used by JobGraph and HopGuiPipelineGraph to share common - * behaviors. + * The beginnings of a common graph object, used by {@code HopGuiWorkflowGraph} and {@code + * HopGuiPipelineGraph} to share common behaviors. */ public abstract class HopGuiAbstractGraph extends DragViewZoomBase implements IGraphSnapAlignDistribute { diff --git a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/DragViewZoomBase.java b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/DragViewZoomBase.java index 7d874a9cb70..bc34371cc64 100644 --- a/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/DragViewZoomBase.java +++ b/ui/src/main/java/org/apache/hop/ui/hopgui/perspective/execution/DragViewZoomBase.java @@ -109,6 +109,7 @@ public void zoomIn() { if (magnification > 10f) { magnification = 10f; } + validateOffset(); setZoomLabel(); redraw(); } @@ -144,6 +145,7 @@ public void zoomIn(MouseEvent mouseEvent) { / 100 * (viewHeight - oldViewHeight); + validateOffset(); setZoomLabel(); redraw(); } @@ -161,6 +163,7 @@ public void zoomOut() { if (magnification < 0.1f) { magnification = 0.1f; } + validateOffset(); setZoomLabel(); redraw(); } @@ -193,6 +196,7 @@ public void zoomOut(MouseEvent mouseEvent) { offset.x = offset.x > 0 ? 0 : offset.x; offset.y = offset.y > 0 ? 0 : offset.y; + validateOffset(); setZoomLabel(); redraw(); } @@ -200,6 +204,7 @@ public void zoomOut(MouseEvent mouseEvent) { @GuiKeyboardShortcut(control = true, key = '0') public void zoom100Percent() { magnification = 1.0f; + validateOffset(); setZoomLabel(); redraw(); } @@ -319,30 +324,24 @@ public void validateOffset() { double viewWidth = area.x / zoomFactor; double viewHeight = area.y / zoomFactor; - // As a percentage of the view area, how much can we go outside the graph area? - // - double overshootPct = 0.75; - double overshootWidth = viewWidth * overshootPct; - double overshootHeight = viewHeight * overshootPct; - // Let's not move the graph off the screen to the top/left // - double minX = -graphWidth - overshootWidth; + double minX = -graphWidth + viewWidth; if (offset.x < minX) { offset.x = minX; } - double minY = -graphHeight - overshootHeight; + double minY = -graphHeight + viewHeight; if (offset.y < minY) { offset.y = minY; } // Are we moving the graph too far down/right? // - double maxX = overshootWidth; + double maxX = 0; if (offset.x > maxX) { offset.x = maxX; } - double maxY = overshootHeight; + double maxY = 0; if (offset.y > maxY) { offset.y = maxY; }