Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

set Metadata to TableColumn

Options
  • 04-10-2016 10:52am
    #1
    Registered Users Posts: 1,454 ✭✭✭


    I am trying to find the best way to get metadata from a media source and present it in a table. I can use the getMetadata() method on a value that returns an ObservableMap but not really sure what should be in my CellFactory.
    TableColumn<Media> artist = new TableColumn<Media>();
    artist.setCellFactory(????)
    

    Maybe I can populate the tablecolumns using TableView?

    Cheers,
    Boggy


Comments

  • Moderators, Society & Culture Moderators Posts: 17,642 Mod ✭✭✭✭Graham


    Cool, I haven't played guess the platform/database/language in ages.:pac:


  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,639 Mod ✭✭✭✭TrueDub


    It's Java, and I'd hazard a guess it's one of the no-SQL libraries, but which one? The tension is high....

    OP, please give us full details of what you're trying to do and with what technologies, libraries and frameworks, otherwise we cannot assist.


  • Registered Users Posts: 1,454 ✭✭✭bogwalrus


    Sorry. Brain fried a bit from staring at screen. Only had two coffees also:o

    It is indeed java.
    I have an ObservableList of Media types in a library class that I want to get metadata from.

    My closest attempt is as follows:
    TableView<Media> tableView = new TableView<Media>();
    tableView.setItems(myLib.getObsList());
    
    TableColumn<Media,String> artistCol= new TableColumn<Media,String>("Artist");
            artistCol.setCellValueFactory(new Callback<CellDataFeatures<Media, String>, ObservableValue<String>>() {
                    public ObservableValue<String> call(CellDataFeatures<Media, String> m) {
                       
                        return m.getValue().getMetadata().get("artist");
                    }
                });
    
    tableView.getColumns().setAll(artistCol);
    


    The issue now is the type that is returned does not match:

    java.lang.Object cannot be converted to javafx.beans.value.ObservableValue


  • Registered Users Posts: 1,454 ✭✭✭bogwalrus


    I made some progress. Now I can add one value to a cell but cant seem to group a few together. I tried adding to a string but it does not show up in the cell. I imagine it has to do with the way observers work.

    I want the cell to print the following:

    Artist: value
    Year: Value
    ALbum: value
    listView = new ListView<Media>(myLib.getObsList());
            listView.setCellFactory(new Callback<ListView<Media>, ListCell<Media>>() {
                    @Override
                    public ListCell<Media> call(ListView<Media> myObjectListView) {
                        ListCell<Media> cell = new ListCell<Media>(){
                                @Override
                                protected void updateItem(Media myObject, boolean b) {
                                    super.updateItem(myObject, b);
    
                                    if(myObject != null) {
                                        ObservableMap<String, Object> m = myObject.getMetadata();
                                        m.addListener(new MapChangeListener<String,Object>(){
                                                @Override
                                                public void onChanged(Change<? extends String, ? extends Object> ch) {  
    
                                                    String key = ch.getKey();
                                                    Object value = ch.getValueAdded();
                                                    
                                                    if(key.equals(value)){
    
                                                        setText(value.toString());
                                                    }
    
    
                                                }});
                                    }
                                }
                            };
    
                        return cell;
                    }
                });
    

    cheers,
    Boggy


Advertisement