Example usage for com.jgoodies.binding.adapter Bindings bind

List of usage examples for com.jgoodies.binding.adapter Bindings bind

Introduction

In this page you can find the example usage for com.jgoodies.binding.adapter Bindings bind.

Prototype

public static void bind(JTextField textField, ValueModel valueModel) 

Source Link

Document

Bind a text fields or password field to the given ValueModel.

Usage

From source file:ambit2.db.results.test.AmbitRowsEventTest.java

License:Open Source License

public static void main(String[] args) {
    // http://www.java2s.com/Code/Java/Swing-Components/JGoodiesBindingSelectionInListModelExample.htm
    try {// w ww .ja  v  a 2  s .  co m
        final AmbitRows<Dictionary> dictionary = new AmbitRows<Dictionary>() {
            /**
             * 
             */
            private static final long serialVersionUID = 6274513733204291475L;

            @Override
            protected synchronized IQueryRetrieval createNewQuery(Dictionary target) throws AmbitException {
                TemplateQuery q = new TemplateQuery();
                q.setValue(target.getTemplate());
                return q;
            }
        };

        final AmbitRows<Property> properties = new AmbitRows<Property>() {
            @Override
            protected synchronized IQueryRetrieval createNewQuery(Property target) throws AmbitException {
                QueryField q = new QueryField();
                q.setFieldname(target);
                return q;
            }

        };
        dictionary.addPropertyChangeListener(dictionary.getPropertyname(), properties);
        dictionary.addPropertyChangeListener("status", properties);

        AmbitRowsEventTest test = new AmbitRowsEventTest();
        test.setUpDatabase(test.getTestDatabase());
        IDatabaseConnection c = test.getConnection("localhost", "ambit2", "3306", "guest", "guest");
        dictionary.setConnection(c.getConnection());
        properties.setConnection(c.getConnection());

        DictionaryObjectQuery q = new DictionaryObjectQuery();
        q.setValue("Dataset");

        PropertyChangeSupport ps = new PropertyChangeSupport(test);
        ps.addPropertyChangeListener("topquery", dictionary);
        ps.firePropertyChange(new QueryChangeEvent(test, "topquery", null, q));

        final QueryField qf = new QueryField();
        properties.addPropertyChangeListener(properties.getPropertyname(), new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {

                try {
                    IQueryRetrieval r = properties.process((Property) evt.getNewValue());
                    qf.setFieldname(((QueryField) r).getFieldname());
                } catch (AmbitException x) {
                    x.printStackTrace();
                }
            }
        });

        ListModel listModel = new RowsModel<Dictionary>(dictionary);
        ValueModel selectedItemHolder1 = new ValueHolder();
        SelectionInList<Dictionary> selectionInList = new SelectionInList<Dictionary>(listModel,
                selectedItemHolder1);

        final JList jlist = new JList();
        Bindings.bind(jlist, selectionInList);

        BeanAdapter beanAdapter = new BeanAdapter(selectionInList);
        ValueModel nameModel = beanAdapter.getValueModel("template");
        ValueModel parentModel = beanAdapter.getValueModel("parentTemplate");

        ListModel listModel2 = new RowsModel<Property>(properties);
        ValueModel selectedItemHolder2 = new ValueHolder();
        SelectionInList<Property> selectionInList2 = new SelectionInList<Property>(listModel2,
                selectedItemHolder2);

        BeanAdapter beanAdapter2 = new BeanAdapter(qf);
        ValueModel fieldnameModel = beanAdapter2.getValueModel("fieldname");
        // ValueModel conditionModel =
        // beanAdapter2.getValueModel("condition");
        ValueModel valueModel = beanAdapter2.getValueModel("value");

        selectionInList.addPropertyChangeListener("value", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                try {
                    dictionary.process((Dictionary) evt.getNewValue());
                } catch (Exception x) {
                    x.printStackTrace();
                }

            }
        });

        selectionInList2.addPropertyChangeListener("value", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                try {

                } catch (Exception x) {
                    x.printStackTrace();
                }

            }
        });
        JPanel p = new JPanel();

        p.add(BasicComponentFactory.createTextField(nameModel));
        p.add(BasicComponentFactory.createTextField(parentModel));

        p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
        p.add(new JLabel("Dictionary"));
        p.add(new JScrollPane(jlist));
        // p.add(new JComboBox(new
        // ComboBoxAdapter<Dictionary>(selectionInList)));
        p.add(new JLabel("Properties"));
        final JComboBox combo = new JComboBox(new ComboBoxAdapter<Property>(selectionInList2));
        p.add(combo);
        p.add(BasicComponentFactory.createTextField(fieldnameModel));
        // p.add(BasicComponentFactory.createTextField(conditionModel));
        p.add(BasicComponentFactory.createIntegerField(valueModel));

        properties.addPropertyChangeListener("status", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                combo.setEnabled((Boolean) evt.getNewValue());
            }
        });
        JOptionPane.showMessageDialog(null, p);
        c.close();

    } catch (Exception x) {
        x.printStackTrace();
    }
}

From source file:ambit2.ui.editors.SelectFieldsPanel.java

License:Open Source License

protected void buildPanel(String help) {
    FormLayout layout = new FormLayout(
            "3dlu,fill:40dlu:grow,fill:120dlu:grow,3dlu,32dlu, 3dlu, fill:40dlu:grow,fill:120dlu:grow,3dlu", //columns
            "3dlu,12dlu,3dlu,top:[pref,36dlu], 24dlu,3dlu,24dlu,3dlu,24dlu,3dlu,24dlu,bottom:[pref,72dlu]:grow,1dlu,pref,pref,pref,pref,pref"); //rows
    setLayout(layout);/*from www  .  j  av  a  2 s  .  c om*/
    CellConstraints cc = new CellConstraints();

    add(createSeparator("Available"), cc.xywh(2, 2, 2, 1));
    add(createSeparator("Selected"), cc.xywh(7, 2, 2, 1));

    tables = new JList[fieldsModel.length];
    for (int i = 0; i < fieldsModel.length; i++) {
        tables[i] = new JList(fieldsModel[i]);

        SelectionInList<Property> selectionInList = new SelectionInList<Property>(fieldsModel[i]);
        Bindings.bind(tables[i], selectionInList);
        JScrollPane p = new JScrollPane(tables[i]);
        p.setBorder(BorderFactory.createEtchedBorder());
        p.setPreferredSize(new Dimension(160, 280));
        int offset = 2 + i * 5;
        add(p, cc.xywh(offset, 4, 2, 9));

        BeanAdapter beanAdapter = new BeanAdapter(selectionInList);

        String[][] config = { { "name", "Name" }, { "label", "Alias" }, { "units", "Units" },
                { "title", "url" }, { "url", "WWW" } };
        for (int j = 0; j < config.length; j++) {
            String[] c = config[j];
            ValueModel model = beanAdapter.getValueModel(c[0]);
            add(BasicComponentFactory.createLabel(new ValueHolder(c[1])), cc.xywh(offset, j + 14, 1, 1));
            JTextField t = BasicComponentFactory.createTextField(model);
            t.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseEntered(MouseEvent e) {
                    super.mouseEntered(e);
                    ((JTextField) e.getSource()).setToolTipText(((JTextField) e.getSource()).getText());
                }
            });
            add(t, cc.xywh(offset + 1, j + 14, 1, 1));
        }
        /*
        ValueModel nameModel = beanAdapter.getValueModel("name");
        ValueModel commentsModel = beanAdapter.getValueModel("label");
        ValueModel titleModel = beanAdapter.getValueModel("title");
        ValueModel urlModel = beanAdapter.getValueModel("url");           
        //p.add(BasicComponentFactory.createTextField(parentModel));         
        add(BasicComponentFactory.createLabel(new ValueHolder("Name")),cc.xywh(offset,14,1,1));
        add(BasicComponentFactory.createTextField(nameModel),cc.xywh(offset+1,14,1,1));
        add(BasicComponentFactory.createLabel(new ValueHolder("Alias")),cc.xywh(offset,15,1,1));
        add(BasicComponentFactory.createTextField(commentsModel),cc.xywh(offset+1,15,1,1));
        add(BasicComponentFactory.createLabel(new ValueHolder("Reference")),cc.xywh(offset,16,1,1));
        add(BasicComponentFactory.createTextField(titleModel),cc.xywh(offset+1,16,1,1));         
        add(BasicComponentFactory.createLabel(new ValueHolder("WWW")),cc.xywh(offset,17,1,1));
        add(BasicComponentFactory.createTextField(urlModel),cc.xywh(offset+1,17,1,1));     
        */
    }

    buttons = new ArrayList<JButton>();
    int i = 0;
    for (MOVE op : MOVE.values()) {
        JButton button = new JButton(op.display());
        button.setPreferredSize(new Dimension(24, 24));
        button.setMaximumSize(new Dimension(24, 24));
        add(button, cc.xywh(5, 5 + (i * 2), 1, 1));
        button.addActionListener(this);
        button.setActionCommand(op.toString());
        i++;
    }

    /*
    JToolBar toolBar[] = new JToolBar[2];
    toolBar[0] = new JToolBar();
    toolBar[0].add(new JButton("Find"));
    toolBar[0].add(new JToolBar.Separator());
    toolBar[0].add(new JButton("Select all"));
    toolBar[0].add(new JButton("Unselect all"));
    toolBar[0].setFloatable(false);
    add(toolBar[0],cc.xywh(2,14,1,1));
            
    toolBar[1] = new JToolBar();
    toolBar[1].add(new JButton("Move Up"));
    toolBar[1].add(new JButton("Move Down"));
    toolBar[1].add(new JToolBar.Separator());
    toolBar[1].add(new JButton("Select all"));
    toolBar[1].add(new JButton("Unselect all"));
    toolBar[1].setFloatable(false);
    add(toolBar[1],cc.xywh(6,14,1,1));
    */
    /*
    helpArea = new JTextPane();
    helpArea.setText(help);
    helpArea.setEditable(false);
    helpArea.setBackground(new Color(255,255,225));
    helpArea.setPreferredSize(new Dimension(288,48));
    add(new JScrollPane(helpArea),cc.xywh(2,16,5,1));
    */

}

From source file:com.eviware.soapui.support.components.SimpleBindingForm.java

License:EUPL

public JCheckBox appendCheckBox(String propertyName, String label, String tooltip) {
    JCheckBox checkBox = super.appendCheckBox(label, tooltip, false);
    Bindings.bind(checkBox, pm.getModel(propertyName));
    return checkBox;
}

From source file:com.eviware.soapui.support.components.SimpleBindingForm.java

License:EUPL

public JComboBox appendComboBox(String propertyName, String label, Object[] values, String tooltip) {
    JComboBox comboBox = super.appendComboBox(label, values, tooltip);
    Bindings.bind(comboBox, new SelectionInList<Object>(values, pm.getModel(propertyName)));

    return comboBox;
}

From source file:com.eviware.soapui.support.components.SimpleBindingForm.java

License:EUPL

public JComboBox appendComboBox(String label, ComboBoxModel model, String tooltip, ValueModel valueModel) {
    JComboBox comboBox = super.appendComboBox(label, model, tooltip);
    Bindings.bind(comboBox, new SelectionInList<Object>(model, valueModel));

    return comboBox;
}

From source file:com.eviware.soapui.support.components.SimpleBindingForm.java

License:EUPL

public JComboBox appendComboBox(String propertyName, String label, ComboBoxModel model, String tooltip) {
    JComboBox comboBox = super.appendComboBox(label, model, tooltip);
    Bindings.bind(comboBox, new SelectionInList<Object>(model, pm.getModel(propertyName)));
    return comboBox;
}

From source file:com.eviware.soapui.support.components.SimpleBindingForm.java

License:EUPL

public void setComboBoxItems(String propertyName, JComboBox comboBox, String[] values) {
    Bindings.bind(comboBox, new SelectionInList<Object>(values, pm.getModel(propertyName)));
}

From source file:com.eviware.soapui.support.components.SimpleBindingForm.java

License:EUPL

public JLabel appendLabel(String propertyName, String label) {
    JLabel jLabel = new JLabel();
    super.append(label, jLabel, "left,bottom");
    Bindings.bind(jLabel, pm.getModel(propertyName));
    return jLabel;
}

From source file:com.eviware.soapui.support.components.SimpleBindingForm.java

License:EUPL

public JPasswordField appendPasswordField(String propertyName, String label, String tooltip) {
    JPasswordField textField = super.appendPasswordField(label, tooltip);
    Bindings.bind(textField, pm.getModel(propertyName));
    return textField;
}

From source file:com.eviware.soapui.support.components.SimpleBindingForm.java

License:EUPL

public JTextArea appendTextArea(String propertyName, String label, String tooltip) {
    JTextArea textArea = super.appendTextArea(label, tooltip);
    Bindings.bind(textArea, pm.getModel(propertyName));
    return textArea;
}