Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6748


Ignore:
Timestamp:
09/13/11 09:38:41 (13 years ago)
Author:
abeham
Message:

#1642

  • Made instantiating of Creatables asynchronous
  • Added progress bar to indicate that there is something going on
Location:
branches/GeneralizedQAP/HeuristicLab.Optimizer/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Optimizer/3.3/NewItemDialog.Designer.cs

    r5445 r6748  
    4949      this.cancelButton = new System.Windows.Forms.Button();
    5050      this.itemsListView = new System.Windows.Forms.ListView();
    51       this.nameColumnHeader = new System.Windows.Forms.ColumnHeader();
    52       this.descriptioncolumnHeader = new System.Windows.Forms.ColumnHeader();
     51      this.nameColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
     52      this.versionColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
     53      this.descriptioncolumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
    5354      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    54       this.versionColumnHeader = new System.Windows.Forms.ColumnHeader();
     55      this.loadingPanel = new System.Windows.Forms.Panel();
     56      this.pleaseWaitLabel = new System.Windows.Forms.Label();
     57      this.loadingProgressBar = new System.Windows.Forms.ProgressBar();
     58      this.loadingPanel.SuspendLayout();
    5559      this.SuspendLayout();
    5660      //
     
    102106      // nameColumnHeader
    103107      //
    104       this.nameColumnHeader.DisplayIndex = 0;
    105108      this.nameColumnHeader.Text = "Name";
    106109      this.nameColumnHeader.Width = 91;
    107110      //
     111      // versionColumnHeader
     112      //
     113      this.versionColumnHeader.Text = "Version";
     114      //
    108115      // descriptioncolumnHeader
    109116      //
    110       this.descriptioncolumnHeader.DisplayIndex = 2;
    111117      this.descriptioncolumnHeader.Text = "Description";
    112118      this.descriptioncolumnHeader.Width = 190;
    113119      //
    114       // versionColumnHeader
     120      // loadingPanel
    115121      //
    116       this.versionColumnHeader.DisplayIndex = 1;
    117       this.versionColumnHeader.Text = "Version";
     122      this.loadingPanel.Controls.Add(this.pleaseWaitLabel);
     123      this.loadingPanel.Controls.Add(this.loadingProgressBar);
     124      this.loadingPanel.Location = new System.Drawing.Point(37, 153);
     125      this.loadingPanel.Name = "loadingPanel";
     126      this.loadingPanel.Size = new System.Drawing.Size(550, 106);
     127      this.loadingPanel.TabIndex = 4;
     128      //
     129      // pleaseWaitLabel
     130      //
     131      this.pleaseWaitLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
     132      this.pleaseWaitLabel.Location = new System.Drawing.Point(44, 59);
     133      this.pleaseWaitLabel.Name = "pleaseWaitLabel";
     134      this.pleaseWaitLabel.Size = new System.Drawing.Size(462, 23);
     135      this.pleaseWaitLabel.TabIndex = 1;
     136      this.pleaseWaitLabel.Text = "Loading items, please wait...";
     137      this.pleaseWaitLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
     138      //
     139      // loadingProgressBar
     140      //
     141      this.loadingProgressBar.Anchor = System.Windows.Forms.AnchorStyles.None;
     142      this.loadingProgressBar.Location = new System.Drawing.Point(44, 32);
     143      this.loadingProgressBar.Name = "loadingProgressBar";
     144      this.loadingProgressBar.Size = new System.Drawing.Size(462, 23);
     145      this.loadingProgressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
     146      this.loadingProgressBar.TabIndex = 0;
    118147      //
    119148      // NewItemDialog
     
    124153      this.CancelButton = this.cancelButton;
    125154      this.ClientSize = new System.Drawing.Size(624, 444);
     155      this.Controls.Add(this.loadingPanel);
    126156      this.Controls.Add(this.itemsListView);
    127157      this.Controls.Add(this.cancelButton);
     
    137167      this.Load += new System.EventHandler(this.NewItemDialog_Load);
    138168      this.Shown += new System.EventHandler(this.NewItemDialog_Shown);
     169      this.loadingPanel.ResumeLayout(false);
    139170      this.ResumeLayout(false);
    140171
     
    150181    private System.Windows.Forms.ColumnHeader descriptioncolumnHeader;
    151182    private System.Windows.Forms.ColumnHeader versionColumnHeader;
     183    private System.Windows.Forms.Panel loadingPanel;
     184    private System.Windows.Forms.Label pleaseWaitLabel;
     185    private System.Windows.Forms.ProgressBar loadingProgressBar;
    152186  }
    153187}
  • branches/GeneralizedQAP/HeuristicLab.Optimizer/3.3/NewItemDialog.cs

    r5445 r6748  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
     26using System.Threading.Tasks;
    2527using System.Windows.Forms;
    2628using HeuristicLab.Core;
     
    4244      item = null;
    4345      InitializeComponent();
     46      SetEnabledStateOfControls();
    4447    }
    4548
    4649    private void NewItemDialog_Load(object sender, EventArgs e) {
     50      TaskScheduler context = TaskScheduler.FromCurrentSynchronizationContext();
     51      Task.Factory
     52        .StartNew((Action<object>)LoadItems, context)
     53        .ContinueWith(PrepareUI);
     54    }
     55
     56    private void NewItemDialog_Shown(object sender, EventArgs e) {
     57      item = null;
     58    }
     59
     60    private void LoadItems(object state) {
     61      TaskScheduler context = (TaskScheduler)state;
    4762      if (!initialized) {
    48         var categories = from t in ApplicationManager.Manager.GetTypes(typeof(IItem))
    49                          where CreatableAttribute.IsCreatable(t)
     63        Type[] creatableTypes = (from t in ApplicationManager.Manager.GetTypes(typeof(IItem))
     64                                 where CreatableAttribute.IsCreatable(t)
     65                                 select t).ToArray();
     66        var categories = from t in creatableTypes
    5067                         orderby CreatableAttribute.GetCategory(t), ItemAttribute.GetName(t), ItemAttribute.GetVersion(t) ascending
    5168                         group t by CreatableAttribute.GetCategory(t) into c
     
    5370
    5471        itemsListView.SmallImageList = new ImageList();
     72        int count = 0;
     73        ListViewItem[] itemsArray = new ListViewItem[creatableTypes.Length];
     74        Image[] smallImagesArray = new Image[creatableTypes.Length];
     75        List<ListViewGroup> itemGroupsList = new List<ListViewGroup>();
    5576        foreach (var category in categories) {
    5677          ListViewGroup group = new ListViewGroup(category.Key);
    57           itemsListView.Groups.Add(group);
     78          itemGroupsList.Add(group);
    5879          foreach (var creatable in category) {
    5980            IItem i = (IItem)Activator.CreateInstance(creatable);
    6081            items.Add(i);
    6182            ListViewItem item = new ListViewItem(new string[] { i.ItemName, i.ItemVersion.ToString(), i.ItemDescription }, group);
    62             itemsListView.SmallImageList.Images.Add(i.ItemImage);
    63             item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     83            item.ImageIndex = count;
    6484            item.Tag = i;
    65             itemsListView.Items.Add(item);
     85            itemsArray[count] = item;
     86            smallImagesArray[count] = i.ItemImage;
     87            count++;
     88            Task.Factory.StartNew(() => {
     89              loadingProgressBar.Value = (int)Math.Round(loadingProgressBar.Minimum + (loadingProgressBar.Maximum - loadingProgressBar.Minimum) * (double)count / creatableTypes.Length);
     90            }, Task.Factory.CancellationToken, TaskCreationOptions.None, context);
    6691          }
    6792        }
    68         for (int i = 0; i < itemsListView.Columns.Count; i++)
    69           itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     93        Task.Factory.StartNew(() => {
     94          itemsListView.SmallImageList.Images.AddRange(smallImagesArray);
     95          itemsListView.Groups.AddRange(itemGroupsList.ToArray());
     96          itemsListView.Items.AddRange(itemsArray);
     97          for (int i = 0; i < itemsListView.Columns.Count; i++)
     98            itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
     99        }, Task.Factory.CancellationToken, TaskCreationOptions.None, context);
    70100        initialized = true;
    71101      }
    72102    }
    73103
    74     private void NewItemDialog_Shown(object sender, EventArgs e) {
    75       item = null;
     104    private void PrepareUI(Task t) {
     105      SetEnabledStateOfControls();
     106      loadingPanel.Visible = false;
     107    }
     108
     109    private void SetEnabledStateOfControls() {
     110      itemsListView.Enabled = initialized;
     111      okButton.Enabled = initialized;
     112      cancelButton.Enabled = initialized;
    76113    }
    77114
Note: See TracChangeset for help on using the changeset viewer.