Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

set Metadata to TableColumn

  • 04-10-2016 10:52AM
    #1
    Registered Users, Registered Users 2 Posts: 1,456 ✭✭✭


    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, Paid Member Posts: 2,691 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, Registered Users 2 Posts: 1,456 ✭✭✭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, Registered Users 2 Posts: 1,456 ✭✭✭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