0

I need some help, guys: The thing is that I want ListView> component to show .toString (or something similar) of the class of underlying dataModel (ObservableList> tests = FXCollections.observableList(list))

so in Java:

public class KinderNonStandard extends SeleneseTestCase {

@Before
public ... {}

@Test
public ... {}

@After
public ... {}

@Override
public String toString() {
 return "I want this string to be shown at presentation layer of listView<T>";
}
}

then I have:

    public class TestWindowController implements Initializable{

    @FXML private ListView<Class<? extends SeleneseTestCase>> availableTests;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

 //list contains classes like KinderNonStandard (extends SeleneseTestCase...) 
    ObservableList<Class<? extends SeleneseTestCase>> tests  = Collections.observableList(list);
availableTests.setItems(tests);   
    }    
   }

And finally, when I run an application, in ListView I see something like "class package.subpackage.KinderNonStandard" instead of what was overriden in toString of that class. Well, Im not quite comfortable with using maps and working with keys as Strings and values as Underlying datamodel classes. So can I somehow manage it to show that overriden toString method?

Thanks for help!

greengold
  • 1,184
  • 3
  • 18
  • 43

1 Answers1

0

Your toString() is inside KinderNonStandard NOT Class<? extends SeleneseTestCase>, while your list contains Class<? extends SeleneseTestCase>. To force to call the toString() method, first you need to instantiate an object of the respective class. Ex:

for(Class<? extends SeleneseTestCase> testItem : tests) {
    System.out.printlin(Class.forName(testItem.getName()).newInstance().toString());
}
amru
  • 1,388
  • 11
  • 14