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

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

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

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

import java.util.Iterator;

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

    public static void init(ChoiceBoxListCell node, Thing thing, ActionContext actionContext){
        ListCellActions.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) {
                Iterator iter = items.iterator();
                while(iter.hasNext()){
                    node.getItems().add(iter.next());
                }
            }
        }
    }

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