Changeset 11451
- Timestamp:
- 10/12/14 00:49:59 (10 years ago)
- 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 45 45 /// </summary> 46 46 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(); 48 52 this.SuspendLayout(); 49 53 // 50 // treeView54 // entitiesTreeView 51 55 // 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; 58 86 // 59 87 // EntitySelector … … 61 89 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 62 90 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 63 this.Controls.Add(this. treeView);91 this.Controls.Add(this.entitiesGroupBox); 64 92 this.Name = "EntitySelector"; 65 93 this.Size = new System.Drawing.Size(345, 288); 94 this.entitiesGroupBox.ResumeLayout(false); 66 95 this.ResumeLayout(false); 67 96 … … 70 99 #endregion 71 100 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 73 105 } 74 106 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/EntitySelector.cs
r11449 r11451 22 22 using System; 23 23 using System.Windows.Forms; 24 using HeuristicLab.Common; 24 25 25 26 namespace HeuristicLab.Optimization.Networks.Views { 26 27 public partial class EntitySelector : UserControl { 27 private IEntity root; 28 protected Func<IEntity, bool> entityCondition; 29 protected IEntity root; 28 30 public IEntity Root { 29 31 get { return root; } 32 } 33 public string Caption { 34 get { return entitiesGroupBox.Text; } 30 35 set { 31 root = value; 32 PopulateTreeView(); 36 if (InvokeRequired) 37 Invoke(new Action<string>(s => { Caption = s; }), value); 38 else 39 entitiesGroupBox.Text = value; 33 40 } 34 41 } 35 private IEntity selectedEntity; 42 public TreeView EntitiesTreeView { 43 get { return entitiesTreeView; } 44 } 45 protected IEntity selectedEntity; 36 46 public IEntity SelectedEntity { 37 47 get { 38 48 return selectedEntity; 39 49 } 40 pr ivateset {50 protected set { 41 51 if (selectedEntity != value) { 42 52 selectedEntity = value; … … 45 55 } 46 56 } 47 public TreeView EntitiesTreeView {48 get { return treeView; }49 }50 57 51 58 public EntitySelector() { 52 59 InitializeComponent(); 60 root = null; 61 entityCondition = null; 62 selectedEntity = null; 53 63 } 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 } 56 95 } 57 96 … … 62 101 } 63 102 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; 72 107 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; 78 110 } 79 111 } 112 #endregion 80 113 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; 86 140 } 141 #endregion 87 142 } 88 143 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/EntitySelectorDialog.Designer.cs
r11449 r11451 77 77 | System.Windows.Forms.AnchorStyles.Left) 78 78 | System.Windows.Forms.AnchorStyles.Right))); 79 this.entitySelector.Caption = "Network Entities"; 79 80 this.entitySelector.Location = new System.Drawing.Point(12, 12); 80 81 this.entitySelector.Name = "entitySelector"; 81 this.entitySelector.Root = null;82 82 this.entitySelector.Size = new System.Drawing.Size(464, 391); 83 83 this.entitySelector.TabIndex = 1; … … 102 102 this.Text = "Select Entity"; 103 103 this.Load += new System.EventHandler(this.EntitySelectorDialog_Load); 104 this.Shown += new System.EventHandler(this.EntitySelectorDialog_Shown); 104 105 this.ResumeLayout(false); 105 106 -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/EntitySelectorDialog.cs
r11449 r11451 45 45 this.entitySelector.EntitiesTreeView.DoubleClick += new System.EventHandler(EntitiesTreeView_DoubleClick); 46 46 } 47 protected virtual void EntitySelectorDialog_Shown(object sender, EventArgs e) { 48 okButton.Enabled = entitySelector.SelectedEntity != null; 49 } 47 50 protected virtual void entitySelector_SelectedEntityChanged(object sender, EventArgs e) { 48 51 okButton.Enabled = entitySelector.SelectedEntity != null; -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/InputPortView.cs
r11449 r11451 21 21 22 22 using HeuristicLab.MainForm; 23 using HeuristicLab.PluginInfrastructure; 23 24 using System; 24 25 using System.Windows.Forms; … … 83 84 entitySelectorDialog = new EntitySelectorDialog(); 84 85 entitySelectorDialog.Caption = "Select Output Port"; 86 entitySelectorDialog.EntitySelector.Caption = "Available Output Ports"; 85 87 } 86 88 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 ); 91 98 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); 94 105 } 95 106 } … … 100 111 protected virtual void outputPortView_DragEnterOver(object sender, DragEventArgs e) { 101 112 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()))) { 103 117 e.Effect = DragDropEffects.Link; 104 118 }
Note: See TracChangeset
for help on using the changeset viewer.