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

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

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

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

public class TreeTableRowActions {
    static{
        PropertyFactory.regist(TreeTableRow.class, "disclosureNodeProperty", o -> {
            TreeTableRow obj = (TreeTableRow) o;
            return obj.disclosureNodeProperty();
        });
    }

    public static void init(TreeTableRow node, Thing thing, ActionContext actionContext){
        IndexedCellActions.init(node, thing, actionContext);

        if(thing.valueExists("disclosureNode")){
            Node disclosureNode = JavaFXUtils.getObject(thing, "disclosureNode", actionContext);
            if(disclosureNode != null){
                node.setDisclosureNode(disclosureNode);
            }
        }
    }

    public static void createDisclosureNode(ActionContext actionContext){
        Thing self = actionContext.getObject("self");
        TreeTableRow parent = actionContext.getObject("parent");

        for(Thing child : self.getChilds()){
            Object obj = child.doAction("create", actionContext);
            if(obj instanceof  Node){
                parent.setDisclosureNode((Node) obj);
            }
        }
    }

    public static TreeTableRow create(ActionContext actionContext){
        Thing self = actionContext.getObject("self");
        TreeTableRow node  = new TreeTableRowActions.ThingTreeTableRow(self, actionContext);
        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;
    }

    public static class ThingTreeTableRow extends TreeTableRow {
        Thing thing;
        ActionContext actionContext;

        public ThingTreeTableRow(Thing thing, ActionContext actionContext){
            this.thing = thing;
            this.actionContext = actionContext;
        }

        @Override
        protected void updateItem(T item, boolean empty) {
            super.updateItem(item, empty);

            thing.doAction("updateItem", actionContext, "cell", this, "item", item, "empty", empty);
        }
    }
}