2013-06-24 13:41:48 +02:00
|
|
|
|
/* Copyright (c) Citrix Systems Inc.
|
|
|
|
|
* 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;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Controls;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
using XenAdmin.Core;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Dialogs;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
using XenAPI;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.TabPages
|
|
|
|
|
{
|
|
|
|
|
public partial class HistoryPage : UserControl
|
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2013-08-13 11:52:15 +02:00
|
|
|
|
private const int MAX_HISTORY_ITEM = 1000;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public HistoryPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
2013-08-12 15:00:29 +02:00
|
|
|
|
dataGridView.Sort(columnDate, ListSortDirection.Descending);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
toolStripTop.Renderer = new CustomToolStripRenderer();
|
2013-08-07 13:10:12 +02:00
|
|
|
|
toolStripSplitButtonDismiss.DefaultItem = tsmiDismissAll;
|
|
|
|
|
toolStripSplitButtonDismiss.Text = tsmiDismissAll.Text;
|
2013-08-12 15:00:29 +02:00
|
|
|
|
ConnectionsManager.History.CollectionChanged += History_CollectionChanged;
|
2013-08-13 11:52:15 +02:00
|
|
|
|
ActionBase.NewAction += Action_NewAction;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 11:15:52 +02:00
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
toolStripDdbFilterLocation.InitializeHostList();
|
|
|
|
|
toolStripDdbFilterLocation.BuildFilterList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 18:08:04 +02:00
|
|
|
|
public void RefreshDisplayedEvents()
|
|
|
|
|
{
|
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 11:52:15 +02:00
|
|
|
|
private void Action_NewAction(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
if (action == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-08-13 18:08:04 +02:00
|
|
|
|
Program.BeginInvoke(Program.MainWindow,
|
2013-08-13 11:52:15 +02:00
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
int count = ConnectionsManager.History.Count;
|
|
|
|
|
if (count >= MAX_HISTORY_ITEM)
|
|
|
|
|
ConnectionsManager.History.RemoveAt(0);
|
|
|
|
|
ConnectionsManager.History.Add(action);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void History_CollectionChanged(object sender, CollectionChangeEventArgs e)
|
|
|
|
|
{
|
2013-08-13 18:08:04 +02:00
|
|
|
|
Program.BeginInvoke(this, () =>
|
2013-08-10 13:29:36 +02:00
|
|
|
|
{
|
|
|
|
|
ActionBase action = (ActionBase)e.Element;
|
|
|
|
|
switch (e.Action)
|
|
|
|
|
{
|
|
|
|
|
case CollectionChangeAction.Add:
|
2013-08-13 11:15:52 +02:00
|
|
|
|
var actions = new List<ActionBase>(ConnectionsManager.History);
|
|
|
|
|
actions.RemoveAll(FilterAction);
|
|
|
|
|
SortActions(actions);
|
|
|
|
|
var index = actions.IndexOf(action);
|
|
|
|
|
if (index > -1)
|
|
|
|
|
InsertActionRow(index, action);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case CollectionChangeAction.Remove:
|
|
|
|
|
RemoveActionRow(action);
|
|
|
|
|
break;
|
|
|
|
|
case CollectionChangeAction.Refresh:
|
|
|
|
|
BuildRowList();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
UpdateButtons();
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
private void action_Changed(ActionBase sender)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-13 18:08:04 +02:00
|
|
|
|
Program.Invoke(this, () =>
|
2013-08-10 13:29:36 +02:00
|
|
|
|
{
|
|
|
|
|
var row = FindRowFromAction(sender);
|
|
|
|
|
if (row != null)
|
|
|
|
|
row.RefreshSelf();
|
|
|
|
|
|
|
|
|
|
UpdateButtons();
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 12:04:08 +02:00
|
|
|
|
private void SetFilterLabel()
|
|
|
|
|
{
|
|
|
|
|
bool filterIsOn = toolStripDdbFilterDates.FilterIsOn
|
|
|
|
|
|| toolStripDdbFilterLocation.FilterIsOn
|
|
|
|
|
|| toolStripDdbFilterStatus.FilterIsOn;
|
|
|
|
|
|
|
|
|
|
toolStripLabelFiltersOnOff.Text = filterIsOn
|
|
|
|
|
? Messages.FILTERS_ON
|
|
|
|
|
: Messages.FILTERS_OFF;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
private void BuildRowList()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-10 13:29:36 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dataGridView.SuspendLayout();
|
|
|
|
|
dataGridView.Rows.Clear();
|
|
|
|
|
|
2013-08-13 11:15:52 +02:00
|
|
|
|
var actions = new List<ActionBase>(ConnectionsManager.History);
|
|
|
|
|
actions.RemoveAll(FilterAction);
|
|
|
|
|
SortActions(actions);
|
2013-08-12 15:00:29 +02:00
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
var rows = new List<DataGridViewActionRow>();
|
2013-08-12 15:00:29 +02:00
|
|
|
|
foreach (ActionBase action in actions)
|
2013-08-10 13:29:36 +02:00
|
|
|
|
{
|
|
|
|
|
var row = CreateActionRow(action);
|
|
|
|
|
rows.Add(row);
|
|
|
|
|
}
|
|
|
|
|
dataGridView.Rows.AddRange(rows.ToArray());
|
|
|
|
|
|
|
|
|
|
foreach(var actionRow in rows)
|
|
|
|
|
RegisterActionEvents(actionRow.Action);
|
2013-08-13 12:04:08 +02:00
|
|
|
|
|
|
|
|
|
SetFilterLabel();
|
2013-08-10 13:29:36 +02:00
|
|
|
|
}
|
|
|
|
|
finally
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-10 13:29:36 +02:00
|
|
|
|
dataGridView.ResumeLayout();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 11:15:52 +02:00
|
|
|
|
private void SortActions(List<ActionBase> actions)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-12 15:00:29 +02:00
|
|
|
|
if (dataGridView.SortedColumn != null)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SortedColumn.Index == columnStatus.Index)
|
|
|
|
|
actions.Sort(ActionBaseExtensions.CompareOnStatus);
|
|
|
|
|
else if (dataGridView.SortedColumn.Index == columnMessage.Index)
|
|
|
|
|
actions.Sort(ActionBaseExtensions.CompareOnTitle);
|
|
|
|
|
else if (dataGridView.SortedColumn.Index == columnLocation.Index)
|
|
|
|
|
actions.Sort(ActionBaseExtensions.CompareOnLocation);
|
|
|
|
|
else if (dataGridView.SortedColumn.Index == columnDate.Index)
|
|
|
|
|
actions.Sort(ActionBaseExtensions.CompareOnDateStarted);
|
|
|
|
|
|
|
|
|
|
if (dataGridView.SortOrder == SortOrder.Descending)
|
|
|
|
|
actions.Reverse();
|
|
|
|
|
}
|
2013-08-13 11:15:52 +02:00
|
|
|
|
}
|
2013-08-12 15:00:29 +02:00
|
|
|
|
|
2013-08-13 11:15:52 +02:00
|
|
|
|
private bool FilterAction(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
bool hide = false;
|
|
|
|
|
Program.Invoke(this, () =>
|
|
|
|
|
hide = toolStripDdbFilterDates.HideByDate(action.Started)
|
|
|
|
|
|| toolStripDdbFilterLocation.HideByLocation(action.GetApplicableHosts())
|
|
|
|
|
|| toolStripDdbFilterStatus.HideByStatus(action));
|
|
|
|
|
return hide;
|
2013-08-12 15:00:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InsertActionRow(int index, ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
if (index < 0)
|
|
|
|
|
index = 0;
|
|
|
|
|
if (index > dataGridView.RowCount)
|
|
|
|
|
index = dataGridView.RowCount;
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
var row = CreateActionRow(action);
|
2013-08-12 15:00:29 +02:00
|
|
|
|
dataGridView.Rows.Insert(index, row);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
RegisterActionEvents(action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DataGridViewActionRow CreateActionRow(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
var row = new DataGridViewActionRow(action);
|
|
|
|
|
row.DismissalRequested += row_DismissalRequested;
|
|
|
|
|
row.GoToXenObjectRequested += row_GoToXenObjectRequested;
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RegisterActionEvents(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
action.Changed -= action_Changed;
|
|
|
|
|
action.Completed -= action_Changed;
|
|
|
|
|
action.Changed += action_Changed;
|
|
|
|
|
action.Completed += action_Changed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveActionRow(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
var row = FindRowFromAction(action);
|
|
|
|
|
if (row != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-10 13:29:36 +02:00
|
|
|
|
action.Changed -= action_Changed;
|
|
|
|
|
action.Completed -= action_Changed;
|
|
|
|
|
dataGridView.Rows.Remove(row);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
private DataGridViewActionRow FindRowFromAction(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
foreach (DataGridViewRow row in dataGridView.Rows)
|
|
|
|
|
{
|
|
|
|
|
var actionRow = row as DataGridViewActionRow;
|
|
|
|
|
if (actionRow == null)
|
|
|
|
|
continue;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
if (actionRow.Action == action)
|
|
|
|
|
return actionRow;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
return null;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
private void ToggleExpandedState(int rowIndex)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-10 13:29:36 +02:00
|
|
|
|
var row = dataGridView.Rows[rowIndex] as DataGridViewActionRow;
|
|
|
|
|
if (row == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (row.Expanded)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-10 13:29:36 +02:00
|
|
|
|
row.Cells[columnExpander.Index].Value = Properties.Resources.contracted_triangle;
|
|
|
|
|
row.Cells[columnMessage.Index].Value = row.Action.GetTitle();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
row.Cells[columnExpander.Index].Value = Properties.Resources.expanded_triangle;
|
|
|
|
|
row.Cells[columnMessage.Index].Value = row.Action.GetDetails();
|
|
|
|
|
}
|
|
|
|
|
row.Expanded = !row.Expanded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateButtons()
|
|
|
|
|
{
|
|
|
|
|
tsmiDismissAll.Enabled = dataGridView.Rows.Cast<DataGridViewActionRow>().Any(row => row.Action.IsCompleted);
|
|
|
|
|
tsmiDismissSelected.Enabled = dataGridView.SelectedRows.Cast<DataGridViewActionRow>().Any(row => row.Action.IsCompleted);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 12:04:08 +02:00
|
|
|
|
#region Control event handlers
|
2013-08-10 13:29:36 +02:00
|
|
|
|
|
|
|
|
|
private void row_DismissalRequested(DataGridViewActionRow row)
|
|
|
|
|
{
|
|
|
|
|
if (ConnectionsManager.History.Count > 0 &&
|
|
|
|
|
(Program.RunInAutomatedTestMode ||
|
|
|
|
|
new ThreeButtonDialog(
|
|
|
|
|
new ThreeButtonDialog.Details(null, Messages.MESSAGEBOX_LOG_DELETE, Messages.MESSAGEBOX_LOG_DELETE_TITLE),
|
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
|
|
|
|
ThreeButtonDialog.ButtonNo).ShowDialog(this) == DialogResult.Yes))
|
|
|
|
|
{
|
|
|
|
|
ConnectionsManager.History.Remove(row.Action);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void row_GoToXenObjectRequested(IXenObject obj)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// If you click on the headers you can get -1 as the index.
|
|
|
|
|
if (e.ColumnIndex < 0 || e.RowIndex < 0 || e.ColumnIndex != columnExpander.Index)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ToggleExpandedState(e.RowIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataGridView_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
tsmiDismissSelected.Enabled = dataGridView.SelectedRows.Cast<DataGridViewActionRow>().Any(row => row.Action.IsCompleted);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2013-08-07 13:10:12 +02:00
|
|
|
|
|
2013-08-12 15:00:29 +02:00
|
|
|
|
private void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.Columns[e.ColumnIndex].SortMode == DataGridViewColumnSortMode.Automatic)
|
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 13:10:12 +02:00
|
|
|
|
|
|
|
|
|
private void toolStripSplitButtonDismiss_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
toolStripSplitButtonDismiss.DefaultItem = e.ClickedItem;
|
|
|
|
|
toolStripSplitButtonDismiss.Text = toolStripSplitButtonDismiss.DefaultItem.Text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiDismissAll_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (ConnectionsManager.History.Count > 0 &&
|
|
|
|
|
(Program.RunInAutomatedTestMode ||
|
|
|
|
|
new ThreeButtonDialog(
|
|
|
|
|
new ThreeButtonDialog.Details(null, Messages.MESSAGEBOX_LOGS_DELETE, Messages.MESSAGEBOX_LOGS_DELETE_TITLE),
|
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
|
|
|
|
ThreeButtonDialog.ButtonNo).ShowDialog(this) == DialogResult.Yes))
|
|
|
|
|
{
|
2013-08-10 13:29:36 +02:00
|
|
|
|
ConnectionsManager.History.RemoveAll(a => a.IsCompleted);
|
2013-08-07 13:10:12 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiDismissSelected_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 11:15:52 +02:00
|
|
|
|
|
|
|
|
|
private void toolStripDdbFilterStatus_FilterChanged()
|
|
|
|
|
{
|
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toolStripDdbFilterLocation_FilterChanged()
|
|
|
|
|
{
|
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toolStripDdbFilterDates_FilterChanged()
|
|
|
|
|
{
|
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 13:10:12 +02:00
|
|
|
|
#endregion
|
2013-08-10 13:29:36 +02:00
|
|
|
|
|
|
|
|
|
#region Nested classes
|
|
|
|
|
|
2013-08-16 13:57:39 +02:00
|
|
|
|
public class DataGridViewActionRow : DataGridViewRow
|
2013-08-10 13:29:36 +02:00
|
|
|
|
{
|
|
|
|
|
private DataGridViewImageCell expanderCell = new DataGridViewImageCell();
|
|
|
|
|
private DataGridViewImageCell statusCell = new DataGridViewImageCell();
|
|
|
|
|
private DataGridViewTextBoxCell messageCell = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell locationCell = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell dateCell = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewDropDownSplitButtonCell actionCell = new DataGridViewDropDownSplitButtonCell();
|
|
|
|
|
|
2013-08-19 14:17:33 +02:00
|
|
|
|
private ToolStripMenuItem cancelItem = new ToolStripMenuItem(Messages.CANCEL);
|
|
|
|
|
private ToolStripMenuItem dismissItem = new ToolStripMenuItem(Messages.ALERT_DISMISS);
|
|
|
|
|
private ToolStripMenuItem goToItem = new ToolStripMenuItem(Messages.HISTORYPAGE_GOTO);
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
public event Action<DataGridViewActionRow> DismissalRequested;
|
|
|
|
|
public event Action<IXenObject> GoToXenObjectRequested;
|
|
|
|
|
|
|
|
|
|
public ActionBase Action { get; private set; }
|
|
|
|
|
public bool Expanded { get; set; }
|
|
|
|
|
|
|
|
|
|
public DataGridViewActionRow(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
Action = action;
|
2013-08-19 14:17:33 +02:00
|
|
|
|
|
|
|
|
|
cancelItem.Click += ToolStripMenuItemCancel_Click;
|
|
|
|
|
dismissItem.Click += ToolStripMenuItemDismiss_Click;
|
|
|
|
|
goToItem.Click += ToolStripMenuItemGoTo_Click;
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
MinimumHeight = DataGridViewDropDownSplitButtonCell.MIN_ROW_HEIGHT;
|
|
|
|
|
Cells.AddRange(expanderCell, statusCell, messageCell, locationCell, dateCell, actionCell);
|
|
|
|
|
RefreshSelf();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RefreshSelf()
|
|
|
|
|
{
|
2013-08-19 14:17:33 +02:00
|
|
|
|
var actionItems = new List<ToolStripItem>();
|
|
|
|
|
if (!Action.IsCompleted && Action.CanCancel)
|
|
|
|
|
actionItems.Add(cancelItem);
|
|
|
|
|
|
|
|
|
|
if (Action.IsCompleted)
|
|
|
|
|
actionItems.Add(dismissItem);
|
|
|
|
|
|
|
|
|
|
var obj = Action.GetRelevantXenObject();
|
|
|
|
|
if (obj != null)
|
|
|
|
|
actionItems.Add(goToItem);
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
actionCell.RefreshItems(actionItems.ToArray());
|
|
|
|
|
|
|
|
|
|
statusCell.Value = Action.GetImage();
|
|
|
|
|
|
|
|
|
|
if (Expanded)
|
|
|
|
|
{
|
|
|
|
|
expanderCell.Value = Properties.Resources.expanded_triangle;
|
|
|
|
|
messageCell.Value = Action.GetDetails();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
expanderCell.Value = Properties.Resources.contracted_triangle;
|
|
|
|
|
messageCell.Value = Action.GetTitle();
|
|
|
|
|
}
|
|
|
|
|
locationCell.Value = Action.GetLocation();
|
|
|
|
|
dateCell.Value = HelpersGUI.DateTimeToString(Action.Started.ToLocalTime(), Messages.DATEFORMAT_DMY_HM, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToolStripMenuItemCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Action.Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToolStripMenuItemDismiss_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (DismissalRequested != null)
|
|
|
|
|
DismissalRequested(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToolStripMenuItemGoTo_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (GoToXenObjectRequested != null)
|
|
|
|
|
GoToXenObjectRequested(Action.GetRelevantXenObject());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class CustomToolStripRenderer : ToolStripProfessionalRenderer
|
|
|
|
|
{
|
|
|
|
|
public CustomToolStripRenderer()
|
|
|
|
|
: base(new CustomToolstripColourTable())
|
|
|
|
|
{
|
|
|
|
|
RoundedEdges = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class CustomToolstripColourTable : ProfessionalColorTable
|
|
|
|
|
{
|
|
|
|
|
public override Color ToolStripBorder
|
|
|
|
|
{
|
|
|
|
|
get { return Color.Gainsboro; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|