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

xworker.javafx.control.CustomMenuItemActions 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.CustomMenuItem;
import ognl.OgnlException;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.lang.util.UtilData;

import java.io.IOException;

public class CustomMenuItemActions {
	static{
		PropertyFactory.regist(CustomMenuItem.class, "contentProperty", o -> {
			CustomMenuItem obj = (CustomMenuItem) o;
			return obj.contentProperty();
		});
		PropertyFactory.regist(CustomMenuItem.class, "hideOnClickProperty", o -> {
			CustomMenuItem obj = (CustomMenuItem) o;
			return obj.hideOnClickProperty();
		});
	}

	public static void init(CustomMenuItem item, Thing thing, ActionContext actionContext) throws OgnlException, IOException {
		MenuItemActions.init(item, thing, actionContext);
		
		if(thing.valueExists("content")) {
			Node content = (Node) UtilData.getData(thing.getString("content"), actionContext);
			if(content != null) {
				item.setContent(content);
			}
		}
		
		if(thing.valueExists("hideOnClick")) {
			item.setHideOnClick(thing.getBoolean("hideOnClick"));
		}
	}
	
	public static CustomMenuItem create(ActionContext actionContext) throws OgnlException, IOException {
		Thing self = actionContext.getObject("self");
		
		CustomMenuItem item = new CustomMenuItem();
		init(item, self, actionContext);
		actionContext.g().put(self.getMetadata().getName(), item);
		
		actionContext.peek().put("parent", item);
		for(Thing child : self.getChilds()) {
			child.doAction("create", actionContext);
		}
		
		return item;
	}

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy