Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12513


Ignore:
Timestamp:
06/25/15 15:26:35 (9 years ago)
Author:
pfleck
Message:

#2366 Merged trunk changes.

Location:
branches/EnumValue in CreateExperiment/HeuristicLab.Optimizer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/EnumValue in CreateExperiment/HeuristicLab.Optimizer

  • branches/EnumValue in CreateExperiment/HeuristicLab.Optimizer/3.3/NewItemDialog.cs

    r12466 r12513  
    2626using System.Linq;
    2727using System.Windows.Forms;
     28using HeuristicLab.Common;
    2829using HeuristicLab.Core;
    2930using HeuristicLab.PluginInfrastructure;
     
    6364      if (isInitialized) return;
    6465
     66      // Sorted by hasOrdering to create category nodes first with concrete ordering.
     67      // Items with categoryname without ordering are inserted afterwards correctly
    6568      var categories =
    6669        from type in ApplicationManager.Manager.GetTypes(typeof(IItem))
     70        where CreatableAttribute.IsCreatable(type)
    6771        let category = CreatableAttribute.GetCategory(type)
     72        let hasOrdering = category.Contains(CreatableAttribute.Categories.OrderToken)
    6873        let name = ItemAttribute.GetName(type)
    6974        let priority = CreatableAttribute.GetPriority(type)
    7075        let version = ItemAttribute.GetVersion(type)
    71         where CreatableAttribute.IsCreatable(type)
    72         orderby category, priority, name, version ascending
     76        orderby category, hasOrdering descending, priority, name, version ascending
    7377        group type by category into categoryGroup
    7478        select categoryGroup;
     
    9498      var rootNode = new TreeNode();
    9599
     100      // CategoryNode
     101      // Tag: raw string, used for sorting, e.g. 1$$$Algorithms###2$$$Single Solution
     102      // Name: full name = combined category name with parent categories, used for finding nodes in tree, e.g. Algorithms###Single Solution
     103      // Text: category name, used for displaying on node itself, e.g. Single Solution
     104
    96105      foreach (var category in categories) {
    97         var fullName = category.Key;
    98         var tokens = fullName.Split('#');
    99         var name = tokens.Last();
    100         var parents = tokens.Take(tokens.Length - 1);
     106        var rawName = category.Key;
     107        string fullName = CreatableAttribute.Categories.GetFullName(rawName);
     108        string name = CreatableAttribute.Categories.GetName(rawName);
     109
     110        // Skip categories with same full name because the raw name can still be different (missing order)
     111        if (rootNode.Nodes.Find(fullName, searchAllChildren: true).Length > 0)
     112          continue;
    101113
    102114        var categoryNode = new TreeNode(name, imageIndex: 1, selectedImageIndex: 1) {
    103115          Name = fullName,
    104           Tag = fullName
     116          Tag = rawName
    105117        };
    106118
     119        var parents = CreatableAttribute.Categories.GetParentRawNames(rawName);
    107120        var parentNode = FindOrCreateParentNode(rootNode, parents);
    108121        if (parentNode != null)
     
    114127      return rootNode;
    115128    }
    116     private TreeNode FindOrCreateParentNode(TreeNode node, IEnumerable<string> parentCategories) {
     129    private TreeNode FindOrCreateParentNode(TreeNode node, IEnumerable<string> rawParentNames) {
    117130      TreeNode parentNode = null;
    118       string fullName = null;
    119       foreach (string parentCategory in parentCategories) {
    120         fullName = fullName == null ? parentCategory : fullName + "#" + parentCategory;
     131      string rawName = null;
     132      foreach (string rawParentName in rawParentNames) {
     133        rawName = rawName == null ? rawParentName : rawName + CreatableAttribute.Categories.SplitToken + rawParentName;
     134        var fullName = CreatableAttribute.Categories.GetFullName(rawName);
    121135        parentNode = node.Nodes.Find(fullName, searchAllChildren: false).SingleOrDefault();
    122136        if (parentNode == null) {
    123           parentNode = new TreeNode(parentCategory, imageIndex: 1, selectedImageIndex: 1) {
     137          var name = CreatableAttribute.Categories.GetName(rawName);
     138          parentNode = new TreeNode(name, imageIndex: 1, selectedImageIndex: 1) {
    124139            Name = fullName,
    125             Tag = fullName
     140            Tag = rawName
    126141          };
    127142          node.Nodes.Add(parentNode);
     
    133148    private void CreateItemNodes(TreeNode node, IEnumerable<IGrouping<string, Type>> categories) {
    134149      foreach (var category in categories) {
    135         var categoryNode = node.Nodes.Find(category.Key, searchAllChildren: true).Single();
     150        var fullName = CreatableAttribute.Categories.GetFullName(category.Key);
     151        var categoryNode = node.Nodes.Find(fullName, searchAllChildren: true).Single();
    136152        foreach (var creatable in category) {
    137153          var itemNode = CreateItemNode(creatable);
    138           itemNode.Name = itemNode.Name + ":" + category.Key;
     154          itemNode.Name = itemNode.Name + ":" + fullName;
    139155          categoryNode.Nodes.Add(itemNode);
    140156        }
     
    165181      SelectedType = null;
    166182      typesTreeView.SelectedNode = null;
    167       typesTreeView.CollapseAll();
    168183      UpdateDescription();
     184
     185      foreach (TreeNode node in typesTreeView.Nodes)
     186        node.Expand();
     187      typesTreeView.Nodes[0].EnsureVisible();
    169188    }
    170189
     
    253272
    254273      if (typesTreeView.SelectedNode != null) {
    255         string category = typesTreeView.SelectedNode.Tag as string;
     274        var node = typesTreeView.SelectedNode;
     275        string category = node.Tag as string;
    256276        if (category != null) {
    257           itemDescriptionTextBox.Text = category;
    258         }
    259         Type type = typesTreeView.SelectedNode.Tag as Type;
     277          itemDescriptionTextBox.Text = string.Join(" - ", node.Name.Split(new[] { CreatableAttribute.Categories.SplitToken }, StringSplitOptions.RemoveEmptyEntries));
     278        }
     279        Type type = node.Tag as Type;
    260280        if (type != null) {
    261281          string description = ItemAttribute.GetDescription(type);
     
    429449
    430450    private class ItemTreeNodeComparer : IComparer {
     451      private static readonly IComparer<string> Comparer = new NaturalStringComparer();
    431452      public int Compare(object x, object y) {
    432453        var lhs = (TreeNode)x;
     
    434455
    435456        if (lhs.Tag is string && rhs.Tag is string) {
    436           return lhs.Name.CompareTo(rhs.Name);
     457          return Comparer.Compare((string)lhs.Tag, (string)rhs.Tag);
    437458        } else if (lhs.Tag is string) {
    438459          return -1;
Note: See TracChangeset for help on using the changeset viewer.