From 07528924379e110de03d8db377e12e85cc194ce6 Mon Sep 17 00:00:00 2001 From: e-cuellar Date: Wed, 22 Jul 2015 15:38:55 -0400 Subject: [PATCH] [BACKLOG-3806] When deleting a step, focus should be set to the "Yes" button --- engine/src/org/pentaho/di/job/JobMeta.java | 11 ++- .../src/org/pentaho/di/trans/TransMeta.java | 10 ++- ui/src/org/pentaho/di/ui/spoon/Spoon.java | 32 ++++++-- .../ui/spoon/delegates/SpoonJobDelegate.java | 79 +++++++++++-------- .../spoon/delegates/SpoonStepsDelegate.java | 39 ++++++++- .../org/pentaho/di/ui/spoon/job/JobGraph.java | 23 +----- .../pentaho/di/ui/spoon/trans/TransGraph.java | 26 +----- 7 files changed, 135 insertions(+), 85 deletions(-) diff --git a/engine/src/org/pentaho/di/job/JobMeta.java b/engine/src/org/pentaho/di/job/JobMeta.java index 6d99e92ec34..68a9e7d4ec2 100644 --- a/engine/src/org/pentaho/di/job/JobMeta.java +++ b/engine/src/org/pentaho/di/job/JobMeta.java @@ -1355,7 +1355,11 @@ public void addJobEntry( int p, JobEntryCopy si ) { * the hi */ public void addJobHop( int p, JobHopMeta hi ) { - jobhops.add( p, hi ); + try { + jobhops.add( p, hi ); + } catch ( IndexOutOfBoundsException e ) { + jobhops.add( hi ); + } changedHops = true; } @@ -2834,4 +2838,9 @@ public List getExtraLogTables() { public void setExtraLogTables( List extraLogTables ) { this.extraLogTables = extraLogTables; } + + public boolean containsJobCopy( JobEntryCopy jobCopy ) { + return jobcopies.contains( jobCopy ); + } + } diff --git a/engine/src/org/pentaho/di/trans/TransMeta.java b/engine/src/org/pentaho/di/trans/TransMeta.java index db8c685892e..1e6e934c837 100644 --- a/engine/src/org/pentaho/di/trans/TransMeta.java +++ b/engine/src/org/pentaho/di/trans/TransMeta.java @@ -825,7 +825,11 @@ public void addStep( int p, StepMeta stepMeta ) { * The hop to be added. */ public void addTransHop( int p, TransHopMeta hi ) { - hops.add( p, hi ); + try { + hops.add( p, hi ); + } catch ( IndexOutOfBoundsException e ) { + hops.add( hi ); + } changed_hops = true; } @@ -6200,4 +6204,8 @@ public void notifyAllListeners( StepMeta oldMeta, StepMeta newMeta ) { listener.onStepChange( this, oldMeta, newMeta ); } } + + public boolean containsStepMeta( StepMeta stepMeta ) { + return steps.contains( stepMeta ); + } } diff --git a/ui/src/org/pentaho/di/ui/spoon/Spoon.java b/ui/src/org/pentaho/di/ui/spoon/Spoon.java index 084560584dc..2c6a5175645 100644 --- a/ui/src/org/pentaho/di/ui/spoon/Spoon.java +++ b/ui/src/org/pentaho/di/ui/spoon/Spoon.java @@ -193,6 +193,7 @@ import org.pentaho.di.imp.ImportRules; import org.pentaho.di.job.Job; import org.pentaho.di.job.JobExecutionConfiguration; +import org.pentaho.di.job.JobHopMeta; import org.pentaho.di.job.JobMeta; import org.pentaho.di.job.entries.job.JobEntryJob; import org.pentaho.di.job.entries.trans.JobEntryTrans; @@ -1493,17 +1494,13 @@ public void cut() { List stepMetas = transMeta.getSelectedSteps(); if ( stepMetas != null && stepMetas.size() > 0 ) { copySteps(); - for ( StepMeta stepMeta : stepMetas ) { - delStep( transMeta, stepMeta ); - } + delSteps( transMeta, stepMetas.toArray( new StepMeta[stepMetas.size()] ) ); } } else if ( jobActive ) { List jobEntryCopies = jobMeta.getSelectedEntries(); if ( jobEntryCopies != null && jobEntryCopies.size() > 0 ) { copyJobentries(); - for ( JobEntryCopy jobEntryCopy : jobEntryCopies ) { - deleteJobEntryCopies( jobMeta, jobEntryCopy ); - } + deleteJobEntryCopies( jobMeta, jobEntryCopies.toArray( new JobEntryCopy[jobEntryCopies.size()] ) ); } } } @@ -7186,9 +7183,24 @@ public void undoAction( UndoInterface undoInterface ) { if ( undoInterface instanceof TransMeta ) { delegates.trans.undoTransformationAction( (TransMeta) undoInterface, ta ); + if ( ta.getType() == TransAction.TYPE_ACTION_DELETE_STEP ) { + setUndoMenu( undoInterface ); // something changed: change the menu + ta = undoInterface.previousUndo(); + if ( ta != null && ta.getType() == TransAction.TYPE_ACTION_DELETE_HOP ) { + delegates.trans.undoTransformationAction( (TransMeta) undoInterface, ta ); + } + } + } if ( undoInterface instanceof JobMeta ) { delegates.jobs.undoJobAction( (JobMeta) undoInterface, ta ); + if ( ta.getType() == TransAction.TYPE_ACTION_DELETE_JOB_ENTRY ) { + setUndoMenu( undoInterface ); // something changed: change the menu + ta = undoInterface.previousUndo(); + if ( ta != null && ta.getType() == TransAction.TYPE_ACTION_DELETE_JOB_HOP ) { + delegates.jobs.undoJobAction( (JobMeta) undoInterface, ta ); + } + } } // Put what we undo in focus @@ -8514,6 +8526,10 @@ public void editJobEntry( JobMeta jobMeta, JobEntryCopy je ) { delegates.jobs.editJobEntry( jobMeta, je ); } + public void deleteJobEntryCopies( JobMeta jobMeta, JobEntryCopy[] jobEntry ) { + delegates.jobs.deleteJobEntryCopies( jobMeta, jobEntry ); + } + public void deleteJobEntryCopies( JobMeta jobMeta, JobEntryCopy jobEntry ) { delegates.jobs.deleteJobEntryCopies( jobMeta, jobEntry ); } @@ -8670,6 +8686,10 @@ public void dupeStep( TransMeta transMeta, StepMeta stepMeta ) { delegates.steps.dupeStep( transMeta, stepMeta ); } + public void delSteps( TransMeta transformation, StepMeta[] steps ) { + delegates.steps.delSteps( transformation, steps ); + } + public void delStep( TransMeta transMeta, StepMeta stepMeta ) { delegates.steps.delStep( transMeta, stepMeta ); } diff --git a/ui/src/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegate.java b/ui/src/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegate.java index 046dc03967f..1d9ae7a559f 100644 --- a/ui/src/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegate.java +++ b/ui/src/org/pentaho/di/ui/spoon/delegates/SpoonJobDelegate.java @@ -284,44 +284,61 @@ public void editJobEntry( JobMeta jobMeta, JobEntryCopy je ) { } } } + + public void deleteJobEntryCopies( JobMeta job, JobEntryCopy[] jobEntries ) { + + // Hops belonging to the deleting jobEntries are placed in a single transaction and removed. + List jobHops = new ArrayList(); + int[] hopIndexes = new int[job.nrJobHops()]; + int hopIndex = 0; + main: for ( int i = job.nrJobHops() - 1; i >= 0; i-- ) { + JobHopMeta hi = job.getJobHop( i ); + for ( int j = 0; j < jobEntries.length; j++ ) { + if ( hi.getFromEntry().equals( jobEntries[j] ) || hi.getToEntry().equals( jobEntries[j] ) ) { + int idx = job.indexOfJobHop( hi ); + jobHops.add( (JobHopMeta) hi.clone() ); + hopIndexes[hopIndex] = idx; + job.removeJobHop( idx ); + spoon.refreshTree(); + continue main; + } + } + hopIndex++; + } + JobHopMeta[] hops = jobHops.toArray( new JobHopMeta[ jobHops.size()] ); + spoon.addUndoDelete( job, hops, hopIndexes ); + + //Deleting jobEntries are placed all in a single transaction and removed. + int[] positions = new int[jobEntries.length]; + for ( int i = 0; i < jobEntries.length; i++ ) { + int pos = job.indexOfJobEntry( jobEntries[i] ); + job.removeJobEntry( pos ); + positions[i] = pos; + } + spoon.addUndoDelete( job, jobEntries, positions ); + + spoon.refreshTree(); + spoon.refreshGraph(); + } public void deleteJobEntryCopies( JobMeta jobMeta, JobEntryCopy jobEntry ) { - String name = jobEntry.getName(); - // TODO Show warning "Are you sure? This operation can't be undone." + - // clear undo buffer. - - // First delete all the hops using entry with name: - JobHopMeta[] hi = jobMeta.getAllJobHopsUsing( name ); - if ( hi.length > 0 ) { - int[] hix = new int[hi.length]; - for ( int i = 0; i < hi.length; i++ ) { - hix[i] = jobMeta.indexOfJobHop( hi[i] ); - } - spoon.addUndoDelete( jobMeta, hi, hix ); - for ( int i = hix.length - 1; i >= 0; i-- ) { - jobMeta.removeJobHop( hix[i] ); + for ( int i = jobMeta.nrJobHops() - 1; i >= 0; i-- ) { + JobHopMeta hi = jobMeta.getJobHop( i ); + if ( hi.getFromEntry().equals( jobEntry ) || hi.getToEntry().equals( jobEntry ) ) { + int idx = jobMeta.indexOfJobHop( hi ); + spoon.addUndoDelete( jobMeta, new JobHopMeta[] { (JobHopMeta) hi.clone() }, new int[] { idx } ); + jobMeta.removeJobHop( idx ); + spoon.refreshTree(); } } - // Then delete all the entries with name: - JobEntryCopy[] je = jobMeta.getAllJobGraphEntries( name ); - int[] jex = new int[je.length]; - for ( int i = 0; i < je.length; i++ ) { - jex[i] = jobMeta.indexOfJobEntry( je[i] ); - } + int pos = jobMeta.indexOfJobEntry( jobEntry ); + jobMeta.removeJobEntry( pos ); + spoon.addUndoDelete( jobMeta, new JobEntryCopy[] { jobEntry }, new int[] { pos } ); - if ( je.length > 0 ) { - spoon.addUndoDelete( jobMeta, je, jex ); - } - for ( int i = jex.length - 1; i >= 0; i-- ) { - jobMeta.removeJobEntry( jex[i] ); - } - - jobMeta.clearUndo(); - spoon.setUndoMenu( jobMeta ); - spoon.refreshGraph(); spoon.refreshTree(); + spoon.refreshGraph(); } public void dupeJobEntry( JobMeta jobMeta, JobEntryCopy jobEntry ) { @@ -1190,7 +1207,7 @@ public void undoJobAction( JobMeta jobMeta, TransAction transAction ) { // // We delete an entry : undo this... - case TransAction.TYPE_ACTION_DELETE_STEP: + case TransAction.TYPE_ACTION_DELETE_JOB_ENTRY: // un-Delete the entry at correct location: re-insert JobEntryCopy[] ce = (JobEntryCopy[]) transAction.getCurrent(); idx = transAction.getCurrentIndex(); diff --git a/ui/src/org/pentaho/di/ui/spoon/delegates/SpoonStepsDelegate.java b/ui/src/org/pentaho/di/ui/spoon/delegates/SpoonStepsDelegate.java index 2dbe45a42a6..59648eb4842 100644 --- a/ui/src/org/pentaho/di/ui/spoon/delegates/SpoonStepsDelegate.java +++ b/ui/src/org/pentaho/di/ui/spoon/delegates/SpoonStepsDelegate.java @@ -24,6 +24,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.List; import org.eclipse.swt.SWT; @@ -197,6 +198,42 @@ public String editStep( TransMeta transMeta, StepMeta stepMeta ) { return stepname; } + public void delSteps( TransMeta transformation, StepMeta[] steps ) { + + // Hops belonging to the deleting steps are placed in a single transaction and removed. + List transHops = new ArrayList(); + int[] hopIndexes = new int[transformation.nrTransHops()]; + int hopIndex = 0; + main: for ( int i = transformation.nrTransHops() - 1; i >= 0; i-- ) { + TransHopMeta hi = transformation.getTransHop( i ); + for ( int j = 0; j < steps.length; j++ ) { + if ( hi.getFromStep().equals( steps[j] ) || hi.getToStep().equals( steps[j] ) ) { + int idx = transformation.indexOfTransHop( hi ); + transHops.add( (TransHopMeta) hi.clone() ); + hopIndexes[hopIndex] = idx; + transformation.removeTransHop( idx ); + spoon.refreshTree(); + continue main; + } + } + hopIndex++; + } + TransHopMeta[] hops = transHops.toArray( new TransHopMeta[ transHops.size()] ); + spoon.addUndoDelete( transformation, hops, hopIndexes ); + + // Deleting steps are placed all in a single transaction and removed. + int[] positions = new int[steps.length]; + for ( int i = 0; i < steps.length; i++ ) { + int pos = transformation.indexOfStep( steps[i] ); + transformation.removeStep( pos ); + positions[i] = pos; + } + spoon.addUndoDelete( transformation, steps, positions ); + + spoon.refreshTree(); + spoon.refreshGraph(); + } + public void delStep( TransMeta transMeta, StepMeta stepMeta ) { spoon.getLog().logDebug( toString(), BaseMessages.getString( PKG, "Spoon.Log.DeleteStep" ) + stepMeta.getName() ); // "Delete @@ -221,7 +258,7 @@ public void delStep( TransMeta transMeta, StepMeta stepMeta ) { spoon.refreshTree(); spoon.refreshGraph(); - } + } public StepDialogInterface getStepDialog( StepMetaInterface stepMeta, TransMeta transMeta, String stepName ) throws KettleException { String dialogClassName = stepMeta.getDialogClassName(); diff --git a/ui/src/org/pentaho/di/ui/spoon/job/JobGraph.java b/ui/src/org/pentaho/di/ui/spoon/job/JobGraph.java index da4be6e11a2..38b8dbea1f0 100644 --- a/ui/src/org/pentaho/di/ui/spoon/job/JobGraph.java +++ b/ui/src/org/pentaho/di/ui/spoon/job/JobGraph.java @@ -154,7 +154,6 @@ import org.pentaho.di.ui.spoon.TabMapEntry.ObjectType; import org.pentaho.di.ui.spoon.XulSpoonResourceBundle; import org.pentaho.di.ui.spoon.XulSpoonSettingsManager; -import org.pentaho.di.ui.spoon.dialog.DeleteMessageBox; import org.pentaho.di.ui.spoon.dialog.NotePadDialog; import org.pentaho.di.ui.spoon.trans.DelayListener; import org.pentaho.di.ui.spoon.trans.DelayTimer; @@ -1546,26 +1545,8 @@ public void delSelected() { return; } - // Load the list of steps - // - List stepList = new ArrayList(); - for ( int i = 0; i < copies.size(); ++i ) { - stepList.add( copies.get( i ).toString() ); - } - - // Display the delete confirmation message box - MessageBox mb = - new DeleteMessageBox( - shell, BaseMessages.getString( PKG, "Spoon.Dialog.DeletionConfirm.Message" ), stepList ); - int answer = mb.open(); - if ( answer == SWT.YES ) { - // Perform the delete - for ( int i = 0; i < copies.size(); i++ ) { - spoon.deleteJobEntryCopies( jobMeta, copies.get( i ) ); - } - spoon.refreshTree(); - spoon.refreshGraph(); - } + JobEntryCopy[] jobEntries = copies.toArray( new JobEntryCopy[copies.size()] ); + spoon.deleteJobEntryCopies( jobMeta, jobEntries ); } public void clearSettings() { diff --git a/ui/src/org/pentaho/di/ui/spoon/trans/TransGraph.java b/ui/src/org/pentaho/di/ui/spoon/trans/TransGraph.java index 0923ba22dac..356180661a5 100644 --- a/ui/src/org/pentaho/di/ui/spoon/trans/TransGraph.java +++ b/ui/src/org/pentaho/di/ui/spoon/trans/TransGraph.java @@ -185,7 +185,6 @@ import org.pentaho.di.ui.spoon.TabItemInterface; import org.pentaho.di.ui.spoon.XulSpoonResourceBundle; import org.pentaho.di.ui.spoon.XulSpoonSettingsManager; -import org.pentaho.di.ui.spoon.dialog.DeleteMessageBox; import org.pentaho.di.ui.spoon.dialog.EnterPreviewRowsDialog; import org.pentaho.di.ui.spoon.dialog.NotePadDialog; import org.pentaho.di.ui.spoon.dialog.SearchFieldsProgressDialog; @@ -2886,29 +2885,8 @@ public void delSelected( StepMeta stMeta ) { return; } - // Get the list of steps that would be deleted - List stepList = new ArrayList(); - for ( int i = transMeta.nrSteps() - 1; i >= 0; i-- ) { - StepMeta stepMeta = transMeta.getStep( i ); - if ( stepMeta.isSelected() || ( stMeta != null && stMeta.equals( stepMeta ) ) ) { - stepList.add( stepMeta.getName() ); - } - } - - // Create and display the delete confirmation dialog - MessageBox mb = - new DeleteMessageBox( shell, BaseMessages.getString( PKG, "TransGraph.Dialog.Warning.DeleteSteps.Message" ), - stepList ); - int result = mb.open(); - if ( result == SWT.YES ) { - // Delete the steps - for ( int i = transMeta.nrSteps() - 1; i >= 0; i-- ) { - StepMeta stepMeta = transMeta.getStep( i ); - if ( stepMeta.isSelected() || ( stMeta != null && stMeta.equals( stepMeta ) ) ) { - spoon.delStep( transMeta, stepMeta ); - } - } - } + StepMeta[] steps = selection.toArray( new StepMeta[selection.size()] ); + spoon.delSteps( transMeta, steps ); } public void editDescription( StepMeta stepMeta ) {