Sub binding property - more easy way?

Look at the code below. It binds to the titleProperty contained in an item stored in an < element > ObjectProperty.
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.stage.Stage;

public class BindingsTest extends Application {
  public static void main(String[] args) {
    launch(args);
  }

  @Override
  public void start(Stage primaryStage) {
    final ObjectProperty<Item> itemProperty = new SimpleObjectProperty<>();
    Item item = new Item();

    item.titleProperty().set("Title");

    StringBinding selectString = Bindings.selectString(itemProperty, "title");

    StringBinding title2 = new StringBinding() {
      {
        bind(itemProperty);
        if(itemProperty.get() != null) {
          bind(itemProperty.get().titleProperty());
        }
      }

      @Override
      protected void onInvalidating() {
        unbind(getDependencies());
        bind(itemProperty);
        if(itemProperty.get() != null) {
          bind(itemProperty.get().titleProperty());
        }
      }

      @Override
      protected String computeValue() {
        Item item2 = itemProperty.get();
        return item2 != null ? item2.getTitle().toUpperCase() : "(null)";
      }
    };

    System.out.println("Title = " + selectString.get() + "; uppercase title = " + title2.get());

    itemProperty.set(item);

    System.out.println("Title = " + selectString.get() + "; uppercase title = " + title2.get());

    item.titleProperty().set("New Title");

    System.out.println("Title = " + selectString.get() + "; uppercase title = " + title2.get());
  }

  public class Item {
    private final StringProperty title = new SimpleStringProperty();
    public String getTitle() { return title.get(); }
    public StringProperty titleProperty() { return title; }
  }
}
The code prints:
Title = null; uppercase title = (null)
Title = Title; uppercase title = TITLE
Title = New Title; uppercase title = NEW TITLE
The constructor of the binding and the onInvalidating() part seems very convuluted. Initially I just put this in the anonymous constructor of StringBinding:
  bind(Bindings.selectString(itemProperty, "title"));
Unfortunately, this doesn't seem to work. It will result in:
Title = null; uppercase title = (null)
Title = Title; uppercase title = TITLE
Title = New Title; uppercase title = TITLE
The idea here is to listen to the changes in the titleProperty... everywhere where itemProperty points to at the time. It works when linking directly, but apparently it does not work as a dependency of StringBinding.

The best solutions?

Published by: john16384 on February 14, 2012 21:56
itemProperty().addListener(new ChangeListener() {
  public void change(ObservableValue observableValue, Item oldValue, Item newValue) {
    if (oldValue != null) {
      uninstallItem(oldValue);
    }
    if (newValue != null) {
      installItem(newValue);
    }
  }
});

private void uninstallItem(Item oldValue) {
  titleProperty().unbind();
}

private void installItem(Item newValue) {
  titleProperty().bind(newValue.itemProperty());
}

Published by: boumedienne on February 16, 2012 12:31

Tags: Java

Similar Questions

  • Is there a more efficient way to use the visible property node to make the inactive/hiding controls on the front?

    I just inherited the labview code to run a system of imaging optics mamography.

    It has 32 sources 128 detectors and 2 games of light and the user has the possibility to control the parameters of gain for each sensor to each source for each source of wavelengths, so as you can imagine there are a lot of orders and LEDs on the front panel.

    The user also has the possibility to choose the number of sources and that they would like to use detectors.  v: * {behavior:url(#default#VML) ;} O'Bryan: * {behavior:url(#default#VML) ;} w\: * {behavior:url(#default#VML) ;} .shape {behavior:url(#default#VML) ;}}}} Normal 0 false false false MicrosoftInternetExplorer4 / * Style Definitions * / table. MsoNormalTable {mso-style-name: "Table Normal" "; mso-knew-rowband-size: 0; mso-knew-colband-size: 0; mso-style - noshow:yes; mso-style-parent:" ";" mso-padding-alt: 0 to 5.4pt 0 to 5.4pt; mso-para-margin: 0; mso-para-margin-bottom: .0001pt; mso-pagination: widow-orphan; do-size: 10.0pt; do-family: "Times New Roman"; mso-ansi-language: #0400; mso-fareast-language: #0400; mso-bidi-language: #0400 ;} "}

    Depending on how many sources are entered labview code through a loop For which in fact a 'smooth box' visible or invisible, on the adjustment of gain control depending on whether the current detector is greater than the seizure of the number by the user.  This loop slows down the program because it works 128 times (max number of detectors) and has 4 structures deal (2 sets of wavelengths, 2 for each breast) with 64 nodes of property each where it is visible property to enabled or disables the box with that covers the detectors.

    I was wondering if there was an easier way to enable or disable controls for unused detectors, not only that slows down the program but to reconfigure the data to use more sources, I stop the program and restart it.

    Any advice on the creation of a dynamic front would be appreciated


  • Is there a more easy/more simple way to achieve this?

    Good morning (afternoon to you, BluShadow).

    I got following exact, as you wish, output (derived from the EMP table):
    D10     D20     D30     PREZ    MGRS    ANALS   SALESM  CLERKS
    ------- ------- ------- ------- ------- ------- ------- -------
    CLARK   JONES   WARD    KING    BLAKE   FORD    ALLEN   ADAMS
    KING    FORD    TURNER          CLARK   SCOTT   MARTIN  JAMES
    MILLER  ADAMS   ALLEN           JONES           TURNER  MILLER
            SMITH   JAMES                           WARD    SMITH
            SCOTT   BLAKE
                    MARTIN
    by using the following query:
     with
       --
       -- pivoted departments  (haven't studied the Oracle PIVOT clause yet)
       --
       depts as
       (
        select max(case deptno
                     when 10 then ename
                   end)                                 as d10,
               max(case deptno
                     when 20 then ename
                   end)                                 as d20,
               max(case deptno
                     when 30 then ename
                   end)                                 as d30,
               rnd
          from (
                select deptno,
                       ename,
                       row_number() over (partition by deptno
                                              order by deptno)  rnd
                  from emp
               )
         group by rnd
         order by rnd
       ),
       --
       -- pivoted jobs
       --
       jobs as
       (
        select max(case job
                     when 'CLERK'         then ename
                   end)                                 as Clerks,
               max(case job
                     when 'PRESIDENT'     then ename
                   end)                                 as Prez,
               max(case job
                     when 'MANAGER'       then ename
                   end)                                 as Mgrs,
               max(case job
                     when 'ANALYST'       then ename
                   end)                                 as Anals,
               max(case job
                     when 'SALESMAN'      then ename
                   end)                                 as SalesM,
               rnj
          from (
                select job,
                       ename,
                       row_number() over (partition by job
                                              order by ename)   as rnj
                  from emp
               )
         group by rnj
         order by rnj
       )
    select d10,
           d20,
           d30,
           Prez,
           Mgrs,
           Anals,
           SalesM,
           Clerks
      from depts a full outer join jobs b
                                on a.rnd = b.rnj
     order by rnj, rnd;
    that takes a total of 5 selects to get there.

    I tried to find a query that would be, I hope more simple, easier and does not require as much selects. My last attempt is the following (which is closer to the desired result, but does not get a cigar yet):
    select case deptno
             when 10 then ename
           end                                 as d10,
           case deptno
             when 20 then ename
           end                                 as d20,
           case deptno
             when 30 then ename
           end                                 as d30,
           case job
             when 'CLERK'         then ename
           end                                 as Clerks,
           case job
             when 'PRESIDENT'     then ename
           end                                 as Prez,
           case job
             when 'MANAGER'       then ename
           end                                 as Mgrs,
           case job
             when 'ANALYST'       then ename
           end                                 as Anals,
           case job
             when 'SALESMAN'      then ename
           end                                 as SalesM,
           row_number() over (partition by deptno
                                  order by deptno)  as rnd,
           row_number() over (partition by job
                                  order by ename)   as rnj
      from emp
     order by rnj;
    The query above annoys me to this result which is encouraging, but... the brand:
    D10     D20     D30     CLERKS  PREZ    MGRS    ANALS   SALESM   RND  RNJ
    ------- ------- ------- ------- ------- ------- ------- ------- ---- ----
                    ALLEN                                   ALLEN      3    1
            ADAMS           ADAMS                                      2    1
                    BLAKE                   BLAKE                      6    1
    KING                            KING                               2    1
            FORD                                    FORD               1    1
            SCOTT                                   SCOTT              5    2
                    JAMES   JAMES                                      5    2
    CLARK                                   CLARK                      3    2
                    MARTIN                                  MARTIN     2    2
                    TURNER                                  TURNER     1    3
    MILLER                  MILLER                                     1    3
    
    D10     D20     D30     CLERKS  PREZ    MGRS    ANALS   SALESM   RND  RNJ
    ------- ------- ------- ------- ------- ------- ------- ------- ---- ----
            JONES                           JONES                      3    3
                    WARD                                    WARD       4    4
            SMITH           SMITH                                      4    4
    It uses a single SELECT statement and contains all the data that should be displayed, but I can't find a way to eliminate NULL values without losing a few jobs or departments

    Your help is welcome and appreciated,

    John.

    PS: I'll be perfectly happy to learn that there is no way more easy/simple. In other words, if the answer is simply "No, there no simpler or easier way", please let me know which is the case. (I ask that you be sure enough of that though, thank you)

    Published by: 440bx - 11 GR 2 on July 25, 2010 07:19 - added PS.

    According to the hoek' suggestion ;-)

    SQL> select d10, d20, d30, prez, mgrs, anals, salesm, clerks
      2    from (select row_number() over(partition by deptno order by ename) rn,
      3                 ename,
      4                 to_char(deptno) deptno
      5            from emp
      6          union all
      7          select row_number() over(partition by job order by ename),
      8                 ename,
      9                 job
     10            from emp) pivot(max(ename) for deptno in(10  d10,
     11                                                     20  d20,
     12                                                     30  d30,
     13                                                     'ANALYST'  anals,
     14                                                     'CLERK'  clerks,
     15                                                     'MANAGER'  mgrs,
     16                                                     'PRESIDENT'  prez,
     17                                                     'SALESMAN'  salesm))
     18   order by rn
     19  /
    
    D10        D20        D30        PREZ       MGRS       ANALS      SALESM     CLERKS
    ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
    CLARK      ADAMS      ALLEN      KING       BLAKE      FORD       ALLEN      ADAMS
    KING       FORD       BLAKE                 CLARK      SCOTT      MARTIN     JAMES
    MILLER     JONES      JAMES                 JONES                 TURNER     MILLER
               SCOTT      MARTIN                                      WARD       SMITH
               SMITH      TURNER
                          WARD
    
    6 rows selected.
    

    Best regards

    Maxim

  • The easy/more faster way to change my IP address?

    Using a DSL with an Actiontec GT784. So far, I had to turn off the modem for a few seconds I don't have the password. Is there an easier way to do this?  Using a DSL connection.  Up til now I had to turn off the modem for a few seconds.  Its an Actiontec 701 d.

    Hello

    Thanks for posting your query on the Microsoft Community.

    According to the description, I understand that you do not want to change your IP address.

    You can try the steps below and check.

    1. find your IP from the ISP.

    2 copy.

    3. open network & sharing Center

    4. open the network properties you what your IP to change. In my case, it's an EVDO modem.

    5. on the network tab, double-click TCP/IPv4, which will open a window to change the IP and DNS IP address.

    6. in this window click on "use following IP address" and paste this IP address you copied in step 2.

    7 change the last digit of the IP address to any value above him for example if its 192.168.23.123 change the last digit to something like 122 so that the IP address becomes 192.168.23.122.

    8. click on OK until that close all windows.

    9 disconnect from this network.

    10 reconnect to this network and if it goes as planned the ISP should force a dynamic IP address.

    Now, check if you have changed the IP address. If you can not browse, go to step 6, and then select "Obtain an IP address automatically" and then disconnect-> reconnect to the network.

    Hope this information helps. Please let us know if you need any other help with Windows in the future. We will be happy to help you.

  • Is there an easy way to remove faces metadata?

    I won't get in my frustrations of moving from iPhoto to Photos, but there more with him a bunch of incorrectly marked faces. Is there an easy way to delete all the metadata of faces of all my photos so I can start over? Thank you

    None

    You can tell Apple that you need to be included in future releases - http://www.apple.com/feedback/photos.html

    (and of course the identification wrong iPhoto has nothing to do with the Photos)

    As for frustration - the solution is to take the time to learn how to use pictures - it's a new and different program that, like all new software, does not exactly work as pref = vious PHotos and software has a learning curve - until you take the time to learn how to use it you will continue to be frustrated because you will be with any new product tha tyou don't understand

    LN

  • An easy way to remove floating ads when they appear (for example, not prevent it)?

    Usually I don't mind the ads on web pages. So, I feel strongly to use ad-blocking software to prevent any or all kinds of ads. But I don't mind the ads that float on web pages because they often block the view.

    Although some floating ads allow the user to close them, more pop ups or other types of malware, can appear after their closure.

    Yes, is there an easy way (an add-on, perhaps) to remove the floating ads after they appear and prevent them from generating more ads or to show again when the page is reloaded?

    Maybe something like "CTRL + Alt + left click on ' applied to the floating ads?

    I don't want to turn off scripts and Flash.

    There are Add-ons that, but they don't have not been updated in a long time, while they might have problems.

    Earlier, I would recommend Adblock Plus, used as follows:

    1. Install Adblock more.

    2. Click on Adblock Plus toolbar icon and click Filter Preferences.
    3. Subscriptions, right-click each subscription tab and choose Remove. Now, Adblock Plus is not blocking anything.
    4. Install the element hidden assistance made to Adblock Plus.
    5. Now when you want to hide something on a web page, click on Adblock Plus toolbar icon and choose "select an item to hide."
    6. Web page preview is acceptable, click the button add element hiding rule. For advanced use, see the following pages.
  • Is there an easy way for me to go back to the old format for Mazilla Firefox?

    I have problems with the new version of Mozilla Firefox. Is there an EASY way for me to go back to the old format?
    Thank you!
    JES
    PS Please, please... Be very specific about what to click on and where to go... I'm still learning about computers. Thanks again.

    I suggest you another go to Firefox 4.0 comfortable for you, and it would be
    be faster for changes that will bring back to 3.6.17 or at least a lot more and the changes you need to do, sooner or later, whether for Firefox 4, Firefox 5 or Firefox 6...

    You can make Firefox 4.0.1 resemble Firefox 3.6.17, paragraphs numbered 1 to 10 in the next topic difficulty Firefox 4.0 UI toolbar, problems (make Firefox 4.0 look like 3.6)

    If still not convinced of the next section on this page is performing Fx3 Fx4 or returning to the Fx3 (#backto3pt6)

  • easy way to make previous Community entries

    I'll periodically with communities in support of review issues people have then I'll be better prepared for the customer calls.

    However, after reading an entry, there is no easy way to return to the previous page I'm viewing, whenever it returns me to the last page, and I have to manually the page through items that I've seen is to make the next "previous" entry which I.

    Many other forums show a 'page 1 of x"and allow you to enter in the address line, or page number manually, see which 'page', you are on and enter it in the address field.

    Any suggestions?

    What I hear you saying is that you use lists of main forum to browse songs (a "Load More" at the end of the list)

    Add '/content' at the end of the URL for a better list (it has "Pages")

    ORDER click on the title to open in a new TAB and close TAB when you're done reading / replying - volia! you're back where you leave - AND the title you have chosen will have an underline invites you to

    After the return if you want more power tips - there are a few that are VERY convenient

  • must be an easier way...

    Here's a screenshot of my block diagram. I keep thinking that there must be an easier way to fill values other than cluster using these two nested for loops, but I can't think one. I am taking 4 rows of an array of bytes and fill of the items in cluster 0-5 to 6 bits of rank 0, cluster items 6-12 with six bits of rank 1, elements of cluster 13-18 with 6 bits of rank 2, then the remaining elements of the 3 cluster with 3 bits of tier 3. Any suggestions or is this the best way? I seem to think there must be something more simple. I have to see this end up in the rube goldberg section easily


  • decorations such as easier way of indicators?

    OK, I am tempted to this post on the thread of Rube Goldberg

    Yes, they have to be round - and they must be in that order. It is well to be an easier way!  Frankly, it's the code more villain that I've written over the years.

    Just use a custom control.  Here is a round box of color.

  • Easy way to search by date in Vista?

    Just updated from XP to Vista & cannot figure out how to find my documents by date.  I liked the search function on XP that would allow you to search by date, for example, created during the month, week, year, etc.  Is there an easy way to do this in Vista?  The instructions in the help of Vista are difficult to follow.  Help!

    Start typing a file name, and then click search everywhere which appears just above the area.  Will take you to the advanced search box.  Delete what you have entered to access the advanced search box and click search.  You will see a section for the date.  Enter the date you want, whether you want files on, before or after this date and if you want date of creation or modified date and click search.  Search will find the files you want.  Don't forget to select the basis of appropriate research (only the indexed locations or drive c:\ or something else) and whether or not you want to not indexed, hidden and system files included.

    I hope this helps.

    Good luck! Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

  • Y at - it an easy way to access the "Ax Files.

    Original title: Ax files

    Is there a easy way to access the "AX FILES" or a free download that can be available?  If there is that no need of them wishes to delete their.  I am running WINDOWS 7 HOME PREMIUM.  It seems downloads, but don't know who his are sure.

    I'm sorry, I accidentally did typo and wrote that windows media player supports, I've corrected the sentence in my response. These types of files are essentially the plugin files, used to play videos on the internet, and the best player is QuickTime player.

    No, Disk Defragmenter is a tool that rearranges the data on your volume and brings together fragmented data so that your computer can run more efficiently.

  • Template file - y at - it an easy way to update the files related to a model, and download them (put) at the same time?

    First of all, I am a user of Adobe software for 20 years now.  I love the adobe range. I want to just clarify.

    Question... Template Files - y at - it an easy way to update the files related to a model, and download them (put) at the same time?

    Its been bothering me since I started using Dreamwever 10 years now, when you use template files to create small, who later turn wholesale websites. Whenever I update a template file I have to find each file in the files Panel, then download them. When I navigate through a lot of directories to find it can get a lot of time and boring.  Whey cant be just a button that does it? See the attached file.

    Is there a way to do this?  Any help would be appreciated.

    Thank you very much

    Andy

    Dreamweaver-Updated-Template-File.jpg

    The sync tool should do what you want (second "circular arrows" icon in the files window).

    Who checks your files against the files of the current server and download all that is changed. By default, is also download any file from the server which is more recent than your local files at the same time, but you can set it to 'Put the latest files remotely' rather than 'get and put newer files' and you should be good to go.

  • Easy way to synchronize the audio left and right, from different sources?

    I mainly filmed concerts of a single camera using a Sony Z1 - when they are available, I'll take a sound card feeds channel 1, and a live auditorium feed a microphone mono channel 2. Because of the distance of the scene (and light is faster than sound, etc.), the power of the sound card is synchronized with the video and power of the auditorium is between 1 and 3 frames behind. Is there an easy way for me to take the tray clips together and just move this auditorium feed back in sync with the video and sound card feed, raw clips?

    Previously, I did this by dropping the clips to the timeline, done to separate tracks, sliding manually sync on the auditorium that feed by the required number of frames and link everything back up again. Synchronize audio visually using the waveform display (before first CC).

    I have two problems with this in Adobe first CC. First, the audio waveforms are not like waveforms more (and it doesn't seem to be possible to change the display to the old way?). So now that I am syncing the auditorium that feed in sound only, because I don't see anything on the screen to sync any more - both channels just look like random noise (or almost).

    Secondly, I film some events of multi camera, and of course, I'd like to be able to use the new functionality of synchronization for the multicam. But I know in advance that the audio channels on all the clips are not synchronized with the video (the camera powered by the sound card will be synchronized, the camera takes live food out as indicated above). Surely, there must be a way where I can fix the sync audio to video on raw clips first, before you say Adobe to synchronize based on the audio clips? Otherwise it will all be misaligned and require adjustment of the manual sync anyway? Again, what I've done previously is set of benchmarks on the identical frames, multi camera sync (so the video is now just good) and then manually set the audio synchronization before editing.

    In the context menu for the timeline, you can uncheck rectified of Audio waveforms for their return to normal.  (I wish that Adobe does not have this as default.  It's just weird.)

    But to synchronize, you can only do in the order.

  • Easy way to hitTestObject all elements of array?

    Hey guys, is there an easy way, using 1 or more for loops, to hit the all test objects in a table against any object in this table.

    So I have a table of 6 work

    If (1 hits 2)

    If (1 typo 3)

    If (1 hits 4)... etc.

    If (the 2 hits 1)

    If (2 hits 3)

    If (the 2 hits 4)... etc.

    Thanks in advance, much appreciated.

    for (var i: int = 0; i<>

    for (var j: int = i + 1; j<>

    {if (array1 [i] .hitTestObject (array1 [j]))}

    do everything.

    }

    }

    }

Maybe you are looking for