Java Code Examples for org.pentaho.di.trans.step.StepMeta#setSelected()

The following examples show how to use org.pentaho.di.trans.step.StepMeta#setSelected() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpoonStepsDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void dupeStep( TransMeta transMeta, StepMeta stepMeta ) {
  spoon.getLog().logDebug(
    toString(), BaseMessages.getString( PKG, "Spoon.Log.DuplicateStep" ) + stepMeta.getName() ); // Duplicate
  // step:

  StepMeta stMeta = (StepMeta) stepMeta.clone();
  if ( stMeta != null ) {
    String newname = transMeta.getAlternativeStepname( stepMeta.getName() );
    int nr = 2;
    while ( transMeta.findStep( newname ) != null ) {
      newname = stepMeta.getName() + " (copy " + nr + ")";
      nr++;
    }
    stMeta.setName( newname );
    // Don't select this new step!
    stMeta.setSelected( false );
    Point loc = stMeta.getLocation();
    stMeta.setLocation( loc.x + 20, loc.y + 20 );
    transMeta.addStep( stMeta );
    spoon.addUndoNew( transMeta, new StepMeta[] { (StepMeta) stMeta.clone() }, new int[] { transMeta
      .indexOfStep( stMeta ) } );
    spoon.refreshTree();
    spoon.refreshGraph();
  }
}
 
Example 2
Source File: GraphTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testRightClickStepSelection() {
  TransGraph graph = mock( TransGraph.class );

  StepMeta meta1 = mock( StepMeta.class );
  StepMeta meta2 = mock( StepMeta.class );
  StepMeta meta3 = mock( StepMeta.class );
  wireSelected( meta1, meta2, meta3 );

  List<StepMeta> selected = new ArrayList<>( 2 );
  meta2.setSelected( true );
  meta3.setSelected( true );
  selected.add( meta2 );
  selected.add( meta3 );

  doCallRealMethod().when( graph ).doRightClickSelection( meta1, selected );
  graph.doRightClickSelection( meta1, selected );

  assertTrue( meta1.isSelected() );
  assertEquals( meta1, selected.get( 0 ) );
  assertEquals( 1, selected.size() );
  assertFalse( meta2.isSelected() || meta3.isSelected() );
}
 
Example 3
Source File: GraphTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testRightClickAlreadySelected() {
  TransGraph graph = mock( TransGraph.class );
  StepMeta meta1 = mock( StepMeta.class );
  StepMeta meta2 = mock( StepMeta.class );
  wireSelected( meta1, meta2 );
  List<StepMeta> selected = new ArrayList<>( 2 );
  meta1.setSelected( true );
  meta2.setSelected( true );
  selected.add( meta1 );
  selected.add( meta2 );

  doCallRealMethod().when( graph ).doRightClickSelection( meta1, selected );
  graph.doRightClickSelection( meta1, selected );

  assertEquals( 2, selected.size() );
  assertTrue( selected.contains( meta1 ) );
  assertTrue( selected.contains( meta2 ) );
  assertTrue( meta1.isSelected() && meta2.isSelected() );
}
 
Example 4
Source File: TransMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsAnySelectedStepUsedInTransHopsAnySelectedCase() {
  StepMeta stepMeta = new StepMeta();
  stepMeta.setName( STEP_NAME );
  TransHopMeta transHopMeta = new TransHopMeta();
  stepMeta.setSelected( true );
  List<StepMeta> selectedSteps = asList( new StepMeta(), stepMeta, new StepMeta() );

  transHopMeta.setToStep( stepMeta );
  transHopMeta.setFromStep( stepMeta );
  transMeta.getSteps().addAll( selectedSteps );
  transMeta.addTransHop( transHopMeta );

  assertTrue( transMeta.isAnySelectedStepUsedInTransHops() );
}
 
Example 5
Source File: SpoonTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * test two steps
 * @see http://jira.pentaho.com/browse/PDI-689
 * 
 * @throws KettleException
 */
@Test
public void testCopyPasteStepsErrorHandling() throws KettleException {

  final TransMeta transMeta = new TransMeta();

  //for check copy both step and hop
  StepMeta sourceStep = new StepMeta( "CsvInput", "Step1", new CsvInputMeta() );
  StepMeta targetStep = new StepMeta( "Dummy", "Dummy Step1", new DummyTransMeta() );

  sourceStep.setSelected( true );
  targetStep.setSelected( true );

  transMeta.addStep( sourceStep );
  transMeta.addStep( targetStep  );

  StepErrorMeta errorMeta = new StepErrorMeta( transMeta, sourceStep, targetStep );
  sourceStep.setStepErrorMeta( errorMeta );
  errorMeta.setSourceStep( sourceStep );
  errorMeta.setTargetStep( targetStep );

  final int stepsSizeBefore = transMeta.getSteps().size();
  doAnswer( new Answer() {
    @Override
    public Object answer( InvocationOnMock invocation ) throws Throwable {
      spoon.pasteXML( transMeta, (String) invocation.getArguments()[0], mock( Point.class ) );
      assertTrue( "Steps was not copied", stepsSizeBefore < transMeta.getSteps().size() );
      //selected copied step
      for ( StepMeta s:transMeta.getSelectedSteps() ) {
        if ( s.getStepMetaInterface() instanceof CsvInputMeta ) {
          //check that stepError was copied
          assertNotNull( "Error hop was not copied", s.getStepErrorMeta() );
        }
      }
      return null;
    }
  } ).when( spoon ).toClipboard( anyString() );
  spoon.copySelected( transMeta, transMeta.getSelectedSteps(), Collections.<NotePadMeta>emptyList() );
}
 
Example 6
Source File: SpoonTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * test copy one step with error handling 
 * @see http://jira.pentaho.com/browse/PDI-13358
 * 
 * @throws KettleException
 */
@Test
public void testCopyPasteOneStepWithErrorHandling() throws KettleException {

  final TransMeta transMeta = new TransMeta();
  StepMeta sourceStep = new StepMeta( "CsvInput", "Step1", new CsvInputMeta() );
  StepMeta targetStep = new StepMeta( "Dummy", "Dummy Step1", new DummyTransMeta() );

  sourceStep.setSelected( true );
  transMeta.addStep( sourceStep );
  transMeta.addStep( targetStep );

  StepErrorMeta errorMeta = new StepErrorMeta( transMeta, sourceStep, targetStep );
  sourceStep.setStepErrorMeta( errorMeta );
  errorMeta.setSourceStep( sourceStep );
  errorMeta.setTargetStep( targetStep );

  final int stepsSizeBefore = transMeta.getSteps().size();
  doAnswer( new Answer() {
    @Override
    public Object answer( InvocationOnMock invocation ) throws Throwable {
      spoon.pasteXML( transMeta, (String) invocation.getArguments()[0], mock( Point.class ) );
      assertTrue( "Steps was not copied", stepsSizeBefore < transMeta.getSteps().size() );
      //selected copied step
      for ( StepMeta s:transMeta.getSelectedSteps() ) {
        if ( s.getStepMetaInterface() instanceof CsvInputMeta ) {
          //check that stepError was empty, because we copy only one step from pair
          assertNull( "Error hop was not copied", s.getStepErrorMeta() );
        }
      }
      return null;
    }
  } ).when( spoon ).toClipboard( anyString() );

  spoon.copySelected( transMeta, transMeta.getSelectedSteps(), Collections.<NotePadMeta>emptyList() );
}