using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Ingenious.Mvc;
namespace Ingenious.Mvc.Visualizers{
public partial class TaskManagerUserControl : UserControl
{
private TaskManager _taskManager;
private CustomListViewItem SelectedItem
{
get
{
if (_tasksListView.SelectedIndices.Count > 0)
{
return _tasksListView.SelectedItems[0] as CustomListViewItem;
}
return null;
}
}
public TaskManager TaskManager
{
get
{
return _taskManager;
}
set
{
_taskManager = value;
Update();
}
}
public Task SelectedTask
{
get
{
CustomListViewItem selectedItem = SelectedItem;
if (selectedItem != null)
{
return selectedItem.Task;
}
return null;
}
set
{
_tasksListView.SelectedItems.Clear();
foreach (CustomListViewItem customListViewItem in _tasksListView.Items)
{
if (customListViewItem.Task == value)
{
customListViewItem.Selected = true;
break;
}
}
}
}
public TaskManagerUserControl()
{
InitializeComponent();
}
private new void Update()
{
PopulateTasks();
_configurationInfoUserControl.ConfigurationInfo = _taskManager.ConfigurationInfo;
}
private void PopulateTasks()
{
_tasksListView.BeginUpdate();
_tasksListView.Items.Clear();
foreach (Task task in _taskManager.Tasks)
{
_tasksListView.Items.Add(new CustomListViewItem(task));
}
_tasksListView.EndUpdate();
}
private sealed class CustomListViewItem : ListViewItem
{
private Task _task;
public Task Task
{
get
{
return _task;
}
}
public CustomListViewItem(Task task)
{
_task = task;
Text = task.Id.ToString();
SubItems.Add(task.Timestamp.ToLongTimeString());
SubItems.Add(task.State.ToString());
SubItems.Add((task.Owner == null) ? "" : task.Owner.Id.ToString());
}
}
}
}
|