323 lines
12 KiB
C#
323 lines
12 KiB
C#
|
|
using System.Collections.ObjectModel;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Windows.Controls;
|
|||
|
|
using System.Windows.Input;
|
|||
|
|
using System.Windows;
|
|||
|
|
using DTS.Common.Base;
|
|||
|
|
using DTS.Common.Interface;
|
|||
|
|
using System.Windows.Media;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System;
|
|||
|
|
|
|||
|
|
// ReSharper disable RedundantDefaultMemberInitializer
|
|||
|
|
// ReSharper disable UnassignedGetOnlyAutoProperty
|
|||
|
|
|
|||
|
|
// ReSharper disable CheckNamespace
|
|||
|
|
|
|||
|
|
namespace DTS.Viewer.GraphList
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Main class to bind to treeview
|
|||
|
|
/// </summary>
|
|||
|
|
public class TreeViewIds : IBaseModel
|
|||
|
|
{
|
|||
|
|
private IBaseViewModel _parent;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Parent ViewModel
|
|||
|
|
/// </summary>
|
|||
|
|
public IBaseViewModel Parent { get => _parent; set { _parent = value; OnPropertyChanged("Parent"); } }
|
|||
|
|
|
|||
|
|
private string _name = string.Empty;
|
|||
|
|
public string Name { get => _name; set { _name = value; OnPropertyChanged("Name"); } }
|
|||
|
|
|
|||
|
|
private int _treeIndex = 0;
|
|||
|
|
public int TreeIndex { get => _treeIndex; set { _treeIndex = value; OnPropertyChanged("TreeIndex"); } }
|
|||
|
|
|
|||
|
|
private int _eventCount = 0;
|
|||
|
|
public int EventCount { get => _eventCount; set { _eventCount = value; OnPropertyChanged("EventCount"); } }
|
|||
|
|
|
|||
|
|
private ObservableCollection<ITestEvent> _events = new ObservableCollection<ITestEvent>();
|
|||
|
|
public ObservableCollection<ITestEvent> Events { get => _events; set { _events = value; _eventCount = _events.Count; OnPropertyChanged("Events"); } }
|
|||
|
|
|
|||
|
|
private string _path = string.Empty;
|
|||
|
|
public string Path { get => _path; set { _path = value; OnPropertyChanged("Path"); } }
|
|||
|
|
|
|||
|
|
public bool IsSaved { get; }
|
|||
|
|
|
|||
|
|
private bool _isExpanded = true;
|
|||
|
|
public bool IsExpanded { get => _isExpanded; set { _isExpanded = value; OnPropertyChanged("IsExpanded"); } }
|
|||
|
|
|
|||
|
|
private bool _isSelected = false;
|
|||
|
|
public bool IsSelected
|
|||
|
|
{
|
|||
|
|
get => _isSelected;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
if ((IExportGraphMainViewModel)Parent == null) return;
|
|||
|
|
|
|||
|
|
if (((IExportGraphMainViewModel)Parent).SettingChildNodesToTrue && !value)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (!IsShiftPressed)
|
|||
|
|
{
|
|||
|
|
((IExportGraphMainViewModel)Parent).SetLastIndexChecked(TreeIndex);
|
|||
|
|
}
|
|||
|
|
_isSelected = value;
|
|||
|
|
((IExportGraphMainViewModel)Parent).SettingChildNodesToTrue = value;
|
|||
|
|
((IExportGraphMainViewModel)Parent).SettingOrResettingChildNodes = true;
|
|||
|
|
OnPropertyChanged("IsSelected");
|
|||
|
|
|
|||
|
|
SetChildNodes(value);
|
|||
|
|
((IExportGraphMainViewModel)Parent).SettingChildNodesToTrue = false;
|
|||
|
|
((IExportGraphMainViewModel)Parent).SettingOrResettingChildNodes = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void SetChildNodes(bool isSelected)
|
|||
|
|
{
|
|||
|
|
foreach (var node in Events)
|
|||
|
|
{
|
|||
|
|
node.IsSelected = isSelected;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region PropertyChanged
|
|||
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|||
|
|
public void OnPropertyChanged(string propertyName)
|
|||
|
|
{
|
|||
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|||
|
|
}
|
|||
|
|
#endregion PropertyChanged
|
|||
|
|
|
|||
|
|
|
|||
|
|
public static readonly DependencyProperty IsItemSelectedProperty =
|
|||
|
|
DependencyProperty.RegisterAttached("IsItemSelected", typeof(bool), typeof(TreeViewIds));
|
|||
|
|
public static void SetIsItemSelected(UIElement element, bool value)
|
|||
|
|
{
|
|||
|
|
element.SetValue(IsItemSelectedProperty, value);
|
|||
|
|
}
|
|||
|
|
private static bool IsShiftPressed
|
|||
|
|
{
|
|||
|
|
get { return Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift); }
|
|||
|
|
}
|
|||
|
|
private static List<TreeViewItem> GetTreeViewItems(ItemsControl parentItem, bool includeCollapsedItems, List<TreeViewItem> itemList = null)
|
|||
|
|
{
|
|||
|
|
if (itemList == null)
|
|||
|
|
itemList = new List<TreeViewItem>();
|
|||
|
|
|
|||
|
|
for (var index = 0; index < parentItem.Items.Count; index++)
|
|||
|
|
{
|
|||
|
|
var tvItem = parentItem.ItemContainerGenerator.ContainerFromIndex(index) as TreeViewItem;
|
|||
|
|
if (tvItem == null) continue;
|
|||
|
|
|
|||
|
|
itemList.Add(tvItem);
|
|||
|
|
if (includeCollapsedItems || tvItem.IsExpanded)
|
|||
|
|
GetTreeViewItems(tvItem, includeCollapsedItems, itemList);
|
|||
|
|
}
|
|||
|
|
return itemList;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Child class for TreeViewIds
|
|||
|
|
/// </summary>
|
|||
|
|
public class TestEvent : ITestEvent
|
|||
|
|
{
|
|||
|
|
private string _path = string.Empty;
|
|||
|
|
public string Path { get => _path; set { _path = value; OnPropertyChanged("Path"); } }
|
|||
|
|
|
|||
|
|
private IBaseViewModel _parent;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Parent ViewModel
|
|||
|
|
/// </summary>
|
|||
|
|
public IBaseViewModel Parent { get => _parent; set { _parent = value; OnPropertyChanged("Parent"); } }
|
|||
|
|
|
|||
|
|
private bool _isLocked = false;
|
|||
|
|
/// <summary>
|
|||
|
|
/// Locked Graph - call parent function to lock Id's events
|
|||
|
|
/// </summary>
|
|||
|
|
public bool IsLocked
|
|||
|
|
{
|
|||
|
|
get => _isLocked;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_isLocked = value;
|
|||
|
|
var parent = Parent;
|
|||
|
|
if (parent.GetType().GetInterfaces().Contains(typeof(IExportGraphMainViewModel))) { ((IExportGraphMainViewModel)parent).AddLockedEvents(TestName, Name, Events.ToList(), _isLocked); }
|
|||
|
|
OnPropertyChanged("IsLocked");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private bool _isGraph = false;
|
|||
|
|
public bool IsGraph { get => _isGraph; set { _isGraph = value; OnPropertyChanged("IsGraph"); } }
|
|||
|
|
|
|||
|
|
private bool _isExpanded = true;
|
|||
|
|
public bool IsExpanded { get => _isExpanded; set { _isExpanded = value; OnPropertyChanged("IsExpanded"); } }
|
|||
|
|
|
|||
|
|
private bool _canLock = true;
|
|||
|
|
|
|||
|
|
public bool CanLock
|
|||
|
|
{
|
|||
|
|
get => _canLock;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_canLock = value;
|
|||
|
|
OnPropertyChanged("CanLock");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private static bool IsShiftPressed
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return Keyboard.IsKeyDown(Key.LeftShift) ||
|
|||
|
|
Keyboard.IsKeyDown(Key.RightShift);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private static bool IsCtrlPressed
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
return Keyboard.IsKeyDown(Key.LeftCtrl) ||
|
|||
|
|
Keyboard.IsKeyDown(Key.RightCtrl);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private bool _isSelected = false;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Selected Event - call parent function to select Id's event
|
|||
|
|
/// </summary>
|
|||
|
|
public bool IsSelected
|
|||
|
|
{
|
|||
|
|
get => _isSelected;
|
|||
|
|
set => SetIsSelected(value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SetIsSelectedShiftPressed(bool value)
|
|||
|
|
{
|
|||
|
|
if (IsShiftPressed &&
|
|||
|
|
!((IExportGraphMainViewModel)Parent).ResettingAllItems &&
|
|||
|
|
!((IExportGraphMainViewModel)Parent).SettingItemsBetween)
|
|||
|
|
{
|
|||
|
|
((IExportGraphMainViewModel)Parent).ResettingAllItems = true;
|
|||
|
|
((IExportGraphMainViewModel)Parent).ResetAllItems();
|
|||
|
|
((IExportGraphMainViewModel)Parent).ResettingAllItems = false;
|
|||
|
|
}
|
|||
|
|
if (IsShiftPressed &&
|
|||
|
|
!((IExportGraphMainViewModel)Parent).SettingItemsBetween)
|
|||
|
|
{
|
|||
|
|
((IExportGraphMainViewModel)Parent).SettingItemsBetween = true;
|
|||
|
|
((IExportGraphMainViewModel)Parent).SetItemsBetween(((IExportGraphMainViewModel)Parent).LastIndexChecked, TreeIndex);
|
|||
|
|
((IExportGraphMainViewModel)Parent).SettingItemsBetween = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private bool ShouldExitSetIsSelected(bool value)
|
|||
|
|
{
|
|||
|
|
if (((IExportGraphMainViewModel)Parent).SettingChildNodesToTrue && !value)
|
|||
|
|
{
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
if (((IExportGraphMainViewModel)Parent).SettingPeerNodeToTrue && !value)
|
|||
|
|
{
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
if (((IExportGraphMainViewModel)Parent).ResettingAllItems && value)
|
|||
|
|
{
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
private void SetIsSelectedShiftNotPressed(bool value)
|
|||
|
|
{
|
|||
|
|
if (!IsShiftPressed &&
|
|||
|
|
!IsCtrlPressed &&
|
|||
|
|
!((IExportGraphMainViewModel)Parent).ResettingAllItems &&
|
|||
|
|
!((IExportGraphMainViewModel)Parent).SettingOrResettingChildNodes)
|
|||
|
|
{
|
|||
|
|
((IExportGraphMainViewModel)Parent).SettingPeerNodeToTrue = false;
|
|||
|
|
|
|||
|
|
((IExportGraphMainViewModel)Parent).ResettingAllItems = true;
|
|||
|
|
((IExportGraphMainViewModel)Parent).ResetAllItems();
|
|||
|
|
((IExportGraphMainViewModel)Parent).ResettingAllItems = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private void SetIsSelected(bool value)
|
|||
|
|
{
|
|||
|
|
if (ShouldExitSetIsSelected(value)) { return; }
|
|||
|
|
((IExportGraphMainViewModel)Parent).SettingPeerNodeToTrue = value;
|
|||
|
|
|
|||
|
|
if (IsShiftPressed) { SetIsSelectedShiftPressed(value); }
|
|||
|
|
|
|||
|
|
if (!IsShiftPressed && !((IExportGraphMainViewModel)Parent).SettingOrResettingChildNodes)
|
|||
|
|
{
|
|||
|
|
((IExportGraphMainViewModel)Parent).SetLastIndexChecked(TreeIndex);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!IsShiftPressed) { SetIsSelectedShiftNotPressed(value); }
|
|||
|
|
|
|||
|
|
if (!IsShiftPressed ||
|
|||
|
|
(IsShiftPressed && ((IExportGraphMainViewModel)Parent).SettingItemsBetween) ||
|
|||
|
|
(IsShiftPressed && ((IExportGraphMainViewModel)Parent).ResettingAllItems))
|
|||
|
|
{
|
|||
|
|
var prevValue = _isSelected;
|
|||
|
|
_isSelected = value;
|
|||
|
|
|
|||
|
|
var myself = new List<ITestEvent>
|
|||
|
|
{
|
|||
|
|
this
|
|||
|
|
};
|
|||
|
|
if (IsSelected != prevValue)
|
|||
|
|
{
|
|||
|
|
if (IsSelected)
|
|||
|
|
{
|
|||
|
|
((IExportGraphMainViewModel)Parent).AddToSelectedEvents(Name, myself);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
((IExportGraphMainViewModel)Parent).RemoveFromSelectedEvents(Name, myself);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
OnPropertyChanged("IsSelected");
|
|||
|
|
}
|
|||
|
|
((IExportGraphMainViewModel)Parent).SettingPeerNodeToTrue = false;
|
|||
|
|
}
|
|||
|
|
private string _testName = string.Empty;
|
|||
|
|
public string TestName { get => _testName; set { _testName = value; OnPropertyChanged("TestName"); } }
|
|||
|
|
|
|||
|
|
private string _name = string.Empty;
|
|||
|
|
public string Name { get => _name; set { _name = value; OnPropertyChanged("Name"); } }
|
|||
|
|
|
|||
|
|
private string _testSetupName = string.Empty;
|
|||
|
|
public string TestSetupName { get => _testSetupName; set { _testSetupName = value; OnPropertyChanged("TestSetupName"); } }
|
|||
|
|
|
|||
|
|
private string _testItem = string.Empty;
|
|||
|
|
public string TestItem { get => _testItem; set { _testItem = value; OnPropertyChanged("TestItem"); } }
|
|||
|
|
|
|||
|
|
private string _dtsFile = string.Empty;
|
|||
|
|
public string DTSFile { get => _dtsFile; set { _dtsFile = value; OnPropertyChanged("DTSFile"); } }
|
|||
|
|
|
|||
|
|
private string _dataType = string.Empty;
|
|||
|
|
public string DataType { get => _dataType; set { _dataType = value; OnPropertyChanged("DataType"); } }
|
|||
|
|
|
|||
|
|
private int _eventCount = 0;
|
|||
|
|
|
|||
|
|
private ObservableCollection<ITestEvent> _events = new ObservableCollection<ITestEvent>();
|
|||
|
|
public ObservableCollection<ITestEvent> Events { get => _events; set { _events = value; _eventCount = _events.Count; OnPropertyChanged("Events"); } }
|
|||
|
|
|
|||
|
|
|
|||
|
|
private string _testId = string.Empty;
|
|||
|
|
public string TestId { get => _testId; set { _testId = value; OnPropertyChanged("TestId"); } }
|
|||
|
|
|
|||
|
|
private int _treeIndex = 0;
|
|||
|
|
public int TreeIndex { get => _treeIndex; set { _treeIndex = value; OnPropertyChanged("TreeIndex"); } }
|
|||
|
|
|
|||
|
|
#region PropertyChanged
|
|||
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|||
|
|
protected virtual void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }
|
|||
|
|
#endregion PropertyChanged
|
|||
|
|
}
|
|||
|
|
}
|