@Test public void shouldInsertColumnUsingGivenFunction(){ @SuppressWarnings("unchecked")//mocking generics Function< TestTreeValueItem, ObjectProperty< Node > > retriever = mock( Function.class ); systemUnderTest.insertColumn( retriever ); assertThat( systemUnderTest.getColumns(), hasSize( 1 ) ); assertThat( systemUnderTest.getColumns().get( 0 ).getCellValueFactory().call( new CellDataFeatures<>( systemUnderTest, null, new TreeItem<>() ) ), is( nullValue() ) ); verifyZeroInteractions( retriever ); assertThat( systemUnderTest.getColumns().get( 0 ).getCellValueFactory().call( new CellDataFeatures<>( systemUnderTest, null, new TreeItem<>( item ) ) ), is( nullValue() ) ); verify( retriever ).apply( item ); }
@Test public void shouldInsertRequiredColumns(){ assertThat( systemUnderTest.getColumns(), hasSize( 2 ) ); UserAssignmentsTreeItem item = mock( UserAssignmentsTreeItem.class ); systemUnderTest.getColumns().get( 0 ).getCellValueFactory().call( new CellDataFeatures<>( systemUnderTest, null, new TreeItem<>( item ) ) ); verify( item ).firstColumnProperty(); systemUnderTest.getColumns().get( 1 ).getCellValueFactory().call( new CellDataFeatures<>( systemUnderTest, null, new TreeItem<>( item ) ) ); verify( item ).secondColumnProperty(); }
@Test public void shouldInsertMultipleColumnInOrder(){ @SuppressWarnings("unchecked")//mocking generics Function< TestTreeValueItem, ObjectProperty< Node > > retrieverA = mock( Function.class ); @SuppressWarnings("unchecked")//mocking generics Function< TestTreeValueItem, ObjectProperty< Node > > retrieverB = mock( Function.class ); @SuppressWarnings("unchecked")//mocking generics Function< TestTreeValueItem, ObjectProperty< Node > > retrieverC = mock( Function.class ); systemUnderTest.insertColumn( retrieverA ); systemUnderTest.insertColumn( retrieverB ); systemUnderTest.insertColumn( retrieverC ); assertThat( systemUnderTest.getColumns(), hasSize( 3 ) ); assertThat( systemUnderTest.getColumns().get( 0 ).getCellValueFactory().call( new CellDataFeatures<>( systemUnderTest, null, new TreeItem<>( item ) ) ), is( nullValue() ) ); verify( retrieverA ).apply( item ); assertThat( systemUnderTest.getColumns().get( 1 ).getCellValueFactory().call( new CellDataFeatures<>( systemUnderTest, null, new TreeItem<>( item ) ) ), is( nullValue() ) ); verify( retrieverB ).apply( item ); assertThat( systemUnderTest.getColumns().get( 2 ).getCellValueFactory().call( new CellDataFeatures<>( systemUnderTest, null, new TreeItem<>( item ) ) ), is( nullValue() ) ); verify( retrieverC ).apply( item ); }
public ObservableValue<T> call(CellDataFeatures<T,T> f) { T v = value(f.getValue(), f.getTreeTableColumn(), f.getTreeTableView()); return new ReadOnlyObjectWrapper<T>(v); }
public BookMarks(){ for(int i=0 ; i< folders.size();i++){ System.out.println(i); parentFolder.getChildren().add(new TreeItem<>(folders.get(i),new ImageView(folderImage))); } bookMarkCol.setCellValueFactory(new Callback<CellDataFeatures<String,String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(CellDataFeatures<String, String> param) { return new SimpleStringProperty(param.getValue().getValue()); } }); nameCol.setCellValueFactory(new PropertyValueFactory<URLdetails,String>("name")); locationCol.setCellValueFactory(new PropertyValueFactory<URLdetails,String>("location")); dateCol.setCellValueFactory(new PropertyValueFactory<URLdetails,String>("date")); timeCol.setCellValueFactory(new PropertyValueFactory<URLdetails,String>("time")); treeView.getSelectionModel().selectedItemProperty().addListener((observable,oldValue,newValue)->{ TreeItem<String> selectedItem = (TreeItem<String>) newValue; System.out.println("Selected Text : " + selectedItem.getValue()); ObservableList<URLdetails> list = new PopulateTable().PopulateTable(selectedItem.getValue()); table.setItems(list); }); table.focusedProperty().addListener((observable,oldValue,newValue)->{ String url = table.getSelectionModel().getSelectedItem().getLocation(); System.out.println("Url of the selected bookmarks: "+url); }); bookMarkCol.setPrefWidth(150); nameCol.setPrefWidth(200); timeCol.setPrefWidth(150); dateCol.setPrefWidth(150); locationCol.setPrefWidth(300); parentFolder.setExpanded(true); treeView.getColumns().add(bookMarkCol); treeView.setRoot(parentFolder); table.getColumns().addAll(nameCol,locationCol,dateCol,timeCol); table.setItems(list); }