/// <summary>
        /// Constructor of the class. It sets up the Commands and initiate the <see cref="filterTypeList"/> and <see cref="filterTree"/>.
        /// </summary>
        public MeasurementFilterViewModel()
        {
            ExpandFilterList = new RelayCommand(() => _ExpandFilterList(), () => true);

            NewProjectCommand = new RelayCommand(() => _NewProjectCommand(), () => true);
            RenameProjectCommand = new RelayCommand(() => _RenameProjectCommand(), () => true);
            DeleteProjectCommand = new RelayCommand(() => _DeleteProjectCommand(), () => true);

            AddMeasurementCommand = new RelayCommand(() => _AddMeasurementCommand(), () => true);
            RemoveMeasurementCommand = new RelayCommand(() => _RemoveMeasurementCommand(), () => true);

            filterTypeList = new AsyncObservableCollection<string> { "Date", "Sample", "Channel" };
            filterTree = new TreeViewModel();
            filterTree.Items = new AsyncObservableCollection<FilterClass>();
            selectedFilter = new FilterClass() { Name = "All", Type = "All" };

            SelectedItemChanged = new RelayCommand<TreeViewHelper.DependencyPropertyEventArgs>(TreeViewItemSelectedChangedCallBack);

            Projects = new ObservableCollection<Project>();

            Init();
        }
        /// <summary>
        /// Function that sends an event containing a list of <see cref="Measurement.MeasurementID"/>s generated from the selected filter.
        /// </summary>
        /// <param name="filter">The filter which has been selected in the <see cref="filterTree"/>.</param>
        public void NewFilterSelected(FilterClass filter)
        {
            if (selectedFilter == null) return;

            trace.Value.TraceEvent(TraceEventType.Information, 0, "New selected filter: '" + filter.Name + " (" + filter.Type + ", " + filter.SubType + ")'");

            using (DatabaseDataContext Database = MyGlobals.Database)
            {
                List<int> MeasurementIDList = new List<int>();

                switch (filter.Type)
                {
                    case "All":
                        { MeasurementIDList = Database.Measurements.Select(x => x.MeasurementID).ToList(); break; }

                    case "Date":
                        {
                            switch (filter.SubType)
                            {
                                case "Today":
                                    { MeasurementIDList = Database.Measurements.Where(x => x.StartTime.Date == DateTime.Today).Select(x => x.MeasurementID).ToList(); break; }

                                case "ThisWeek":
                                    {
                                        int DayOfWeek = (int)DateTime.Today.DayOfWeek;
                                        MeasurementIDList = Database.Measurements.Where(x => x.StartTime.DayOfYear > (DateTime.Today.DayOfYear - DayOfWeek) && x.StartTime.DayOfYear < (DateTime.Today.DayOfYear - DayOfWeek + 7)).Select(x => x.MeasurementID).ToList(); //Todo!!!
                                        break;
                                    }

                                case "ThisMonth":
                                    { MeasurementIDList = Database.Measurements.Where(x => x.StartTime.Date.Month == DateTime.Now.Month).Select(x => x.MeasurementID).ToList(); break; }

                                case "ThisYear":
                                    { MeasurementIDList = Database.Measurements.Where(x => x.StartTime.Date.Year == DateTime.Now.Year).Select(x => x.MeasurementID).ToList(); break; }

                                case "Year":
                                    { MeasurementIDList = Database.Measurements.Where(x => x.StartTime.Date.Year == filter.Year).Select(x => x.MeasurementID).ToList(); break; }

                                case "Month":
                                    { MeasurementIDList = Database.Measurements.Where(x => x.StartTime.Date.Year == filter.Year && x.StartTime.Date.Month == filter.Month).Select(x => x.MeasurementID).ToList(); break; }

                                case "Day":
                                    { MeasurementIDList = Database.Measurements.Where(x => x.StartTime.Date.Year == filter.Year && x.StartTime.Date.Month == filter.Month && x.StartTime.Date.Day == filter.Day).Select(x => x.MeasurementID).ToList(); break; }
                            }
                        }
                        break;

                    case "Sample":
                        { MeasurementIDList = Database.Measurements.Where(x => x.Sample.SampleName == filter.SampleName).Select(x => x.MeasurementID).ToList(); break; }

                    case "Channel":
                        { MeasurementIDList = Database.Measurements.Where(x => x.Channel == filter.Channel).Select(x => x.MeasurementID).ToList(); break; }
                }

                // Send event (to SpectraListView...)
                if (EventNewFilter != null) EventNewFilter(MeasurementIDList);
            }
        }
        /// <summary>
        /// Function that populates the filter tree with the selected filterType from the <see cref="filterTypeList"/>.
        /// </summary>
        /// <param name="filterType">The string of the selected filterType.</param>
        public void FillFilterList(string filterType)
        {
            trace.Value.TraceEvent(TraceEventType.Information, 0, "New selected filterType: '" + filterType + "'");

            ClearFilterTreeSelectedItem();

            if (filterTree.Items.Count() > 0)
            {
                while (filterTree.Items.Count > 0)
                    filterTree.Items.RemoveAt(0);
            }

            switch (filterType)
            {
                case "Date":
                    filterTree.Items.Add(new FilterClass() { Name = "All", Type = "All" });
                    filterTree.Items.Add(new FilterClass() { Name = "Today", Type = "Date", SubType = "Today" });
                    filterTree.Items.Add(new FilterClass() { Name = "This Week", Type = "Date", SubType = "ThisWeek" });
                    filterTree.Items.Add(new FilterClass() { Name = "This Month", Type = "Date", SubType = "ThisMonth" });
                    filterTree.Items.Add(new FilterClass() { Name = "This Year", Type = "Date", SubType = "ThisYear" });

                    using (DatabaseDataContext Database = MyGlobals.Database)
                    {
                        List<int> allYears = (from spec in Database.Measurements select spec.StartTime.Year).Distinct().ToList();
                        foreach (int Year in allYears)
                        {
                            FilterClass newYearNode = new FilterClass() { Name = Year.ToString(), Type = "Date", SubType = "Year", Year = Year };

                            List<int> allMonths = Database.Measurements.Where(x => x.StartTime.Year == Year).Select(x => x.StartTime.Month).Distinct().ToList();
                            if (allMonths.Count > 0)
                            {
                                newYearNode.Children = new AsyncObservableCollection<FilterClass>();
                                foreach (int Month in allMonths)
                                {
                                    FilterClass newMonthNode = new FilterClass() { Name = Month.ToString("D2"), Type = "Date", SubType = "Month", Year = Year, Month = Month };

                                    List<int> allDays = Database.Measurements.Where(x => x.StartTime.Year == Year && x.StartTime.Month == Month).Select(x => x.StartTime.Day).Distinct().ToList();
                                    if (allDays.Count > 0)
                                    {
                                        newMonthNode.Children = new AsyncObservableCollection<FilterClass>();
                                        foreach (int Day in allDays)
                                        {
                                            FilterClass newDayNode = new FilterClass() { Name = Day.ToString("D2"), Type = "Date", SubType = "Day", Year = Year, Month = Month, Day = Day };
                                            newMonthNode.Children.Add(newDayNode);
                                        }
                                    }
                                    newYearNode.Children.Add(newMonthNode);
                                }
                            }
                            filterTree.Items.Add(newYearNode);
                        }
                    }
                    break;

                case "Channel":
                    filterTree.Items.Add(new FilterClass() { Name = "All", Type = "All" });

                    using (DatabaseDataContext Database = MyGlobals.Database)
                    {
                        List<int> allChannels = Database.Measurements.Select(x => x.Channel).Distinct().ToList();

                        foreach (int Channel in allChannels)
                        {
                            filterTree.Items.Add(new FilterClass() { Name = Channel.ToString(), Type = "Channel", Channel = Channel });
                        }
                    }
                    break;

                case "Sample":
                    filterTree.Items.Add(new FilterClass() { Name = "All", Type = "All" });

                    using (DatabaseDataContext Database = MyGlobals.Database)
                    {
                        //List<string> allSampleNames = (from sample in Database.Samples select sample.SampleName).Distinct().ToList();
                        List<string> allSampleNames = Database.Samples.Select(x => x.SampleName).ToList();

                        foreach (string sampleName in allSampleNames)
                        {
                            filterTree.Items.Add(new FilterClass() { Name = sampleName, Type = "Sample", SampleName = sampleName });
                        }
                    }
                    break;

                default:
                    trace.Value.TraceEvent(TraceEventType.Warning, 0, "No action found for filterType: '" + filterType +"'");
                    break;
            }
            if (EventNewFilter != null) EventNewFilter(new List<int>());
        }