Skip to content

Commit

Permalink
Merge pull request #3947 from nadment/3944
Browse files Browse the repository at this point in the history
Avoid multiple hops to the same destination #3944
  • Loading branch information
hansva authored May 27, 2024
2 parents beee921 + 35ee939 commit 0df4d9a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 46 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.insertAction(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 Expand Up @@ -2455,7 +2448,7 @@ public void insertAction(HopGuiWorkflowHopContext context) {
plugin.getDescription(),
plugin.getImageFile(),
(shiftClicked, controlClicked, t) ->
workflowActionDelegate.insetAction(
workflowActionDelegate.insertAction(
workflowMeta,
context.getHopMeta(),
plugin.getIds()[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,17 @@ public ActionMeta newAction(
}
}

public ActionMeta insetAction(
public ActionMeta insertAction(
WorkflowMeta workflowMeta,
WorkflowHopMeta hop,
String pluginId,
String pluginName,
Point location) {
ActionMeta actionMeta = this.newAction(workflowMeta, pluginId, pluginName, false, location);
return insetAction(workflowMeta, hop, actionMeta);
return insertAction(workflowMeta, hop, actionMeta);
}

public ActionMeta insetAction(
public ActionMeta insertAction(
WorkflowMeta workflowMeta, WorkflowHopMeta hop, ActionMeta actionMeta) {

hopGui.undoDelegate.addUndoDelete(
Expand Down

0 comments on commit 0df4d9a

Please sign in to comment.