- Timestamp:
- 11/21/10 18:19:39 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs
r4300 r4883 35 35 [Content(typeof(RunCollection), true)] 36 36 [Content(typeof(IItemCollection<IRun>), false)] 37 public partial class RunCollectionView : ItemView { 37 public sealed partial class RunCollectionView : ItemView { 38 private Dictionary<IRun, List<ListViewItem>> runListViewItemMapping; 39 38 40 public new IItemCollection<IRun> Content { 39 41 get { return (IItemCollection<IRun>)base.Content; } … … 52 54 InitializeComponent(); 53 55 itemsGroupBox.Text = "Runs"; 56 runListViewItemMapping = new Dictionary<IRun, List<ListViewItem>>(); 54 57 } 55 58 … … 68 71 RegisterRunEvents(Content); 69 72 } 70 pr otected virtualvoid RegisterRunEvents(IEnumerable<IRun> runs) {73 private void RegisterRunEvents(IEnumerable<IRun> runs) { 71 74 foreach (IRun run in runs) 72 75 run.Changed += new EventHandler(Run_Changed); 73 76 } 74 pr otected virtualvoid DeregisterRunEvents(IEnumerable<IRun> runs) {77 private void DeregisterRunEvents(IEnumerable<IRun> runs) { 75 78 foreach (IRun run in runs) 76 79 run.Changed -= new EventHandler(Run_Changed); … … 143 146 } 144 147 145 pr otected virtualListViewItem CreateListViewItem(IRun item) {148 private ListViewItem CreateListViewItem(IRun item) { 146 149 ListViewItem listViewItem = new ListViewItem(); 147 150 listViewItem.Text = item.ToString(); … … 160 163 return listViewItem; 161 164 } 162 pr otected virtualvoid AddListViewItem(ListViewItem listViewItem) {165 private void AddListViewItem(ListViewItem listViewItem) { 163 166 itemsListView.Items.Add(listViewItem); 164 ((IRun)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged); 165 ((IRun)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged); 166 } 167 protected virtual void RemoveListViewItem(ListViewItem listViewItem) { 168 ((IRun)listViewItem.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged); 169 ((IRun)listViewItem.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged); 167 IRun run = listViewItem.Tag as IRun; 168 if (run != null) { 169 if (!runListViewItemMapping.ContainsKey(run)) 170 runListViewItemMapping.Add(run, new List<ListViewItem>()); 171 runListViewItemMapping[run].Add(listViewItem); 172 run.ItemImageChanged += new EventHandler(Item_ItemImageChanged); 173 run.ToStringChanged += new EventHandler(Item_ToStringChanged); 174 } 175 } 176 private void RemoveListViewItem(ListViewItem listViewItem) { 177 IRun run = listViewItem.Tag as IRun; 178 if (run != null) { 179 runListViewItemMapping[run].Remove(listViewItem); 180 if (runListViewItemMapping[run].Count == 0) { 181 runListViewItemMapping.Remove(run); 182 run.ItemImageChanged -= new EventHandler(Item_ItemImageChanged); 183 run.ToStringChanged -= new EventHandler(Item_ToStringChanged); 184 } 185 } 170 186 listViewItem.Remove(); 171 187 foreach (ListViewItem other in itemsListView.Items) … … 173 189 itemsListView.SmallImageList.Images.RemoveAt(listViewItem.ImageIndex); 174 190 } 175 pr otected virtualvoid UpdateListViewItemImage(ListViewItem listViewItem) {191 private void UpdateListViewItemImage(ListViewItem listViewItem) { 176 192 int i = listViewItem.ImageIndex; 177 193 listViewItem.ImageList.Images[i] = ((IRun)listViewItem.Tag).ItemImage; … … 179 195 listViewItem.ImageIndex = i; 180 196 } 181 pr otected virtualvoid UpdateListViewItemText(ListViewItem listViewItem) {197 private void UpdateListViewItemText(ListViewItem listViewItem) { 182 198 if (!listViewItem.Text.Equals(listViewItem.Tag.ToString())) 183 199 listViewItem.Text = listViewItem.Tag.ToString(); 184 200 } 185 protected virtual IEnumerable<ListViewItem> GetListViewItemsForItem(IRun item) { 186 foreach (ListViewItem listViewItem in itemsListView.Items) { 187 if (((IRun)listViewItem.Tag) == item) 188 yield return listViewItem; 189 } 201 private IEnumerable<ListViewItem> GetListViewItemsForItem(IRun run) { 202 return runListViewItemMapping[run]; 190 203 } 191 204 192 205 #region ListView Events 193 pr otected virtualvoid itemsListView_SelectedIndexChanged(object sender, EventArgs e) {206 private void itemsListView_SelectedIndexChanged(object sender, EventArgs e) { 194 207 removeButton.Enabled = itemsListView.SelectedItems.Count > 0 && (Content != null) && !Content.IsReadOnly && !ReadOnly; 195 208 AdjustListViewColumnSizes(); … … 205 218 } 206 219 } 207 pr otected virtualvoid itemsListView_KeyDown(object sender, KeyEventArgs e) {220 private void itemsListView_KeyDown(object sender, KeyEventArgs e) { 208 221 if (e.KeyCode == Keys.Delete) { 209 222 if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly && !ReadOnly) { … … 213 226 } 214 227 } 215 pr otected virtualvoid itemsListView_DoubleClick(object sender, EventArgs e) {228 private void itemsListView_DoubleClick(object sender, EventArgs e) { 216 229 if (itemsListView.SelectedItems.Count == 1) { 217 230 IRun item = (IRun)itemsListView.SelectedItems[0].Tag; … … 223 236 } 224 237 } 225 pr otected virtualvoid itemsListView_ItemDrag(object sender, ItemDragEventArgs e) {238 private void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) { 226 239 if (!Locked) { 227 240 ListViewItem listViewItem = (ListViewItem)e.Item; … … 239 252 } 240 253 } 241 pr otected virtualvoid itemsListView_DragEnterOver(object sender, DragEventArgs e) {254 private void itemsListView_DragEnterOver(object sender, DragEventArgs e) { 242 255 e.Effect = DragDropEffects.None; 243 256 Type type = e.Data.GetData("Type") as Type; … … 250 263 } 251 264 } 252 pr otected virtualvoid itemsListView_DragDrop(object sender, DragEventArgs e) {265 private void itemsListView_DragDrop(object sender, DragEventArgs e) { 253 266 if (e.Effect != DragDropEffects.None) { 254 267 IRun item = e.Data.GetData("Value") as IRun; … … 260 273 261 274 #region Button Events 262 pr otected virtualvoid menuItem_Click(object sender, EventArgs e) {275 private void menuItem_Click(object sender, EventArgs e) { 263 276 ToolStripMenuItem menuItem = (ToolStripMenuItem)sender; 264 277 Type viewType = (Type)menuItem.Tag; … … 269 282 } 270 283 } 271 pr otected virtualvoid removeButton_Click(object sender, EventArgs e) {284 private void removeButton_Click(object sender, EventArgs e) { 272 285 if (itemsListView.SelectedItems.Count > 0) { 273 286 foreach (ListViewItem item in itemsListView.SelectedItems) … … 276 289 } 277 290 } 278 pr otected virtualvoid clearButton_Click(object sender, EventArgs e) {291 private void clearButton_Click(object sender, EventArgs e) { 279 292 Content.Clear(); 280 293 } … … 282 295 283 296 #region CheckBox Events 284 pr otected virtualvoid showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {297 private void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) { 285 298 if (showDetailsCheckBox.Checked) { 286 299 splitContainer.Panel2Collapsed = false; … … 295 308 296 309 #region Content Events 297 pr otected virtualvoid Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {310 private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) { 298 311 if (InvokeRequired) 299 312 Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded), sender, e); … … 309 322 } 310 323 } 311 pr otected virtualvoid Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {324 private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) { 312 325 if (InvokeRequired) 313 326 Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved), sender, e); … … 316 329 foreach (IRun item in e.Items) { 317 330 //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection 318 ListViewItem listviewItem = GetListViewItemsForItem(item).FirstOrDefault(); 319 if (listviewItem != null) 320 RemoveListViewItem(listviewItem); 331 ListViewItem listViewItem = GetListViewItemsForItem(item).FirstOrDefault(); 332 if (listViewItem != null) RemoveListViewItem(listViewItem); 321 333 } 322 334 analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0; … … 325 337 } 326 338 } 327 pr otected virtualvoid Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {339 private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 328 340 if (InvokeRequired) 329 341 Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset), sender, e); … … 331 343 DeregisterRunEvents(e.OldItems); 332 344 foreach (IRun item in e.OldItems) { 333 //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection 334 ListViewItem listviewItem = GetListViewItemsForItem(item).FirstOrDefault(); 335 if (listviewItem != null) 336 RemoveListViewItem(listviewItem); 345 ListViewItem listViewItem = GetListViewItemsForItem(item).FirstOrDefault(); 346 if (listViewItem != null) RemoveListViewItem(listViewItem); 337 347 } 338 348 RegisterRunEvents(e.Items); … … 349 359 350 360 #region Item Events 351 pr otected virtualvoid Item_ItemImageChanged(object sender, EventArgs e) {361 private void Item_ItemImageChanged(object sender, EventArgs e) { 352 362 if (InvokeRequired) 353 363 Invoke(new EventHandler(Item_ItemImageChanged), sender, e); … … 358 368 } 359 369 } 360 pr otected virtualvoid Item_ToStringChanged(object sender, EventArgs e) {370 private void Item_ToStringChanged(object sender, EventArgs e) { 361 371 if (InvokeRequired) 362 372 Invoke(new EventHandler(Item_ToStringChanged), sender, e); … … 368 378 } 369 379 } 370 pr otected virtualvoid Run_Changed(object sender, EventArgs e) {380 private void Run_Changed(object sender, EventArgs e) { 371 381 if (InvokeRequired) 372 382 this.Invoke(new EventHandler(Run_Changed), sender, e); … … 377 387 } 378 388 379 pr otected virtualvoid UpdateRun(IRun run) {389 private void UpdateRun(IRun run) { 380 390 foreach (ListViewItem listViewItem in GetListViewItemsForItem(run)) { 381 391 if (run.Visible) { … … 391 401 392 402 #region Helpers 393 pr otected virtualvoid AdjustListViewColumnSizes() {403 private void AdjustListViewColumnSizes() { 394 404 if (itemsListView.Items.Count > 0) { 395 405 for (int i = 0; i < itemsListView.Columns.Count; i++) {
Note: See TracChangeset
for help on using the changeset viewer.