From a43bfd1d86d109b71b3dce38569e6779cc4bece3 Mon Sep 17 00:00:00 2001
From: "harald.martini@student.tugraz.at" <harald.martini@student.tugraz.at>
Date: Fri, 2 Jul 2021 08:32:44 +0200
Subject: [PATCH] Added CanBeSimulated Property to IDocumentViewModel

Closing Popup when Button is clicked in JobListView
---
 .../PopUpHorizontalAlignmentBehavior.cs       | 31 +++++++++----------
 VECTO3GUI2020/Resources/Converter.xaml        |  6 ++--
 .../Implementation/CreateVifViewModel.cs      |  6 ++++
 .../Document/DeclarationJobViewModel.cs       |  5 +++
 .../DeclarationTrailerJobDocumentViewModel.cs |  6 ++++
 .../Document/SimulationOnlyDeclarationJob.cs  |  9 +++++-
 .../Implementation/JobListViewModel.cs        |  5 ++-
 .../Interfaces/Document/IDocumentViewModel.cs |  2 ++
 .../MultistageJobViewModel_v0_1.cs            |  9 ++++++
 .../Implementation/StageInputViewModel.cs     |  6 ++++
 VECTO3GUI2020/Views/JoblistView.xaml          |  6 +---
 VECTO3GUI2020/Views/JoblistView.xaml.cs       | 15 +++++++++
 .../ViewModelTests/JobListViewModelTests.cs   | 11 ++++++-
 13 files changed, 90 insertions(+), 27 deletions(-)

diff --git a/VECTO3GUI2020/Behaviours/PopUpHorizontalAlignmentBehavior.cs b/VECTO3GUI2020/Behaviours/PopUpHorizontalAlignmentBehavior.cs
index c24414e79c..16d62fcbc8 100644
--- a/VECTO3GUI2020/Behaviours/PopUpHorizontalAlignmentBehavior.cs
+++ b/VECTO3GUI2020/Behaviours/PopUpHorizontalAlignmentBehavior.cs
@@ -12,12 +12,6 @@ namespace VECTO3GUI2020.Behaviours
 		private double _popUpWidth;
 
 
-		private void _placementTarget_SizeChanged(object sender, SizeChangedEventArgs e)
-		{
-			if (e.WidthChanged) {
-				SetHorizontalAlignment(e.NewSize.Width, this.AssociatedObject.ActualWidth);
-			}
-		}
 
 		private void SetHorizontalAlignment(double placeMentTargetActualWidth, double popUpActualWidth)
 		{
@@ -25,6 +19,17 @@ namespace VECTO3GUI2020.Behaviours
 				this.AssociatedObject.HorizontalOffset = placeMentTargetActualWidth - popUpActualWidth;
 			}
 		}
+		private void AssociatedObject_Opened(object sender, System.EventArgs e)
+		{
+
+			var popUpWidth = this.AssociatedObject.ActualWidth;
+			if (this.AssociatedObject.ActualWidth == 0 && this.AssociatedObject.IsMeasureValid) {
+				popUpWidth = this.AssociatedObject.DesiredSize.Width;
+			}
+
+			//SetHorizontalAlignment(_placementTarget.ActualWidth, this.AssociatedObject.ActualWidth != 0 ? : this.AssociatedObject.ActualWidth);
+		}
+
 
 		#region Overrides of Behavior
 
@@ -33,22 +38,14 @@ namespace VECTO3GUI2020.Behaviours
 		{
 			_placementTarget = this.AssociatedObject.PlacementTarget as FrameworkElement;
 			_popUpWidth = this.AssociatedObject.MinWidth;
-			_initialHorizontalOffset = this.AssociatedObject.HorizontalOffset;
-            _placementTarget.SizeChanged += _placementTarget_SizeChanged;
-            this.AssociatedObject.SizeChanged += AssociatedObject_SizeChanged;
-			SetHorizontalAlignment(_placementTarget.ActualWidth, this.AssociatedObject.ActualWidth);
+            this.AssociatedObject.Opened += AssociatedObject_Opened;
 			base.OnAttached();
 		}
 
-        private void AssociatedObject_SizeChanged(object sender, SizeChangedEventArgs e)
-		{
-			_popUpWidth = e.NewSize.Width;
-            SetHorizontalAlignment(_placementTarget.ActualWidth, e.NewSize.Width);
-        }
 
-        protected override void OnDetaching()
+
+		protected override void OnDetaching()
 		{
-			_placementTarget.SizeChanged -= _placementTarget_SizeChanged;
 			this.AssociatedObject.HorizontalOffset = _initialHorizontalOffset;
 			base.OnDetaching();
 		}
diff --git a/VECTO3GUI2020/Resources/Converter.xaml b/VECTO3GUI2020/Resources/Converter.xaml
index ee924cdf0b..fcffe93fcd 100644
--- a/VECTO3GUI2020/Resources/Converter.xaml
+++ b/VECTO3GUI2020/Resources/Converter.xaml
@@ -1,7 +1,7 @@
 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-                    xmlns:converter="clr-namespace:VECTO3GUI2020.Helper.Converter"
-                    xmlns:helper="clr-namespace:VECTO3GUI2020.Helper">
+                    xmlns:converter="clr-namespace:VECTO3GUI2020.Helper.Converter">
+
     <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
 
     <converter:SIToUnitString x:Shared="False" x:Key="SIToUnitStringConverter"/>
@@ -19,6 +19,8 @@
     <converter:BoolToIntConverter x:Key="BoolToIntConverter"></converter:BoolToIntConverter>
 
 
+    
+
 
 </ResourceDictionary>
 
diff --git a/VECTO3GUI2020/ViewModel/Implementation/CreateVifViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/CreateVifViewModel.cs
index c2977f2112..13fa7f41f9 100644
--- a/VECTO3GUI2020/ViewModel/Implementation/CreateVifViewModel.cs
+++ b/VECTO3GUI2020/ViewModel/Implementation/CreateVifViewModel.cs
@@ -99,6 +99,12 @@ namespace VECTO3GUI2020.ViewModel.Implementation
 			set => throw new NotImplementedException();
 		}
 
+		public bool CanBeSimulated
+		{
+			get => throw new NotImplementedException();
+			set => throw new NotImplementedException();
+		}
+
 		#endregion
 
 		#region Implementation of IEditViewModel
diff --git a/VECTO3GUI2020/ViewModel/Implementation/Document/DeclarationJobViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/Document/DeclarationJobViewModel.cs
index 578aaf2543..73c78aa2a2 100644
--- a/VECTO3GUI2020/ViewModel/Implementation/Document/DeclarationJobViewModel.cs
+++ b/VECTO3GUI2020/ViewModel/Implementation/Document/DeclarationJobViewModel.cs
@@ -32,6 +32,11 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Document
 			set => SetProperty(ref _selected, value);
 		}
 
+		public bool CanBeSimulated
+		{
+			get => throw new System.NotImplementedException();
+			set => throw new System.NotImplementedException();
+		}
 
 		#endregion
         #region Members
diff --git a/VECTO3GUI2020/ViewModel/Implementation/Document/DeclarationTrailerJobDocumentViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/Document/DeclarationTrailerJobDocumentViewModel.cs
index 435206562a..e683225046 100644
--- a/VECTO3GUI2020/ViewModel/Implementation/Document/DeclarationTrailerJobDocumentViewModel.cs
+++ b/VECTO3GUI2020/ViewModel/Implementation/Document/DeclarationTrailerJobDocumentViewModel.cs
@@ -26,6 +26,12 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Document
 			set => throw new System.NotImplementedException();
 		}
 
+		public bool CanBeSimulated
+		{
+			get => throw new System.NotImplementedException();
+			set => throw new System.NotImplementedException();
+		}
+
 		IEditViewModel IDocumentViewModel.EditViewModel => throw new System.NotImplementedException();
 
         private IXMLInputDataReader _xMLInputDataReader;
diff --git a/VECTO3GUI2020/ViewModel/Implementation/Document/SimulationOnlyDeclarationJob.cs b/VECTO3GUI2020/ViewModel/Implementation/Document/SimulationOnlyDeclarationJob.cs
index b43ba9ae6f..f41a42d55b 100644
--- a/VECTO3GUI2020/ViewModel/Implementation/Document/SimulationOnlyDeclarationJob.cs
+++ b/VECTO3GUI2020/ViewModel/Implementation/Document/SimulationOnlyDeclarationJob.cs
@@ -1,4 +1,5 @@
-using System.Configuration;
+using System;
+using System.Configuration;
 using TUGraz.VectoCommon.InputData;
 using TUGraz.VectoCore.Utils;
 using VECTO3GUI2020.ViewModel.Implementation.Common;
@@ -42,6 +43,12 @@ namespace VECTO3GUI2020.ViewModel.Implementation.Document
 			set => SetProperty(ref _selected, value);
 		}
 
+		public bool CanBeSimulated
+		{
+			get => true;
+			set => throw new NotImplementedException();
+		}
+
 		#endregion
 
 		public SimulationOnlyDeclarationJob(DataSource dataSource, string name, XmlDocumentType documentType)
diff --git a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs
index 678aaf6759..dcb1fc98c0 100644
--- a/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs
+++ b/VECTO3GUI2020/ViewModel/Implementation/JobListViewModel.cs
@@ -621,7 +621,10 @@ namespace VECTO3GUI2020.ViewModel.Implementation
 		{
 			get => _openNewFilePopUpCommand ??
 					(_openNewFilePopUpCommand = new RelayCommand(() => {
-						NewFilePopUpIsOpen = true;
+						if (NewFilePopUpIsOpen == false) {
+							NewFilePopUpIsOpen = true;
+						}
+						
 					}));
 		}
 
diff --git a/VECTO3GUI2020/ViewModel/Interfaces/Document/IDocumentViewModel.cs b/VECTO3GUI2020/ViewModel/Interfaces/Document/IDocumentViewModel.cs
index 0216c11ef6..2824842b4e 100644
--- a/VECTO3GUI2020/ViewModel/Interfaces/Document/IDocumentViewModel.cs
+++ b/VECTO3GUI2020/ViewModel/Interfaces/Document/IDocumentViewModel.cs
@@ -11,5 +11,7 @@ namespace VECTO3GUI2020.ViewModel.Interfaces.Document
 		DataSource DataSource { get; }
 		IEditViewModel EditViewModel { get; }
 		bool Selected { get; set; }
+
+        bool CanBeSimulated { get; set; }
 	}
 }
diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs
index 9d5226e402..ba3b4bce84 100644
--- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs
+++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/MultistageJobViewModel_v0_1.cs
@@ -273,6 +273,15 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
 			set => SetProperty(ref _selected, value);
 		}
 
+		public bool CanBeSimulated
+		{
+			get
+			{
+				throw new NotImplementedException();
+			}
+			set => throw new NotImplementedException();
+		}
+
 		#endregion
 
 		#region Implementation of IMultistageVIFInputData
diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs
index 51f2ff8f33..098b23d75d 100644
--- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs
+++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageInputViewModel.cs
@@ -73,6 +73,12 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation
 			set => SetProperty(ref _selected, value);
 		}
 
+		public bool CanBeSimulated
+		{
+			get => false;
+			set => throw new System.NotImplementedException();
+		}
+
 		#endregion
 
 		#region Implementation of IEditViewModel
diff --git a/VECTO3GUI2020/Views/JoblistView.xaml b/VECTO3GUI2020/Views/JoblistView.xaml
index 6da05e9e0f..a43520f222 100644
--- a/VECTO3GUI2020/Views/JoblistView.xaml
+++ b/VECTO3GUI2020/Views/JoblistView.xaml
@@ -120,11 +120,7 @@
                                Margin="{Binding ElementName=newFileButton, Path=Margin}" 
                                MinWidth="{Binding ElementName=newFileButton, Path=ActualWidth}" 
                                IsOpen="{Binding NewFilePopUpIsOpen, Mode=TwoWay}" 
-                               StaysOpen="False">
-                     
-                            <!--<i:Interaction.Behaviors>
-                                <behavior:PopUpHorizontalAlignmentBehavior/>
-                            </i:Interaction.Behaviors>-->
+                               StaysOpen="False" PreviewMouseLeftButtonUp="NewFilePopup_OnPreviewMouseLeftButtonDown">
                             <Border BorderThickness="1px" BorderBrush="{StaticResource AccentColorButton}">
                                 <StackPanel Background="White">
                                     <Button Style="{StaticResource MultiStageButtonStyle1}" Command="{Binding NewManufacturingStageFileCommand}">New Manufacturing Stage</Button>
diff --git a/VECTO3GUI2020/Views/JoblistView.xaml.cs b/VECTO3GUI2020/Views/JoblistView.xaml.cs
index 99cca39297..9139145be8 100644
--- a/VECTO3GUI2020/Views/JoblistView.xaml.cs
+++ b/VECTO3GUI2020/Views/JoblistView.xaml.cs
@@ -53,5 +53,20 @@ namespace VECTO3GUI2020.Views
 		{
 				CommandManager.InvalidateRequerySuggested();
 		}
+
+		private void NewFilePopup_OnMouseLeave(object sender, MouseEventArgs e)
+		{
+			
+		}
+
+		private void NewFilePopup_OnMouseDown(object sender, MouseButtonEventArgs e)
+		{
+			newFilePopup.IsOpen = false;
+		}
+
+		private void NewFilePopup_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+		{
+			newFilePopup.IsOpen = false;
+		}
 	}
 }
diff --git a/Vecto3GUI2020Test/ViewModelTests/JobListViewModelTests.cs b/Vecto3GUI2020Test/ViewModelTests/JobListViewModelTests.cs
index ac682750c3..7c9a142101 100644
--- a/Vecto3GUI2020Test/ViewModelTests/JobListViewModelTests.cs
+++ b/Vecto3GUI2020Test/ViewModelTests/JobListViewModelTests.cs
@@ -16,7 +16,16 @@ namespace Vecto3GUI2020Test.ViewModelTests
 	{
 		private string finalVIF = "final.VIF_Report_4.xml";
 
-		
+
+		[Test]
+		public async Task LoadPrimaryFile()
+		{
+			var jobListViewModel = _kernel.Get<IJobListViewModel>() as JobListViewModel;
+			Write("Trying to load {}");
+
+
+		}
+
 
 		[Test]
 		public async Task CancelSimulationWhileLoadingFiles()
-- 
GitLab