diff --git a/Tests/ViewModels/SettingsViewModelTest.cs b/Tests/ViewModels/SettingsViewModelTest.cs index f06d5d8..65a1d56 100755 --- a/Tests/ViewModels/SettingsViewModelTest.cs +++ b/Tests/ViewModels/SettingsViewModelTest.cs @@ -22,6 +22,7 @@ using System.Text; using NUnit.Framework; using zaaReloaded2.ViewModels; using zaaReloaded2.Controller; +using zaaReloaded2.Controller.Elements; namespace Tests.ViewModels { @@ -51,7 +52,16 @@ namespace Tests.ViewModels [Test] public void CannotAddChildElementToFormatElement() { - + ControlElementViewModel parent = new ControlElementViewModel( + new SelectFirstDay()); + _settingsVM.AddElementViewModel(parent); + parent.IsSelected = true; + Assert.IsTrue(_settingsVM.AddChildElementCommand.CanExecute(null)); + FormatElementViewModel child = new FormatElementViewModel(new Items()); + parent.AddChildElement(child); + parent.IsSelected = false; + child.IsSelected = true; + Assert.IsFalse(_settingsVM.AddChildElementCommand.CanExecute(null)); } [Test] diff --git a/zaaReloaded2/ViewModels/CategoryViewModel.cs b/zaaReloaded2/ViewModels/CategoryViewModel.cs new file mode 100755 index 0000000..8402275 --- /dev/null +++ b/zaaReloaded2/ViewModels/CategoryViewModel.cs @@ -0,0 +1,46 @@ +/* CategoryViewModel.cs + * part of zaaReloaded2 + * + * Copyright 2015 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Bovender.Mvvm.ViewModels; + +namespace zaaReloaded2.ViewModels +{ + /// + /// A simple view model that can be used to categorize items + /// in a tree view. It has a custom DisplayString and holds + /// a collection of child view model items. + /// + class CategoryViewModel : ViewModelBase + { + public IEnumerable Children { get; private set; } + + public CategoryViewModel(string name, IEnumerable children) + { + DisplayString = name; + Children = children; + } + + public override object RevealModelObject() + { + throw new NotImplementedException(); + } + } +} diff --git a/zaaReloaded2/ViewModels/ControlElementViewModel.cs b/zaaReloaded2/ViewModels/ControlElementViewModel.cs index 1826c42..c5452b1 100755 --- a/zaaReloaded2/ViewModels/ControlElementViewModel.cs +++ b/zaaReloaded2/ViewModels/ControlElementViewModel.cs @@ -46,5 +46,16 @@ namespace zaaReloaded2.ViewModels { } #endregion + + #region Public methods + + public void AddChildElement(FormatElementViewModel viewModel) + { + Elements.Add(viewModel); + ControlElementBase e = Element as ControlElementBase; + e.FormatElements.Add(viewModel.RevealModelObject() as FormatElementBase); + } + + #endregion } } diff --git a/zaaReloaded2/ViewModels/ElementPickerViewModel.cs b/zaaReloaded2/ViewModels/ElementPickerViewModel.cs new file mode 100755 index 0000000..24d75eb --- /dev/null +++ b/zaaReloaded2/ViewModels/ElementPickerViewModel.cs @@ -0,0 +1,122 @@ +/* ElementPickerViewModel.cs + * part of zaaReloaded2 + * + * Copyright 2015 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Bovender.Mvvm; +using Bovender.Mvvm.Messaging; +using Bovender.Mvvm.ViewModels; +using System.Collections.ObjectModel; +using zaaReloaded2.Controller.Elements; + +namespace zaaReloaded2.ViewModels +{ + /// + /// View model that presents a list of zaaReloaded2.Contorller.Elements.ElementBase + /// classes to choose from. + /// + class ElementPickerViewModel : ViewModelBase + { + #region Properties + + /// + /// A two-dimensional tree + /// + public IList AvailableElements { get; private set; } + + #endregion + + #region Constructors + + public ElementPickerViewModel(SettingsViewModel caller, bool allowControlElements) + { + _caller = caller; + AvailableElements = new List(); + if (allowControlElements) + { + AvailableElements.Add( + new CategoryViewModel( + "Kontroll-Elemente", + new Collection() + { + CreateControlElementViewModel(new SelectFirstDay()), + CreateControlElementViewModel(new SelectLastDay()), + CreateControlElementViewModel(new SelectEachDay()) + } + ) + ); + } + AvailableElements.Add( + new CategoryViewModel( + "Ausgabe-Elemente", + new Collection() + { + CreateFormatElementViewModel("Laborparameter", new Items()), + CreateFormatElementViewModel("Beliebiger Text", new CustomText()), + } + ) + ); + } + + #endregion + + #region Private methods + + /// + /// Creates a new ControlElementViewModel that wraps a ControlElementBase + /// object. The display string of the ControlElementViewModel is taken + /// from the canonical Label of the control element. + /// + ViewModelBase CreateControlElementViewModel(ControlElementBase element) + { + ControlElementViewModel vm = new ControlElementViewModel(element); + vm.DisplayString = element.Label; + return vm; + } + + /// + /// Creates a new FormatElementViewModel that wraps a FormatElementBase + /// object and has a custom display string. The custom display string + /// is necessary because format elements do not have a canonical label. + /// + ViewModelBase CreateFormatElementViewModel(string name, FormatElementBase element) + { + FormatElementViewModel vm = new FormatElementViewModel(element); + vm.DisplayString = name; + return vm; + } + + #endregion + + #region Implementation ov ViewModelBase + + public override object RevealModelObject() + { + throw new NotImplementedException(); + } + + #endregion + + #region Fields + + SettingsViewModel _caller; + + #endregion + } +} diff --git a/zaaReloaded2/ViewModels/SettingsViewModel.cs b/zaaReloaded2/ViewModels/SettingsViewModel.cs index b573097..c662f1b 100755 --- a/zaaReloaded2/ViewModels/SettingsViewModel.cs +++ b/zaaReloaded2/ViewModels/SettingsViewModel.cs @@ -22,6 +22,7 @@ using System.Linq; using System.Text; using Bovender.Mvvm; using Bovender.Mvvm.ViewModels; +using Bovender.Mvvm.Messaging; using zaaReloaded2.Controller; using zaaReloaded2.Controller.Elements; using zaaReloaded2.Formatter; @@ -161,6 +162,20 @@ namespace zaaReloaded2.ViewModels } } + public DelegatingCommand AddChildElementCommand + { + get + { + if (_addChildElementCommand == null) + { + _addChildElementCommand = new DelegatingCommand( + param => DoAddChildElement(), + param => CanAddChildElement()); + } + return _addChildElementCommand; + } + } + public DelegatingCommand DeleteElementCommand { get @@ -191,10 +206,31 @@ namespace zaaReloaded2.ViewModels #endregion + #region Public methods + + /// + /// Wires the OnProperty changed event of an ElementViewModel's + /// wrapped model and adds the view model to the Elements collection. + /// + public void AddElementViewModel(ElementViewModel elementViewModel) + { + elementViewModel.PropertyChanged += ElementViewModel_PropertyChanged; + Elements.Add(elementViewModel); + } + + #endregion + #region Private methods void DoAddElement() { } + void DoAddChildElement() { } + + bool CanAddChildElement() + { + return SelectedElement is ControlElementViewModel; + } + void DoDeleteElement() { } bool CanDeleteElement() { return _selectedElement != null; } @@ -203,17 +239,6 @@ namespace zaaReloaded2.ViewModels bool CanCopyElement() { return _selectedElement != null; } - /// - /// Internal function that creates wires the OnProperty changed event - /// of an ElementViewModel's wrapped model and adds the view model - /// to the Elements collection. - /// - void AddElementViewModel(ElementViewModel elementViewModel) - { - elementViewModel.PropertyChanged += ElementViewModel_PropertyChanged; - Elements.Add(elementViewModel); - } - /// /// Sets or unsets the SelectedElement property whenever the IsSelected /// property of an ElementViewModel changes. @@ -251,8 +276,10 @@ namespace zaaReloaded2.ViewModels Settings _settings; DelegatingCommand _addElementCommand; + DelegatingCommand _addChildElementCommand; DelegatingCommand _deleteElementCommand; DelegatingCommand _copyElementCommand; + List _elements; ElementViewModel _selectedElement; EnumProvider _referenceStyle; diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj index 07a446a..d595215 100755 --- a/zaaReloaded2/zaaReloaded2.csproj +++ b/zaaReloaded2/zaaReloaded2.csproj @@ -219,6 +219,8 @@ + +