protected void initializeXulMenu( Document doc, List<StepMeta> selection, StepMeta stepMeta ) throws KettleException {
    XulMenuitem item = (XulMenuitem) doc.getElementById( "trans-graph-entry-newhop" );
    int sels = selection.size();
    item.setDisabled( sels != 2 );

    item = (XulMenuitem) doc.getElementById( "trans-graph-entry-align-snap" );

    item.setAcceltext( "ALT-HOME" );
    item.setLabel( BaseMessages.getString( PKG, "TransGraph.PopupMenu.SnapToGrid" ) );
    item.setAccesskey( "alt-home" );

    item = (XulMenuitem) doc.getElementById( "trans-graph-entry-open-mapping" );

    XulMenu men = (XulMenu) doc.getElementById( TRANS_GRAPH_ENTRY_SNIFF );
    men.setDisabled( trans == null || trans.isRunning() == false );
    item = (XulMenuitem) doc.getElementById( "trans-graph-entry-sniff-input" );
    item.setDisabled( trans == null || trans.isRunning() == false );
    item = (XulMenuitem) doc.getElementById( "trans-graph-entry-sniff-output" );
    item.setDisabled( trans == null || trans.isRunning() == false );
    item = (XulMenuitem) doc.getElementById( "trans-graph-entry-sniff-error" );
    item.setDisabled( !( stepMeta.supportsErrorHandling() && stepMeta.getStepErrorMeta() != null
      && stepMeta.getStepErrorMeta().getTargetStep() != null && trans != null && trans.isRunning() ) );

    XulMenu aMenu = (XulMenu) doc.getElementById( TRANS_GRAPH_ENTRY_AGAIN );
    if ( aMenu != null ) {
      aMenu.setDisabled( sels < 2 );
    }

    // item = (XulMenuitem) doc.getElementById("trans-graph-entry-data-movement-distribute");
    // item.setSelected(stepMeta.isDistributes());

    item = (XulMenuitem) doc.getElementById( "trans-graph-entry-partitioning" );
    item.setDisabled( spoon.getPartitionSchemasNames( transMeta ).isEmpty() );

    item = (XulMenuitem) doc.getElementById( "trans-graph-entry-data-movement-copy" );
    item.setSelected( !stepMeta.isDistributes() );

    item = (XulMenuitem) doc.getElementById( "trans-graph-entry-hide" );
    item.setDisabled( !( stepMeta.isDrawn() && !transMeta.isAnySelectedStepUsedInTransHops() ) );

    item = (XulMenuitem) doc.getElementById( "trans-graph-entry-detach" );
    item.setDisabled( !transMeta.isStepUsedInTransHops( stepMeta ) );

    item = (XulMenuitem) doc.getElementById( "trans-graph-entry-errors" );
    item.setDisabled( !stepMeta.supportsErrorHandling() );
  }
@SuppressWarnings( "unchecked" )
  @Test
  public void testInitializeXulMenu() throws KettleException {
    StepMeta stepMeta = mock( StepMeta.class );
    TransGraph transGraph = mock( TransGraph.class );
    TransMeta transMeta = mock( TransMeta.class );
    Document document = mock( Document.class );
    XulMenuitem xulItem = mock( XulMenuitem.class );
    XulMenu xulMenu = mock( XulMenu.class );
    StepErrorMeta stepErrorMeta = mock( StepErrorMeta.class );
    Spoon spoon = mock( Spoon.class );
    List<StepMeta> selection = Arrays.asList( new StepMeta(), stepMeta, new StepMeta() );

    doCallRealMethod().when( transGraph ).setTransMeta( any( TransMeta.class ) );
    doCallRealMethod().when( transGraph ).setSpoon( any( Spoon.class ) );
    transGraph.setTransMeta( transMeta );
    transGraph.setSpoon( spoon );

    when( stepMeta.getStepErrorMeta() ).thenReturn( stepErrorMeta );
    when( stepMeta.isDrawn() ).thenReturn( true );
    when( document.getElementById( any( String.class ) ) ).thenReturn( xulItem );
    when( document.getElementById( TransGraph.TRANS_GRAPH_ENTRY_AGAIN ) ).thenReturn( xulMenu );
    when( document.getElementById( TransGraph.TRANS_GRAPH_ENTRY_SNIFF ) ).thenReturn( xulMenu );

    doCallRealMethod().when( transGraph ).initializeXulMenu( any( Document.class ),
      any( List.class ), any( StepMeta.class ) );

    transGraph.initializeXulMenu( document, selection, stepMeta );
    verify( transMeta ).isAnySelectedStepUsedInTransHops();
  }