Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7375


Ignore:
Timestamp:
01/19/12 17:51:26 (13 years ago)
Author:
ascheibe
Message:

#1648 switched user controls to a CheckedItemListView

Location:
branches/ClientUserManagement
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/AccessClient.cs

    r7368 r7375  
    4848
    4949    #region Refresh
    50     private void Refresh() {
    51       OnRefreshing();
     50    public void Refresh() {
    5251      users = new ItemList<LightweightUser>();
    53 
    54       try {
    55         users.AddRange(CallRunCreationService<ItemList<LightweightUser>>(s => new ItemList<LightweightUser>(s.GetAllLightweightUsers())));
    56       }
    57       finally {
    58         OnRefreshed();
    59       }
     52      users.AddRange(CallRunCreationService<ItemList<LightweightUser>>(s => new ItemList<LightweightUser>(s.GetAllLightweightUsers())));
    6053    }
    6154    public void RefreshAsync(Action<Exception> exceptionCallback) {
    6255      var call = new Func<Exception>(delegate() {
    6356        try {
     57          OnRefreshing();
    6458          Refresh();
    6559        }
    6660        catch (Exception ex) {
    6761          return ex;
     62        }
     63        finally {
     64          OnRefreshed();
     65        }
     66        return null;
     67      });
     68      call.BeginInvoke(delegate(IAsyncResult result) {
     69        Exception ex = call.EndInvoke(result);
     70        if (ex != null) exceptionCallback(ex);
     71      }, null);
     72    }
     73    public void ExecuteActionAsync(Action action, Action<Exception> exceptionCallback) {
     74      var call = new Func<Exception>(delegate() {
     75        try {
     76          OnRefreshing();
     77          action();
     78        }
     79        catch (Exception ex) {
     80          return ex;
     81        }
     82        finally {
     83          OnRefreshed();
    6884        }
    6985        return null;
  • branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/ServiceClients/LightweightUser.cs

    r7368 r7375  
    3939
    4040    public override string ToString() {
    41       return UserName + " ( " + FullName + ")";
     41      return UserName + " (" + FullName + ")";
    4242    }
    4343  }
  • branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/Views/LightweightUserView.Designer.cs

    r7368 r7375  
    2424    /// </summary>
    2525    private void InitializeComponent() {
    26       this.checkedListBox = new System.Windows.Forms.CheckedListBox();
    2726      this.SuspendLayout();
    28       //
    29       // checkedListBox
    30       //
    31       this.checkedListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    32                   | System.Windows.Forms.AnchorStyles.Left)
    33                   | System.Windows.Forms.AnchorStyles.Right)));
    34       this.checkedListBox.CheckOnClick = true;
    35       this.checkedListBox.FormattingEnabled = true;
    36       this.checkedListBox.Location = new System.Drawing.Point(3, 3);
    37       this.checkedListBox.Name = "checkedListBox";
    38       this.checkedListBox.Size = new System.Drawing.Size(532, 229);
    39       this.checkedListBox.TabIndex = 0;
    4027      //
    4128      // LightweightUserView
     
    4330      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    4431      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    45       this.Controls.Add(this.checkedListBox);
    4632      this.Name = "LightweightUserView";
    4733      this.Size = new System.Drawing.Size(538, 235);
     
    5238    #endregion
    5339
    54     private System.Windows.Forms.CheckedListBox checkedListBox;
    5540  }
    5641}
  • branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/Views/LightweightUserView.cs

    r7368 r7375  
    2121
    2222using System;
    23 using System.Collections.Generic;
     23using System.Windows.Forms;
     24using HeuristicLab.Collections;
    2425using HeuristicLab.Core;
     26using HeuristicLab.Core.Views;
    2527using HeuristicLab.MainForm;
    2628using HeuristicLab.MainForm.WindowsForms;
     
    2931
    3032  [View("LightweightUser View")]
    31   [Content(typeof(ItemList<LightweightUser>), true)]
    32   public partial class LightweightUserView : ContentView {
    33     public new ItemList<LightweightUser> Content {
    34       get { return (ItemList<LightweightUser>)base.Content; }
    35       set { base.Content = value; }
     33  [Content(typeof(CheckedItemList<LightweightUser>), true)]
     34  public partial class LightweightUserView : CheckedItemListView<LightweightUser> {
     35    public LightweightUserView() {
     36      InitializeComponent();
     37      this.showDetailsCheckBox.Checked = false;
    3638    }
    3739
    38     public List<Guid> SelectedUsers { get; set; }
    39 
    40     public LightweightUserView() {
    41       InitializeComponent();
    42       SelectedUsers = new List<Guid>();
     40    protected override void SetEnabledStateOfControls() {
     41      base.SetEnabledStateOfControls();
     42      this.addButton.Enabled = false;
     43      this.showDetailsCheckBox.Enabled = false;
     44      this.removeButton.Enabled = false;
    4345    }
    4446
    45     protected override void OnContentChanged() {
    46       base.OnContentChanged();
     47    protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
     48      base.itemsListView_SelectedIndexChanged(sender, e);
     49      this.removeButton.Enabled = false;
     50    }
    4751
    48       SelectedUsers.Clear();
    49       if (Content == null) {
    50         checkedListBox.Items.Clear();
    51       } else {
    52         Content.ForEach(x => checkedListBox.Items.Add(x));
     52    protected override void Content_CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<LightweightUser>> e) {
     53      base.Content_CheckedItemsChanged(sender, e);
     54      OnSelectedUsersChanged();
     55    }
     56
     57    public event EventHandler SelectedUsersChanged;
     58    protected virtual void OnSelectedUsersChanged() {
     59      if (InvokeRequired)
     60        Invoke((MethodInvoker)OnSelectedUsersChanged);
     61      else {
     62        EventHandler handler = SelectedUsersChanged;
     63        if (handler != null)
     64          handler(this, EventArgs.Empty);
    5365      }
    5466    }
  • branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/Views/RefreshableLightweightUserView.Designer.cs

    r7368 r7375  
    2424    /// </summary>
    2525    private void InitializeComponent() {
    26       this.refreshButton = new System.Windows.Forms.Button();
    27       this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
     26      this.lightweightUserView = new HeuristicLab.Clients.Access.Views.LightweightUserView();
    2827      this.SuspendLayout();
    2928      //
    30       // refreshButton
     29      // lightweightUserView
    3130      //
    32       this.refreshButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Refresh;
    33       this.refreshButton.Location = new System.Drawing.Point(3, 3);
    34       this.refreshButton.Name = "refreshButton";
    35       this.refreshButton.Size = new System.Drawing.Size(24, 24);
    36       this.refreshButton.TabIndex = 1;
    37       this.refreshButton.UseVisualStyleBackColor = true;
    38       this.refreshButton.Click += new System.EventHandler(this.refreshButton_Click);
    39       //
    40       // viewHost
    41       //
    42       this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     31      this.lightweightUserView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    4332                  | System.Windows.Forms.AnchorStyles.Left)
    4433                  | System.Windows.Forms.AnchorStyles.Right)));
    45       this.viewHost.Caption = "View";
    46       this.viewHost.Content = null;
    47       this.viewHost.Enabled = false;
    48       this.viewHost.Location = new System.Drawing.Point(3, 33);
    49       this.viewHost.Name = "viewHost";
    50       this.viewHost.ReadOnly = false;
    51       this.viewHost.Size = new System.Drawing.Size(500, 218);
    52       this.viewHost.TabIndex = 2;
    53       this.viewHost.ViewsLabelVisible = true;
    54       this.viewHost.ViewType = null;
     34      this.lightweightUserView.Caption = "LightweightUser View";
     35      this.lightweightUserView.Content = null;
     36      this.lightweightUserView.Location = new System.Drawing.Point(3, 33);
     37      this.lightweightUserView.Name = "lightweightUserView";
     38      this.lightweightUserView.ReadOnly = false;
     39      this.lightweightUserView.Size = new System.Drawing.Size(500, 218);
     40      this.lightweightUserView.TabIndex = 2;
     41      this.lightweightUserView.SelectedUsersChanged += new System.EventHandler(this.lightweightUserView_SelectedUsersChanged);
    5542      //
    56       // RefreshableView
     43      // RefreshableLightweightUserView
    5744      //
    5845      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    5946      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    60       this.Controls.Add(this.viewHost);
    61       this.Controls.Add(this.refreshButton);
    62       this.Name = "RefreshableView";
    63       this.Size = new System.Drawing.Size(506, 254);
     47      this.Controls.Add(this.lightweightUserView);
     48      this.Name = "RefreshableLightweightUserView";
     49      this.Controls.SetChildIndex(this.lightweightUserView, 0);
     50      this.Controls.SetChildIndex(this.refreshButton, 0);
    6451      this.ResumeLayout(false);
    6552
     
    6855    #endregion
    6956
    70     private System.Windows.Forms.Button refreshButton;
    71     private MainForm.WindowsForms.ViewHost viewHost;
     57    private LightweightUserView lightweightUserView;
    7258  }
    7359}
  • branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/Views/RefreshableLightweightUserView.cs

    r7368 r7375  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Windows.Forms;
     25using HeuristicLab.Core;
    2326using HeuristicLab.MainForm;
    2427using HeuristicLab.MainForm.WindowsForms;
     
    3134    public RefreshableLightweightUserView() {
    3235      InitializeComponent();
     36
    3337    }
    3438
     39    //set an action like a webservice call to retrieve the users which should be marked as checked       
     40    //TODO: disable refresh button if not set
     41    public Func<List<Guid>> FetchSelectedUsers { get; set; }
     42    private List<Guid> selectedUsers;
     43
    3544    protected override void RefreshData() {
    36       Content.RefreshAsync(new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
     45      Action completeRefreshAction = new Action(delegate {
     46        selectedUsers = FetchSelectedUsers();
     47        Content.Refresh();
     48      });
     49
     50      Content.ExecuteActionAsync(completeRefreshAction, new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
    3751    }
    3852
    3953    protected override void Content_Refreshing(object sender, EventArgs e) {
    4054      base.Content_Refreshing(sender, e);
    41       viewHost.Content = null;
     55      lightweightUserView.Content = null;
    4256    }
    4357
     
    4559      base.Content_Refreshed(sender, e);
    4660
    47       viewHost.Content = Content.Users;
     61      var checkedUsers = new CheckedItemList<LightweightUser>(Content.Users);
     62      checkedUsers.ForEach(u => {
     63        int idx = checkedUsers.IndexOf(u);
     64        checkedUsers.SetItemCheckedState(idx, selectedUsers.Contains(u.Id));
     65      });
     66      lightweightUserView.Content = checkedUsers;
     67    }
     68
     69    public ICheckedItemList<LightweightUser> GetCheckedUsers() {
     70      if (lightweightUserView.Content == null)
     71        return null;
     72      else
     73        return lightweightUserView.Content;
     74    }
     75
     76    public event EventHandler SelectedUsersChanged;
     77    protected virtual void OnSelectedUsersChanged() {
     78      if (InvokeRequired)
     79        Invoke((MethodInvoker)OnSelectedUsersChanged);
     80      else {
     81        EventHandler handler = SelectedUsersChanged;
     82        if (handler != null)
     83          handler(this, EventArgs.Empty);
     84      }
     85    }
     86
     87    private void lightweightUserView_SelectedUsersChanged(object sender, EventArgs e) {
     88      OnSelectedUsersChanged();
    4889    }
    4990  }
  • branches/ClientUserManagement/HeuristicLab.Clients.Access/3.3/Views/RefreshableView.Designer.cs

    r7368 r7375  
    2424    /// </summary>
    2525    private void InitializeComponent() {
     26      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RefreshableView));
    2627      this.refreshButton = new System.Windows.Forms.Button();
    27       this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    2828      this.SuspendLayout();
    2929      //
    3030      // refreshButton
    3131      //
    32       this.refreshButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Refresh;
     32      this.refreshButton.Image = ((System.Drawing.Image)(resources.GetObject("refreshButton.Image")));
    3333      this.refreshButton.Location = new System.Drawing.Point(3, 3);
    3434      this.refreshButton.Name = "refreshButton";
     
    3838      this.refreshButton.Click += new System.EventHandler(this.refreshButton_Click);
    3939      //
    40       // viewHost
    41       //
    42       this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    43                   | System.Windows.Forms.AnchorStyles.Left)
    44                   | System.Windows.Forms.AnchorStyles.Right)));
    45       this.viewHost.Caption = "View";
    46       this.viewHost.Content = null;
    47       this.viewHost.Enabled = false;
    48       this.viewHost.Location = new System.Drawing.Point(3, 33);
    49       this.viewHost.Name = "viewHost";
    50       this.viewHost.ReadOnly = false;
    51       this.viewHost.Size = new System.Drawing.Size(500, 218);
    52       this.viewHost.TabIndex = 2;
    53       this.viewHost.ViewsLabelVisible = true;
    54       this.viewHost.ViewType = null;
    55       //
    5640      // RefreshableView
    5741      //
    5842      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    5943      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    60       this.Controls.Add(this.viewHost);
    6144      this.Controls.Add(this.refreshButton);
    6245      this.Name = "RefreshableView";
     
    6851    #endregion
    6952
    70     private System.Windows.Forms.Button refreshButton;
    71     private MainForm.WindowsForms.ViewHost viewHost;
     53    protected System.Windows.Forms.Button refreshButton;
    7254  }
    7355}
Note: See TracChangeset for help on using the changeset viewer.