Create rudimentary view models, default settings.
This commit is contained in:
50
zaaReloaded2/ViewModels/ControlElementViewModel.cs
Executable file
50
zaaReloaded2/ViewModels/ControlElementViewModel.cs
Executable file
@ -0,0 +1,50 @@
|
||||
/* ElementViewModelBase.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;
|
||||
using zaaReloaded2.Controller.Elements;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace zaaReloaded2.ViewModels
|
||||
{
|
||||
class ControlElementViewModel : ElementViewModel
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public ObservableCollection<ElementViewModel> Elements
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ControlElementViewModel() : base() { }
|
||||
|
||||
public ControlElementViewModel(ControlElementBase controlElement)
|
||||
: base(controlElement)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
73
zaaReloaded2/ViewModels/ElementViewModel.cs
Executable file
73
zaaReloaded2/ViewModels/ElementViewModel.cs
Executable file
@ -0,0 +1,73 @@
|
||||
/* ElementViewModel.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.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Bovender.Mvvm.ViewModels;
|
||||
using zaaReloaded2.Controller.Elements;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace zaaReloaded2.ViewModels
|
||||
{
|
||||
abstract class ElementViewModel : ViewModelBase
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets the label of the wrapped element.
|
||||
/// </summary>
|
||||
public virtual string Label
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
get
|
||||
{
|
||||
return Element.Label;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ElementViewModel() { }
|
||||
|
||||
public ElementViewModel(ElementBase element)
|
||||
{
|
||||
Element = element;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected properties
|
||||
|
||||
protected ElementBase Element { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of ViewModelBase
|
||||
|
||||
public override object RevealModelObject()
|
||||
{
|
||||
return Element;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
56
zaaReloaded2/ViewModels/FormatElementViewModel.cs
Executable file
56
zaaReloaded2/ViewModels/FormatElementViewModel.cs
Executable file
@ -0,0 +1,56 @@
|
||||
/* FormatElementViewModel.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.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using zaaReloaded2.Controller.Elements;
|
||||
|
||||
namespace zaaReloaded2.ViewModels
|
||||
{
|
||||
class FormatElementViewModel : ElementViewModel
|
||||
{
|
||||
#region Public properties
|
||||
|
||||
public string Content
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
get { return ((FormatElementBase)Element).Content; }
|
||||
set
|
||||
{
|
||||
((FormatElementBase)Element).Content = value;
|
||||
OnPropertyChanged("Content");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public FormatElementViewModel() : base() { }
|
||||
|
||||
public FormatElementViewModel(FormatElementBase formatElement)
|
||||
: this()
|
||||
{
|
||||
Element = formatElement;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
253
zaaReloaded2/ViewModels/SettingsViewModel.cs
Executable file
253
zaaReloaded2/ViewModels/SettingsViewModel.cs
Executable file
@ -0,0 +1,253 @@
|
||||
/* SettingsViewModel.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.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Bovender.Mvvm;
|
||||
using Bovender.Mvvm.ViewModels;
|
||||
using zaaReloaded2.Controller;
|
||||
using zaaReloaded2.Controller.Elements;
|
||||
using zaaReloaded2.Formatter;
|
||||
|
||||
namespace zaaReloaded2.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// View model for the zaaReloaded2.Controller.Settings class.
|
||||
/// </summary>
|
||||
class SettingsViewModel : ViewModelBase
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the Settings
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
get
|
||||
{
|
||||
return _settings.Name;
|
||||
}
|
||||
[DebuggerStepThrough]
|
||||
set
|
||||
{
|
||||
_settings.Name = value;
|
||||
OnPropertyChanged("Name");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is true if the settings' name is editable.
|
||||
/// If the settings' name is a default, preconfigured name,
|
||||
/// this will be false.
|
||||
/// </summary>
|
||||
public bool IsNameEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Name != Properties.Settings.Default.SettingsNameClinic) &&
|
||||
(Name != Properties.Settings.Default.SettingsNameWard);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of element view models.
|
||||
/// </summary>
|
||||
public IList<ElementViewModel> Elements
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_elements == null) { _elements = new List<ElementViewModel>(); }
|
||||
return _elements;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the currently selected element.
|
||||
/// </summary>
|
||||
public ElementViewModel SelectedElement
|
||||
{
|
||||
get { return _selectedElement; }
|
||||
set
|
||||
{
|
||||
_selectedElement = value;
|
||||
OnPropertyChanged("SelectedElement");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an EnumProvider object for the ReferenceStyle
|
||||
/// </summary>
|
||||
public EnumProvider<ReferenceStyle> ReferenceStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_referenceStyle == null)
|
||||
{
|
||||
_referenceStyle = new EnumProvider<ReferenceStyle>(_settings.ReferenceStyle);
|
||||
}
|
||||
return _referenceStyle;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public SettingsViewModel()
|
||||
: this(new Settings())
|
||||
{ }
|
||||
|
||||
public SettingsViewModel(Settings settings)
|
||||
: base()
|
||||
{
|
||||
_settings = settings;
|
||||
_elements = new List<ElementViewModel>();
|
||||
foreach (ElementBase element in settings.Elements)
|
||||
{
|
||||
ElementViewModel vm;
|
||||
if (element is FormatElementBase)
|
||||
{
|
||||
vm = new FormatElementViewModel(element as FormatElementBase);
|
||||
}
|
||||
else if (element is ControlElementBase)
|
||||
{
|
||||
vm = new ControlElementViewModel(element as ControlElementBase);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot create ViewModel for " + element.GetType().ToString());
|
||||
}
|
||||
AddElementViewModel(vm);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Messages
|
||||
|
||||
#endregion
|
||||
|
||||
#region Commands
|
||||
|
||||
public DelegatingCommand AddElementCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_addElementCommand == null)
|
||||
{
|
||||
_addElementCommand = new DelegatingCommand(
|
||||
param => DoAddElement());
|
||||
}
|
||||
return _addElementCommand;
|
||||
}
|
||||
}
|
||||
|
||||
public DelegatingCommand DeleteElementCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_deleteElementCommand == null)
|
||||
{
|
||||
_deleteElementCommand = new DelegatingCommand(
|
||||
param => DoDeleteElement(),
|
||||
param => CanDeleteElement());
|
||||
}
|
||||
return _deleteElementCommand;
|
||||
}
|
||||
}
|
||||
|
||||
public DelegatingCommand CopyElementCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_copyElementCommand == null)
|
||||
{
|
||||
_copyElementCommand = new DelegatingCommand(
|
||||
param => DoCopyElement(),
|
||||
param => CanCopyElement());
|
||||
}
|
||||
return _copyElementCommand;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
void DoAddElement() { }
|
||||
|
||||
void DoDeleteElement() { }
|
||||
|
||||
bool CanDeleteElement() { return _selectedElement != null; }
|
||||
|
||||
void DoCopyElement() { }
|
||||
|
||||
bool CanCopyElement() { return _selectedElement != null; }
|
||||
|
||||
/// <summary>
|
||||
/// Internal function that creates wires the OnProperty changed event
|
||||
/// of an ElementViewModel's wrapped model and adds the view model
|
||||
/// to the Elements collection.
|
||||
/// </summary>
|
||||
void AddElementViewModel(ElementViewModel elementViewModel)
|
||||
{
|
||||
elementViewModel.PropertyChanged += ElementViewModel_PropertyChanged;
|
||||
Elements.Add(elementViewModel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets or unsets the SelectedElement property whenever the IsSelected
|
||||
/// property of an ElementViewModel changes.
|
||||
/// </summary>
|
||||
void ElementViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
ElementViewModel vm = sender as ElementViewModel;
|
||||
if (vm != null)
|
||||
{
|
||||
SelectedElement = vm.IsSelected ? vm : null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of ViewModelBase
|
||||
|
||||
public override object RevealModelObject()
|
||||
{
|
||||
return _settings;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
Settings _settings;
|
||||
DelegatingCommand _addElementCommand;
|
||||
DelegatingCommand _deleteElementCommand;
|
||||
DelegatingCommand _copyElementCommand;
|
||||
List<ElementViewModel> _elements;
|
||||
ElementViewModel _selectedElement;
|
||||
EnumProvider<ReferenceStyle> _referenceStyle;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user