Exemple #1
0
        /// <summary>
        /// Set up and show a vehicle data window for a unit.
        /// </summary>
        /// <param name="unit">Unit to display</param>
        private void ShowVcleData(IUnitViewModel unit)
        {
            VehicleDataWindow window;

            if (this.vcleWindows.Exists(vw => vw.DataContext == unit))
            {
                window = this.vcleWindows.Find(vw => vw.DataContext == unit);
            }
            else
            {
                window =
                    new VehicleDataWindow
                {
                    DataContext = unit
                };

                if (unit.JourneysList != null)
                {
                    window.SetUpGraph(unit.JourneysList);
                }
                else
                {
                    window.SetUpGraph(new List <IJourneyViewModel>());
                }
                window.Closed += this.VcleDataWindowClosed;

                this.vcleWindows.Add(window);
            }

            window.Show();
            window.Activate();
        }
Exemple #2
0
        /// <summary>
        /// Change the data context of an existing window to display the indicated unit.
        /// Update the graphs.
        /// </summary>
        /// <remarks>
        /// The command is rejected if there is a window which already displays the indicated unit.
        /// In that case, the other window is focused.
        /// </remarks>
        /// <param name="window">Window to change</param>
        /// <param name="unit">Unit to display on the window</param>
        private void ChangeWindowUnit(
            VehicleDataWindow window,
            IUnitViewModel unit)
        {
            // Focus on an existing window if one already exists.
            if (this.vcleWindows.Exists(vw => vw.DataContext == unit))
            {
                VehicleDataWindow existingWindow =
                    this.vcleWindows.Find(
                        vw => vw.DataContext == unit);
                existingWindow.Show();
                existingWindow.Activate();

                return;
            }

            if (window == null)
            {
                Logger.Instance.WriteLog("SubClassViewModel: failed to change unit in a window, failed to find valid window");
                return;
            }

            window.DataContext = unit;

            if (unit.JourneysList != null)
            {
                window.SetUpGraph(unit.JourneysList);
            }
            else
            {
                window.SetUpGraph(new List <IJourneyViewModel>());
            }
        }
Exemple #3
0
 /// <summary>
 /// Close a vehicle data window.
 /// </summary>
 /// <param name="unit">unit to close</param>
 private void CloseVcleData(IUnitViewModel unit)
 {
     if (this.vcleWindows.Exists(vw => vw.DataContext == unit))
     {
         this.vcleWindows.Find(vw => vw.DataContext == unit).Close();
     }
 }
Exemple #4
0
        /// <summary>
        /// Find and return the index of a unit.
        /// </summary>
        /// <param name="unit">unit to search for</param>
        /// <returns>found index</returns>
        private int?GetUnitIndex(IUnitViewModel unit)
        {
            for (int index = 0; index < this.Units?.Count; ++index)
            {
                if (this.Units[index] == unit)
                {
                    return(index);
                }
            }

            return(null);
        }
Exemple #5
0
        /// <summary>
        /// Display the previous unit.
        /// </summary>
        /// <param name="unit">Unit to display</param>
        private void PreviousUnit(IUnitViewModel unit)
        {
            int?index = this.GetUnitIndex(unit);

            if (index != null &&
                index > 0)
            {
                VehicleDataWindow window = this.vcleWindows.Find(vw => vw.DataContext == unit);

                this.ChangeWindowUnit(
                    window,
                    this.Units[(int)index - 1]);
            }
        }