Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6529


Ignore:
Timestamp:
07/07/11 10:55:11 (13 years ago)
Author:
mkommend
Message:

#1555: Corrected drag & drop in ExperimentTreeView.

File:
1 edited

Legend:

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

    r6526 r6529  
    435435      TreeNode selectedNode = (TreeNode)e.Item;
    436436      var item = (IItem)selectedNode.Tag;
     437      if (item == null) return;
     438
    437439      DataObject data = new DataObject();
    438440      data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, item);
     
    462464      validDragOperation = false;
    463465      if (!ReadOnly) {
    464         if ((e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IOptimizer)) validDragOperation = true;
    465         else if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable) {
     466        var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     467        if (data is IOptimizer) validDragOperation = true;
     468        else if (data is IProblem) validDragOperation = true;
     469        else if (data is IEnumerable) {
     470          IEnumerable items = (IEnumerable)data;
    466471          validDragOperation = true;
    467           IEnumerable items = (IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    468472          foreach (object item in items)
    469473            validDragOperation = validDragOperation && (item is IOptimizer);
     
    473477    private void optimizerTreeView_DragOver(object sender, DragEventArgs e) {
    474478      e.Effect = DragDropEffects.None;
    475       if (validDragOperation) {
    476         Point coordinates = treeView.PointToClient(new Point(e.X, e.Y));
    477         TreeNode node = treeView.GetNodeAt(coordinates);
    478         Experiment experiment = null;
    479         BatchRun batchRun = null;
    480 
    481         if (node == null) experiment = Content;
    482         else {
    483           experiment = node.Tag as Experiment;
    484           batchRun = node.Tag as BatchRun;
    485         }
    486 
    487         if (batchRun == null && experiment == null) return;
    488         if (batchRun != null) {
    489           var optimizer = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IOptimizer;
    490           if (optimizer == null) return;
    491           if (batchRun.Optimizer != null) return;
    492           if (optimizer.NestedOptimizers.Contains(batchRun)) return;
    493         }
    494 
    495         //do not allow recursive nesting of contents
    496         if (experiment != null) {
    497           var optimizer = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IOptimizer;
    498           IEnumerable<IOptimizer> optimizers = null;
    499           var enumerable = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IEnumerable;
    500           if (enumerable != null) optimizers = enumerable.Cast<IOptimizer>();
    501 
    502           if (optimizer != null && optimizer.NestedOptimizers.Contains(experiment)) return;
    503           if (optimizers != null && optimizers.Any(x => x.NestedOptimizers.Contains(experiment))) return;
    504         }
    505 
    506         if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    507         else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
    508         else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
    509         else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
    510         else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
    511       }
    512     }
    513     private void optimizerTreeView_DragDrop(object sender, DragEventArgs e) {
     479      if (!validDragOperation) return;
    514480      Point coordinates = treeView.PointToClient(new Point(e.X, e.Y));
    515481      TreeNode node = treeView.GetNodeAt(coordinates);
    516482      Experiment experiment = null;
    517483      BatchRun batchRun = null;
     484      Algorithm algorithm = null;
    518485
    519486      if (node == null) experiment = Content;
     
    521488        experiment = node.Tag as Experiment;
    522489        batchRun = node.Tag as BatchRun;
    523       }
    524 
    525       if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IOptimizer) {
    526         IOptimizer optimizer = (IOptimizer)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     490        algorithm = node.Tag as Algorithm;
     491      }
     492
     493      if (batchRun == null && experiment == null && algorithm == null) return;
     494
     495      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     496
     497      if (algorithm != null) {
     498        var problem = data as IProblem;
     499        if (problem == null) return;
     500        if (!algorithm.ProblemType.IsAssignableFrom(problem.GetType())) return;
     501      } else if (batchRun != null) {
     502        var optimizer = data as IOptimizer;
     503        if (optimizer == null) return;
     504        if (batchRun == optimizer) return;
     505        if (optimizer.NestedOptimizers.Contains(batchRun)) return;
     506      } //do not allow recursive nesting of contents
     507      else if (experiment != null) {
     508        var optimizer = data as IOptimizer;
     509        IEnumerable<IOptimizer> optimizers = null;
     510        var enumerable = data as IEnumerable;
     511        if (enumerable != null) optimizers = enumerable.Cast<IOptimizer>();
     512        if (experiment == optimizer) return;
     513        if (optimizer != null && optimizer.NestedOptimizers.Contains(experiment)) return;
     514        if (optimizers != null && optimizers.Any(x => x.NestedOptimizers.Contains(experiment))) return;
     515      }
     516
     517      if ((e.KeyState & 32) == 32 && e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;  // ALT key
     518      else if ((e.KeyState & 4) == 4 && e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;  // SHIFT key
     519      else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     520      else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
     521      else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
     522    }
     523
     524    private void optimizerTreeView_DragDrop(object sender, DragEventArgs e) {
     525      Point coordinates = treeView.PointToClient(new Point(e.X, e.Y));
     526      TreeNode node = treeView.GetNodeAt(coordinates);
     527      Algorithm algorithm = null;
     528      BatchRun batchRun = null;
     529      Experiment experiment = null;
     530
     531      if (node == null) experiment = Content;
     532      else {
     533        algorithm = node.Tag as Algorithm;
     534        batchRun = node.Tag as BatchRun;
     535        experiment = node.Tag as Experiment;
     536      }
     537
     538      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     539      if (data is IProblem) {
     540        var problem = (IProblem)data;
     541        if (e.Effect.HasFlag(DragDropEffects.Copy)) problem = (IProblem)problem.Clone();
     542        algorithm.Problem = problem;
     543      } else if (data is IOptimizer) {
     544        IOptimizer optimizer = (IOptimizer)data;
    527545        if (e.Effect.HasFlag(DragDropEffects.Copy)) optimizer = (IOptimizer)optimizer.Clone();
    528546        if (batchRun != null) batchRun.Optimizer = optimizer;
    529547        else if (experiment != null) experiment.Optimizers.Add(optimizer);
    530548        else throw new NotSupportedException("Handling for specific type not implemented" + node.Tag.GetType());
    531       } else if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable) {
    532         IEnumerable<IOptimizer> optimizers = ((IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat)).Cast<IOptimizer>();
     549      } else if (data is IEnumerable) {
     550        IEnumerable<IOptimizer> optimizers = ((IEnumerable)data).Cast<IOptimizer>();
    533551        if (e.Effect.HasFlag(DragDropEffects.Copy)) {
    534552          Cloner cloner = new Cloner();
    535           optimizers = optimizers.Select(o => (IOptimizer)o.Clone(cloner));
     553          optimizers = optimizers.Select(o => cloner.Clone(o));
    536554        }
    537555        if (experiment != null) experiment.Optimizers.AddRange(optimizers);
Note: See TracChangeset for help on using the changeset viewer.