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

List:       openjdk-openjfx-dev
Subject:    Re: How to pause service when it's not visible in TabPane
From:       Tomas Mikula <tomas.mikula () gmail ! com>
Date:       2014-07-30 22:52:45
Message-ID: CA+THruqbJWcGkucEOJxA1TY+jvaxSfm-byjEgBfGAEEDavzc8Q () mail ! gmail ! com
[Download RAW message or body]

On Thu, Jul 31, 2014 at 12:51 AM, Tomas Mikula <tomas.mikula@gmail.com> wrote:
> I'm not sure I understand: you have many service subclasses, each of
> them associated with a tab? If so, they can take the tab as an
> argument to the constructor:
>
>     abstract class TabService extends Service {
>         protected MyAbstractService(Tab tab) {

This should have been

        protected TabService(Tab tab) {

>             tab.selectedProperty().addListener((obs, old, selected) -> {
>                 if(selected) {
>                     restart();
>                 } else {
>                     cancel();
>                 }
>             });
>         }
>     }
>
>     class FooService extends TabService {
>         public FooService(Tab tab) {
>             super(tab);
>         }
>     }
>
> Alternatively, you can have a Tab subclass that takes Service as
> constructor argument.
>
> Alternatively, you can have a static helper method that binds the
> service to the tab and use it from any class:
>
>     static bind(Service service, Tab tab) {
>         tab.selectedProperty().addListener((obs, old, selected) -> {
>             if(selected) {
>                 service.restart();
>             } else {
>                 service.cancel();
>             }
>         });
>     }
>
> Was that an answer to your question?
>
> Best,
> Tomas
>
> On Wed, Jul 30, 2014 at 3:44 PM, Peter Penzov <peter.penzov@gmail.com> wrote:
>> Hi Tomas,
>>   I'm not 100% sure but I tested the proposed code and it seems that it's
>> working. One more question. I have too many Java Classes into which I need
>> to implement this. Is there a quick and easy way to get the Tab Object into
>> the service class where I need to implement this?
>>
>> BR,
>> Peter
>>
>>
>> On Wed, Jul 30, 2014 at 1:22 PM, Tomas Mikula <tomas.mikula@gmail.com>
>> wrote:
>>>
>>> What about
>>>
>>>     tab.selectedProperty().addListener((obs, old, selected) -> {
>>>         if(selected) {
>>>             service.restart();
>>>         } else {
>>>             service.cancel();
>>>         }
>>>     });
>>>
>>> ?
>>>
>>> Best,
>>> Tomas
>>>
>>> On Wed, Jul 30, 2014 at 9:07 AM, Peter Penzov <peter.penzov@gmail.com>
>>> wrote:
>>> > Hi All,
>>> >    I have a TabPane with JavaFX service which displays some data. I'm
>>> > interested is there a way to pause the service when I switch the tabs
>>> > and
>>> > the service is not visible? It 'will same me a lot of CPU resources if
>>> > there is a way to implement this.
>>> >
>>> > BR,
>>> > Peter
>>
>>
[prev in list] [next in list] [prev in thread] [next in thread] 

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