public override void Initialize(IApp app) { var customeUICmd = "Rafy.customization.cmd.CustomizeUI"; WebCommandNames.CustomizeUI = customeUICmd; WebCommandNames.SysCommands.Add(customeUICmd); WebCommandNames.SysQueryCommands.Add(customeUICmd); if (RafyEnvironment.IsDebuggingEnabled) { WebCommandNames.TreeCommands.Insert(0, customeUICmd); WebCommandNames.CommonCommands.Insert(0, customeUICmd); } app.MetaCompiled += (o, e) => { UIModel.AggtBlocks.DefineBlocks("ViewConfigurationModel模块界面", m => { var blocks = new AggtBlocks { MainBlock = new Block(typeof(ViewConfigurationModel)) { BlockType = BlockType.Detail }, Children = { new ChildBlock("属性", ViewConfigurationModel.ViewConfigurationPropertyListProperty), new ChildBlock("命令", ViewConfigurationModel.ViewConfigurationCommandListProperty) } }; blocks.Layout.Class = "Rafy.autoUI.layouts.RightChildren"; return blocks; }); }; }
protected override void OnBlocksDefined(AggtBlocks blocks) { //添加一个升级数据库的按钮。 blocks.MainBlock.ViewMeta.AsWPFView().UseCommands(typeof(MigrateDatabaseCommand)); base.OnBlocksDefined(blocks); }
/// <summary> /// 生成条件查询和主体模块 /// </summary> /// <returns></returns> protected override AggtBlocks DefineBlocks() { var entityType = this.EntityType; AggtBlocks result = new AggtBlocks { MainBlock = new Block(entityType), Layout = new LayoutMeta(typeof(ConditionQueryLayout)) }; var conAttri = entityType.GetSingleAttribute<ConditionQueryTypeAttribute>(); if (conAttri != null) { result.Surrounders.Add(new AggtBlocks { MainBlock = new ConditionBlock() { EntityType = conAttri.QueryType, }, Layout = new LayoutMeta(typeof(HorizentalConditionLayout)) }); } return result; }
/// <summary> /// 创建某个模块定义的界面块 /// </summary> /// <param name="moduleMeta"></param> /// <returns></returns> public AggtBlocks GetModuleBlocks(ModuleMeta moduleMeta) { AggtBlocks blocks = null; //如果模块自己指定的模板类,则使用模板类生成聚合块。 if (moduleMeta.BlocksTemplate != null) { var template = Activator.CreateInstance(moduleMeta.BlocksTemplate) as BlocksTemplate; if (template == null) { throw new InvalidProgramException("模板类需要从 BlocksTemplate 类继承。"); } template.EntityType = moduleMeta.EntityType; blocks = template.GetBlocks(); } else { if (!string.IsNullOrEmpty(moduleMeta.AggtBlocksName)) { blocks = GetDefinedBlocks(moduleMeta.AggtBlocksName); } else { blocks = GetDefaultBlocks(moduleMeta.EntityType); } } return(blocks); }
protected AggtBlocks ReadCode(EntityMeta em, Block mainBlock, ReadCodeTemplateOptions op = null) { op = op ?? new ReadCodeTemplateOptions { ReadChildren = true, ReadQueryPanels = true }; AggtBlocks result = mainBlock; if (op.ReadChildren) { foreach (var property in em.ChildrenProperties) { var childBlock = new ChildBlock(property.ManagedProperty as IListProperty); var childAggt = this.ReadCode(property.ChildType, childBlock); result.Children.Add(childAggt); } } if (op.ReadQueryPanels) { this.ReadQueryPanels(em, result); } return(result); }
private void ReadQueryPanels(EntityMeta em, AggtBlocks result) { //导航实体的关系对象 var queryTypes = em.EntityType.GetCustomAttributes(typeof(ConditionQueryTypeAttribute), false); foreach (ConditionQueryTypeAttribute conAttri in queryTypes) { var surBlock = new ConditionBlock { EntityType = conAttri.QueryType, }; var surEM = CommonModel.Entities.Get(surBlock.EntityType); var surAggt = this.ReadCode(surEM, surBlock); result.Surrounders.Add(surAggt); } queryTypes = em.EntityType.GetCustomAttributes(typeof(NavigationQueryTypeAttribute), false); foreach (NavigationQueryTypeAttribute naviAttri in queryTypes) { var surBlock = new NavigationBlock { EntityType = naviAttri.QueryType, }; var surEM = CommonModel.Entities.Get(surBlock.EntityType); var surAggt = this.ReadCode(surEM, surBlock); result.Surrounders.Add(surAggt); } }
public override void Initialize(IApp app) { WPFCommandNames.CustomizeUI = typeof(CustomizeUI); if (RafyEnvironment.IsDebuggingEnabled) { WPFCommandNames.SysCommands.Insert(0, typeof(CustomizeUI)); WPFCommandNames.SysQueryCommands.Insert(0, typeof(CustomizeUI)); } app.MetaCompiled += (o, e) => { UIModel.AggtBlocks.DefineBlocks("ViewConfigurationModel模块界面", m => { var blocks = new AggtBlocks { MainBlock = new Block(typeof(ViewConfigurationModel)) { BlockType = BlockType.Detail }, Children = { new ChildBlock("属性", ViewConfigurationModel.ViewConfigurationPropertyListProperty), new ChildBlock("命令", ViewConfigurationModel.ViewConfigurationCommandListProperty) } }; blocks.Layout.IsLayoutChildrenHorizonal = true; return blocks; }); }; }
public ControlResult(FrameworkElement control, LogicalView view, AggtBlocks blocks) { if (control == null) throw new ArgumentNullException("control"); if (view == null) throw new ArgumentNullException("control"); this.Control = control; this.MainView = view; this.Blocks = blocks; }
/// <summary> /// 整个聚合块的元数据生成完毕后的事件。 /// </summary> /// <param name="blocks"></param> protected virtual void OnBlocksDefined(AggtBlocks blocks) { var handler = this.BlocksDefined; if (handler != null) { handler(this, new BlocksDefinedEventArgs(blocks)); } }
/// <summary> /// 对于每一个聚合块,生成其主块中的视图元数据。 /// /// 子类可重写此方法,并在基类调用之前定义各 blocks 的 ExtendView。 /// </summary> /// <param name="blocks"></param> protected virtual void InitViewMeta(AggtBlocks blocks) { foreach (var item in blocks.EnumerateAllBlocks()) { var mainBlock = item.MainBlock; mainBlock.InitViewMeta(); this.OnViewMetaCreated(mainBlock); } }
public static void MakeBlockReadonly(AggtBlocks block) { var childMeta = block.MainBlock.ViewMeta; childMeta.DisableEditing(); var commands = childMeta.AsWPFView().Commands; for (int i = commands.Count - 1; i >= 0; i--) { var cmd = commands[i]; if (cmd.GroupType != CommandGroupType.View && cmd.GroupType != CommandGroupType.System) { commands.Remove(cmd); } } }
/// <summary> /// 创建某个自定义的聚合块 /// </summary> /// <param name="blocksName"></param> /// <returns></returns> public AggtBlocks GetDefinedBlocks(string blocksName) { AggtBlocks res = null; Func <ModuleMeta, AggtBlocks> creator = null; if (this._memory.TryGetValue(blocksName, out creator)) { res = creator(null); } else { res = this._xmlCfgMgr.GetBlocks(blocksName); if (res == null) { throw new InvalidOperationException("没有找到相应的聚合视图配置文件:" + blocksName); } } return(res); }
protected override void SetItem(int index, AggtBlocks item) { base.SetItem(index, item); (item.MainBlock as ChildBlock).Owner = this._owner; }
/// <summary> /// 根据聚合元数据,生成最终的聚合控件 /// </summary> /// <param name="aggt"> /// 集合中的第一个,是主区域对应的View</param> /// <param name="recurChildren"></param> /// <param name="recurSurrounders"></param> /// <param name="ownerView"></param> /// <param name="type"></param> /// <returns></returns> public ControlResult GenerateControl(AggtBlocks aggt) { var mainView = this._viewFactory.CreateView(aggt.MainBlock); this.CreateCommandsUI(mainView, aggt.MainBlock); var result = this.GenerateCompoundControl(aggt, mainView); Zoom.EnableZoom(result.Control); if (this.GesturesLocation == GesturesLocation.Whole) { this.CreateCommandBindingsOnWhole(result.Control, mainView); } return result; }
public AggtChildrenCollection(AggtBlocks owner) { this._owner = owner; }
/// <summary> /// 根据元数据创建一个布局的方案 /// </summary> /// <param name="meta"></param> /// <returns></returns> private static LayoutMethod CreateLayoutMethod(AggtBlocks meta) { if (meta.Layout.Class != null) { var type = Type.GetType(meta.Layout.Class); var instance = Activator.CreateInstance(type); if (instance is ILayoutControl) { return new ControlLayoutMethod(instance as ILayoutControl); } if (instance is LayoutMethod) { return instance as LayoutMethod; } throw new InvalidProgramException(string.Format( "{0} 类型不能用于布局。原因:WPF 中用于布局类型必须实现 ILayoutControl 接口或者继承自 LayoutMethod 类!", type.FullName)); } var mainBlock = meta.MainBlock; var generateType = mainBlock.BlockType; if (generateType == BlockType.Detail) { return new ControlLayoutMethod(new DetailLayout()); } //var entityViewInfo = mainBlock.EntityViewInfo; //if (entityViewInfo.EntityInfo.IsDefaultObject && // entityViewInfo.BusinessObjectAttribute.ModuleType != ModuleType.Query) //{ // return new TraditionalLayout<NaviListDetailLayoutControl>(); //} return new ControlLayoutMethod(new ListDetailLayout()); //return new TraditionalLayout<ListDetailPopupChildrenLayoutControl>(); }
/// <summary> /// 创建一个实体控件。 /// /// 本方法提供了生成期扩展性。 /// /// ( /// 重写时注意,可以不使用 AutoUI,但是这样的话, /// 界面可能与模板的结构定义并不一致,这会产生一些影响,例如权限系统无法控制。 /// ) /// </summary> /// <returns></returns> protected virtual ControlResult CreateUICore(AggtBlocks blocks) { return AutoUI.AggtUIFactory.GenerateControl(blocks); }
internal ControlResult CreateUI(AggtBlocks blocks) { var ui = this.CreateUICore(blocks); this.OnUIGenerated(ui); return ui; }
/// <summary> /// 递归获取某个聚合块中所有可用的操作列表 /// </summary> /// <param name="blocks"></param> /// <param name="list"></param> private void GetByBlocksRecur(AggtBlocks blocks, OperationACList list) { var mainBlock = blocks.MainBlock; //查看,编辑 list.Add(new OperationAC { ScopeKeyLabel = mainBlock.KeyLabel.Translate(), OperationKey = SystemOperationKeys.Read, Label = SystemOperationKeys.Read.Translate(), }); //list.Add(new OperationAC //{ // ScopeKeyLabel = mainBlock.KeyLabel.Translate(), // OperationKey = SystemOperationKeys.Edit, // Label = SystemOperationKeys.Edit.Translate(), //}); if (RafyEnvironment.Location.IsWebUI) { //功能按钮权限 foreach (var cmd in mainBlock.ViewMeta.AsWebView().Commands) { list.Add(new OperationAC { ScopeKeyLabel = mainBlock.KeyLabel.Translate(), OperationKey = cmd.Name, Label = cmd.Label.Translate(), }); } } else { //功能按钮权限 foreach (var cmd in mainBlock.ViewMeta.AsWPFView().Commands) { list.Add(new OperationAC { ScopeKeyLabel = mainBlock.KeyLabel.Translate(), OperationKey = cmd.Name, Label = cmd.Label.Translate(), }); } } foreach (var surrounder in blocks.Surrounders) { this.GetByBlocksRecur(surrounder, list); } foreach (var child in blocks.Children) { this.GetByBlocksRecur(child, list); } }
internal ClientAggtMeta ConvertToAggtMeta(AggtBlocks aggt, string childPropertyName = null) { var meta = new ClientAggtMeta(); ConvertToAggtMeta(aggt, meta, childPropertyName); return meta; }
private void ConvertToAggtMeta(AggtBlocks aggt, ClientAggtMeta meta, string childPropertyName = null) { var mainBlock = aggt.MainBlock; meta.mainBlock = ConvertToClientMeta(mainBlock.ViewMeta.AsWebView(), mainBlock.BlockType == BlockType.Detail); if (mainBlock is ChildBlock) { meta.mainBlock.label = (mainBlock as ChildBlock).Label; } meta.childProperty = childPropertyName; meta.layoutClass = aggt.Layout.Class; //surrounders foreach (var surAggt in aggt.Surrounders) { var surBlock = surAggt.MainBlock as SurrounderBlock; var surroundMeta = new SurrounderMeta { surrounderType = surBlock.SurrounderType }; ConvertToAggtMeta(surAggt, surroundMeta); meta.surrounders.Add(surroundMeta); } //children foreach (var childAggt in aggt.Children) { var childBlock = childAggt.MainBlock as ChildBlock; var child = ConvertToAggtMeta(childAggt, childBlock.ChildrenPropertyName); meta.children.Add(child); } }
public RegionContainer(AggtBlocks aggt) { if (aggt == null) throw new ArgumentNullException("aggt"); this._aggt = aggt; }
/// <summary> /// 整个聚合块的元数据生成完毕后的事件。 /// </summary> /// <param name="blocks"></param> protected virtual void OnBlocksDefined(AggtBlocks blocks) { var handler = this.BlocksDefined; if (handler != null) handler(this, new BlocksDefinedEventArgs(blocks)); }
public BlocksDefinedEventArgs(AggtBlocks blocks) { this.Blocks = blocks; }
/// <summary> /// 把某个自定义的聚合块保存到硬盘上。 /// </summary> /// <param name="blocksName"></param> /// <param name="blocks"></param> public void Save(string blocksName, AggtBlocks blocks) { var path = XmlConfigFileSystem.GetCompositeBlocksFilePath(blocksName); var xml = blocks.ToXmlString(); File.WriteAllText(path, xml); }
/// <summary> /// 为聚合对象生成组合控件。 /// </summary> /// <param name="aggt"> /// 需要生成聚合控件的聚合对象元数据 /// </param> /// <param name="mainView"> /// 已经生成好的聚合对象 aggt 中的“根”对象所对应的 LogicalView。 /// </param> /// <returns></returns> private ControlResult GenerateCompoundControl(AggtBlocks aggt, LogicalView mainView) { var regions = new RegionContainer(aggt); //如果不要查询面板,则需要生成主区域 var viewInfo = aggt.MainBlock.ViewMeta; regions.Add(TraditionalRegions.Main, AutoUIHelper.CreateBusyControlResult(mainView)); if (mainView.CommandsContainer != null) { regions.Add(TraditionalRegions.CommandsContainer, new ControlResult(mainView.CommandsContainer, mainView)); } //Surrounders this.SurroundersToRegions(aggt.Surrounders, mainView, regions); //Children this.ChildrenToRegions(aggt.Children, mainView, regions); //Layout var layout = CreateLayoutMethod(aggt); var result = layout.Arrange(regions); //在 View 中保存最终布局完成的控件。 mainView.LayoutControl = result; //返回布局后的整个控件。 var ui = new ControlResult(result, mainView, aggt); if (this.GesturesLocation == GesturesLocation.Layout) { this.CreateCommandBindings(ui.Control, ui.MainView); } return ui; }