using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Reflection;
using System.Windows.Forms;
using Rmake.Model;
using Rmake.Model.Casts;
using Rmake.Model.Processable.Orders;
using Rmake.Model.Processable.Attributes;
using Rmake.GUI.Helpers;
using Rmake.Framework.Logging;
namespace Rmake.GUI.Controls
{
///
/// OrderSelectListPanel の概要の説明です。
///
public class OrderSelectListPanel : System.Windows.Forms.UserControl
{
///
/// 必要なデザイナ変数です。
///
private System.ComponentModel.Container components = null;
private System.Windows.Forms.ListView orderCommandList;
private Type selectedType = null;
public Type SelectedType
{
get
{
if (orderCommandList.SelectedItems.Count > 0)
{
Object selectedItem = orderCommandList.SelectedItems[0].Tag;
if (selectedItem is Type)
{
selectedType = (Type) selectedItem;
}
else
{
selectedType = null;
}
}
else
{
selectedType = null;
}
return selectedType;
}
set {selectedType = value;}
}
public void ClearList()
{
try
{
orderCommandList.SelectedItems.Clear();
}
catch (Exception ex)
{
Logger.Fatal(ex);
}
}
public OrderSelectListPanel()
{
// この呼び出しは、Windows.Forms フォーム デザイナで必要です。
InitializeComponent();
// TODO: InitializeComponent 呼び出しの後に初期化処理を追加します。
try
{
ShowOrderList(typeof(OrderAttribute));
}
catch (Exception ex)
{
Logger.Fatal(ex);
}
}
private void ShowOrderList(Type attributeType)
{
orderCommandList.Clear();
Assembly assembly = Assembly.GetAssembly(typeof(Character));
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
Object[] attributes = type.GetCustomAttributes(typeof(OrderAttribute), true);
foreach (Object attribute in attributes)
{
if ((attribute is OrderAttribute) && (type.GetCustomAttributes(attributeType, true).Length > 0))
{
String name = ((OrderAttribute) attribute).Name;
CommonListViewDesigner.AddItem(orderCommandList, name, type, ImageIndexes.Order);
}
}
}
orderCommandList.SelectedItems.Clear();
}
public void ChangeOrderType(Type type)
{
try
{
// Order の Type を設定します
ShowOrderList(type);
}
catch (Exception ex)
{
Logger.Fatal(ex);
}
}
public void SetListDoubleClickEventHandler(EventHandler listDoubleClick)
{
if (listDoubleClick != null)
{
orderCommandList.DoubleClick += listDoubleClick;
}
}
///
/// 使用されているリソースに後処理を実行します。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region コンポーネント デザイナで生成されたコード
///
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
///
private void InitializeComponent()
{
this.orderCommandList = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// orderCommandList
//
this.orderCommandList.Dock = System.Windows.Forms.DockStyle.Fill;
this.orderCommandList.Location = new System.Drawing.Point(0, 0);
this.orderCommandList.MultiSelect = false;
this.orderCommandList.Name = "orderCommandList";
this.orderCommandList.Size = new System.Drawing.Size(192, 336);
this.orderCommandList.TabIndex = 1;
this.orderCommandList.View = System.Windows.Forms.View.List;
//
// OrderSelectListPanel
//
this.Controls.Add(this.orderCommandList);
this.Name = "OrderSelectListPanel";
this.Size = new System.Drawing.Size(192, 336);
this.ResumeLayout(false);
}
#endregion
}
}