Skip to content

Commit

Permalink
Normalize the selection area in workflow graph #4620
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
nadment committed Nov 24, 2024
1 parent 8231c06 commit 666516e
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.apache.hop.core.gui.IGc;
import org.apache.hop.core.gui.IRedrawable;
import org.apache.hop.core.gui.Point;
import org.apache.hop.core.gui.Rectangle;
import org.apache.hop.core.gui.SnapAllignDistribute;
import org.apache.hop.core.gui.plugin.GuiPlugin;
import org.apache.hop.core.gui.plugin.IGuiActionLambda;
Expand Down Expand Up @@ -1491,49 +1492,7 @@ public void mouseMove(MouseEvent event) {
}
}

selectedNotes = pipelineMeta.getSelectedNotes();
selectedTransforms = pipelineMeta.getSelectedTransforms();

// Check minimum location of selected elements
if (selectedTransforms != null) {
for (TransformMeta transformMeta : selectedTransforms) {
Point location = transformMeta.getLocation();
if (location.x + dx < 0) {
dx = -location.x;
}
if (location.y + dy < 0) {
dy = -location.y;
}
}
}
if (selectedNotes != null) {
for (NotePadMeta notePad : selectedNotes) {
Point location = notePad.getLocation();
if (location.x + dx < 0) {
dx = -location.x;
}
if (location.y + dy < 0) {
dy = -location.y;
}
}
}

// Adjust location of selected transforms...
if (selectedTransforms != null) {
for (TransformMeta transformMeta : selectedTransforms) {
PropsUi.setLocation(
transformMeta,
transformMeta.getLocation().x + dx,
transformMeta.getLocation().y + dy);
}
}
// Adjust location of selected notes...
if (selectedNotes != null) {
for (NotePadMeta notePadMeta : selectedNotes) {
PropsUi.setLocation(
notePadMeta, notePadMeta.getLocation().x + dx, notePadMeta.getLocation().y + dy);
}
}
moveSelected(dx, dy);

doRedraw = true;
} else if ((startHopTransform != null && endHopTransform == null)
Expand Down Expand Up @@ -1599,25 +1558,7 @@ public void mouseMove(MouseEvent event) {
int dx = note.x - selectedNote.getLocation().x;
int dy = note.y - selectedNote.getLocation().y;

selectedNotes = pipelineMeta.getSelectedNotes();
selectedTransforms = pipelineMeta.getSelectedTransforms();

// Adjust location of selected transforms...
if (selectedTransforms != null) {
for (TransformMeta transformMeta : selectedTransforms) {
PropsUi.setLocation(
transformMeta,
transformMeta.getLocation().x + dx,
transformMeta.getLocation().y + dy);
}
}
// Adjust location of selected hops...
if (selectedNotes != null) {
for (NotePadMeta notePadMeta : selectedNotes) {
PropsUi.setLocation(
notePadMeta, notePadMeta.getLocation().x + dx, notePadMeta.getLocation().y + dy);
}
}
moveSelected(dx, dy);

doRedraw = true;
}
Expand Down Expand Up @@ -1659,6 +1600,50 @@ public void mouseHover(MouseEvent event) {
}
}

protected void moveSelected(int dx, int dy) {
selectedNotes = pipelineMeta.getSelectedNotes();
selectedTransforms = pipelineMeta.getSelectedTransforms();

// Check minimum location of selected elements
if (selectedTransforms != null) {
for (TransformMeta transformMeta : selectedTransforms) {
Point location = transformMeta.getLocation();
if (location.x + dx < 0) {
dx = -location.x;
}
if (location.y + dy < 0) {
dy = -location.y;
}
}
}
if (selectedNotes != null) {
for (NotePadMeta notePad : selectedNotes) {
Point location = notePad.getLocation();
if (location.x + dx < 0) {
dx = -location.x;
}
if (location.y + dy < 0) {
dy = -location.y;
}
}
}

// Adjust location of selected transforms...
if (selectedTransforms != null) {
for (TransformMeta transformMeta : selectedTransforms) {
PropsUi.setLocation(
transformMeta, transformMeta.getLocation().x + dx, transformMeta.getLocation().y + dy);
}
}
// Adjust location of selected hops...
if (selectedNotes != null) {
for (NotePadMeta notePadMeta : selectedNotes) {
PropsUi.setLocation(
notePadMeta, notePadMeta.getLocation().x + dx, notePadMeta.getLocation().y + dy);
}
}
}

private void addCandidateAsHop(int mouseX, int mouseY) {

boolean forward = startHopTransform != null;
Expand Down Expand Up @@ -1992,41 +1977,33 @@ protected void hideToolTips() {
}

/**
* Select all the transforms in a certain (screen) rectangle
* Select all the transforms and notes in a certain (screen) rectangle
*
* @param rect The selection area as a rectangle
*/
public void selectInRect(PipelineMeta pipelineMeta, org.apache.hop.core.gui.Rectangle rect) {
if (rect.height < 0 || rect.width < 0) {
org.apache.hop.core.gui.Rectangle rectified =
new org.apache.hop.core.gui.Rectangle(rect.x, rect.y, rect.width, rect.height);

// Only for people not dragging from left top to right bottom
if (rectified.height < 0) {
rectified.y = rectified.y + rectified.height;
rectified.height = -rectified.height;
}
if (rectified.width < 0) {
rectified.x = rectified.x + rectified.width;
rectified.width = -rectified.width;
}
rect = rectified;
public void selectInRect(PipelineMeta pipelineMeta, Rectangle rect) {

// Normalize the selection area
// Only for people not dragging from left top to right bottom
if (rect.height < 0) {
rect.y = rect.y + rect.height;
rect.height = -rect.height;
}
if (rect.width < 0) {
rect.x = rect.x + rect.width;
rect.width = -rect.width;
}

for (int i = 0; i < pipelineMeta.nrTransforms(); i++) {
TransformMeta transformMeta = pipelineMeta.getTransform(i);
Point a = transformMeta.getLocation();
if (rect.contains(a.x, a.y)) {
transformMeta.setSelected(true);
for (TransformMeta transform : pipelineMeta.getTransforms()) {
if (rect.contains(transform.getLocation())) {
transform.setSelected(true);
}
}

for (int i = 0; i < pipelineMeta.nrNotes(); i++) {
NotePadMeta ni = pipelineMeta.getNote(i);
Point a = ni.getLocation();
Point b = new Point(a.x + ni.width, a.y + ni.height);
if (rect.contains(a.x, a.y) && rect.contains(b.x, b.y)) {
ni.setSelected(true);
for (NotePadMeta note : pipelineMeta.getNotes()) {
Point a = note.getLocation();
Point b = new Point(a.x + note.width, a.y + note.height);
if (rect.contains(a) && rect.contains(b)) {
note.setSelected(true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.hop.core.gui.IGc;
import org.apache.hop.core.gui.IRedrawable;
import org.apache.hop.core.gui.Point;
import org.apache.hop.core.gui.Rectangle;
import org.apache.hop.core.gui.SnapAllignDistribute;
import org.apache.hop.core.gui.WorkflowTracker;
import org.apache.hop.core.gui.plugin.GuiPlugin;
Expand Down Expand Up @@ -1204,45 +1205,7 @@ public void mouseMove(MouseEvent event) {
}
}

selectedNotes = workflowMeta.getSelectedNotes();
selectedActions = workflowMeta.getSelectedActions();

// Check minimum location of selected elements
if (selectedActions != null) {
for (ActionMeta action : selectedActions) {
Point location = action.getLocation();
if (location.x + dx < 0) {
dx = -location.x;
}
if (location.y + dy < 0) {
dy = -location.y;
}
}
}
if (selectedNotes != null) {
for (NotePadMeta notePad : selectedNotes) {
Point location = notePad.getLocation();
if (location.x + dx < 0) {
dx = -location.x;
}
if (location.y + dy < 0) {
dy = -location.y;
}
}
}

// Adjust location of selected actions...
if (selectedActions != null) {
for (ActionMeta action : selectedActions) {
PropsUi.setLocation(action, action.getLocation().x + dx, action.getLocation().y + dy);
}
}
// Adjust location of selected notes...
if (selectedNotes != null) {
for (NotePadMeta notePad : selectedNotes) {
PropsUi.setLocation(notePad, notePad.getLocation().x + dx, notePad.getLocation().y + dy);
}
}
moveSelected(dx, dy);

doRedraw = true;
} else if ((startHopAction != null && endHopAction == null)
Expand Down Expand Up @@ -1299,21 +1262,7 @@ public void mouseMove(MouseEvent event) {
int dx = note.x - selectedNote.getLocation().x;
int dy = note.y - selectedNote.getLocation().y;

selectedNotes = workflowMeta.getSelectedNotes();
selectedActions = workflowMeta.getSelectedActions();

// Adjust location of selected actions...
if (selectedActions != null) {
for (ActionMeta action : selectedActions) {
PropsUi.setLocation(action, action.getLocation().x + dx, action.getLocation().y + dy);
}
}
// Adjust location of selected notes...
if (selectedNotes != null) {
for (NotePadMeta notePad : selectedNotes) {
PropsUi.setLocation(notePad, notePad.getLocation().x + dx, notePad.getLocation().y + dy);
}
}
moveSelected(dx, dy);

doRedraw = true;
}
Expand Down Expand Up @@ -1655,24 +1604,34 @@ private void readMagnification() {
redraw();
}

public void selectInRect(WorkflowMeta workflowMeta, org.apache.hop.core.gui.Rectangle rect) {
int i;
for (i = 0; i < workflowMeta.nrActions(); i++) {
ActionMeta je = workflowMeta.getAction(i);
Point p = je.getLocation();
if (((p.x >= rect.x && p.x <= rect.x + rect.width)
|| (p.x >= rect.x + rect.width && p.x <= rect.x))
&& ((p.y >= rect.y && p.y <= rect.y + rect.height)
|| (p.y >= rect.y + rect.height && p.y <= rect.y))) {
je.setSelected(true);
/**
* Select all the actions and notes in a certain (screen) rectangle
*
* @param rect The selection area as a rectangle
*/
public void selectInRect(WorkflowMeta workflowMeta, Rectangle rect) {

// Normalize the selection area
// Only for people not dragging from left top to right bottom
if (rect.height < 0) {
rect.y = rect.y + rect.height;
rect.height = -rect.height;
}
if (rect.width < 0) {
rect.x = rect.x + rect.width;
rect.width = -rect.width;
}

for (ActionMeta action : workflowMeta.getActions()) {
if (rect.contains(action.getLocation())) {
action.setSelected(true);
}
}
for (i = 0; i < workflowMeta.nrNotes(); i++) {
NotePadMeta ni = workflowMeta.getNote(i);
Point a = ni.getLocation();
Point b = new Point(a.x + ni.width, a.y + ni.height);
if (rect.contains(a.x, a.y) && rect.contains(b.x, b.y)) {
ni.setSelected(true);
for (NotePadMeta note : workflowMeta.getNotes()) {
Point a = note.getLocation();
Point b = new Point(a.x + note.width, a.y + note.height);
if (rect.contains(a) && rect.contains(b)) {
note.setSelected(true);
}
}
}
Expand Down Expand Up @@ -2555,6 +2514,48 @@ private Set<ActionMeta> enableDisableNextHops(
return checkedActions;
}

protected void moveSelected(int dx, int dy) {
selectedNotes = workflowMeta.getSelectedNotes();
selectedActions = workflowMeta.getSelectedActions();

// Check minimum location of selected elements
if (selectedActions != null) {
for (ActionMeta action : selectedActions) {
Point location = action.getLocation();
if (location.x + dx < 0) {
dx = -location.x;
}
if (location.y + dy < 0) {
dy = -location.y;
}
}
}
if (selectedNotes != null) {
for (NotePadMeta notePad : selectedNotes) {
Point location = notePad.getLocation();
if (location.x + dx < 0) {
dx = -location.x;
}
if (location.y + dy < 0) {
dy = -location.y;
}
}
}

// Adjust location of selected actions...
if (selectedActions != null) {
for (ActionMeta action : selectedActions) {
PropsUi.setLocation(action, action.getLocation().x + dx, action.getLocation().y + dy);
}
}
// Adjust location of selected notes...
if (selectedNotes != null) {
for (NotePadMeta notePad : selectedNotes) {
PropsUi.setLocation(notePad, notePad.getLocation().x + dx, notePad.getLocation().y + dy);
}
}
}

private void modalMessageDialog(String title, String message, int swtFlags) {
MessageBox messageBox = new MessageBox(hopShell(), swtFlags);
messageBox.setMessage(message);
Expand Down

0 comments on commit 666516e

Please sign in to comment.