public List <EditorValidationErrorViewModel> CheckItem(List <EditorValidationErrorViewModel> initialErrors,
                                                               IConfigurationItemViewModel configurationEditorItemViewModel,
                                                               IConfigurationEditorViewModel configurationEditorViewModel)
        {
            if (configurationEditorItemViewModel is IPropertyEditorViewModel propertyEditorViewModel &&
                !(configurationEditorItemViewModel is IComplexPropertyEditorViewModel))
            {
                if (propertyEditorViewModel.FormatterParametersViewModel == null ||
                    (propertyEditorViewModel.FormatterParametersViewModel.RelatedUshortsFormatterViewModel == null &&
                     !propertyEditorViewModel.FormatterParametersViewModel.IsFromSharedResources))
                {
                    initialErrors.Add(new EditorValidationErrorViewModel(
                                          $"{propertyEditorViewModel.Name} ({_localizerService.GetLocalizedString("Address")}:{propertyEditorViewModel.Address}): {_localizerService.GetLocalizedString(ApplicationGlobalNames.StatusMessages.EMPTY_FORMATTING_MESSAGE)}",
                                          Result <Action> .Create(
                                              () =>
                    {
                        _formatterEditorFactory.EditFormatterByUser(propertyEditorViewModel,
                                                                    configurationEditorViewModel.RootConfigurationItemViewModels.ToList());
                    }, true)));
                }

                if (propertyEditorViewModel.FormatterParametersViewModel != null &&

                    propertyEditorViewModel.FormatterParametersViewModel.IsFromSharedResources &&
                    _sharedResourcesGlobalViewModel.GetResourceByName(propertyEditorViewModel
                                                                      .FormatterParametersViewModel.Name) == null)
                {
                    initialErrors.Add(new EditorValidationErrorViewModel(
                                          $"{propertyEditorViewModel.Name} ({_localizerService.GetLocalizedString("Address")}:{propertyEditorViewModel.Address}): {_localizerService.GetLocalizedString(ApplicationGlobalNames.StatusMessages.FORMATTING_RESOURCE_NOT_FOUND_MESSAGE)}",
                                          Result <Action> .Create(
                                              () =>
                    {
                        _formatterEditorFactory.EditFormatterByUser(propertyEditorViewModel,
                                                                    configurationEditorViewModel.RootConfigurationItemViewModels.ToList());
                    }, true)));
                }
            }

            if (configurationEditorItemViewModel is IConfigurationGroupEditorViewModel configurationGroupEditorViewModel
                )
            {
                configurationGroupEditorViewModel.ChildStructItemViewModels.ForEach(model =>
                                                                                    CheckItem(initialErrors, model, configurationEditorViewModel));
            }

            if (configurationEditorItemViewModel is IComplexPropertyEditorViewModel complexPropertyEditorViewModel)
            {
                complexPropertyEditorViewModel.SubPropertyEditorViewModels.ForEach(model =>
                                                                                   CheckItem(initialErrors, model, configurationEditorViewModel));
            }

            return(initialErrors);
        }
        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);
        }