Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/18/11 01:38:23 (13 years ago)
Author:
swagner
Message:

Implemented dragging of multiple items in all collection views and refactored drag & drop code (#1112)

Location:
trunk/sources/HeuristicLab.Optimization.Views/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r5445 r5744  
    278278    protected virtual void problemTabPage_DragEnterOver(object sender, DragEventArgs e) {
    279279      e.Effect = DragDropEffects.None;
    280       Type type = e.Data.GetData("Type") as Type;
    281       if ((type != null) && (Content.ProblemType.IsAssignableFrom(type))) {
     280      if (!ReadOnly && (e.Data.GetData("HeuristicLab") != null) && Content.ProblemType.IsAssignableFrom(e.Data.GetData("HeuristicLab").GetType())) {
    282281        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    283282        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    284         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    285         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    286         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     283        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     284        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     285        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    287286      }
    288287    }
    289288    protected virtual void problemTabPage_DragDrop(object sender, DragEventArgs e) {
    290289      if (e.Effect != DragDropEffects.None) {
    291         IProblem problem = e.Data.GetData("Value") as IProblem;
    292         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) problem = (IProblem)problem.Clone();
     290        IProblem problem = e.Data.GetData("HeuristicLab") as IProblem;
     291        if (e.Effect.HasFlag(DragDropEffects.Copy)) problem = (IProblem)problem.Clone();
    293292        Content.Problem = problem;
    294293      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.cs

    r5445 r5744  
    253253    private void optimizerTabPage_DragEnterOver(object sender, DragEventArgs e) {
    254254      e.Effect = DragDropEffects.None;
    255       if (ReadOnly)
    256         return;
    257       Type type = e.Data.GetData("Type") as Type;
    258       if ((type != null) && (typeof(IOptimizer).IsAssignableFrom(type))) {
     255      if (!ReadOnly && (e.Data.GetData("HeuristicLab") is IOptimizer)) {
    259256        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    260257        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    261         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    262         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    263         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     258        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     259        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     260        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    264261      }
    265262    }
    266263    private void optimizerTabPage_DragDrop(object sender, DragEventArgs e) {
    267264      if (e.Effect != DragDropEffects.None) {
    268         IOptimizer optimizer = e.Data.GetData("Value") as IOptimizer;
    269         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) optimizer = (IOptimizer)optimizer.Clone();
     265        IOptimizer optimizer = e.Data.GetData("HeuristicLab") as IOptimizer;
     266        if (e.Effect.HasFlag(DragDropEffects.Copy)) optimizer = (IOptimizer)optimizer.Clone();
    270267        Content.Optimizer = optimizer;
    271268      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.cs

    r5445 r5744  
    452452        if (this.draggedRun != null && h.ChartElementType != ChartElementType.DataPoint) {
    453453          DataObject data = new DataObject();
    454           data.SetData("Type", draggedRun.GetType());
    455           data.SetData("Value", draggedRun);
     454          data.SetData("HeuristicLab", draggedRun);
    456455          if (ReadOnly)
    457456            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.Designer.cs

    r5466 r5744  
    170170      this.itemsListView.SelectedIndexChanged += new System.EventHandler(this.itemsListView_SelectedIndexChanged);
    171171      this.itemsListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragDrop);
    172       this.itemsListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnterOver);
    173       this.itemsListView.DragOver += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnterOver);
     172      this.itemsListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragEnter);
     173      this.itemsListView.DragOver += new System.Windows.Forms.DragEventHandler(this.itemsListView_DragOver);
    174174      this.itemsListView.DoubleClick += new System.EventHandler(this.itemsListView_DoubleClick);
    175175      this.itemsListView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.itemsListView_KeyDown);
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r5702 r5744  
    2121
    2222using System;
     23using System.Collections;
    2324using System.Collections.Generic;
    2425using System.Drawing;
     
    3738  public sealed partial class RunCollectionView : ItemView {
    3839    private Dictionary<IRun, List<ListViewItem>> itemListViewItemMapping;
     40    private bool validDragOperation;
    3941
    4042    public new IItemCollection<IRun> Content {
     
    271273        if (items.Count > 0) {
    272274          DataObject data = new DataObject();
    273           if (items.Count == 1) {
    274             data.SetData("Type", items[0].GetType());
    275             data.SetData("Value", items[0]);
    276           } else {
    277             data.SetData("Type", typeof(IEnumerable<IRun>));
    278             data.SetData("Value", items);
    279           }
     275          if (items.Count == 1) data.SetData("HeuristicLab", items[0]);
     276          else data.SetData("HeuristicLab", items);
    280277          if (Content.IsReadOnly || ReadOnly) {
    281278            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    282279          } else {
    283280            DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    284             if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
     281            if (result.HasFlag(DragDropEffects.Move)) {
    285282              foreach (IRun item in items) Content.Remove(item);
    286283            }
     
    289286      }
    290287    }
    291     private void itemsListView_DragEnterOver(object sender, DragEventArgs e) {
     288    private void itemsListView_DragEnter(object sender, DragEventArgs e) {
     289      validDragOperation = false;
     290      if (e.Data.GetData("HeuristicLab") is IRun) {
     291        validDragOperation = true;
     292      } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     293        validDragOperation = true;
     294        IEnumerable items = (IEnumerable)e.Data.GetData("HeuristicLab");
     295        foreach (object item in items)
     296          validDragOperation = validDragOperation && (item is IRun);
     297      }
     298      validDragOperation = validDragOperation && !Content.IsReadOnly && !ReadOnly;
     299    }
     300    private void itemsListView_DragOver(object sender, DragEventArgs e) {
    292301      e.Effect = DragDropEffects.None;
    293       Type type = e.Data.GetData("Type") as Type;
    294       if (!Content.IsReadOnly && !ReadOnly && (type != null) && (typeof(IRun).IsAssignableFrom(type) || typeof(IEnumerable<IRun>).IsAssignableFrom(type))) {
     302      if (validDragOperation) {
    295303        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    296304        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    297         else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    298         else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
    299         else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
     305        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     306        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     307        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    300308      }
    301309    }
    302310    private void itemsListView_DragDrop(object sender, DragEventArgs e) {
    303311      if (e.Effect != DragDropEffects.None) {
    304         object value = e.Data.GetData("Value");
    305         IEnumerable<IRun> items = Enumerable.Empty<IRun>();
    306         if (value is IRun)
    307           items = new IRun[] { (IRun)value };
    308         else if (value is IEnumerable<IRun>)
    309           items = (IEnumerable<IRun>)value;
    310 
    311         foreach (IRun item in items) {
    312           if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) Content.Add((IRun)item.Clone());
    313           else Content.Add(item);
     312        if (e.Data.GetData("HeuristicLab") is IRun) {
     313          IRun item = (IRun)e.Data.GetData("HeuristicLab");
     314          Content.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (IRun)item.Clone() : item);
     315        } else if (e.Data.GetData("HeuristicLab") is IEnumerable) {
     316          IEnumerable<IRun> items = ((IEnumerable)e.Data.GetData("HeuristicLab")).Cast<IRun>();
     317          foreach (IRun item in items)
     318            Content.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (IRun)item.Clone() : item);
    314319        }
    315320      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunView.cs

    r5445 r5744  
    149149        if (item != null) {
    150150          DataObject data = new DataObject();
    151           data.SetData("Type", item.GetType());
    152           data.SetData("Value", item);
     151          data.SetData("HeuristicLab", item);
    153152          DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy);
    154153        }
Note: See TracChangeset for help on using the changeset viewer.