- Timestamp:
- 09/13/11 09:38:41 (13 years ago)
- Location:
- branches/GeneralizedQAP/HeuristicLab.Optimizer/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP/HeuristicLab.Optimizer/3.3/NewItemDialog.Designer.cs
r5445 r6748 49 49 this.cancelButton = new System.Windows.Forms.Button(); 50 50 this.itemsListView = new System.Windows.Forms.ListView(); 51 this.nameColumnHeader = new System.Windows.Forms.ColumnHeader(); 52 this.descriptioncolumnHeader = new System.Windows.Forms.ColumnHeader(); 51 this.nameColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 52 this.versionColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 53 this.descriptioncolumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 53 54 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 54 this.versionColumnHeader = new System.Windows.Forms.ColumnHeader(); 55 this.loadingPanel = new System.Windows.Forms.Panel(); 56 this.pleaseWaitLabel = new System.Windows.Forms.Label(); 57 this.loadingProgressBar = new System.Windows.Forms.ProgressBar(); 58 this.loadingPanel.SuspendLayout(); 55 59 this.SuspendLayout(); 56 60 // … … 102 106 // nameColumnHeader 103 107 // 104 this.nameColumnHeader.DisplayIndex = 0;105 108 this.nameColumnHeader.Text = "Name"; 106 109 this.nameColumnHeader.Width = 91; 107 110 // 111 // versionColumnHeader 112 // 113 this.versionColumnHeader.Text = "Version"; 114 // 108 115 // descriptioncolumnHeader 109 116 // 110 this.descriptioncolumnHeader.DisplayIndex = 2;111 117 this.descriptioncolumnHeader.Text = "Description"; 112 118 this.descriptioncolumnHeader.Width = 190; 113 119 // 114 // versionColumnHeader120 // loadingPanel 115 121 // 116 this.versionColumnHeader.DisplayIndex = 1; 117 this.versionColumnHeader.Text = "Version"; 122 this.loadingPanel.Controls.Add(this.pleaseWaitLabel); 123 this.loadingPanel.Controls.Add(this.loadingProgressBar); 124 this.loadingPanel.Location = new System.Drawing.Point(37, 153); 125 this.loadingPanel.Name = "loadingPanel"; 126 this.loadingPanel.Size = new System.Drawing.Size(550, 106); 127 this.loadingPanel.TabIndex = 4; 128 // 129 // pleaseWaitLabel 130 // 131 this.pleaseWaitLabel.Anchor = System.Windows.Forms.AnchorStyles.None; 132 this.pleaseWaitLabel.Location = new System.Drawing.Point(44, 59); 133 this.pleaseWaitLabel.Name = "pleaseWaitLabel"; 134 this.pleaseWaitLabel.Size = new System.Drawing.Size(462, 23); 135 this.pleaseWaitLabel.TabIndex = 1; 136 this.pleaseWaitLabel.Text = "Loading items, please wait..."; 137 this.pleaseWaitLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 138 // 139 // loadingProgressBar 140 // 141 this.loadingProgressBar.Anchor = System.Windows.Forms.AnchorStyles.None; 142 this.loadingProgressBar.Location = new System.Drawing.Point(44, 32); 143 this.loadingProgressBar.Name = "loadingProgressBar"; 144 this.loadingProgressBar.Size = new System.Drawing.Size(462, 23); 145 this.loadingProgressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous; 146 this.loadingProgressBar.TabIndex = 0; 118 147 // 119 148 // NewItemDialog … … 124 153 this.CancelButton = this.cancelButton; 125 154 this.ClientSize = new System.Drawing.Size(624, 444); 155 this.Controls.Add(this.loadingPanel); 126 156 this.Controls.Add(this.itemsListView); 127 157 this.Controls.Add(this.cancelButton); … … 137 167 this.Load += new System.EventHandler(this.NewItemDialog_Load); 138 168 this.Shown += new System.EventHandler(this.NewItemDialog_Shown); 169 this.loadingPanel.ResumeLayout(false); 139 170 this.ResumeLayout(false); 140 171 … … 150 181 private System.Windows.Forms.ColumnHeader descriptioncolumnHeader; 151 182 private System.Windows.Forms.ColumnHeader versionColumnHeader; 183 private System.Windows.Forms.Panel loadingPanel; 184 private System.Windows.Forms.Label pleaseWaitLabel; 185 private System.Windows.Forms.ProgressBar loadingProgressBar; 152 186 } 153 187 } -
branches/GeneralizedQAP/HeuristicLab.Optimizer/3.3/NewItemDialog.cs
r5445 r6748 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 26 using System.Threading.Tasks; 25 27 using System.Windows.Forms; 26 28 using HeuristicLab.Core; … … 42 44 item = null; 43 45 InitializeComponent(); 46 SetEnabledStateOfControls(); 44 47 } 45 48 46 49 private void NewItemDialog_Load(object sender, EventArgs e) { 50 TaskScheduler context = TaskScheduler.FromCurrentSynchronizationContext(); 51 Task.Factory 52 .StartNew((Action<object>)LoadItems, context) 53 .ContinueWith(PrepareUI); 54 } 55 56 private void NewItemDialog_Shown(object sender, EventArgs e) { 57 item = null; 58 } 59 60 private void LoadItems(object state) { 61 TaskScheduler context = (TaskScheduler)state; 47 62 if (!initialized) { 48 var categories = from t in ApplicationManager.Manager.GetTypes(typeof(IItem)) 49 where CreatableAttribute.IsCreatable(t) 63 Type[] creatableTypes = (from t in ApplicationManager.Manager.GetTypes(typeof(IItem)) 64 where CreatableAttribute.IsCreatable(t) 65 select t).ToArray(); 66 var categories = from t in creatableTypes 50 67 orderby CreatableAttribute.GetCategory(t), ItemAttribute.GetName(t), ItemAttribute.GetVersion(t) ascending 51 68 group t by CreatableAttribute.GetCategory(t) into c … … 53 70 54 71 itemsListView.SmallImageList = new ImageList(); 72 int count = 0; 73 ListViewItem[] itemsArray = new ListViewItem[creatableTypes.Length]; 74 Image[] smallImagesArray = new Image[creatableTypes.Length]; 75 List<ListViewGroup> itemGroupsList = new List<ListViewGroup>(); 55 76 foreach (var category in categories) { 56 77 ListViewGroup group = new ListViewGroup(category.Key); 57 item sListView.Groups.Add(group);78 itemGroupsList.Add(group); 58 79 foreach (var creatable in category) { 59 80 IItem i = (IItem)Activator.CreateInstance(creatable); 60 81 items.Add(i); 61 82 ListViewItem item = new ListViewItem(new string[] { i.ItemName, i.ItemVersion.ToString(), i.ItemDescription }, group); 62 itemsListView.SmallImageList.Images.Add(i.ItemImage); 63 item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1; 83 item.ImageIndex = count; 64 84 item.Tag = i; 65 itemsListView.Items.Add(item); 85 itemsArray[count] = item; 86 smallImagesArray[count] = i.ItemImage; 87 count++; 88 Task.Factory.StartNew(() => { 89 loadingProgressBar.Value = (int)Math.Round(loadingProgressBar.Minimum + (loadingProgressBar.Maximum - loadingProgressBar.Minimum) * (double)count / creatableTypes.Length); 90 }, Task.Factory.CancellationToken, TaskCreationOptions.None, context); 66 91 } 67 92 } 68 for (int i = 0; i < itemsListView.Columns.Count; i++) 69 itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 93 Task.Factory.StartNew(() => { 94 itemsListView.SmallImageList.Images.AddRange(smallImagesArray); 95 itemsListView.Groups.AddRange(itemGroupsList.ToArray()); 96 itemsListView.Items.AddRange(itemsArray); 97 for (int i = 0; i < itemsListView.Columns.Count; i++) 98 itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 99 }, Task.Factory.CancellationToken, TaskCreationOptions.None, context); 70 100 initialized = true; 71 101 } 72 102 } 73 103 74 private void NewItemDialog_Shown(object sender, EventArgs e) { 75 item = null; 104 private void PrepareUI(Task t) { 105 SetEnabledStateOfControls(); 106 loadingPanel.Visible = false; 107 } 108 109 private void SetEnabledStateOfControls() { 110 itemsListView.Enabled = initialized; 111 okButton.Enabled = initialized; 112 cancelButton.Enabled = initialized; 76 113 } 77 114
Note: See TracChangeset
for help on using the changeset viewer.