Пример #1
0
        public static bool MoveToSearchControls(IEntityOperationContext eoc)
        {
            var controls = eoc.EntityControl.Children <SearchControl>()
                           .Where(sc => eoc.OperationInfo.OperationSymbol.Equals(OperationClient.GetConstructFromOperationKey(sc)) ||
                                  sc.NotSet(OperationClient.ConstructFromOperationKeyProperty) && sc.EntityType == eoc.OperationInfo.ReturnType).ToList();

            if (!controls.Any())
            {
                return(false);
            }

            foreach (var sc in controls)
            {
                if (sc.NotSet(OperationClient.ConstructFromOperationKeyProperty))
                {
                    OperationClient.SetConstructFromOperationKey(sc, eoc.OperationInfo.OperationSymbol);
                }

                sc.Create = false;

                var menu = sc.Child <Menu>(b => b.Name == "menu");

                var panel = (StackPanel)menu.Parent;

                var oldButton = panel.Children <ToolBarButton>(tb => tb.Tag is OperationInfo && ((OperationInfo)tb.Tag).OperationSymbol.Equals(eoc.OperationInfo.OperationSymbol)).FirstOrDefault();
                if (oldButton != null)
                {
                    panel.Children.Remove(oldButton);
                }

                var index = panel.Children.IndexOf(menu);
                panel.Children.Insert(index, NewToolbarButton(eoc));
            }
            return(true);
        }
        public static MenuItem Construct(IContextualOperationContext coc)
        {
            MenuItem miResult = new MenuItem
            {
                Header = OperationClient.GetText(coc.Type, coc.OperationInfo.OperationSymbol),
                Icon   = OperationClient.GetImage(coc.Type, coc.OperationInfo.OperationSymbol).ToSmallImage(),
                Tag    = coc,
            };

            if (coc.OperationSettings != null && coc.OperationSettings.Order != 0)
            {
                Common.SetOrder(miResult, coc.OperationSettings.Order);
            }

            if (coc.CanExecute != null)
            {
                miResult.ToolTip   = coc.CanExecute;
                miResult.IsEnabled = false;
                ToolTipService.SetShowOnDisabled(miResult, true);
                AutomationProperties.SetHelpText(miResult, coc.CanExecute);
            }

            miResult.Click += (object sender, RoutedEventArgs e) =>
            {
                coc.SearchControl.SetDirtySelectedItems();

                if (coc.OperationSettings != null && coc.OperationSettings.HasClick)
                {
                    coc.OperationSettings.OnClick(coc);
                }
                else
                {
                    if (coc.ConfirmMessage())
                    {
                        Entity result = (Entity) new ConstructorContext(coc.SearchControl, coc.OperationInfo).SurroundConstructUntyped(coc.OperationInfo.ReturnType, ctx =>
                                                                                                                                       Server.Return((IOperationServer s) => s.ConstructFromMany(coc.SearchControl.SelectedItems.ToList(), coc.Type, coc.OperationInfo.OperationSymbol, ctx.Args)));

                        if (result != null)
                        {
                            Navigator.Navigate(result);
                        }
                        else
                        {
                            MessageBox.Show(Window.GetWindow(coc.SearchControl), OperationMessage.TheOperation0DidNotReturnAnEntity.NiceToString().FormatWith(coc.OperationInfo.OperationSymbol.NiceToString()));
                        }
                    }
                }
            };

            return(miResult);
        }
Пример #3
0
        protected internal virtual Entity Construct(ConstructorContext ctx)
        {
            var dic = (from oi in OperationInfos(ctx.Type)
                       where oi.OperationType == OperationType.Constructor
                       let os = GetSettings <ConstructorOperationSettingsBase>(ctx.Type, oi.OperationSymbol)
                                let coc = newConstructorOperationContext.GetInvoker(ctx.Type)(oi, ctx, os)
                                          where os != null && os.HasIsVisible ? os.OnIsVisible(coc) : true
                                          select coc).ToDictionary(a => a.OperationInfo.OperationSymbol);

            if (dic.Count == 0)
            {
                return(null);
            }

            OperationSymbol selected = null;

            if (dic.Count == 1)
            {
                selected = dic.Keys.SingleEx();
            }
            else
            {
                if (!SelectorWindow.ShowDialog(dic.Keys.ToArray(), out selected,
                                               elementIcon: k => OperationClient.GetImage(ctx.Type, k),
                                               elementText: k => OperationClient.GetText(ctx.Type, k),
                                               title: SelectorMessage.ConstructorSelector.NiceToString(),
                                               message: SelectorMessage.PleaseSelectAConstructor.NiceToString(),
                                               owner: Window.GetWindow(ctx.Element)))
                {
                    return(null);
                }
            }

            var selCoc = dic[selected];

            if (selCoc.Settings != null && selCoc.Settings.HasConstructor)
            {
                return(selCoc.Settings.OnConstructor(selCoc));
            }
            else
            {
                return(Server.Return((IOperationServer s) => s.Construct(ctx.Type, selected, ctx.Args)));
            }
        }