Skip to content

Commit

Permalink
Avoid multiple hops to the same destination apache#3944
Browse files Browse the repository at this point in the history
  • Loading branch information
nadment committed May 16, 2024
1 parent 2cf44e4 commit c4479a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ private void showActionDialog(
}
}

private void splitHop(PipelineHopMeta hi) {
private void splitHop(PipelineHopMeta hop) {
int id = 0;
if (!hopGui.getProps().getAutoSplit()) {
MessageDialogWithToggle md =
Expand All @@ -1349,7 +1349,7 @@ private void splitHop(PipelineHopMeta hi) {
BaseMessages.getString(PKG, "PipelineGraph.Dialog.SplitHop.Title"),
BaseMessages.getString(PKG, "PipelineGraph.Dialog.SplitHop.Message")
+ Const.CR
+ hi.toString(),
+ hop.toString(),
SWT.ICON_QUESTION,
new String[] {
BaseMessages.getString(PKG, "System.Button.Yes"),
Expand All @@ -1362,24 +1362,11 @@ private void splitHop(PipelineHopMeta hi) {
}

if ((id & 0xFF) == 0) { // Means: "Yes" button clicked!

// Only split A-->--B by putting C in between IF...
// C-->--A or B-->--C don't exists...
// A ==> hi.getFromTransform()
// B ==> hi.getToTransform()
// C ==> selectedTransform
//
boolean caExists =
pipelineMeta.findPipelineHop(selectedTransform, hi.getFromTransform()) != null;
boolean bcExists =
pipelineMeta.findPipelineHop(hi.getToTransform(), selectedTransform) != null;
if (!caExists && !bcExists) {
pipelineTransformDelegate.insertTransform(pipelineMeta, hi, currentTransform);
redraw();
}

// else: Silently discard this hop-split attempt.
pipelineTransformDelegate.insertTransform(pipelineMeta, hop, currentTransform);
redraw();
}
// Discard this hop-split attempt.
splitHop = false;
}

@Override
Expand Down Expand Up @@ -1502,9 +1489,14 @@ public void mouseMove(MouseEvent event) {
findPipelineHop(icon.x + iconSize / 2, icon.y + iconSize / 2, selectedTransform);
if (hi != null) {
// OK, we want to split the hop in 2

// Check if we can split A-->--B and insert the selected transform C if
// C-->--A or C-->--B or A-->--C or B-->--C don't exists...
//
if (!hi.getFromTransform().equals(selectedTransform)
&& !hi.getToTransform().equals(selectedTransform)) {
if (pipelineMeta.findPipelineHop(selectedTransform, hi.getFromTransform()) == null
&& pipelineMeta.findPipelineHop(selectedTransform, hi.getToTransform()) == null
&& pipelineMeta.findPipelineHop(hi.getToTransform(), selectedTransform) == null
&& pipelineMeta.findPipelineHop(hi.getFromTransform(), selectedTransform) == null) {
splitHop = true;
lastHopSplit = hi;
hi.split = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,11 @@ public void mouseUp(MouseEvent event) {
}
}

// OK, we moved the transform, did we move it across a hop?
// OK, we moved the action, did we move it across a hop?
// If so, ask to split the hop!
if (splitHop) {
WorkflowHopMeta hi = findHop(icon.x + iconSize / 2, icon.y + iconSize / 2, selectedAction);
if (hi != null) {
WorkflowHopMeta hop = findHop(icon.x + iconSize / 2, icon.y + iconSize / 2, selectedAction);
if (hop != null) {
int id = 0;
if (!hopGui.getProps().getAutoSplit()) {
MessageDialogWithToggle md =
Expand All @@ -850,7 +850,7 @@ public void mouseUp(MouseEvent event) {
BaseMessages.getString(PKG, "HopGuiWorkflowGraph.Dialog.SplitHop.Title"),
BaseMessages.getString(PKG, "HopGuiWorkflowGraph.Dialog.SplitHop.Message")
+ Const.CR
+ hi.toString(),
+ hop.toString(),
SWT.ICON_QUESTION,
new String[] {
BaseMessages.getString(PKG, "System.Button.Yes"),
Expand All @@ -863,23 +863,11 @@ public void mouseUp(MouseEvent event) {
hopGui.getProps().setAutoSplit(md.getToggleState());
}

if ((id & 0xFF) == 0) {
// Means: "Yes" button clicked!

// Only split A-->--B by putting C in between IF...
// C-->--A or B-->--C don't exists...
// A ==> hi.getFromAction()
// B ==> hi.getToAction()
// C ==> selectedTransform
//
if (workflowMeta.findWorkflowHop(selectedAction, hi.getFromAction()) == null
&& workflowMeta.findWorkflowHop(hi.getToAction(), selectedAction) == null) {

workflowActionDelegate.insetAction(workflowMeta, hi, selectedAction);
}
// else: Silently discard this hop-split attempt.
if ((id & 0xFF) == 0) { // Means: "Yes" button clicked!
workflowActionDelegate.insetAction(workflowMeta, hop, selectedAction);
}
}
// Discard this hop-split attempt.
splitHop = false;
}

Expand Down Expand Up @@ -1190,9 +1178,14 @@ public void mouseMove(MouseEvent event) {
WorkflowHopMeta hi = findHop(icon.x + iconSize / 2, icon.y + iconSize / 2, selectedAction);
if (hi != null) {
// OK, we want to split the hop in 2

// Check if we can split A-->--B and insert the selected transform C if
// C-->--A or C-->--B or A-->--C or B-->--C don't exists...
//
if (!hi.getFromAction().equals(selectedAction)
&& !hi.getToAction().equals(selectedAction)) {
if (workflowMeta.findWorkflowHop(selectedAction, hi.getFromAction()) == null
&& workflowMeta.findWorkflowHop(selectedAction, hi.getToAction()) == null
&& workflowMeta.findWorkflowHop(hi.getToAction(), selectedAction) == null
&& workflowMeta.findWorkflowHop(hi.getFromAction(), selectedAction) == null) {
splitHop = true;
lastHopSplit = hi;
hi.split = true;
Expand Down

0 comments on commit c4479a6

Please sign in to comment.