Announcement Announcement Module
Collapse
No announcement yet.
DataEditor problem with DetailsForm Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DataEditor problem with DetailsForm

    I have a problem with the data editor DefaultDataEditorWidget, which creates the TabbedForm me once so combobox type fields are not refreshed me if there are changes in the database.
    In my case I have a set of companies which have facilities. I needed to manage the company which has a name and an incremental id. The facility has a code, a description, type of installation and a company which is associated with this installation.
    The problem is that I have a DataEditor to manage a business and to manage the facilities. To add an installation Select the company that exist in the database is a drop down list, a combobox . What happens is that I want to create new companies and that the combobox of the facilities is cool and me not doing it seems that the views of the dataeditor me FormDetails load data once and not how to solve this..
    Please I would need urgent help with this Thanks.

  • #2
    You can create a combo box that uses a RefreshableValueHolder that executes a Closure to provide the selectable values. I have created my own form builder that extends the default form builder to provide convenience methods for adding components with complex setups like this to my forms. Here is an example:

    Code:
    public JComponent[] addComobBoxRefreshedOnPopupAndLabel(String propertyName, Closure closure, String renderedProperty, int column, int row, int widthSpan, int heightSpan, String attributes) {
        JLabel label = addLabel(propertyName, column, row, attributes);
        final RefreshableValueHolder refreshableValueHolder = new RefreshableValueHolder(closure, false, false);
        Binding binding = ((SwingBindingFactory)getBindingFactory()).createBoundComboBox(propertyName, refreshableValueHolder, renderedProperty);
        JComboBox comboBox = (JComboBox)binding.getControl();
        comboBox.addPopupMenuListener(new PopupMenuListener() {
    
          /**
           * Refreshes the refreshable value holder when the popup menu will become visible.
           * This results in the popup menu being popuplated with current data on demand when
           * the user performs an action that will display it so the popup always shows the most
           * current data, but only retrieves this data when needed.
           *
           * @param e The popup menu event.
           */
          @Override
          public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            refreshableValueHolder.refresh();
          }
    
          /**
           * Does nothing.
           *
           * @param e The popup menu event.
           */
          @Override
          public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // Does nothing.
          }
    
          /**
           * Does nothing.
           *
           * @param e The popup menu event.
           */
          @Override
          public void popupMenuCanceled(PopupMenuEvent e) {
            // Does nothing.
          }
    
        });
        comboBox.setMaximumRowCount(10);
        addComponent(comboBox, column + 2, row, widthSpan, heightSpan);
        return new JComponent[] {label, comboBox};
      }
    This method adds a combo box to my form that refreshes its list of selectable items when the user performs an action that causes the
    popup menu to display. This ensures the selectable items in my combo box are always as current as possible. Here is an example of how you might add one to a form and provide a closure:

    Code:
    builder.addComobBoxRefreshedOnPopupAndLabel("facility", new Closure() {
    
              @Override
              public Object call(Object o) {
                return facilityService.getFacilities();
              }
    
            }, "name");

    The idea here is that this will add a label for the "facility" property, then add a combo box bound to the "facility" property that gets refreshed just before the popup menu appears by getting the list of facilities from the getFacilities() method call. This could be a call to remote method on your application server that gets the list from the database. The list of items is rendered by the combo box using the "name" property. This assumes your form backing object has a "facility" property to bind to and that the objects backing the list have a "name" property. Hopefully this addresses your question.

    Comment


    • #3
      It Works well, but also a ShutteList update

      Hi, Thanks to This solved part of the problem, can you tell me how to update a ShuttleList, I try to do the same idea but the problem is that it is a panel.


      And Thanks again

      Comment


      • #4
        yep, a ShuttleList setup works similarly. In my builder I have an add shuttle list method:

        Code:
        public JComponent addShuttleList(String propertyName, ValueModel selectableItemsHolder, String renderedProperty, int column, int row, int widthSpan, int heightSpan) {
            Map context = ShuttleListBinder.createBindingContext(getFormModel(), propertyName, selectableItemsHolder, renderedProperty);
            Binding binding = getBindingFactory().createBinding(ShuttleList.class, propertyName, context);
            ShuttleList shuttleList = (ShuttleList)binding.getControl();
            addComponent(shuttleList, column, row, widthSpan, heightSpan);
            return shuttleList;
          }
        and in the createFormControl method you can then simply add a ShuttleList with a RefreshableValueHolder and Closure as before:

        Code:
        refreshableValueHolder = new RefreshableValueHolder(new Closure() {
        
                  @Override
                  public Object call(Object o) {
                    if(company != null) {
                      return companyService.getAvailableFacilities(company.getId());
                    } else {
                      return Collections.EMPTY_LIST;
                    }
                  }
        
                }, false, false);
                ShuttleList shuttleList = (ShuttleList)builder.addShuttleList("facilities", refreshableValueHolder, "name", 1, 3, 5, 1);
        This will create a ShuttleList bound to the "facilities" property of your form backing object. The list will render the facility using the "name" property. This time you can see that I have a reference to the refreshableValueHolder, this is important. Elsewhere in my form, I may have (attempting to stick to your example here) a combo box that allows the user to select which company they are assigning facilities to. You would then add a listener to the combo box that forces a refresh on the refreshableValueHolder to get the new list of selectable items, like this:

        Code:
        combobox.addActionListener(new ActionListener() {
        
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    refreshableValueHolder.refresh();
                    // anything else you may need to do...
                  }
                  
                });
        This is set up like this because unlike the combo box example, where we refreshed the selectable values when the popup menu was about to be shown, the ShuttleList doesn't have a self-contained idea of when the selectable list should be updated. In this case it is more natural for the refresh to be triggered by an external action such as the user selecting a new company or facility, creating a new company to add to the database, etc.

        Comment

        Working...
        X