public static IModelUI CreateBlackboard(this ElementBuilder elementBuilder, CommandDispatcher commandDispatcher, IBlackboardGraphModel model) { var ui = new Blackboard { Windowed = true }; ui.SetupBuildAndUpdate(model, commandDispatcher, elementBuilder.View, elementBuilder.Context); return(ui); }
public static IModelUI CreateVariableDeclarationModelUI(this ElementBuilder elementBuilder, CommandDispatcher commandDispatcher, IVariableDeclarationModel model) { IModelUI ui; if (elementBuilder.Context == BlackboardVariablePropertiesPart.blackboardVariablePropertiesPartCreationContext) { ui = new BlackboardVariablePropertyView(); } else if (elementBuilder.Context == BlackboardVariablePart.blackboardVariablePartCreationContext) { ui = new BlackboardField(); } else { ui = new BlackboardRow(); } ui.SetupBuildAndUpdate(model, commandDispatcher, elementBuilder.View, elementBuilder.Context); return(ui); }
public static IModelUI CreateNode(this ElementBuilder elementBuilder, CommandDispatcher commandDispatcher, INodeModel model) { IModelUI ui; if (model is ISingleInputPortNodeModel || model is ISingleOutputPortNodeModel) { ui = new TokenNode(); } else if (model is IPortNodeModel) { ui = new CollapsibleInOutNode(); } else { ui = new Node(); } ui.SetupBuildAndUpdate(model, commandDispatcher, elementBuilder.View, elementBuilder.Context); return(ui); }
/// <summary> /// Creates an instance of a class implementing <see cref="IModelUI"/> to display <paramref name="model"/>. /// </summary> /// <param name="view">The view in which to put the UI.</param> /// <param name="commandDispatcher">The command dispatcher.</param> /// <param name="model">The model.</param> /// <param name="context">A context creation string. When a model needs different UI in /// different contexts, use this parameter to differentiate between contexts.</param> /// <typeparam name="T">The type of the returned object.</typeparam> /// <returns>An instance of <see cref="IModelUI"/> that display <paramref name="model"/>.</returns> public static T CreateUI <T>(IModelView view, CommandDispatcher commandDispatcher, IGraphElementModel model, string context) where T : class, IModelUI { if (view == null) { Debug.LogError("GraphElementFactory could not create element because view is null."); return(null); } if (model == null) { Debug.LogError("GraphElementFactory could not create element because model is null."); return(null); } var ext = ExtensionMethodCache <ElementBuilder> .GetExtensionMethod( view.GetType(), model.GetType(), FilterMethods, KeySelector ); T newElem = null; if (ext != null) { var nodeBuilder = new ElementBuilder { View = view, Context = context }; newElem = ext.Invoke(null, new object[] { nodeBuilder, commandDispatcher, model }) as T; } if (newElem == null) { Debug.LogError($"GraphElementFactory doesn't know how to create a UI of type {typeof(T)} for model of type: {model.GetType()}"); return(null); } return(newElem); }