Search in sources :

Example 6 with VariantPropertyPersistent

use of com.ramussoft.core.attribute.simple.VariantPropertyPersistent in project ramus by Vitaliy-Yakovchuk.

the class VariantAttributePlugin method getTableCellEditor.

@SuppressWarnings("unchecked")
@Override
public TableCellEditor getTableCellEditor(final Engine engine, AccessRules rules, final Attribute attribute) {
    final JComboBox box = new JComboBox();
    final List<VariantPropertyPersistent> list = (List<VariantPropertyPersistent>) engine.getAttribute(null, attribute);
    box.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            List<VariantPropertyPersistent> newList = (List<VariantPropertyPersistent>) engine.getAttribute(null, attribute);
            for (VariantPropertyPersistent p : newList) {
                boolean add = true;
                for (VariantPropertyPersistent p1 : list) if (p1.getValue().equals(p.getValue()))
                    add = false;
                if (add) {
                    box.addItem(p.getValue());
                    list.add(p);
                }
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        }
    });
    box.setName("Table.editor");
    box.addItem(null);
    for (VariantPropertyPersistent p : list) {
        box.addItem(p.getValue());
    }
    box.setEditable(true);
    return new DefaultCellEditor(box) {

        /**
         */
        private static final long serialVersionUID = 7436784278964767871L;

        @Override
        public Object getCellEditorValue() {
            Object object = super.getCellEditorValue();
            if ("".equals(object))
                return null;
            return object;
        }
    };
}
Also used : JComboBox(javax.swing.JComboBox) PopupMenuListener(javax.swing.event.PopupMenuListener) VariantPropertyPersistent(com.ramussoft.core.attribute.simple.VariantPropertyPersistent) ArrayList(java.util.ArrayList) List(java.util.List) PopupMenuEvent(javax.swing.event.PopupMenuEvent) DefaultCellEditor(javax.swing.DefaultCellEditor)

Aggregations

VariantPropertyPersistent (com.ramussoft.core.attribute.simple.VariantPropertyPersistent)6 List (java.util.List)3 Engine (com.ramussoft.common.Engine)2 ArrayList (java.util.ArrayList)2 Attribute (com.ramussoft.common.Attribute)1 IEngine (com.ramussoft.common.IEngine)1 Function (com.ramussoft.pb.Function)1 Row (com.ramussoft.pb.Row)1 Stream (com.ramussoft.pb.Stream)1 NRow (com.ramussoft.pb.data.negine.NRow)1 MovingFunction (com.ramussoft.pb.idef.visual.MovingFunction)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 JComboBox (javax.swing.JComboBox)1 PopupMenuEvent (javax.swing.event.PopupMenuEvent)1 PopupMenuListener (javax.swing.event.PopupMenuListener)1