Ignore:
Timestamp:
02/13/10 05:21:23 (11 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • added method ShowView to ViewHost to be able to set the currently shown view.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/ViewHost.cs

    r2790 r2792  
    3535    private Dictionary<Type, ToolStripMenuItem> typeMenuItemTable;
    3636
     37    public IEnumerable<Type> AvailableViewTypes {
     38      get { return typeMenuItemTable.Keys; }
     39    }
     40
    3741    private object content;
    3842    public object Content {
     
    5054      InitializeComponent();
    5155      Initialize();
     56    }
     57
     58    public void ShowView(Type viewType) {
     59      if (!typeMenuItemTable.ContainsKey(viewType))
     60        throw new ArgumentException(string.Format("View \"{0}\" cannot display content \"{1}\".",
     61                                                  viewType.GetPrettyName(),
     62                                                  content.GetType().GetPrettyName()));
     63
     64      foreach (ToolStripMenuItem item in typeMenuItemTable.Values) {
     65        item.Checked = false;
     66        item.Enabled = true;
     67      }
     68      typeMenuItemTable[viewType].Checked = true;
     69      typeMenuItemTable[viewType].Enabled = false;
     70
     71      if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();
     72      viewPanel.Controls.Clear();
     73      Control view = (Control)MainFormManager.CreateView(viewType, Content);
     74      viewPanel.Controls.Add(view);
     75      viewPanel.Tag = view;
     76      view.Dock = DockStyle.Fill;
     77      viewPanel.Enabled = true;
     78      viewPanel.Visible = true;
    5279    }
    5380
     
    6895                        orderby t.Name ascending
    6996                        select t;
    70         foreach (Type viewType in viewTypes) {
    71           ToolStripMenuItem item = new ToolStripMenuItem(viewType.GetPrettyName());
    72           item.Name = viewType.FullName;
    73           item.ToolTipText = viewType.GetPrettyName(true);
    74           item.Tag = viewType;
     97        foreach (Type v in viewTypes) {
     98          ToolStripMenuItem item = new ToolStripMenuItem(v.GetPrettyName());
     99          item.Name = v.FullName;
     100          item.ToolTipText = v.GetPrettyName(true);
     101          item.Tag = v;
    75102          contextMenuStrip.Items.Add(item);
    76           typeMenuItemTable.Add(viewType, item);
     103          typeMenuItemTable.Add(v, item);
    77104        }
    78105        if (contextMenuStrip.Items.Count == 0) {
     
    85112        }
    86113
    87         Control view = (Control)MainFormManager.CreateDefaultView(Content);
    88         if ((view == null) && (contextMenuStrip.Items.Count > 0))  // create first available view if default view is not available
    89           view = (Control)MainFormManager.CreateView((Type)contextMenuStrip.Items[0].Tag, Content);
    90         if (view != null) {
    91           viewPanel.Controls.Add(view);
    92           viewPanel.Tag = view;
    93           view.Dock = DockStyle.Fill;
    94           viewPanel.Enabled = true;
    95           viewPanel.Visible = true;
    96           typeMenuItemTable[view.GetType()].Checked = true;
    97           typeMenuItemTable[view.GetType()].Enabled = false;
    98         }
     114        Type viewType = MainFormManager.GetDefaultViewType(Content.GetType());
     115        if ((viewType == null) && (contextMenuStrip.Items.Count > 0))  // create first available view if default view is not available
     116          viewType = (Type)contextMenuStrip.Items[0].Tag;
     117        if (viewType != null)
     118          ShowView(viewType);
    99119      }
    100120    }
     
    105125    protected void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {
    106126      Type viewType = (Type)e.ClickedItem.Tag;
    107       foreach (ToolStripMenuItem item in typeMenuItemTable.Values) {
    108         item.Checked = false;
    109         item.Enabled = true;
    110       }
    111       typeMenuItemTable[viewType].Checked = true;
    112       typeMenuItemTable[viewType].Enabled = false;
    113 
    114       if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();
    115       viewPanel.Controls.Clear();
    116       Control view = (Control)MainFormManager.CreateView(viewType, Content);
    117       viewPanel.Controls.Add(view);
    118       viewPanel.Tag = view;
    119       view.Dock = DockStyle.Fill;
     127      ShowView(viewType);
    120128    }
    121129  }
Note: See TracChangeset for help on using the changeset viewer.