Announcement Announcement Module
Collapse
No announcement yet.
RefreshableValueHolder + ComboBox not refreshing Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RefreshableValueHolder + ComboBox not refreshing

    Hi all,

    I just updated my project to use the newest sources. Before that I used "pre-0.1" sources.

    The new sources give me a new problem. I have a combobox on my form,and a button next to it which is used to open a new form. The form is used to create a new object to the selection list of the combobox.

    The Combobox is bound to a RefreshableValueHolder.

    The problem is that the combobox is not refreshing, although debug messages indicate:

    Code:
    &#91;DEBUG,RefreshableValueHolder,AWT-EventQueue-0&#93; Setting held value from '&#91;<list of old values>&#93;' to '&#91;<list of new values>&#93;'
    
    &#91;DEBUG,RefreshableValueHolder,AWT-EventQueue-0&#93; Firing value changed event. Old value= '&#91;<list of old values>&#93;' new value='&#91;<list of new values>&#93;'
    
    DEBUG DynamicComboBoxListModel,AWT-EventQueue-0&#58;125 - Backing collection of selectable items changed; refreshing combo box with contents of new collection.
    But the actual contents remain unchanged.
    This worked fine before upgrading to the newest sources.

    Explanation of my code:

    I call RefreshableValueHolder.refresh() when the creation form has finished.

    For example I have combobox that has "Grade" objects.

    Code:
            gradeListHolder = new RefreshableValueHolder&#40;new Closure&#40;&#41; &#123;
                public Object call&#40;Object object&#41; &#123;
                    return getDAO&#40;&#41;.getGrades&#40;&#41;;
                &#125;
            &#125;, true,false&#41;;

    Code:
    JComboBox gradeCombo = &#40;JComboBox&#41; sbf.createBoundComboBox&#40;"grade",gradeListHolder,"description"&#41;.getControl&#40;&#41;;
    Thanks for any advice. Ask me more details if needed.

    Regards,
    Antti

  • #2
    I debugged this a little bit, and it seems that DynamicComboBoxListModel's listenerList somehow loses the combobox.
    Code:
    listenerList= Object&#91;6&#93;  &#40;id=779&#41;
    	&#91;0&#93;= Class &#40;javax.swing.event.ListDataListener&#41; &#40;id=122&#41;
    	&#91;1&#93;= JComboBox  &#40;id=746&#41;
    	&#91;2&#93;= Class &#40;javax.swing.event.ListDataListener&#41; &#40;id=122&#41;
    	&#91;3&#93;= BasicListUI$ListDataHandler  &#40;id=780&#41;
    	&#91;4&#93;= Class &#40;javax.swing.event.ListDataListener&#41; &#40;id=122&#41;
    	&#91;5&#93;= BasicComboBoxUI$ListDataHandler  &#40;id=781&#41;
    It seems that the combobox is contained in the list first (when the combobox is binded and created), but somehow it is not there anymore when the RefreshableValueHolder is refreshed. I haven't yet noticed when and why the listenerlist is modified and the reference to the combobox is lost.

    I don't know if this makes sense. But with the older RCP sources this seems to work, and I can see the combobox in the listenerlist when I debug it. With the newer sources I can see only the ComboBoxAutoCompletion object, which I use.

    Code:
    listenerList= Object&#91;2&#93;  &#40;id=703&#41;
    	&#91;0&#93;= Class &#40;javax.swing.event.ListDataListener&#41; &#40;id=122&#41;
    	&#91;1&#93;= ComboBoxAutoCompletion$ModelChangeHandler  &#40;id=701&#41;
    So I think this is the reason why the changes are not propagated to the combobox. Could somebody help me fix this?




    Thanks,
    Antti

    Comment


    • #3
      Ok, I got this (with some side effects) to work. The reason was my mistake, as usual. I didn't understand the new binding system correctly.

      I was actually binding this property twice.

      Like:

      Code:
      clubCombo = &#40;JComboBox&#41; sbf.createBoundComboBox&#40;"club",clubListHolder,"abbrev"&#41;.getControl&#40;&#41;;
      
      formBuilder.add&#40;"club",clubCombo&#41;;
      Which binds the property twice...

      But the correct way is obviously:

      Code:
      formBuilder.add&#40;sbf.createBoundComboBox&#40;"club",clubListHolder,"abbrev"&#41;&#41;;
      This makes the RefreshableValueholder backed combo to update correctly when refreshed.

      However, the with ComboBoxAutoCompletion the combobox won't initialize (ie. the textfield is empty although the formmodel has a value for that property). Oddly it initialized correctly when binding the property twice!?

      Any advice? I can live without the ComboBoxAutoCompletion, but it would be a nice feature...

      Regards,
      Antti

      Comment


      • #4
        From looking at the code in ComboBoxAutoCompletion.fillItem2StringMap it appears that the currently selected item should be retained. So, my guess is that it's not being selected initially.

        Does your combobox list model contain the current item (in the form model) at the time the control is created?

        Larry.

        Comment


        • #5
          Hello Larry, thanks for your reply.




          Does your combobox list model contain the current item (in the form model) at the time the control is created?
          Yes, I think so. If I disable the ComboBoxAutoCompletion from the FormComponentInterceptorFactory the current item is selected.

          When enabled, the textfield of the combobox is initially empty. However I noticed that the current item is selected in the dropdown list... If I select it (or any other item) then the autocompletion works ok. More specifically, the autocompletion works also if I start typing into the empty field. But it would be nicer if the textfield could show the selected item's rendered property straight away...

          Antti

          Comment


          • #6
            Not to be flippant, but it must be something you're doing

            I use a number of comboboxes (all with autocompletion enabled) and they properly show the selected item in the text area. I can only assume it is some interaction between your selectable items value holder and the autocompletion code.

            Sorry to be of so little help.

            Larry.

            Comment


            • #7
              Not to be flippant, but it must be something you're doing
              I agree

              I still haven't found the answer (about the combobox autocompletion).

              Here's my form's code:



              Code:
              public class ParticipationGeneralForm extends ParkFermeForm implements ActionListener &#123;
                  public static final String GENERAL_FORM_PAGE = "participationForm";
              
                  private JComponent partNoField;
                  
                  RefreshableValueHolder clubListHolder;
                  
                  RefreshableValueHolder gradeListHolder;
                  
                  RefreshableValueHolder groupListHolder;
                  
                  JComboBox clubCombo;
                  
                  public ParticipationGeneralForm&#40;&#41;  &#123;
                      setId&#40;GENERAL_FORM_PAGE&#41;;
                      
                  &#125;
                  
                  
                  /* &#40;non-Javadoc&#41;
                   * @see java.awt.event.ActionListener#actionPerformed&#40;java.awt.event.ActionEvent&#41;
                   */
                  public void actionPerformed&#40;ActionEvent e&#41; &#123;
                     String command = e.getActionCommand&#40;&#41;;
                     if &#40;command.equals&#40;"newClub"&#41;&#41; &#123;
                        
                         NewClubCommandExecutor exec = &#40;NewClubCommandExecutor&#41; getApplicationContext&#40;&#41;.getBean&#40;"newClubCommandExecutor"&#41;;
                         exec.execute&#40;&#41;;
                         Club c = &#40;Club&#41; exec.getNewObject&#40;&#41;;
                         if &#40;c.getId&#40;&#41; != null&#41; &#123;
                             Participation p = &#40;Participation&#41; getFormObject&#40;&#41;;
                             
                             clubListHolder.refresh&#40;&#41;;
                            
                             getFormModel&#40;&#41;.getValueModel&#40;"club"&#41;.setValue&#40;c&#41;;
                            
              
                         &#125;
                     &#125;
                     else if &#40;command.equals&#40;"newGrade"&#41;&#41; &#123;
                         NewGradeCommandExecutor exec = &#40;NewGradeCommandExecutor&#41; getApplicationContext&#40;&#41;.getBean&#40;"newGradeCommandExecutor"&#41;;
                         exec.execute&#40;&#41;;
                         Grade g = &#40;Grade&#41; exec.getNewObject&#40;&#41;;
                         if &#40;g.getId&#40;&#41; != null&#41; &#123;
                             Participation p = &#40;Participation&#41; getFormObject&#40;&#41;;
                             gradeListHolder.refresh&#40;&#41;;
                             getFormModel&#40;&#41;.getValueModel&#40;"grade"&#41;.setValue&#40;g&#41;;
                            
              
                         &#125;
                     &#125;
                     else if &#40;command.equals&#40;"newGroup"&#41;&#41; &#123;
                         NewGroupCommandExecutor exec = &#40;NewGroupCommandExecutor&#41; getApplicationContext&#40;&#41;.getBean&#40;"newGroupCommandExecutor"&#41;;
                         exec.execute&#40;&#41;;
                         Group g = &#40;Group&#41; exec.getNewObject&#40;&#41;;
                         if &#40;g.getId&#40;&#41; != null&#41; &#123;
                             Participation p = &#40;Participation&#41; getFormObject&#40;&#41;;
                             groupListHolder.refresh&#40;&#41;;
                             getFormModel&#40;&#41;.getValueModel&#40;"car.group"&#41;.setValue&#40;g&#41;;
                             
              
                         &#125;
                     &#125;
                  &#125;
              
                  protected JComponent createFormControl&#40;&#41; &#123;
                      
                      
                      SwingBindingFactory sbf = &#40;SwingBindingFactory&#41; getBindingFactory&#40;&#41;;
                      TableFormBuilder formBuilder = new TableFormBuilder&#40;sbf&#41;;
                      
                      clubListHolder = new RefreshableValueHolder&#40;new Closure&#40;&#41; &#123;
                          public Object call&#40;Object object&#41; &#123;
                              return getDAO&#40;&#41;.getClubs&#40;&#41;;
                          &#125;
                      &#125;, true,false&#41;; 
                      
                      groupListHolder = new RefreshableValueHolder&#40;new Closure&#40;&#41; &#123;
                          public Object call&#40;Object object&#41; &#123;
                              return getDAO&#40;&#41;.getGroups&#40;&#41;;
                          &#125;
                      &#125;, true,false&#41;; 
                      
                      gradeListHolder = new RefreshableValueHolder&#40;new Closure&#40;&#41; &#123;
                          public Object call&#40;Object object&#41; &#123;
                              return getDAO&#40;&#41;.getGrades&#40;&#41;;
                          &#125;
                      &#125;, true,false&#41;; 
                      
                      formBuilder.addSeparator&#40;"separator.driver"&#41;;
                      formBuilder.row&#40;&#41;;
                      partNoField = formBuilder.add&#40;"partNo"&#41;&#91;1&#93;;
                      formBuilder.row&#40;&#41;;
                      JComponent jt = formBuilder.add&#40;"driver.licenseNo"&#41;&#91;1&#93;;
                      jt.addFocusListener&#40;new LicenseNoFocusListener&#40;&#41;&#41;;
                      formBuilder.row&#40;&#41;;
                      formBuilder.add&#40;"driver.firstName"&#41;;
                      formBuilder.row&#40;&#41;;
                      formBuilder.add&#40;"driver.lastName"&#41;;
                      formBuilder.row&#40;&#41;;
              
              
                      formBuilder.addSeparator&#40;"separator.guardian"&#41;;
                      formBuilder.row&#40;&#41;;
                      formBuilder.add&#40;"guardianName"&#41;;
                      formBuilder.row&#40;&#41;;
                      formBuilder.add&#40;"guardianLicenseNo"&#41;;
                      formBuilder.row&#40;&#41;;
                      formBuilder.addSeparator&#40;"separator.address"&#41;;
                      formBuilder.row&#40;&#41;;
                      formBuilder.add&#40;"driver.address.streetAddress1"&#41;;
                      formBuilder.row&#40;&#41;;
                      formBuilder.add&#40;"driver.address.zipCode"&#41;;
                      formBuilder.row&#40;&#41;;
                      formBuilder.add&#40;"driver.address.city"&#41;;
                    
                      
                      formBuilder.row&#40;&#41;;
                      formBuilder.addSeparator&#40;"separator.race"&#41;;
                      formBuilder.row&#40;&#41;;
                      
                      JButton newClubButton = new JButton&#40;"..."&#41;;
                      newClubButton.setActionCommand&#40;"newClub"&#41;;
                      newClubButton.addActionListener&#40;this&#41;;
                      
                      JButton newGradeButton = new JButton&#40;"..."&#41;;
                      newGradeButton.setActionCommand&#40;"newGrade"&#41;;
                      newGradeButton.addActionListener&#40;this&#41;;
                      
                      JButton newGroupButton = new JButton&#40;"..."&#41;;
                      newGroupButton.setActionCommand&#40;"newGroup"&#41;;
                      newGroupButton.addActionListener&#40;this&#41;;
                      
              
                      formBuilder.add&#40;sbf.createBoundComboBox&#40;"club",clubListHolder,"abbrev"&#41;&#41;;
              
                      formBuilder.getLayoutBuilder&#40;&#41;.gapCol&#40;&#41;;
                      formBuilder.getLayoutBuilder&#40;&#41;.cell&#40;newClubButton&#41;;
                      formBuilder.row&#40;&#41;;
                      
                      Binding gradeBinding = sbf.createBoundComboBox&#40;"grade",gradeListHolder,"description"&#41;;
                      formBuilder.add&#40;gradeBinding&#41;;
                      
                      formBuilder.getLayoutBuilder&#40;&#41;.gapCol&#40;&#41;;
                      formBuilder.getLayoutBuilder&#40;&#41;.cell&#40;newGradeButton&#41;;
                      formBuilder.row&#40;&#41;;
                      
                      formBuilder.add&#40;"announcer"&#41;;
                      formBuilder.row&#40;&#41;;
                      
                      formBuilder.addSeparator&#40;"separator.car"&#41;;
                      formBuilder.row&#40;&#41;;
                      
                      formBuilder.add&#40;"car.brand"&#41;;
                      formBuilder.row&#40;&#41;;
                      
                      Binding groupBinding = sbf.createBoundComboBox&#40;"car.group",groupListHolder,"description"&#41;;
                      formBuilder.add&#40;groupBinding&#41;;
                      formBuilder.getLayoutBuilder&#40;&#41;.gapCol&#40;&#41;;
                      formBuilder.getLayoutBuilder&#40;&#41;.cell&#40;newGroupButton&#41;;
                      formBuilder.row&#40;&#41;;
                      
                      formBuilder.add&#40;"car.engineCC"&#41;;
                      formBuilder.row&#40;&#41;;
                      
                      formBuilder.add&#40;"car.inspectionNo"&#41;;
                      
                      return formBuilder.getForm&#40;&#41;;
                  &#125;
              
                  public boolean requestFocusInWindow&#40;&#41; &#123;
                      return partNoField.requestFocusInWindow&#40;&#41;;
                  &#125;
              
              
                  
                  private class LicenseNoFocusListener extends FocusAdapter &#123;
              
                      /* &#40;non-Javadoc&#41;
                       * @see java.awt.event.FocusAdapter#focusLost&#40;java.awt.event.FocusEvent&#41;
                       */
                      public void focusLost&#40;FocusEvent e&#41; &#123;
                          final JTextComponent c = &#40;JTextComponent&#41;e.getSource&#40;&#41;;
                          String text = c.getText&#40;&#41;;
                          Driver d = getDAO&#40;&#41;.getDriver&#40;text.trim&#40;&#41;&#41;;
                          if &#40;d != null&#41; &#123;
                              Participation part  = &#40;Participation&#41; getFormObject&#40;&#41;;
                              part.setDriver&#40;d&#41;;
                              
                          &#125;
                          
                      &#125;
                      
                  &#125;
              
              
              
              
              
              
              
              
                  
                  
              &#125;

              Comment

              Working...
              X