Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11451


Ignore:
Timestamp:
10/12/14 00:49:59 (10 years ago)
Author:
swagner
Message:

#2205: Worked on optimization networks

Location:
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/EntitySelector.Designer.cs

    r11449 r11451  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.treeView = new System.Windows.Forms.TreeView();
     47      this.components = new System.ComponentModel.Container();
     48      this.entitiesTreeView = new System.Windows.Forms.TreeView();
     49      this.entitiesGroupBox = new System.Windows.Forms.GroupBox();
     50      this.imageList = new System.Windows.Forms.ImageList(this.components);
     51      this.entitiesGroupBox.SuspendLayout();
    4852      this.SuspendLayout();
    4953      //
    50       // treeView
     54      // entitiesTreeView
    5155      //
    52       this.treeView.Dock = System.Windows.Forms.DockStyle.Fill;
    53       this.treeView.Location = new System.Drawing.Point(0, 0);
    54       this.treeView.Name = "treeView";
    55       this.treeView.Size = new System.Drawing.Size(345, 288);
    56       this.treeView.TabIndex = 0;
    57       this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
     56      this.entitiesTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     57            | System.Windows.Forms.AnchorStyles.Left)
     58            | System.Windows.Forms.AnchorStyles.Right)));
     59      this.entitiesTreeView.HideSelection = false;
     60      this.entitiesTreeView.ImageIndex = 0;
     61      this.entitiesTreeView.ImageList = this.imageList;
     62      this.entitiesTreeView.Location = new System.Drawing.Point(6, 19);
     63      this.entitiesTreeView.Name = "entitiesTreeView";
     64      this.entitiesTreeView.SelectedImageIndex = 0;
     65      this.entitiesTreeView.ShowNodeToolTips = true;
     66      this.entitiesTreeView.Size = new System.Drawing.Size(333, 263);
     67      this.entitiesTreeView.TabIndex = 0;
     68      this.entitiesTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.entitiesTreeView_AfterSelect);
     69      //
     70      // entitiesGroupBox
     71      //
     72      this.entitiesGroupBox.Controls.Add(this.entitiesTreeView);
     73      this.entitiesGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     74      this.entitiesGroupBox.Location = new System.Drawing.Point(0, 0);
     75      this.entitiesGroupBox.Name = "entitiesGroupBox";
     76      this.entitiesGroupBox.Size = new System.Drawing.Size(345, 288);
     77      this.entitiesGroupBox.TabIndex = 0;
     78      this.entitiesGroupBox.TabStop = false;
     79      this.entitiesGroupBox.Text = "Network Entities";
     80      //
     81      // imageList
     82      //
     83      this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
     84      this.imageList.ImageSize = new System.Drawing.Size(16, 16);
     85      this.imageList.TransparentColor = System.Drawing.Color.Transparent;
    5886      //
    5987      // EntitySelector
     
    6189      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    6290      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    63       this.Controls.Add(this.treeView);
     91      this.Controls.Add(this.entitiesGroupBox);
    6492      this.Name = "EntitySelector";
    6593      this.Size = new System.Drawing.Size(345, 288);
     94      this.entitiesGroupBox.ResumeLayout(false);
    6695      this.ResumeLayout(false);
    6796
     
    7099    #endregion
    71100
    72     private System.Windows.Forms.TreeView treeView;
     101    protected System.Windows.Forms.GroupBox entitiesGroupBox;
     102    protected System.Windows.Forms.TreeView entitiesTreeView;
     103    protected System.Windows.Forms.ImageList imageList;
     104
    73105  }
    74106}
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/EntitySelector.cs

    r11449 r11451  
    2222using System;
    2323using System.Windows.Forms;
     24using HeuristicLab.Common;
    2425
    2526namespace HeuristicLab.Optimization.Networks.Views {
    2627  public partial class EntitySelector : UserControl {
    27     private IEntity root;
     28    protected Func<IEntity, bool> entityCondition;
     29    protected IEntity root;
    2830    public IEntity Root {
    2931      get { return root; }
     32    }
     33    public string Caption {
     34      get { return entitiesGroupBox.Text; }
    3035      set {
    31         root = value;
    32         PopulateTreeView();
     36        if (InvokeRequired)
     37          Invoke(new Action<string>(s => { Caption = s; }), value);
     38        else
     39          entitiesGroupBox.Text = value;
    3340      }
    3441    }
    35     private IEntity selectedEntity;
     42    public TreeView EntitiesTreeView {
     43      get { return entitiesTreeView; }
     44    }
     45    protected IEntity selectedEntity;
    3646    public IEntity SelectedEntity {
    3747      get {
    3848        return selectedEntity;
    3949      }
    40       private set {
     50      protected set {
    4151        if (selectedEntity != value) {
    4252          selectedEntity = value;
     
    4555      }
    4656    }
    47     public TreeView EntitiesTreeView {
    48       get { return treeView; }
    49     }
    5057
    5158    public EntitySelector() {
    5259      InitializeComponent();
     60      root = null;
     61      entityCondition = null;
     62      selectedEntity = null;
    5363    }
    54     public EntitySelector(IEntity root) : this() {
    55       Root = root;
     64
     65    public virtual void Configure(IEntity root) {
     66      Configure(root, null, (e) => true);
     67    }
     68    public virtual void Configure(IEntity root, IEntity selectedEntity) {
     69      Configure(root, selectedEntity, (e) => true);
     70    }
     71    public virtual void Configure(IEntity root, IEntity selectedEntity, Type entityType) {
     72      Configure(root, selectedEntity, (e) => { return entityType.IsAssignableFrom(e.GetType()); });
     73    }
     74    public virtual void Configure(IEntity root, IEntity selectedEntity, Func<IEntity, bool> entityCondition) {
     75      if (root == null) throw new ArgumentNullException("root");
     76      if (entityCondition == null) throw new ArgumentNullException("entityCondition");
     77      if (InvokeRequired)
     78        Invoke(new Action<IEntity, IEntity, Func<IEntity, bool>>(Configure), root, selectedEntity, entityCondition);
     79      else {
     80        this.root = root;
     81        this.entityCondition = entityCondition;
     82        this.selectedEntity = null;
     83        entitiesTreeView.Nodes.Clear();
     84        imageList.Images.Clear();
     85
     86        TreeNode selectedNode;
     87        var n = CreateTreeNode(Root, selectedEntity, entityCondition, out selectedNode);
     88        if (n != null)
     89          entitiesTreeView.Nodes.Add(n);
     90        if (selectedNode != null) {
     91          entitiesTreeView.SelectedNode = selectedNode;
     92          selectedNode.EnsureVisible();
     93        }
     94      }
    5695    }
    5796
     
    62101    }
    63102
    64 
    65     private void PopulateTreeView() {
    66       treeView.Nodes.Clear();
    67       treeView.Nodes.Add(CreateTreeNode(Root));
    68     }
    69     private TreeNode CreateTreeNode(IEntity entity) {
    70       if (entity == null)
    71         return new TreeNode("null");
     103    #region Control Events
     104    protected virtual void entitiesTreeView_AfterSelect(object sender, TreeViewEventArgs e) {
     105      if (entitiesTreeView.SelectedNode == null)
     106        SelectedEntity = null;
    72107      else {
    73         TreeNode node = new TreeNode(entity.Name);
    74         node.Tag = entity;
    75         foreach (var child in entity.Children)
    76           node.Nodes.Add(CreateTreeNode(child));
    77         return node;
     108        var selected = (IEntity)entitiesTreeView.SelectedNode.Tag;
     109        SelectedEntity = ((entityCondition != null) && !entityCondition(selected)) ? null : selected;
    78110      }
    79111    }
     112    #endregion
    80113
    81     private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
    82       if (treeView.SelectedNode != null)
    83         SelectedEntity = (IEntity)treeView.SelectedNode.Tag;
    84       else
    85         SelectedEntity = null;
     114    #region Helpers
     115    protected virtual TreeNode CreateTreeNode(IEntity entity, IEntity selectedEntity, Func<IEntity, bool> entityCondition, out TreeNode selectedNode) {
     116      selectedNode = null;
     117      if (entity == null) return null;
     118
     119      TreeNode node = new TreeNode(entity.Name);
     120      node.Tag = entity;
     121      foreach (var child in entity.Children) {
     122        TreeNode selected;
     123        var n = CreateTreeNode(child, selectedEntity, entityCondition, out selected);
     124        if (n != null) {
     125          node.Nodes.Add(n);
     126          if (selected != null) selectedNode = selected;
     127        }
     128
     129      }
     130      if (!entityCondition(entity) && (node.Nodes.Count == 0))
     131        return null;
     132
     133      imageList.Images.Add(entity.ItemImage);
     134      node.ImageIndex = imageList.Images.Count - 1;
     135      node.SelectedImageIndex = node.ImageIndex;
     136      node.ToolTipText = entity.GetType().GetPrettyName();
     137
     138      if (entity == selectedEntity) selectedNode = node;
     139      return node;
    86140    }
     141    #endregion
    87142  }
    88143}
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/EntitySelectorDialog.Designer.cs

    r11449 r11451  
    7777            | System.Windows.Forms.AnchorStyles.Left)
    7878            | System.Windows.Forms.AnchorStyles.Right)));
     79      this.entitySelector.Caption = "Network Entities";
    7980      this.entitySelector.Location = new System.Drawing.Point(12, 12);
    8081      this.entitySelector.Name = "entitySelector";
    81       this.entitySelector.Root = null;
    8282      this.entitySelector.Size = new System.Drawing.Size(464, 391);
    8383      this.entitySelector.TabIndex = 1;
     
    102102      this.Text = "Select Entity";
    103103      this.Load += new System.EventHandler(this.EntitySelectorDialog_Load);
     104      this.Shown += new System.EventHandler(this.EntitySelectorDialog_Shown);
    104105      this.ResumeLayout(false);
    105106
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/EntitySelectorDialog.cs

    r11449 r11451  
    4545      this.entitySelector.EntitiesTreeView.DoubleClick += new System.EventHandler(EntitiesTreeView_DoubleClick);
    4646    }
     47    protected virtual void EntitySelectorDialog_Shown(object sender, EventArgs e) {
     48      okButton.Enabled = entitySelector.SelectedEntity != null;
     49    }
    4750    protected virtual void entitySelector_SelectedEntityChanged(object sender, EventArgs e) {
    4851      okButton.Enabled = entitySelector.SelectedEntity != null;
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/InputPortView.cs

    r11449 r11451  
    2121
    2222using HeuristicLab.MainForm;
     23using HeuristicLab.PluginInfrastructure;
    2324using System;
    2425using System.Windows.Forms;
     
    8384        entitySelectorDialog = new EntitySelectorDialog();
    8485        entitySelectorDialog.Caption = "Select Output Port";
     86        entitySelectorDialog.EntitySelector.Caption = "Available Output Ports";
    8587      }
    8688
    87       IEntity root = Content;
    88       while (root.Parent != null)
    89         root = root.Parent;
    90       entitySelectorDialog.EntitySelector.Root = root;
     89      try {
     90        IEntity root = Content;
     91        while (root.Parent != null)
     92          root = root.Parent;
     93        entitySelectorDialog.EntitySelector.Configure(
     94          root,
     95          Content.OutputPort,
     96          typeof(IOutputPort<>).MakeGenericType(Content.GetType().GetGenericArguments()[0])
     97        );
    9198
    92       if (entitySelectorDialog.ShowDialog(this) == DialogResult.OK) {
    93         Content.OutputPort = entitySelectorDialog.EntitySelector.SelectedEntity as IOutputPort;
     99        if (entitySelectorDialog.ShowDialog(this) == DialogResult.OK) {
     100          Content.OutputPort = entitySelectorDialog.EntitySelector.SelectedEntity as IOutputPort;
     101        }
     102      }
     103      catch (Exception ex) {
     104        ErrorHandling.ShowErrorDialog(this, ex);
    94105      }
    95106    }
     
    100111    protected virtual void outputPortView_DragEnterOver(object sender, DragEventArgs e) {
    101112      e.Effect = DragDropEffects.None;
    102       if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IOutputPort)) {
     113      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     114      var type = typeof(IOutputPort<>).MakeGenericType(Content.GetType().GetGenericArguments()[0]);
     115
     116      if (!ReadOnly && (type.IsAssignableFrom(data.GetType()))) {
    103117        e.Effect = DragDropEffects.Link;
    104118      }
Note: See TracChangeset for help on using the changeset viewer.