@Test public void testInitializeMultiple() throws Exception { ParameterValues paramValues = mock( ParameterValues.class ); Calendar cal = Calendar.getInstance(); cal.set( 2015, 5, 10 ); Set<Object> keys = new HashSet<Object>(); keys.add( "key_0" ); keys.add( new BigDecimal( 1.0 ) ); keys.add( cal.getTime() ); keys.add( "key_3" ); doReturn( keys ).when( updateContext ).getParameterValue( PARAM_NAME ); doReturn( paramValues ).when( listParameter ).getValues( parameterContext ); doReturn( 3 ).when( paramValues ).getRowCount(); doReturn( "key_0" ).when( paramValues ).getKeyValue( 0 ); doReturn( new BigDecimal( 1.1 ) ).when( paramValues ).getKeyValue( 1 ); cal.add( Calendar.DAY_OF_MONTH, 2 ); doReturn( cal.getTime() ).when( paramValues ).getKeyValue( 2 ); doReturn( "val_0" ).when( paramValues ).getTextValue( 0 ); doReturn( "val_1" ).when( paramValues ).getTextValue( 1 ); doReturn( "val_2" ).when( paramValues ).getTextValue( 2 ); testCreateMultipleListComponent(); comp.initialize(); JList list = findView( comp ); assertThat( list, is( notNullValue() ) ); assertThat( list.getModel(), is( instanceOf( KeyedComboBoxModel.class ) ) ); assertThat( list.getSelectedValuesList().size(), is( equalTo( 1 ) ) ); assertThat( (String) list.getSelectedValue(), is( equalTo( "val_0" ) ) ); ListSelectionEvent evt = mock( ListSelectionEvent.class ); doReturn( true ).when( evt ).getValueIsAdjusting(); ListSelectionListener listener = list.getListSelectionListeners()[0]; listener.valueChanged( evt ); verify( updateContext, never() ).setParameterValue( anyString(), anyObject() ); doReturn( false ).when( evt ).getValueIsAdjusting(); listener.valueChanged( evt ); verify( updateContext ).setParameterValue( PARAM_NAME, new String[] { "key_0" } ); }
public void initialize() throws ReportDataFactoryException { adjustingToExternalInput = true; try { final KeyedComboBoxModel keyedComboBoxModel = DefaultParameterComponentFactory.createModel( listParameter, parameterContext ); list.setModel( keyedComboBoxModel ); final ListSelectionModel selectionModel = list.getSelectionModel(); final Object value = updateContext.getParameterValue( listParameter.getName() ); final HashSet keylist = getNormalizedSet( value ); selectionModel.setValueIsAdjusting( true ); list.clearSelection(); final int size = keyedComboBoxModel.getSize(); for ( int i = 0; i < size; i++ ) { final Object key = keyedComboBoxModel.getKeyAt( i ); if ( isSafeMatch( key, keylist ) ) { selectionModel.addSelectionInterval( i, i ); } } selectionModel.setValueIsAdjusting( false ); } finally { adjustingToExternalInput = false; } }
ListParameterComponent extends MinimalScrollPane implements ParameterComponent { public void initialize() throws ReportDataFactoryException { adjustingToExternalInput = true; try { final KeyedComboBoxModel keyedComboBoxModel = DefaultParameterComponentFactory.createModel( listParameter, parameterContext ); list.setModel( keyedComboBoxModel ); final ListSelectionModel selectionModel = list.getSelectionModel(); final Object value = updateContext.getParameterValue( listParameter.getName() ); final HashSet keylist = getNormalizedSet( value ); selectionModel.setValueIsAdjusting( true ); list.clearSelection(); final int size = keyedComboBoxModel.getSize(); for ( int i = 0; i < size; i++ ) { final Object key = keyedComboBoxModel.getKeyAt( i ); if ( isSafeMatch( key, keylist ) ) { selectionModel.addSelectionInterval( i, i ); } } selectionModel.setValueIsAdjusting( false ); } finally { adjustingToExternalInput = false; } } }
ListParameterComponent extends MinimalScrollPane implements ParameterComponent { public void initialize() throws ReportDataFactoryException { adjustingToExternalInput = true; try { final KeyedComboBoxModel keyedComboBoxModel = DefaultParameterComponentFactory.createModel( listParameter, parameterContext ); list.setModel( keyedComboBoxModel ); final ListSelectionModel selectionModel = list.getSelectionModel(); final Object value = updateContext.getParameterValue( listParameter.getName() ); final HashSet keylist = getNormalizedSet( value ); selectionModel.setValueIsAdjusting( true ); list.clearSelection(); final int size = keyedComboBoxModel.getSize(); for ( int i = 0; i < size; i++ ) { final Object key = keyedComboBoxModel.getKeyAt( i ); if ( isSafeMatch( key, keylist ) ) { selectionModel.addSelectionInterval( i, i ); } } selectionModel.setValueIsAdjusting( false ); } finally { adjustingToExternalInput = false; } } ListParameterComponent( final ListParameter listParameter, final ParameterUpdateContext updateContext,
      final ParameterContext parameterContext ); }
ListParameterComponent extends MinimalScrollPane implements ParameterComponent { public void initialize() throws ReportDataFactoryException { adjustingToExternalInput = true; try { final KeyedComboBoxModel keyedComboBoxModel = DefaultParameterComponentFactory.createModel( listParameter, parameterContext ); list.setModel( keyedComboBoxModel ); final ListSelectionModel selectionModel = list.getSelectionModel(); final Object value = updateContext.getParameterValue( listParameter.getName() ); final HashSet keylist = getNormalizedSet( value ); selectionModel.setValueIsAdjusting( true ); list.clearSelection(); final int size = keyedComboBoxModel.getSize(); for ( int i = 0; i < size; i++ ) { final Object key = keyedComboBoxModel.getKeyAt( i ); if ( isSafeMatch( key, keylist ) ) { selectionModel.addSelectionInterval( i, i ); } } selectionModel.setValueIsAdjusting( false ); } finally { adjustingToExternalInput = false; } } ListParameterComponent( final ListParameter listParameter, final ParameterUpdateContext updateContext,
      final ParameterContext parameterContext ); JComponent getUIComponent(); void initialize(); }
ListParameterComponent extends MinimalScrollPane implements ParameterComponent { public void initialize() throws ReportDataFactoryException { adjustingToExternalInput = true; try { final KeyedComboBoxModel keyedComboBoxModel = DefaultParameterComponentFactory.createModel( listParameter, parameterContext ); list.setModel( keyedComboBoxModel ); final ListSelectionModel selectionModel = list.getSelectionModel(); final Object value = updateContext.getParameterValue( listParameter.getName() ); final HashSet keylist = getNormalizedSet( value ); selectionModel.setValueIsAdjusting( true ); list.clearSelection(); final int size = keyedComboBoxModel.getSize(); for ( int i = 0; i < size; i++ ) { final Object key = keyedComboBoxModel.getKeyAt( i ); if ( isSafeMatch( key, keylist ) ) { selectionModel.addSelectionInterval( i, i ); } } selectionModel.setValueIsAdjusting( false ); } finally { adjustingToExternalInput = false; } } ListParameterComponent( final ListParameter listParameter, final ParameterUpdateContext updateContext,
      final ParameterContext parameterContext ); JComponent getUIComponent(); void initialize();  }