All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xworker.javafx.control.cell.ComboBoxTreeCellActions Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package xworker.javafx.control.cell;

import javafx.scene.control.cell.ComboBoxTreeCell;
import javafx.util.StringConverter;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.control.TreeCellActions;
import xworker.javafx.util.JavaFXUtils;

public class ComboBoxTreeCellActions {
    static{
        PropertyFactory.regist(ComboBoxTreeCell.class, "comboBoxEditableProperty", o -> {
            ComboBoxTreeCell obj = (ComboBoxTreeCell) o;
            return obj.comboBoxEditableProperty();
        });
        PropertyFactory.regist(ComboBoxTreeCell.class, "converterProperty", o -> {
            ComboBoxTreeCell obj = (ComboBoxTreeCell) o;
            return obj.converterProperty();
        });
    }

    public static void init(ComboBoxTreeCell node, Thing thing, ActionContext actionContext){
        TreeCellActions.init(node, thing, actionContext);

        if(thing.valueExists("converter")){
            StringConverter converter = JavaFXUtils.getObject(thing, "converter", actionContext);
            if(converter != null) {
                node.setConverter(converter);
            }
        }
        if(thing.valueExists("items")){
            Iterable items = JavaFXUtils.getObject(thing, "items", actionContext);

            if(items != null) {
                for (Object item : items) {
                    node.getItems().add(item);
                }
            }
        }
        if(thing.valueExists("comboBoxEditable")){
            node.setComboBoxEditable(thing.getBoolean("comboBoxEditable"));
        }
    }

    public static ComboBoxTreeCell create(ActionContext actionContext){
        Thing self = actionContext.getObject("self");
        ComboBoxTreeCell node = new ComboBoxTreeCell<>();
        init(node, self, actionContext);
        actionContext.g().put(self.getMetadata().getName(), node);

        actionContext.peek().put("parent", node);
        for(Thing child : self.getChilds()){
            Object obj = child.doAction("create", actionContext);
            if(obj instanceof  StringConverter){
                node.setConverter((StringConverter) obj);
            }
        }

        return node;
    }
}