Example usage for com.jgoodies.binding.list SelectionInList SelectionInList

List of usage examples for com.jgoodies.binding.list SelectionInList SelectionInList

Introduction

In this page you can find the example usage for com.jgoodies.binding.list SelectionInList SelectionInList.

Prototype

public SelectionInList(ValueModel listHolder, ValueModel selectionHolder) 

Source Link

Document

Constructs a SelectionInList on the given list holder, selection holder and selection index holder.

Constraints: 1) The listHolder must hold instances of List or ListModel and 2) must report a value change whenever the value's identity changes.

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 {//from  ww w  .  jav a  2  s .  com
        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.dbui.dictionary.DictionaryQueryPanel.java

License:Open Source License

@Override
protected JComponent createConditionComponent() {
    return BasicComponentFactory.createComboBox(new SelectionInList<StringCondition>(
            new StringCondition[] { StringCondition.getInstance(StringCondition.C_EQ),
                    StringCondition.getInstance(StringCondition.C_LIKE),
                    StringCondition.getInstance(StringCondition.C_NOTLIKE),
                    StringCondition.getInstance(StringCondition.C_REGEXP),
                    StringCondition.getInstance(StringCondition.C_SOUNDSLIKE), },
            presentationModel.getModel("condition")));
}

From source file:ambit2.dbui.dictionary.DictionaryQueryPanel.java

License:Open Source License

protected JComponent createFieldnameComponent() {
    ValueHolder vh = new ValueHolder();
    SelectionInList<Dictionary> fieldnames = new SelectionInList<Dictionary>(new RowsModel<Dictionary>(parents),
            vh);//  w  w  w.  j a v  a  2s  .c o m
    fieldnames.addPropertyChangeListener("value", new PropertyChangeListener() {
        final TemplateQuery tq = new TemplateQuery();

        public void propertyChange(PropertyChangeEvent evt) {
            try {

                if (evt.getNewValue() != null) {
                    tq.setCondition(StringCondition.getInstance(StringCondition.C_EQ));
                    tq.setValue(((Dictionary) evt.getNewValue()).getTemplate());
                    details.setQuery(tq);
                    if (details.size() == 0)
                        details.close();
                    else {
                        details.beforeFirst();
                        while (details.next()) {
                            profile.add(details.getObject());
                        }
                    }
                }

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

        }
    });

    JComboBox box = BasicComponentFactory.createComboBox(fieldnames);
    box.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if ((value != null) && (c instanceof JLabel))
                ((JLabel) c).setText(((Dictionary) value).getTemplate());
            return c;
        }
    });
    return box;

}

From source file:ambit2.dbui.QueryChemicalEditor.java

License:Open Source License

@Override
protected JComponent createConditionComponent() {
    JComboBox box = BasicComponentFactory.createComboBox(new SelectionInList<StringCondition>(
            new StringCondition[] { StringCondition.getInstance(StringCondition.C_EQ),
                    StringCondition.getInstance(StringCondition.C_LIKE),
                    StringCondition.getInstance(StringCondition.C_NOTLIKE),
                    StringCondition.getInstance(StringCondition.C_REGEXP),
                    StringCondition.getInstance(StringCondition.C_SOUNDSLIKE), },
            presentationModel.getModel("condition")));
    AutoCompleteDecorator.decorate(box);
    return box;/*from   ww w . j  a  v  a2s .  c o  m*/
}

From source file:ambit2.dbui.QueryChemicalEditor.java

License:Open Source License

@Override
protected JComponent createFieldnameComponent() {
    JComboBox box = BasicComponentFactory
            .createComboBox(new SelectionInList<String>(
                    new String[] { ExactStructureSearchMode.inchi.name(),
                            ExactStructureSearchMode.smiles.name(), ExactStructureSearchMode.formula.name(), },
                    presentationModel.getModel("fieldname")));
    AutoCompleteDecorator.decorate(box);
    return box;//  www .  j  a v a 2s  .co  m
}

From source file:ambit2.dbui.QueryDatasetEditor.java

License:Open Source License

@Override
protected JComponent createConditionComponent() {

    JComboBox box = BasicComponentFactory.createComboBox(new SelectionInList<StringCondition>(
            new StringCondition[] { StringCondition.getInstance(StringCondition.C_EQ),
                    StringCondition.getInstance(StringCondition.C_NOTEQ),
                    StringCondition.getInstance(StringCondition.C_LIKE),
                    StringCondition.getInstance(StringCondition.C_NOTLIKE),
                    StringCondition.getInstance(StringCondition.C_REGEXP),
                    StringCondition.getInstance(StringCondition.C_SOUNDSLIKE), },
            presentationModel.getModel("condition")));
    //AutoCompleteDecorator.decorate(box);
    return box;/*from   w ww . j av a2  s.co m*/
}

From source file:ambit2.dbui.QueryDatasetEditor.java

License:Open Source License

@Override
protected JComponent createValueComponent() {
    ListModel fieldnames = new RowsModel<SourceDataset>(datasets);
    JComboBox box = BasicComponentFactory.createComboBox(
            new SelectionInList<SourceDataset>(fieldnames, presentationModel.getModel("dataset")));
    AutoCompleteDecorator.decorate(box);
    return box;//from  w  ww  . j a  va  2 s . c o m
}

From source file:ambit2.dbui.QueryFieldNumericEditor.java

License:Open Source License

@Override
protected JComponent createFieldnameComponent() {

    ListModel fieldnames = new RowsModel<Property>(properties) {
        @Override/* w ww  . j  a  v  a2s  . c o  m*/
        public int getSize() {
            return super.getSize() + 1;
        }

        @Override
        public Property getElementAt(int index) {
            if (index == 0)
                return null;
            else
                return super.getElementAt(index - 1);
        }
    };
    SelectionInList<Property> p = new SelectionInList<Property>(fieldnames,
            presentationModel.getModel("fieldname"));
    p.addPropertyChangeListener("value", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            statsQuery.setFieldname((Property) evt.getNewValue());

        }
    });
    JComboBox box = BasicComponentFactory.createComboBox(p);
    AutoCompleteDecorator.decorate(box);
    return box;

}

From source file:ambit2.dbui.QueryFieldNumericEditor.java

License:Open Source License

@Override
protected JComponent createConditionComponent() {
    NumberCondition[] nc = new NumberCondition[NumberCondition.conditions.length];
    for (int i = 0; i < nc.length; i++)
        nc[i] = NumberCondition.getInstance(NumberCondition.conditions[i]);

    SelectionInList<NumberCondition> selectionInList = new SelectionInList<NumberCondition>(nc,
            presentationModel.getModel("condition"));
    selectionInList.addPropertyChangeListener("value", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            presentationModel.getComponentModel("maxValue")
                    .setVisible(NumberCondition.between.equals(evt.getNewValue().toString()));
        }/* w ww  . ja v  a2 s .co  m*/
    });
    JComboBox box = BasicComponentFactory.createComboBox(selectionInList);
    AutoCompleteDecorator.decorate(box);
    return box;
}

From source file:ambit2.dbui.QuerySimilarityEditor.java

License:Open Source License

@Override
protected JComponent createConditionComponent() {
    NumberCondition[] nc = new NumberCondition[NumberCondition.conditions.length - 1];
    for (int i = 0; i < nc.length; i++) {
        nc[i] = NumberCondition.getInstance(NumberCondition.conditions[i]);
    }// w  ww .java  2  s.c om
    SelectionInList<NumberCondition> selectionInList = new SelectionInList<NumberCondition>(nc,
            presentationModel.getModel("condition"));
    JComboBox box = BasicComponentFactory.createComboBox(selectionInList);
    AutoCompleteDecorator.decorate(box);
    return box;
}