diff --git a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionGroup.cs b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionGroup.cs
index aa92c2476..c4529322f 100644
--- a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionGroup.cs
+++ b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionGroup.cs
@@ -35,7 +35,7 @@ namespace Artemis.Core.Models.Profile.Conditions
public override void ApplyToEntity()
{
DisplayConditionGroupEntity.Id = EntityId;
- DisplayConditionGroupEntity.ParentId = Parent?.EntityId ?? new Guid();
+ DisplayConditionGroupEntity.ParentId = Parent?.EntityId ?? Guid.Empty;
DisplayConditionGroupEntity.BooleanOperator = (int) BooleanOperator;
foreach (var child in Children)
diff --git a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionListPredicate.cs b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionListPredicate.cs
index 38e8e4705..40d379ef6 100644
--- a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionListPredicate.cs
+++ b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionListPredicate.cs
@@ -6,6 +6,10 @@ namespace Artemis.Core.Models.Profile.Conditions
{
public ListOperator ListOperator { get; set; }
+ public override void ApplyToEntity()
+ {
+
+ }
}
public enum ListOperator
diff --git a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionPredicate.cs b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionPredicate.cs
index 8dca8a826..458ffb4ee 100644
--- a/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionPredicate.cs
+++ b/src/Artemis.Core/Models/Profile/Conditions/DisplayConditionPredicate.cs
@@ -11,9 +11,10 @@ namespace Artemis.Core.Models.Profile.Conditions
{
public class DisplayConditionPredicate : DisplayConditionPart
{
- public DisplayConditionPredicate(DisplayConditionPart parent)
+ public DisplayConditionPredicate(DisplayConditionPart parent, PredicateType predicateType)
{
Parent = parent;
+ PredicateType = predicateType;
DisplayConditionPredicateEntity = new DisplayConditionPredicateEntity();
}
@@ -30,7 +31,7 @@ namespace Artemis.Core.Models.Profile.Conditions
public DisplayConditionPredicateEntity DisplayConditionPredicateEntity { get; set; }
public PredicateType PredicateType { get; set; }
- public DisplayConditionOperator Operator { get; set; }
+ public DisplayConditionOperator Operator { get; private set; }
public DataModel LeftDataModel { get; private set; }
public string LeftPropertyPath { get; private set; }
@@ -45,20 +46,37 @@ namespace Artemis.Core.Models.Profile.Conditions
public void UpdateLeftSide(DataModel dataModel, string path)
{
- if (!dataModel.ContainsPath(path))
- throw new ArtemisCoreException($"Data model of type {dataModel.GetType().Name} does not contain a property at path '{path}'");
+ if (dataModel != null && path == null)
+ throw new ArtemisCoreException("If a data model is provided, a path is also required");
+ if (dataModel == null && path != null)
+ throw new ArtemisCoreException("If path is provided, a data model is also required");
+
+ if (dataModel != null)
+ {
+ if (!dataModel.ContainsPath(path))
+ throw new ArtemisCoreException($"Data model of type {dataModel.GetType().Name} does not contain a property at path '{path}'");
+ }
LeftDataModel = dataModel;
LeftPropertyPath = path;
+ ValidateOperator();
ValidateRightSide();
CreateExpression();
}
public void UpdateRightSide(DataModel dataModel, string path)
{
- if (!dataModel.ContainsPath(path))
- throw new ArtemisCoreException($"Data model of type {dataModel.GetType().Name} does not contain a property at path '{path}'");
+ if (dataModel != null && path == null)
+ throw new ArtemisCoreException("If a data model is provided, a path is also required");
+ if (dataModel == null && path != null)
+ throw new ArtemisCoreException("If path is provided, a data model is also required");
+
+ if (dataModel != null)
+ {
+ if (!dataModel.ContainsPath(path))
+ throw new ArtemisCoreException($"Data model of type {dataModel.GetType().Name} does not contain a property at path '{path}'");
+ }
PredicateType = PredicateType.Dynamic;
RightDataModel = dataModel;
@@ -77,6 +95,25 @@ namespace Artemis.Core.Models.Profile.Conditions
CreateExpression();
}
+ public void UpdateOperator(DisplayConditionOperator displayConditionOperator)
+ {
+ if (displayConditionOperator == null)
+ {
+ Operator = null;
+ return;
+ }
+
+ if (LeftDataModel == null)
+ {
+ Operator = displayConditionOperator;
+ return;
+ }
+
+ var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
+ if (displayConditionOperator.SupportsType(leftType))
+ Operator = displayConditionOperator;
+ }
+
public void CreateExpression()
{
if (PredicateType == PredicateType.Dynamic)
@@ -89,6 +126,17 @@ namespace Artemis.Core.Models.Profile.Conditions
{
}
+ private void ValidateOperator()
+ {
+ if (LeftDataModel == null)
+ return;
+
+ var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
+ if (!Operator.SupportsType(leftType))
+ Operator = null;
+ }
+
+
///
/// Validates the right side, ensuring it is still compatible with the current left side
///
@@ -97,14 +145,19 @@ namespace Artemis.Core.Models.Profile.Conditions
var leftSideType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
if (PredicateType == PredicateType.Dynamic)
{
+ if (RightDataModel == null)
+ return;
+
var rightSideType = RightDataModel.GetTypeAtPath(RightPropertyPath);
if (!leftSideType.IsCastableFrom(rightSideType))
UpdateRightSide(null, null);
}
else
{
- // Just update the value with itself, it'll validate :)
- UpdateRightSide(RightStaticValue);
+ if (RightStaticValue != null && leftSideType.IsCastableFrom(RightStaticValue.GetType()))
+ UpdateRightSide(RightStaticValue);
+ else
+ UpdateRightSide(null);
}
}
diff --git a/src/Artemis.UI.Shared/DataModelVisualization/DataModelInputViewModel.cs b/src/Artemis.UI.Shared/DataModelVisualization/DataModelInputViewModel.cs
index 24931edc3..cb1bbcb00 100644
--- a/src/Artemis.UI.Shared/DataModelVisualization/DataModelInputViewModel.cs
+++ b/src/Artemis.UI.Shared/DataModelVisualization/DataModelInputViewModel.cs
@@ -1,18 +1,17 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
-using Artemis.UI.Shared.Exceptions;
using Stylet;
namespace Artemis.UI.Shared.DataModelVisualization
{
public abstract class DataModelInputViewModel : DataModelInputViewModel
{
+ private bool _closed;
private T _inputValue;
protected DataModelInputViewModel(DataModelPropertyAttribute description, T initialValue)
@@ -33,6 +32,10 @@ namespace Artemis.UI.Shared.DataModelVisualization
///
public sealed override void Submit()
{
+ if (_closed)
+ return;
+ _closed = true;
+
foreach (var sourceUpdatingBinding in BindingOperations.GetSourceUpdatingBindings(View))
sourceUpdatingBinding.UpdateSource();
@@ -43,6 +46,10 @@ namespace Artemis.UI.Shared.DataModelVisualization
///
public sealed override void Cancel()
{
+ if (_closed)
+ return;
+ _closed = true;
+
OnCancel();
UpdateCallback(InputValue, false);
}
@@ -62,7 +69,8 @@ namespace Artemis.UI.Shared.DataModelVisualization
internal Action