2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Controls.CustomDataGraph;
|
2016-11-10 15:42:45 +01:00
|
|
|
|
using XenAdmin.Core;
|
2017-11-17 02:04:45 +01:00
|
|
|
|
using XenCenterLib;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Dialogs
|
|
|
|
|
{
|
|
|
|
|
public partial class GraphDetailsDialog : XenDialogBase
|
|
|
|
|
{
|
|
|
|
|
private const int ColorSquareSize = 12;
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
private readonly DesignedGraph designedGraph;
|
|
|
|
|
private readonly GraphList graphList;
|
|
|
|
|
private readonly bool isNew;
|
|
|
|
|
private bool _updating;
|
|
|
|
|
private List<DataSourceItem> _dataSourceItems = new List<DataSourceItem>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
public GraphDetailsDialog(GraphList graphList, DesignedGraph designedGraph = null)
|
|
|
|
|
: base(graphList.XenObject?.Connection)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2016-10-20 01:03:47 +02:00
|
|
|
|
tableLayoutPanel1.Visible = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
this.graphList = graphList;
|
2021-09-23 14:13:07 +02:00
|
|
|
|
|
|
|
|
|
if (designedGraph == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
isNew = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
this.designedGraph = new DesignedGraph();
|
2016-11-10 15:42:45 +01:00
|
|
|
|
// Generate an unique suggested name for the graph
|
2021-09-23 14:13:07 +02:00
|
|
|
|
this.designedGraph.DisplayName = Helpers.MakeUniqueName(Messages.GRAPH_NAME, graphList.DisplayNames);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
base.Text = Messages.GRAPHS_NEW_TITLE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.designedGraph = new DesignedGraph(designedGraph);
|
2021-09-23 14:13:07 +02:00
|
|
|
|
base.Text = string.Format(Messages.GRAPHS_EDIT_TITLE, this.designedGraph.DisplayName);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2021-09-23 14:13:07 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
ActiveControl = GraphNameTextBox;
|
|
|
|
|
GraphNameTextBox.Text = this.designedGraph.DisplayName;
|
2021-09-23 14:13:07 +02:00
|
|
|
|
EnableControlsAfterCheckChanged();
|
|
|
|
|
EnableControlsAfterSelectionChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadDataSources()
|
|
|
|
|
{
|
|
|
|
|
if (graphList.XenObject == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
tableLayoutPanel1.Visible = true;
|
|
|
|
|
searchTextBox.Enabled = false;
|
|
|
|
|
|
|
|
|
|
var action = new GetDataSourcesAction(graphList.XenObject);
|
|
|
|
|
action.Completed += getDataSourcesAction_Completed;
|
|
|
|
|
action.RunAsync();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
private void getDataSourcesAction_Completed(ActionBase sender)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (!(sender is GetDataSourcesAction action))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Program.Invoke(this, () =>
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2016-10-20 01:03:47 +02:00
|
|
|
|
tableLayoutPanel1.Visible = false;
|
2021-09-23 14:13:07 +02:00
|
|
|
|
_dataSourceItems = DataSourceItemList.BuildList(action.XenObject, action.DataSources);
|
|
|
|
|
PopulateDataGridView();
|
2016-10-20 01:03:47 +02:00
|
|
|
|
searchTextBox.Enabled = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 01:03:47 +02:00
|
|
|
|
private void PopulateDataGridView()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
_updating = true;
|
2016-10-20 01:03:47 +02:00
|
|
|
|
dataGridView.SuspendLayout();
|
|
|
|
|
dataGridView.Rows.Clear();
|
2021-09-23 14:13:07 +02:00
|
|
|
|
|
|
|
|
|
var rowList = new List<DataSourceGridViewRow>();
|
|
|
|
|
|
|
|
|
|
foreach (DataSourceItem dataSourceItem in _dataSourceItems)
|
2016-10-20 01:03:47 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (!toolStripMenuItemHidden.Checked && dataSourceItem.Hidden)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!toolStripMenuItemDisabled.Checked && !dataSourceItem.Enabled)
|
|
|
|
|
continue;
|
|
|
|
|
|
2016-10-20 01:03:47 +02:00
|
|
|
|
if (!searchTextBox.Matches(dataSourceItem.ToString()))
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
bool displayOnGraph = designedGraph.DataSourceItems.Contains(dataSourceItem);
|
|
|
|
|
rowList.Add(new DataSourceGridViewRow(dataSourceItem, displayOnGraph));
|
2016-10-20 01:03:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
|
|
|
|
|
dataGridView.Rows.AddRange(rowList.Cast<DataGridViewRow>().ToArray());
|
|
|
|
|
dataGridView.Sort(dataGridView.Columns[ColumnDisplayOnGraph.Index], ListSortDirection.Ascending);
|
|
|
|
|
|
2016-10-20 01:03:47 +02:00
|
|
|
|
if (dataGridView.Rows.Count > 0)
|
2021-09-23 14:13:07 +02:00
|
|
|
|
dataGridView.Rows[0].Cells[ColumnDisplayOnGraph.Index].Selected = true;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
dataGridView.ResumeLayout();
|
|
|
|
|
_updating = false;
|
|
|
|
|
EnableControlsAfterCheckChanged();
|
|
|
|
|
EnableControlsAfterSelectionChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EnableControlsAfterCheckChanged()
|
|
|
|
|
{
|
|
|
|
|
int checkedRowCount = dataGridView.Rows.Cast<DataSourceGridViewRow>().Count(row => row.IsChecked);
|
|
|
|
|
buttonClearAll.Enabled = checkedRowCount > 0;
|
|
|
|
|
SaveButton.Enabled = checkedRowCount > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EnableControlsAfterSelectionChanged()
|
|
|
|
|
{
|
|
|
|
|
if (_updating)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var selectedRows = dataGridView.SelectedRows.Cast<DataSourceGridViewRow>().ToList();
|
|
|
|
|
buttonEnable.Enabled = selectedRows.Count == 1 && selectedRows.TrueForAll(r => !r.Recording);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ClearAll()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (var row in dataGridView.Rows)
|
2016-10-20 01:03:47 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (!(row is DataSourceGridViewRow dsRow))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
dsRow.ClearCheck();
|
|
|
|
|
designedGraph.DataSourceItems.Remove(dsRow.Dsi);
|
2016-10-20 01:03:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
EnableControlsAfterCheckChanged();
|
2016-10-20 01:03:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
private void EnableDatasource()
|
|
|
|
|
{
|
|
|
|
|
if (graphList.XenObject?.Connection == null || dataGridView.SelectedRows.Count != 1)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-21 16:53:46 +01:00
|
|
|
|
if (!(dataGridView.SelectedRows[0] is DataSourceGridViewRow row))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var dataSource = row.Dsi.DataSource;
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (dataSource == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
buttonEnable.Enabled = false;
|
|
|
|
|
var action = new EnableDataSourceAction(graphList.XenObject, dataSource, row.Dsi.ToString());
|
|
|
|
|
|
|
|
|
|
using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Marquee)
|
|
|
|
|
{
|
|
|
|
|
ShowTryAgainMessage = false,
|
|
|
|
|
ShowException = false
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
dialog.ShowDialog(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EnableControlsAfterSelectionChanged();
|
|
|
|
|
|
|
|
|
|
if (action.Succeeded && action is EnableDataSourceAction enableAction && enableAction.DataSources != null)
|
|
|
|
|
{
|
|
|
|
|
var updated = enableAction.DataSources.FirstOrDefault(d => d.name_label == dataSource.name_label);
|
|
|
|
|
row.Recording = updated != null && updated.enabled;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Event handlers
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void datasourcesGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
|
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (e.ColumnIndex == ColumnColour.Index && 0 <= e.RowIndex && e.RowIndex <= dataGridView.RowCount -1)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Rectangle rect = dataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
|
|
|
|
|
e.PaintBackground(rect, true);
|
|
|
|
|
|
|
|
|
|
rect.X += 3;
|
|
|
|
|
rect.Y += 5;
|
|
|
|
|
|
|
|
|
|
rect.Width = ColorSquareSize;
|
|
|
|
|
rect.Height = ColorSquareSize;
|
|
|
|
|
|
|
|
|
|
using (var brush = new SolidBrush((Color)e.Value))
|
|
|
|
|
e.Graphics.FillRectangle(brush, rect);
|
|
|
|
|
|
|
|
|
|
e.Graphics.DrawRectangle(SystemPens.Window, rect);
|
|
|
|
|
|
|
|
|
|
using (var pen = new Pen(SystemColors.ControlDark, 1.5f))
|
|
|
|
|
e.Graphics.DrawRectangle(pen, Rectangle.Inflate(rect, 1, 1));
|
|
|
|
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void datasourcesGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (e.RowIndex < 0 || e.RowIndex > dataGridView.RowCount - 1)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
var row = dataGridView.Rows[e.RowIndex] as DataSourceGridViewRow;
|
|
|
|
|
if (row == null)
|
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (e.ColumnIndex == ColumnDisplayOnGraph.Index)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (row.IsChecked)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
row.ClearCheck();
|
|
|
|
|
designedGraph.DataSourceItems.Remove(row.Dsi);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
row.Check();
|
|
|
|
|
designedGraph.DataSourceItems.Add(row.Dsi);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
EnableControlsAfterCheckChanged();
|
|
|
|
|
}
|
|
|
|
|
else if (e.ColumnIndex == ColumnColour.Index)
|
|
|
|
|
{
|
|
|
|
|
using (var cd = new ColorDialog
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
Color = row.Colour,
|
|
|
|
|
AllowFullOpen = true,
|
|
|
|
|
AnyColor = true,
|
|
|
|
|
FullOpen = true,
|
|
|
|
|
SolidColorOnly = true
|
|
|
|
|
})
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (cd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
row.Colour = cd.Color;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-23 14:13:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataGridView_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
EnableControlsAfterSelectionChanged();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataGridView_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
|
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
var row1 = dataGridView.Rows[e.RowIndex1] as DataSourceGridViewRow;
|
|
|
|
|
var row2 = dataGridView.Rows[e.RowIndex2] as DataSourceGridViewRow;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
int result;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (row1 == null && row2 == null)
|
|
|
|
|
result = 0;
|
|
|
|
|
else if (row1 == null)
|
|
|
|
|
result = 1;
|
|
|
|
|
else if (row2 == null)
|
|
|
|
|
result = -1;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
else
|
2021-09-23 14:13:07 +02:00
|
|
|
|
{
|
|
|
|
|
result = row1.CompareByCell(row2, e.Column.Index);
|
|
|
|
|
|
|
|
|
|
if (result == 0)
|
|
|
|
|
{
|
|
|
|
|
for (var i = 0; i < dataGridView.ColumnCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i == e.Column.Index)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
result = row1.CompareByCell(row2, i);
|
|
|
|
|
if (result == 0)
|
|
|
|
|
continue;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
//the columns other than the clicked one should always be ascending
|
|
|
|
|
if (dataGridView.SortOrder == SortOrder.Descending)
|
|
|
|
|
result = -result;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e.SortResult = result;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
|
|
|
|
|
private void GraphDetailsDialog_Load(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
LoadDataSources();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
|
|
|
|
|
private void searchTextBox_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
PopulateDataGridView();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
|
|
|
|
|
private void toolStripMenuItemDisabled_CheckedChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
PopulateDataGridView();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
private void toolStripMenuItemHidden_CheckedChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
PopulateDataGridView();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
private void buttonClearAll_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
ClearAll();
|
|
|
|
|
}
|
2021-09-23 14:13:07 +02:00
|
|
|
|
|
|
|
|
|
private void buttonEnable_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
EnableDatasource();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
|
|
|
|
|
private void SaveButton_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (graphList.XenObject == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
designedGraph.DisplayName = GraphNameTextBox.Text;
|
|
|
|
|
|
|
|
|
|
if (isNew)
|
|
|
|
|
graphList.AddGraph(designedGraph);
|
|
|
|
|
else
|
|
|
|
|
graphList.ReplaceGraphAt(graphList.SelectedGraphIndex, designedGraph);
|
|
|
|
|
|
|
|
|
|
var dataSourceItems = new List<DataSourceItem>();
|
|
|
|
|
foreach (DataGridViewRow row in dataGridView.Rows)
|
2016-10-20 01:03:47 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
if (!(row is DataSourceGridViewRow dsRow))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (dsRow.Dsi.ColorChanged)
|
|
|
|
|
Palette.SetCustomColor(Palette.GetUuid(dsRow.Dsi.DataSource.name_label, graphList.XenObject), dsRow.Dsi.Color);
|
|
|
|
|
dataSourceItems.Add(dsRow.Dsi);
|
2016-10-20 01:03:47 +02:00
|
|
|
|
}
|
2021-09-23 14:13:07 +02:00
|
|
|
|
graphList.SaveGraphs(dataSourceItems);
|
2016-10-20 01:03:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 14:13:07 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Nested classes
|
|
|
|
|
|
|
|
|
|
private class DataSourceGridViewRow : DataGridViewRow
|
2016-10-20 01:03:47 +02:00
|
|
|
|
{
|
2021-09-23 14:13:07 +02:00
|
|
|
|
private readonly DataGridViewCheckBoxCell _checkBoxCell = new DataGridViewCheckBoxCell();
|
|
|
|
|
private readonly DataGridViewTextBoxCell _datasourceCell = new DataGridViewTextBoxCell();
|
|
|
|
|
private readonly DataGridViewTextBoxCell _typeCell = new DataGridViewTextBoxCell();
|
|
|
|
|
private readonly DataGridViewTextBoxCell _enabledCell = new DataGridViewTextBoxCell();
|
|
|
|
|
private readonly DataGridViewTextBoxCell _colourCell = new DataGridViewTextBoxCell();
|
|
|
|
|
|
|
|
|
|
public DataSourceGridViewRow(DataSourceItem dataSourceItem, bool displayOnGraph)
|
|
|
|
|
{
|
|
|
|
|
Dsi = dataSourceItem;
|
|
|
|
|
|
|
|
|
|
_checkBoxCell.Value = displayOnGraph;
|
|
|
|
|
_datasourceCell.Value = Dsi.ToString();
|
|
|
|
|
_typeCell.Value = Dsi.Category.ToStringI18N();
|
|
|
|
|
_enabledCell.Value = Dsi.Enabled.ToYesNoStringI18n();
|
|
|
|
|
_colourCell.Value = Dsi.Color;
|
|
|
|
|
Cells.AddRange(_checkBoxCell, _datasourceCell, _typeCell, _enabledCell, _colourCell);
|
|
|
|
|
|
|
|
|
|
if (Dsi.Hidden)
|
|
|
|
|
base.DefaultCellStyle = new DataGridViewCellStyle
|
|
|
|
|
{
|
|
|
|
|
ForeColor = SystemColors.GrayText,
|
|
|
|
|
SelectionForeColor = SystemColors.GrayText,
|
|
|
|
|
SelectionBackColor = SystemColors.ControlLight
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal DataSourceItem Dsi { get; }
|
|
|
|
|
|
|
|
|
|
internal Color Colour
|
|
|
|
|
{
|
|
|
|
|
get => (Color)_colourCell.Value;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Dsi.ColorChanged = Dsi.Color != value;
|
|
|
|
|
Dsi.Color = value;
|
|
|
|
|
_colourCell.Value = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal bool IsChecked => (bool)_checkBoxCell.Value;
|
|
|
|
|
|
|
|
|
|
internal bool Recording
|
|
|
|
|
{
|
|
|
|
|
get => Dsi.Enabled;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Dsi.Enabled = value;
|
|
|
|
|
_enabledCell.Value = value.ToYesNoStringI18n();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void Check()
|
|
|
|
|
{
|
|
|
|
|
_checkBoxCell.Value = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void ClearCheck()
|
|
|
|
|
{
|
|
|
|
|
_checkBoxCell.Value = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int CompareByCell(DataSourceGridViewRow other, int index)
|
|
|
|
|
{
|
|
|
|
|
if (other == null)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
//In .NET false precedes true, but we want the checked rows to appear first
|
|
|
|
|
if (index == _checkBoxCell.ColumnIndex)
|
|
|
|
|
return -IsChecked.CompareTo(other.IsChecked);
|
|
|
|
|
|
|
|
|
|
if (_checkBoxCell.ColumnIndex < index && index < _colourCell.ColumnIndex)
|
|
|
|
|
return StringUtility.NaturalCompare(Cells[index].Value.ToString(),
|
|
|
|
|
other.Cells[index].Value.ToString());
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2021-09-23 14:13:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|