[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-openjfx-dev
Subject:    Access to ListView Cells
From:       scekics () gmail ! com (Slavko Scekic)
Date:       2012-08-31 16:45:47
Message-ID: CAOMrua8+ozeORaVa=3sKO+TbKhPmbeObFG5i_FqFBrd5B9FCsA () mail ! gmail ! com
[Download RAW message or body]

Well, as I said before, you'd do that using the ListCell, but you don't
need to access every single cell. Instead, you'll need an Observable
property (JFX property) which will represent the user's state. So, when
that property's value changes, the ListCell will be notified and update the
visual indicator automatically.

Here's the simple example - let's suppose we have this little class:

public class User{
    private SimpleStringProperty username;
    private SimpleBooleanProperty isOnline;
}

I'd create a ListCell that looks like this:

//I've changed ListView<String> to ListView<User>
NodeStatusView extends ListCell<User> {
        ...
        StatusIndicator statusIndicator;
        ...
        public void updateItem(User item, boolean empty) {

                super.updateItem(item, empty);
                if (!empty && item != null) {
                        setText(item.getUsername);
                        myStatusNode = new StatusIndicator();
                        //note that you'd had to implement a method in your
StatusIndicator which would make it change it's appearance depending on
isOnline
                        myStatusNode.setIsOnline(item.isOnline)
                        //Another option is to create a constructor that
takes Boolean and creates a desired look. In that case the setIsOnline()
method would be unnecessary.
                        setGraphic(this.myStatusNode);
                }
        }
        ...
        public StatusIndicator getStatusIndicator() {
                return statusIndicator;
        }
        ...
}

Hope I understood you correctly and  this helps. Cheers!

On Fri, Aug 31, 2012 at 3:22 PM, Will Hoover <java.whoover at gmail.com> wrote:

> Maybe I wasn't clear enough in my description, but I'm not looking to
> manipulate any business data, but rather just the visual indicator. I'm
> also not looking to perform any actions based upon a selection. I just need
> to status indicator to show a visual aide to the user when say another
> connected user makes a change. Think of a chat application where you have a
> roster of users. As each user in the roster comes online a green indicator
> is displayed for them.****
>
> ** **
>
> *From:* centarforumi at gmail.com [mailto:centarforumi at gmail.com] *On Behalf
> Of *Slavko Scekic
> *Sent:* Friday, August 31, 2012 8:24 AM
> *To:* Will Hoover
> *Cc:* jonathan.giles at oracle.com; openjfx-dev at openjdk.java.net
>
> *Subject:* Re: Access to ListView Cells****
>
> ** **
>
> Well, I think that ListView's selectionModel property is what you need,
> if you want to change the process' state from within the GUI list (i.e.
> user selects a row and issues a command). If you want to update process'
> state programmatically, you can use ListView's getItems() method.
>
> To my understanding, ListCell is intended only to display, not manipulate
> data in this sense. So, if you have more than one possible state (i.e. node
> to display), you'd change your StatusIndicator to look something like this:
>
> StatusIndicator extends Parent {
>         ...
>         public Status getStatus() {
>                 return status;
>         }
>         public void setStatus(Status status) {
>                 if(status.equals(oneOption))
>                 {
>                     this.graphic= oneOptionGraphic;
>                 }
>                 else
>                 {
>                    this.praphic= anotherOptionGraphic;
>                 }
>         }
>         ...
> }
> Or something similar, this is just a guess based on your code.****
>
> On Fri, Aug 31, 2012 at 1:39 PM, Will Hoover <java.whoover at gmail.com>
> wrote:****
>
> Hi Jonathan,
>
> I have a ListView that contains custom ListCells which have a node that
> visually indicates a status of a business process and a label for the
> process name. I would like to be able to allow the user to set the status
> of
> an item at any given time. How would I do so without accessing the cell
> from
> myListView?
>
> myListView.setCellFactory(new Callback<ListView<String>,
> ListCell<String>>()
> {
>         public ListCell<String> call(ListView<String> list) {
>                 return new NodeStatusView();
>         }
> });
>
> NodeStatusView extends ListCell<String> {
>         ...
>         StatusIndicator statusIndicator;
>         ...
>         public void updateItem(String item, boolean empty) {
>                 super.updateItem(item, empty);
>                 if (!empty && item != null) {
>                         setText(item);
>                         myStatusNode = new StatusIndicator();
>                         setGraphic(this.myStatusNode);
>                 }
>         }
>         ...
>         public StatusIndicator getStatusIndicator() {
>                 return statusIndicator;
>         }
>         ...
> }
>
> StatusIndicator extends Parent {
>         ...
>         public Status getStatus() {
>                 return status;
>         }
>         public void setStatus(Status status) {
>                 this.status = status;
>         }
>         ...****
>
> }
>
> -----Original Message-----
> From: Jonathan Giles [mailto:jonathan.giles at oracle.com]
> Sent: Thursday, August 30, 2012 4:57 PM
> To: Will Hoover
> Cc: openjfx-dev at openjdk.java.net
> Subject: Re: Access to ListView Cells
>
> There isn't any API to access the cells within a ListView, unless you
> provide the cell factory yourself. It would be useful to understand your
> use
> case for wanting to access the cells outside of a cell factory.
>
> -- Jonathan
>
> On 31/08/2012 4:28 a.m., Will Hoover wrote:
> > I may be missing something, but there doesn't seem to be a way to
> > access cells generated from a ListView?
> >
> >
> >****
>
> ** **
>

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic