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

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

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

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

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

    public static void init(TextFieldTableCell node, Thing thing, ActionContext actionContext){
        TableCellActions.init(node, thing, actionContext);

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

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