protected override void ExecuteAction(ObjectBuilderContext context, BaseItemAction action, dynamic metadata)
 {
     ViewHelper.ShowView(null,
                         () => context.Build(action.GetView(), metadata.View),
                         childDataSource => OnInitializeChildView(childDataSource),
                         childDataSource => OnAcceptedChildView(action, childDataSource));
 }
예제 #2
0
        private static void OnAcceptedChildView(BaseItemAction action, IDataSource childDataSource, dynamic selectedItem)
        {
            var newItem = childDataSource.GetSelectedItem();

            if (newItem != null)
            {
                action.ReplaceItem(selectedItem, newItem);
                action.SetSelectedItem(newItem);
            }
        }
        private static void OnAcceptedChildView(BaseItemAction action, IDataSource childDataSource)
        {
            var newItem = childDataSource.GetSelectedItem();

            if (newItem != null)
            {
                action.AddItem(newItem);
                action.SetSelectedItem(newItem);
            }
        }
예제 #4
0
        protected override void ExecuteAction(ObjectBuilderContext context, BaseItemAction action, dynamic metadata)
        {
            var selectedItem = action.GetSelectedItem();

            if (selectedItem != null)
            {
                ViewHelper.ShowView(selectedItem,
                                    () => context.Build(action.GetView(), metadata.View),
                                    childDataSource => OnInitializeChildView(childDataSource, selectedItem),
                                    childDataSource => OnAcceptedChildView(action, childDataSource, selectedItem));
            }
        }
예제 #5
0
        protected override void ExecuteAction(ObjectBuilderContext context, BaseItemAction action, dynamic metadata)
        {
            var selectedItem = action.GetSelectedItem();

            if (selectedItem != null && (Convert.ToBoolean(metadata.Accept) == false
                                         ||
                                         MessageBox.Show(Resources.DeleteItemActionQuestion, action.GetView().GetText(),
                                                         MessageBoxButton.YesNo, MessageBoxImage.Question,
                                                         MessageBoxResult.No) == MessageBoxResult.Yes))
            {
                action.RemoveItem(selectedItem);
            }
        }
예제 #6
0
        public object Build(ObjectBuilderContext context, View parent, dynamic metadata)
        {
            var action = new BaseItemAction(parent);

            IElementDataBinding itemsDataBinding = context.Build(parent, metadata.Items);

            if (itemsDataBinding != null)
            {
                itemsDataBinding.OnPropertyValueChanged += (c, a) => action.SetItems(a.Value);
                action.OnValueChanged += (c, a) => itemsDataBinding.SetPropertyValue(a.Value);

                var sourceItemsDataBinding = itemsDataBinding as ISourceDataBinding;

                if (sourceItemsDataBinding != null)
                {
                    var dataSourceName = sourceItemsDataBinding.GetDataSource();
                    var propertyName   = sourceItemsDataBinding.GetProperty();

                    // Публикация сообщений в шину при возникновении событий

                    action.NotifyWhenEventAsync(i => i.OnSetSelectedItem, a =>
                    {
                        a.DataSource = dataSourceName;
                        a.Property   = propertyName;
                        return(true);
                    });

                    // Подписка на сообщения шины от внешних элементов

                    action.SubscribeOnEvent(OnSetSelectedItem, a => a.DataSource == dataSourceName &&
                                            a.Property == propertyName);
                }
            }

            action.SetAction(() => ExecuteAction(context, action, metadata));

            return(action);
        }
예제 #7
0
        // Обработчики сообщений шины (внимание: наименования обработчиков совпадают с наименованиями событий)

        private static void OnSetSelectedItem(BaseItemAction target, dynamic arguments)
        {
            target.SetSelectedItem(arguments.Value);
        }
예제 #8
0
 protected abstract void ExecuteAction(ObjectBuilderContext context, BaseItemAction action, dynamic metadata);