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;
}
};
}
Aggregations