Skip to content

Commit

Permalink
Enhance the navigation thumbnail apache#4617
Browse files Browse the repository at this point in the history
A little code clean-up
  • Loading branch information
nadment committed Nov 24, 2024
1 parent a822d35 commit fc6387c
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 98 deletions.
18 changes: 11 additions & 7 deletions engine/src/main/java/org/apache/hop/core/gui/BasePainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
12 changes: 4 additions & 8 deletions engine/src/main/java/org/apache/hop/pipeline/PipelineMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -2310,8 +2310,7 @@ public int[] getTransformIndexes(List<TransformMeta> 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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
33 changes: 11 additions & 22 deletions engine/src/main/java/org/apache/hop/pipeline/PipelinePainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}

Expand Down
25 changes: 10 additions & 15 deletions engine/src/main/java/org/apache/hop/workflow/WorkflowPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public class HopGuiPipelineGraph extends HopGuiAbstractGraph

protected int currentMouseY = 0;

protected NotePadMeta ni = null;
protected NotePadMeta currentNotePad = null;

protected TransformMeta currentTransform;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public class HopGuiWorkflowGraph extends HopGuiAbstractGraph

protected int currentMouseY = 0;

protected NotePadMeta ni = null;
private NotePadMeta currentNotePad = null;

private SashForm sashForm;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -1267,7 +1264,7 @@ public void mouseMove(MouseEvent event) {
}
}

// Move around notes & transforms
// Move around notes & actions
//
if (selectedNote != null && lastButton == 1 && !shift) {
/*
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit fc6387c

Please sign in to comment.