Exemplo n.º 1
0
        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;
                });
            };
        }
Exemplo n.º 2
0
        protected override void OnBlocksDefined(AggtBlocks blocks)
        {
            //添加一个升级数据库的按钮。
            blocks.MainBlock.ViewMeta.AsWPFView().UseCommands(typeof(MigrateDatabaseCommand));

            base.OnBlocksDefined(blocks);
        }
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
        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;
                });
            };
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        /// <summary>
        /// 整个聚合块的元数据生成完毕后的事件。
        /// </summary>
        /// <param name="blocks"></param>
        protected virtual void OnBlocksDefined(AggtBlocks blocks)
        {
            var handler = this.BlocksDefined;

            if (handler != null)
            {
                handler(this, new BlocksDefinedEventArgs(blocks));
            }
        }
Exemplo n.º 11
0
        /// <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);
            }
        }
Exemplo n.º 12
0
        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);
                }
            }
        }
Exemplo n.º 13
0
        /// <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);
        }
Exemplo n.º 14
0
        /// <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);
            }
        }
Exemplo n.º 15
0
        protected override void SetItem(int index, AggtBlocks item)
        {
            base.SetItem(index, item);

            (item.MainBlock as ChildBlock).Owner = this._owner;
        }
Exemplo n.º 16
0
        /// <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;
        }
Exemplo n.º 17
0
 public AggtChildrenCollection(AggtBlocks owner)
 {
     this._owner = owner;
 }
Exemplo n.º 18
0
        /// <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>();
        }
Exemplo n.º 19
0
 /// <summary>
 /// 创建一个实体控件。
 /// 
 /// 本方法提供了生成期扩展性。
 /// 
 /// (
 /// 重写时注意,可以不使用 AutoUI,但是这样的话,
 /// 界面可能与模板的结构定义并不一致,这会产生一些影响,例如权限系统无法控制。
 /// )
 /// </summary>
 /// <returns></returns>
 protected virtual ControlResult CreateUICore(AggtBlocks blocks)
 {
     return AutoUI.AggtUIFactory.GenerateControl(blocks);
 }
Exemplo n.º 20
0
        internal ControlResult CreateUI(AggtBlocks blocks)
        {
            var ui = this.CreateUICore(blocks);

            this.OnUIGenerated(ui);

            return ui;
        }
Exemplo n.º 21
0
        /// <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);
            }
        }
Exemplo n.º 22
0
 internal ClientAggtMeta ConvertToAggtMeta(AggtBlocks aggt, string childPropertyName = null)
 {
     var meta = new ClientAggtMeta();
     ConvertToAggtMeta(aggt, meta, childPropertyName);
     return meta;
 }
Exemplo n.º 23
0
        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);
            }
        }
Exemplo n.º 24
0
 public RegionContainer(AggtBlocks aggt)
 {
     if (aggt == null) throw new ArgumentNullException("aggt");
     this._aggt = aggt;
 }
Exemplo n.º 25
0
 /// <summary>
 /// 整个聚合块的元数据生成完毕后的事件。
 /// </summary>
 /// <param name="blocks"></param>
 protected virtual void OnBlocksDefined(AggtBlocks blocks)
 {
     var handler = this.BlocksDefined;
     if (handler != null) handler(this, new BlocksDefinedEventArgs(blocks));
 }
Exemplo n.º 26
0
 public BlocksDefinedEventArgs(AggtBlocks blocks)
 {
     this.Blocks = blocks;
 }
Exemplo n.º 27
0
 public BlocksDefinedEventArgs(AggtBlocks blocks)
 {
     this.Blocks = blocks;
 }
Exemplo n.º 28
0
 /// <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);
 }
Exemplo n.º 29
0
        /// <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;
        }