private void OnResetExecute()
 {
     UshortsFormatterViewModels.Clear();
     UshortsFormatterViewModels.AddCollection(_container.ResolveAll <IUshortsFormatterViewModel>());
     SelectedUshortsFormatterViewModel = null;
     IsFormatterFromResource           = false;
     CurrentResourceString             = null;
 }
        public FormatterSelectionViewModel(ITypesContainer container,
                                           List <IUshortFormattableEditorViewModel> ushortFormattableViewModels,
                                           List <IConfigurationItemViewModel> rootConfigurationItemViewModels)
        {
            CurrentResourceString       = null;
            _container                  = container;
            _ushortFormattableViewModel = ushortFormattableViewModels;

            _sharedResourcesGlobalViewModel = _container.Resolve <ISharedResourcesGlobalViewModel>();

            _ushortsFormatterViewModels = new ObservableCollection <IUshortsFormatterViewModel>();
            UshortsFormatterViewModels.AddCollection(_container.ResolveAll <IUshortsFormatterViewModel>());
            BitNumbersInWord = new ObservableCollection <IBitViewModel>();

            // for (int i = 15; i >= 0; i--)
            // {
            //    IBitViewModel bitViewModel = new BitViewModel(i, true);
            //   BitNumbersInWord.Add(bitViewModel);
            //}

            IsBitsEditingEnabled = false;


            if (ushortFormattableViewModels.Count == 1)
            {
                var ushortFormattableViewModel = ushortFormattableViewModels.First();

                if (ushortFormattableViewModel is IBitsConfigViewModel bitsConfigViewModel)
                {
                    BitNumbersInWord.AddCollection(
                        BitOwnershipHelper.CreateBitViewModelsWithOwnership(bitsConfigViewModel,
                                                                            rootConfigurationItemViewModels));
                    bitsConfigViewModel.CopyBitsTo(this);
                    IsBitsEditingEnabled = true;
                }

                if (ushortFormattableViewModel.FormatterParametersViewModel != null)
                {
                    if (_sharedResourcesGlobalViewModel.GetResourceViewModelByName(
                            ushortFormattableViewModel.FormatterParametersViewModel.Name).IsSuccess)
                    {
                        CurrentResourceString    = ushortFormattableViewModel.FormatterParametersViewModel.Name;
                        _isFormatterFromResource = true;
                        ushortFormattableViewModel.FormatterParametersViewModel.RelatedUshortsFormatterViewModel =
                            container.Resolve <IFormatterViewModelFactory>().CreateFormatterViewModel(
                                _sharedResourcesGlobalViewModel.GetResourceByName(_currentResourceString) as
                                IUshortsFormatter).RelatedUshortsFormatterViewModel;
                    }

                    var formatter =
                        _ushortsFormatterViewModels.FirstOrDefault(f =>
                                                                   f.StrongName == ushortFormattableViewModel.FormatterParametersViewModel
                                                                   .RelatedUshortsFormatterViewModel.StrongName);
                    var existingIndex =
                        _ushortsFormatterViewModels.IndexOf(formatter);
                    _ushortsFormatterViewModels.RemoveAt(existingIndex);
                    _ushortsFormatterViewModels.Insert(existingIndex,
                                                       ushortFormattableViewModel.FormatterParametersViewModel.RelatedUshortsFormatterViewModel);
                    SelectedUshortsFormatterViewModel = ushortFormattableViewModel.FormatterParametersViewModel
                                                        .RelatedUshortsFormatterViewModel;
                }
            }

            CancelCommand              = new RelayCommand <object>(OnCancelExecute);
            OkCommand                  = new RelayCommand <object>(OnOkExecute);
            ResetCommand               = new RelayCommand(OnResetExecute);
            AddAsResourceCommand       = new RelayCommand(OnAddAsResourceExecute);
            SelectFromResourcesCommand = new RelayCommand(OnSelectFromResourcesExecute);
        }