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

xworker.javafx.util.converter.ThingStringConverter Maven / Gradle / Ivy

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

import javafx.util.StringConverter;
import org.xmeta.ActionContext;
import org.xmeta.Thing;

public class ThingStringConverter extends StringConverter {
    Thing thing;
    ActionContext actionContext;

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

    @Override
    public String toString(Object object) {
        return thing.doAction("toString", actionContext, "object", object);
    }

    @Override
    public Object fromString(String string) {
        return thing.doAction("fromString", actionContext, "string", string);
    }

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

        ThingStringConverter converter = new ThingStringConverter(self, actionContext);
        actionContext.g().put(self.getMetadata().getName(), converter);

        return converter;
    }

    public static String defaultToString(ActionContext actionContext){
        return String.valueOf(actionContext.get("object"));
    }

    public static Object defaultFromString(ActionContext actionContext){
        return actionContext.get("string");
    }
}