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

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

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

import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.control.FocusModel;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import javafx.util.Callback;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import org.xmeta.util.UtilData;
import xworker.javafx.beans.property.PropertyFactory;

public class ListViewActions {
	static{
		PropertyFactory.regist(ListView.class, "itemsProperty", o -> {
			ListView obj = (ListView) o;
			return obj.itemsProperty();
		});
		PropertyFactory.regist(ListView.class, "onEditCommitProperty", o -> {
			ListView obj = (ListView) o;
			return obj.onEditCommitProperty();
		});
		PropertyFactory.regist(ListView.class, "onEditCancelProperty", o -> {
			ListView obj = (ListView) o;
			return obj.onEditCancelProperty();
		});
		PropertyFactory.regist(ListView.class, "fixedCellSizeProperty", o -> {
			ListView obj = (ListView) o;
			return obj.fixedCellSizeProperty();
		});
		PropertyFactory.regist(ListView.class, "onEditStartProperty", o -> {
			ListView obj = (ListView) o;
			return obj.onEditStartProperty();
		});
		PropertyFactory.regist(ListView.class, "placeholderProperty", o -> {
			ListView obj = (ListView) o;
			return obj.placeholderProperty();
		});
		PropertyFactory.regist(ListView.class, "cellFactoryProperty", o -> {
			ListView obj = (ListView) o;
			return obj.cellFactoryProperty();
		});
		PropertyFactory.regist(ListView.class, "orientationProperty", o -> {
			ListView obj = (ListView) o;
			return obj.orientationProperty();
		});
		PropertyFactory.regist(ListView.class, "selectionModelProperty", o -> {
			ListView obj = (ListView) o;
			return obj.selectionModelProperty();
		});
		PropertyFactory.regist(ListView.class, "editableProperty", o -> {
			ListView obj = (ListView) o;
			return obj.editableProperty();
		});
		PropertyFactory.regist(ListView.class, "onScrollToProperty", o -> {
			ListView obj = (ListView) o;
			return obj.onScrollToProperty();
		});
		PropertyFactory.regist(ListView.class, "focusModelProperty", o -> {
			ListView obj = (ListView) o;
			return obj.focusModelProperty();
		});
	}

	public static void init(ListView list, Thing thing, ActionContext actionContext) {
		ControlActions.init(list, thing, actionContext);
		
        if(thing.valueExists("cellFactory")){
        	@SuppressWarnings("unchecked")
			Callback,ListCell> cellFactory = (Callback,ListCell>) UtilData.getData(thing.getString("cellFactory"), actionContext);
        	if(cellFactory != null) {
        		list.setCellFactory(cellFactory);
        	}
        }
        if(thing.valueExists("editable")){
            list.setEditable(thing.getBoolean("editable"));
        }
        if(thing.valueExists("fixedCellSize")){
            list.setFixedCellSize(thing.getDouble("fixedCellSize"));
        }
        if(thing.valueExists("focusModel")){
        	@SuppressWarnings("unchecked")
			FocusModel focusModel = (FocusModel) UtilData.getData(thing.getString("focusModel"), actionContext);
        	if(focusModel != null) {
        		list.setFocusModel(focusModel);
        	}
        }
        if(thing.valueExists("orientation")){
            list.setOrientation(Orientation.valueOf(thing.getString("orientation")));
        }
        if(thing.valueExists("placeholder")){
        	Node placeholder = (Node) UtilData.getData(thing.getString("placeholder"), actionContext);
        	if(placeholder != null) {
        		list.setPlaceholder(placeholder);
        	}
        }
        if(thing.valueExists("selectionModel")){
        	String selectionModel = thing.getString("selectionModel");
        	if("MULTIPLE".equals(selectionModel)) {
        		list.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        	}else if("SINGLE".equals(selectionModel)) {
        		list.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
        	}
        }
	}
	
	public static ListView create(ActionContext actionContext) {
		Thing self = actionContext.getObject("self");
		
		ListView item = new ListView();
		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;
	}
}