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

xworker.javafx.control.CellActions Maven / Gradle / Ivy

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

import javafx.scene.control.Cell;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.util.JavaFXUtils;

public class CellActions {
    static{
        PropertyFactory.regist(Cell.class, "itemProperty", o -> {
            Cell obj = (Cell) o;
            return obj.itemProperty();
        });
        PropertyFactory.regist(Cell.class, "editableProperty", o -> {
            Cell obj = (Cell) o;
            return obj.editableProperty();
        });
    }

    public static void init(Cell node, Thing thing, ActionContext actionContext){
        LabeledActions.init(node, thing, actionContext);

        if(thing.valueExists("editable")){
            node.setEditable(thing.getBoolean("editable"));
        }
        if(thing.valueExists("item")){
            Object item = JavaFXUtils.getObject(thing, "item", actionContext);
            node.setItem(item);
        }
    }

    public static Cell create(ActionContext actionContext){
        Thing self = actionContext.getObject("self");

        Cell node = new Cell();
        init(node, self, actionContext);
        actionContext.g().put(self.getMetadata().getName(), node);

        actionContext.peek().put("parent", node);
        for(Thing child : self.getChilds()) {
            child.doAction("create", actionContext);
        }

        return node;
    }
}