0

I have following code.. I realize that "setSearchedText" is not invoked. So binding is not happening.. SearchInvestigationPanel is inside InvestigationsPanel. Note that textField inside SearchInvestigationPanel cannot be retrieved by outside the class. What did I miss here?

public class SearchInvestigationPanel extends JPanel {
    private JTextField textField;
    public SearchInvestigationPanel() {
        init();
    }

    public String getText()
    {
        return (textField != null)? textField.getText() : "";
    }

    private void init() {
    <code to add textField to this panel>
    }
}

import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.Bindings;

public class InvestigationsPanel extends JPanel {
    private SearchInvestigationPanel searchInvestigationPanel;
    private InvestigationsPanelModel investigationsPanelModel;

    public InvestigationsPanel() {
        init();
    }

    private SearchInvestigationPanel getSearchInvestigationPanel() {
        if (searchInvestigationPanel == null) {
            searchInvestigationPanel = new SearchInvestigationPanel();
        }
        return searchInvestigationPanel;
    }

    private void init() {
        <code to add SearchInvestigationPanel inside this panel>
    }

    public void initBinding() {
        BeanProperty<SearchInvestigationPanel, String> SearchInvestigationPanelSearchedTextProperty = BeanProperty
                .create("text");
        BeanProperty<InvestigationsPanelModel, String> investigationsPanelModelSearchedTextProperty = BeanProperty
                .create("searchedText");
        AutoBinding<SearchInvestigationPanel, String, InvestigationsPanelModel, String> filteredTextInvTreeBinding = Bindings
                .createAutoBinding(AutoBinding.UpdateStrategy.READ,
                        getSearchInvestigationPanel(),
                        SearchInvestigationPanelSearchedTextProperty,
                        investigationsPanelModel,
                        investigationsPanelModelSearchedTextProperty);
        filteredTextInvTreeBinding.bind();
    }
}

public class InvestigationsPanelModel extends AbstractModelObject{
    private String searchedText = "";

    public String getSearchedText() {
        return searchedText;
    }

    public void setSearchedText(String newSearchedText) {
        String oldValue = searchedText;
        this.searchedText = newSearchedText;
        System.out.println(newSearchedText);
        firePropertyChange("searchedText", oldValue, newSearchedText);
    }
}

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public abstract class AbstractModelObject {
    private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(listener);
    }

    public void addPropertyChangeListener(String propertyName,
            PropertyChangeListener listener) {
        propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(String propertyName,
            PropertyChangeListener listener) {
        propertyChangeSupport.removePropertyChangeListener(propertyName,
                listener);
    }

    protected void firePropertyChange(String propertyName, Object oldValue,
            Object newValue) {
        propertyChangeSupport.firePropertyChange(propertyName, oldValue,
                newValue);
    }
}
divibisan
  • 11,659
  • 11
  • 40
  • 58
Brunthavan
  • 27
  • 5
  • 1
    couldn't be variable `` instead of `` inside - `BeanProperty investigationsPanelModelSearchedTextProperty = BeanProperty .create("searchedText");` because I think that `BeanProperty` should be addresed directly to JComponent, maybe it could be something abstract, but nothing else without an SSCCE / MCVE, short, runnable, compilable – mKorbel Feb 05 '17 at 17:53
  • 1
    please where is implemented (pseudocode) filteredTextInvTreeBinding.unbind(); – mKorbel Feb 05 '17 at 17:57
  • hello @Hovercraft Full Of Eels, have nice day(s) ::) – mKorbel Feb 05 '17 at 18:23

0 Answers0