create generic graph avoid instanceof

Question

Hello everybody,

I was looking for javafx implementation of graphs, here, but for the id, I would like to have any type. The problem is that when I want to show it, It depends of the type, so I can do this :

public class LabelCell<T> extends Cell<T> {

public LabelCell(T id) {
    super(id);
    Pane pane=new Pane();
    Label view;

    if (id instanceof SQLTableVertex) {

     String labelString="";

     labelString+=((SQLTableVertex) id).getName();
     labelString+="\n"+"________________________";
     for (Identifier i:((SQLTableVertex) id).getIdentifiers())
         labelString+= "\n" +i;

     view = new Label(labelString);

    }       

    else 
        view=new Label(id.toString());


    view.setStyle("-fx-background-color: lightgray;");
    pane.getChildren().add(view);
    setView(pane);

}

But I lose the fact that it's generic. I could also add a case in the switch of the model but it is the same problem

How can I deal with it ? Thank's by advance.


Show source
| generics   | java   | graph   2016-12-18 13:12 0 Answers

Answers ( 0 )

◀ Go back