Пример #1
0
 public SelectionHandler(IMultiSelector multiSelector)
 {
     this.multiSelector              = multiSelector;
     multiSelector.ItemSpecified    += MultiSelectorOnItemSpecified;
     multiSelector.SelectionCleared += MultiSelectorOnSelectionCleared;
     SelectionMode = SelectionMode.Direct;
 }
 public SelectionHandler(IMultiSelector multiSelector)
 {
     this.multiSelector = multiSelector;
     multiSelector.ItemSpecified += MultiSelectorOnItemSpecified;
     multiSelector.NoneSpecified += MultiSelectorOnNoneSpecified;
     SelectionMode = SelectionMode.Direct;
 }
        public void TestVWG_SelectButtonIsEnabledWhenItemIsDeselected()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.AllOptions = CreateListWithTwoOptions();
            _selector.AvailableOptionsListBox.SelectedIndex = 0;
            //---------------Execute Test ----------------------
            _selector.AvailableOptionsListBox.SelectedIndex = -1;
            //---------------Test Result -----------------------
            Assert.IsTrue(_selector.GetButton(MultiSelectorButton.Select).Enabled);
        }
        public void TestVWG_DeselectButtonStateAtSet()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();
            List <TestT>           options   = CreateListWithTwoOptions();

            _selector.AllOptions = options;
            //---------------Execute Test ----------------------
            _selector.SelectedOptions = options;
            //---------------Test Result -----------------------
            Assert.IsTrue(_selector.GetButton(MultiSelectorButton.Deselect).Enabled);
        }
Пример #5
0
        public void Test_Win_SelectButtonStateAtSet()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            //---------------Execute Test ----------------------
            _selector.AllOptions = CreateListWithTwoOptions();

            //---------------Test Result -----------------------
            Assert.IsFalse(_selector.GetButton(MultiSelectorButton.Select).Enabled);
            //---------------Tear Down -------------------------
        }
Пример #6
0
        public void TestCreateMultiSelector()
        {
            //---------------Set up test pack-------------------

            //---------------Execute Test ----------------------
            IMultiSelector <object> multiSelector = GetControlFactory().CreateMultiSelector <object>();

            //---------------Test Result -----------------------

            Assert.IsNotNull(multiSelector);
            //---------------Tear Down -------------------------
        }
        public void TestVWG_ClickSelectButtonWithNoItemSelected()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.AllOptions = CreateListWithTwoOptions();
            _selector.AvailableOptionsListBox.SelectedIndex = -1;
            //---------------Execute Test ----------------------
            _selector.GetButton(MultiSelectorButton.Select).PerformClick();
            //---------------Test Result -----------------------
            AssertNoneSelected(_selector);
        }
Пример #8
0
        public void TestSelectionsMirrorsModelSelections()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.Model.SelectedOptions = CreateListWithTwoOptions();
            Assert.AreEqual(_selector.SelectedOptions, _selector.Model.SelectedOptions);
            //---------------Execute Test ----------------------
            _selector.AllOptions = new List <TestT>();
            //---------------Test Result -----------------------
            Assert.AreEqual(_selector.SelectedOptions, _selector.Model.SelectedOptions);
            //---------------Tear Down -------------------------
        }
Пример #9
0
        public void TestSettingBlankOptionsClearsListbox()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.Model.AllOptions = CreateListWithTwoOptions();

            //---------------Execute Test ----------------------
            _selector.Model.AllOptions = new List <TestT>();
            //---------------Test Result -----------------------
            Assert.AreEqual(0, _selector.AvailableOptionsListBox.Items.Count);
            //---------------Tear Down -------------------------
        }
Пример #10
0
        public void TestRemoveOptionRemovesFromListbox()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.AllOptions = CreateListWithTwoOptions();

            //---------------Execute Test ----------------------
            _selector.Model.RemoveOption(_selector.Model.OptionsView[0]);

            //---------------Test Result -----------------------
            Assert.AreEqual(1, _selector.AvailableOptionsListBox.Items.Count);
            //---------------Tear Down -------------------------
        }
Пример #11
0
        public void TestAddingOptionAddsToListbox()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.AllOptions = CreateListWithTwoOptions();

            //---------------Execute Test ----------------------
            _selector.Model.AddOption(new TestT());

            //---------------Test Result -----------------------
            Assert.AreEqual(3, _selector.AvailableOptionsListBox.Items.Count);
            //---------------Tear Down -------------------------
        }
Пример #12
0
        public void Test_Win_SelectButtonStateUponSelection()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.AllOptions = CreateListWithTwoOptions();
            //---------------Execute Test ----------------------

            _selector.AvailableOptionsListBox.SelectedIndex = 0;

            //---------------Test Result -----------------------
            Assert.IsTrue(_selector.GetButton(MultiSelectorButton.Select).Enabled);
            //---------------Tear Down -------------------------
        }
Пример #13
0
        public void TestDeselectAllButton_click()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.AllOptions = CreateListWithTwoOptions();
            _selector.Model.SelectAll();

            //---------------Execute Test ----------------------
            _selector.GetButton(MultiSelectorButton.DeselectAll).PerformClick();
            //---------------Test Result -----------------------
            AssertNoneSelected(_selector);
            //---------------Tear Down -------------------------
        }
Пример #14
0
        public void TestSettingOptionsPopulatesModel()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector  = GetControlFactory().CreateMultiSelector <TestT>();
            List <TestT>           twoOptions = CreateListWithTwoOptions();

            //---------------Execute Test ----------------------
            _selector.AllOptions = twoOptions;

            //---------------Test Result -----------------------
            Assert.AreEqual(2, _selector.Model.OptionsView.Count);

            //---------------Tear Down -------------------------
        }
Пример #15
0
        public void TestDeselectAllUpdatesListboxes()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> selector = GetControlFactory().CreateMultiSelector <TestT>();

            selector.AllOptions = CreateListWithTwoOptions();
            selector.Model.SelectAll();

            //---------------Execute Test ----------------------
            selector.Model.DeselectAll();

            //---------------Test Result -----------------------
            AssertNoneSelected(selector);
            //---------------Tear Down -------------------------
        }
Пример #16
0
        public void Test_Win_DeselectButtonIsDisabledWhenItemIsDeselected()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();
            List <TestT>           options   = CreateListWithTwoOptions();

            _selector.AllOptions      = options;
            _selector.SelectedOptions = options;
            _selector.SelectedOptionsListBox.SelectedIndex = 0;
            //---------------Execute Test ----------------------
            _selector.SelectedOptionsListBox.SelectedIndex = -1;
            //---------------Test Result -----------------------
            Assert.IsFalse(_selector.GetButton(MultiSelectorButton.Deselect).Enabled);
            //---------------Tear Down -------------------------
        }
Пример #17
0
        public void TestSelectAllUpdatesListboxes()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> selector = GetControlFactory().CreateMultiSelector <TestT>();

            selector.AllOptions = CreateListWithTwoOptions();

            //---------------Execute Test ----------------------
            selector.Model.SelectAll();

            //---------------Test Result -----------------------
            AssertAllSelected(selector);
            Assert.AreEqual(selector.SelectedOptionsListBox.Items.Count, selector.SelectionsView.Count);
            //---------------Tear Down -------------------------
        }
Пример #18
0
        public void Test_SetAllOptions_ToNull_ShouldClearAllOptions()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector  = GetControlFactory().CreateMultiSelector <TestT>();
            List <TestT>           twoOptions = CreateListWithTwoOptions();

            _selector.AllOptions = twoOptions;
            //---------------Assert Preconditions -------------
            Assert.AreEqual(2, _selector.AvailableOptionsListBox.Items.Count);
            //---------------Execute Test ----------------------
            _selector.AllOptions = null;
            //---------------Test Result -----------------------
            Assert.AreEqual(0, _selector.AvailableOptionsListBox.Items.Count);
            Assert.AreEqual(0, _selector.SelectedOptionsListBox.Items.Count);
        }
Пример #19
0
        private static void SyncSelectedItemsPropertyChanged(DependencyObject element, DependencyPropertyChangedEventArgs e)
        {
            var selector = element as Selector;

            if (selector == null)
            {
                throw new ArgumentException("The attached property SelectedItems can only be used with a Selector.", nameof(element));
            }

            TryCleanUpOldItem(selector);
            try
            {
                IMultiSelector multiSelector = TryGetMultiSelector(selector);
                if (multiSelector == null)
                {
                    return;
                }

                IList list = GetSyncSelectedItems(selector);
                if (list == null)
                {
                    return;
                }

                if (multiSelector.SelectedItems.Count > 0)
                {
                    multiSelector.SelectedItems.Clear();
                }

                foreach (object item in list)
                {
                    multiSelector.SelectedItems.Add(item);
                }

                var observableList = list as INotifyCollectionChanged;
                if (observableList == null)
                {
                    return;
                }

                multiSelectorWithObservableList.Add(new Tuple <IMultiSelector, INotifyCollectionChanged>(multiSelector, observableList));
                CollectionChangedEventManager.AddHandler(observableList, ListCollectionChanged);
            }
            finally
            {
                selector.SelectionChanged += SelectorSelectionChanged;
            }
        }
Пример #20
0
        public void TestSetSelectionsRemovesItemsFromOptionsListbox()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector  = GetControlFactory().CreateMultiSelector <TestT>();
            List <TestT>           twoOptions = CreateListWithTwoOptions();

            _selector.AllOptions = twoOptions;

            //---------------Execute Test ----------------------
            _selector.SelectedOptions = twoOptions;

            //---------------Test Result -----------------------
            Assert.AreEqual(0, _selector.AvailableOptionsListBox.Items.Count);

            //---------------Tear Down -------------------------
        }
Пример #21
0
        public void TestDeselectButtonUpdatesListboxes_Click()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.AllOptions = CreateListWithTwoOptions();
            _selector.Model.Select(_selector.Model.OptionsView[0]);
            _selector.SelectedOptionsListBox.SelectedIndex = 0;

            //---------------Execute Test ----------------------
            _selector.GetButton(MultiSelectorButton.Deselect).PerformClick();
            //---------------Test Result -----------------------

            AssertNoneSelected(_selector);
            //---------------Tear Down -------------------------
        }
Пример #22
0
        public void Test_DoubleClickingHandlersAssigned()
        {
            //---------------Set up test pack-------------------

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, TestUtil.CountEventSubscribers(_selector.AvailableOptionsListBox, "DoubleClick"));
            Assert.AreEqual(1, TestUtil.CountEventSubscribers(_selector.SelectedOptionsListBox, "DoubleClick"));

            Assert.IsTrue(TestUtil.EventHasSubscriber(_selector.AvailableOptionsListBox, "DoubleClick", "DoSelect"));
            Assert.IsTrue(TestUtil.EventHasSubscriber(_selector.SelectedOptionsListBox, "DoubleClick", "DoDeselect"));
        }
        protected virtual void OnSelectorChanged(IMultiSelector oldValue, IMultiSelector newValue)
        {
            if (oldValue != null)
            {
                oldValue.SelectionChanged -= OnSelectorSelectionChanged;
                (oldValue.Items as INotifyCollectionChanged).CollectionChanged -= OnItemsChanged;
            }

            if (newValue != null)
            {
                newValue.SelectionChanged += OnSelectorSelectionChanged;
                (newValue.Items as INotifyCollectionChanged).CollectionChanged += OnItemsChanged;
            }

            IsEnabled = Selector != null && Selector.Items.Count > 0;
        }
Пример #24
0
        public void TestSetEmptySelectionsRepopulatesOptionsAndSelections()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector  = GetControlFactory().CreateMultiSelector <TestT>();
            List <TestT>           twoOptions = CreateListWithTwoOptions();

            _selector.AllOptions      = twoOptions;
            _selector.SelectedOptions = twoOptions;

            //---------------Execute Test ----------------------
            _selector.SelectedOptions = new List <TestT>();
            //---------------Test Result -----------------------
            AssertNoneSelected(_selector);

            //---------------Tear Down -------------------------
        }
Пример #25
0
        public virtual void TestDeselectingMultipleItemsAtOnce_Click()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();
            List <TestT>           options   = CreateListWithTwoOptions();

            _selector.AllOptions = options;
            _selector.Model.SelectAll();
            _selector.SelectedOptionsListBox.SelectedItems.Add(options[0]);
            _selector.SelectedOptionsListBox.SelectedItems.Add(options[1]);
            //---------------Execute Test ----------------------
            _selector.GetButton(MultiSelectorButton.Deselect).PerformClick();

            //---------------Test Result -----------------------
            AssertNoneSelected(_selector);
            //---------------Tear Down -------------------------
        }
Пример #26
0
        public void TestSelectButton_Click()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.AllOptions = CreateListWithTwoOptions();
            _selector.AvailableOptionsListBox.SelectedIndex = 0;

            //---------------Execute Test ----------------------
            _selector.GetButton(MultiSelectorButton.Select).PerformClick();

            //---------------Test Result -----------------------
            Assert.AreEqual(1, _selector.AvailableOptionsListBox.Items.Count);
            Assert.AreEqual(1, _selector.SelectedOptionsListBox.Items.Count);
            Assert.AreEqual(_selector.SelectedOptionsListBox.Items.Count, _selector.SelectionsView.Count);
            //---------------Tear Down -------------------------
        }
Пример #27
0
        private static void ListCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (syncListsThatAreUpdating.Contains(sender))
            {
                return;
            }

            IMultiSelector multiSelector = multiSelectorWithObservableList.First(x => x.Item2 == sender).Item1;

            selectorsThatAreUpdating.Add(multiSelector.Selector);
            try
            {
                if (e.Action == NotifyCollectionChangedAction.Add)
                {
                    foreach (object items in e.NewItems)
                    {
                        multiSelector.SelectedItems.Add(items);
                    }
                }
                else if (e.Action == NotifyCollectionChangedAction.Remove)
                {
                    foreach (object items in e.OldItems)
                    {
                        multiSelector.SelectedItems.Remove(items);
                    }
                }
                else if (e.Action == NotifyCollectionChangedAction.Reset)
                {
                    multiSelector.SelectedItems.Clear();
                    foreach (var item in (IEnumerable)sender)
                    {
                        multiSelector.SelectedItems.Add(item);
                    }
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            finally
            {
                selectorsThatAreUpdating.Remove(multiSelector.Selector);
            }
        }
Пример #28
0
        public virtual void TestSelectingMultipleItemsAtOnce_Click()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.AllOptions = CreateListWithTwoOptions();
            ReadOnlyCollection <TestT> options = _selector.Model.OptionsView;
            IListBox availableOptionsListbox   = _selector.AvailableOptionsListBox;

            availableOptionsListbox.SelectedItems.Add(options[0]);
            availableOptionsListbox.SelectedItems.Add(options[1]);

            //---------------Execute Test ----------------------
            _selector.GetButton(MultiSelectorButton.Select).PerformClick();

            //---------------Test Result -----------------------
            AssertAllSelected(_selector);
            Assert.AreEqual(_selector.SelectedOptionsListBox.Items.Count, _selector.SelectionsView.Count);
            //---------------Tear Down -------------------------
        }
Пример #29
0
        /// <summary>
        /// Constructor for <see cref="MultiSelectorManager{T}"/>
        /// </summary>
        /// <param name="multiSelector"></param>
        public MultiSelectorManager(IMultiSelector <T> multiSelector)
        {
            _multiSelector      = multiSelector;
            _model              = new MultiSelectorModel <T>();
            _model.OptionAdded += ((sender, e) => AvailableOptionsListBox.Items.Add(e.Item));

            _model.OptionRemoved += ((sender, e) => AvailableOptionsListBox.Items.Remove(e.Item));

            _model.OptionsChanged += delegate { UpdateListBoxes(); };

            _model.SelectionsChanged += delegate { UpdateListBoxes(); };

            _model.Selected += delegate(object sender, MultiSelectorModel <T> .ModelEventArgs <T> e)
            {
                AvailableOptionsListBox.Items.Remove(e.Item);
                SelectionsListBox.Items.Add(e.Item);
            };
            _model.Deselected += delegate(object sender, MultiSelectorModel <T> .ModelEventArgs <T> e)
            {
                AvailableOptionsListBox.Items.Add(e.Item);
                SelectionsListBox.Items.Remove(e.Item);
            };

            IButton selectButton = GetButton(MultiSelectorButton.Select);

            selectButton.Click += DoSelect;

            IButton deselectButton = GetButton(MultiSelectorButton.Deselect);

            deselectButton.Click += DoDeselect;

            IButton selectAllButton = GetButton(MultiSelectorButton.SelectAll);

            selectAllButton.Click += delegate { _model.SelectAll(); };

            IButton deselectAllButton = GetButton(MultiSelectorButton.DeselectAll);

            deselectAllButton.Click += delegate { _model.DeselectAll(); };
        }
Пример #30
0
        public virtual void TestSelectingIListBoxItemsCollectionEnumerator()
        {
            //---------------Set up test pack-------------------
            IMultiSelector <TestT> _selector = GetControlFactory().CreateMultiSelector <TestT>();

            _selector.AllOptions = CreateListWithTwoOptions();
            ReadOnlyCollection <TestT> options = _selector.Model.OptionsView;
            IListBox availableOptionsListbox   = _selector.AvailableOptionsListBox;

            availableOptionsListbox.SelectedItems.Add(options[0]);
            availableOptionsListbox.SelectedItems.Add(options[1]);

            //---------------Execute Test ----------------------
            _selector.GetButton(MultiSelectorButton.Select).PerformClick();

            //---------------Test Result -----------------------
            foreach (object o in _selector.SelectedOptionsListBox.Items)
            {
                Assert.IsNotNull(o);
            }
            //---------------Tear Down -------------------------
        }
Пример #31
0
 private static void AssertAllSelected(IMultiSelector<TestT> _selector)
 {
     Assert.AreEqual(0, _selector.AvailableOptionsListBox.Items.Count);
     Assert.AreEqual(2, _selector.SelectedOptionsListBox.Items.Count);
 }
Пример #32
0
 private static void AssertAllSelected(IMultiSelector <TestT> _selector)
 {
     Assert.AreEqual(0, _selector.AvailableOptionsListBox.Items.Count);
     Assert.AreEqual(2, _selector.SelectedOptionsListBox.Items.Count);
 }