Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1398


Ignore:
Timestamp:
03/23/09 15:44:53 (16 years ago)
Author:
epitzer
Message:

Complete GUI for persistence configuration. (#506)

Location:
branches/New Persistence Exploration/Persistence
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/HeuristicLab.Persistence.GUI/PersistenceConfigurationForm.Designer.cs

    r1382 r1398  
    2525    private void InitializeComponent() {
    2626      System.Windows.Forms.TabPage nullFormatterConfig;
    27       System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("Bli");
    28       System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("Bla");
    29       System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("Blo");
     27      System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("Bli");
     28      System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem("Bla");
     29      System.Windows.Forms.ListViewItem listViewItem6 = new System.Windows.Forms.ListViewItem("Blo");
    3030      this.dataGridView1 = new System.Windows.Forms.DataGridView();
    3131      this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
     
    100100      this.decomposerList.GridLines = true;
    101101      this.decomposerList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
    102       listViewItem1.Checked = true;
    103       listViewItem1.StateImageIndex = 1;
    104       listViewItem1.Tag = "";
    105       listViewItem2.Checked = true;
    106       listViewItem2.StateImageIndex = 1;
    107       listViewItem3.Checked = true;
    108       listViewItem3.StateImageIndex = 1;
     102      listViewItem4.Checked = true;
     103      listViewItem4.StateImageIndex = 1;
     104      listViewItem4.Tag = "";
     105      listViewItem5.Checked = true;
     106      listViewItem5.StateImageIndex = 1;
     107      listViewItem6.Checked = true;
     108      listViewItem6.StateImageIndex = 1;
    109109      this.decomposerList.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
    110             listViewItem1,
    111             listViewItem2,
    112             listViewItem3});
     110            listViewItem4,
     111            listViewItem5,
     112            listViewItem6});
    113113      this.decomposerList.Location = new System.Drawing.Point(0, 0);
    114114      this.decomposerList.Name = "decomposerList";
     
    167167      //
    168168      this.checkbox.Dock = System.Windows.Forms.DockStyle.Fill;
     169      this.checkbox.Enabled = false;
    169170      this.checkbox.FormattingEnabled = true;
    170171      this.checkbox.Location = new System.Drawing.Point(0, 0);
  • branches/New Persistence Exploration/Persistence/HeuristicLab.Persistence.GUI/PersistenceConfigurationForm.cs

    r1382 r1398  
    1010namespace HeuristicLab.Persistence.GUI {
    1111
    12   public partial class PersistenceConfigurationForm : Form {   
     12  public partial class PersistenceConfigurationForm : Form {
     13
     14    private readonly Dictionary<string, IFormatter> formatterTable;
     15    private readonly Dictionary<string, Type> typeNameTable;   
     16
    1317    public PersistenceConfigurationForm() {
    1418      InitializeComponent();
    15       decomposerList.Items.Clear();           
     19      formatterTable = new Dictionary<string, IFormatter>();
     20      typeNameTable = new Dictionary<string, Type>();
     21      decomposerList.Items.Clear();
    1622      foreach ( IDecomposer decomposer in ConfigurationService.Instance.AllDecomposers ) {
    1723        var item = decomposerList.Items.Add(decomposer.GetType().Name);
     
    1925        item.Tag = decomposer;
    2026      }
    21      
     27
    2228      foreach ( var formats in ConfigurationService.Instance.AllFormatters ) {
    23         TabPage page = new TabPage(formats.Key.Name);
     29        TabPage page = new TabPage(formats.Key.Name) {Tag = formats.Key};
    2430        formatterTabs.TabPages.Add(page);
    2531        DataGridView gridView = new DataGridView {
     
    2834          AllowUserToAddRows = false,
    2935          AllowUserToDeleteRows = false,
    30           AllowUserToResizeRows = false,                                       
     36          AllowUserToResizeRows = false,
     37          Name = "GridView",
    3138        };
    32         //gridView.CellValueChanged += gridView_CellValueChanged;
    33         //gridView.DataError += gridView_DataError;
    34         //gridView.CellFormatting += gridView_CellFormatting;
    35         page.Controls.Add(gridView);
     39        gridView.CellValueChanged += gridView_CellValueChanged;
     40        page.Controls.Add(gridView);       
    3641        gridView.Columns.Add(new DataGridViewTextBoxColumn {
    3742          Name = "Type", ReadOnly = true,
     
    4247        gridView.Columns.Add(new DataGridViewComboBoxColumn
    4348          { AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill });               
    44         var formatterMap = new Dictionary<Type, List<IFormatter>>();
     49        var formatterMap = new Dictionary<string, List<string>>();
    4550        foreach (var formatter in formats.Value) {
    46           if (!formatterMap.ContainsKey(formatter.Type))
    47             formatterMap.Add(formatter.Type, new List<IFormatter>());
    48           formatterMap[formatter.Type].Add(formatter);
     51          string formatterName = formatter.GetType().Name;
     52          if (formatterTable.ContainsKey(formatterName)) {
     53            IFormatter otherFormatter = formatterTable[formatterName];
     54            formatterTable.Remove(formatterName);
     55            formatterTable.Add(otherFormatter.GetType().FullName, otherFormatter);
     56            formatterName = formatter.GetType().FullName;
     57          }
     58          formatterTable.Add(formatterName, formatter);
     59          string typeName = formatter.Type.Name;
     60          if (typeNameTable.ContainsKey(typeName)) {
     61            Type otherType = typeNameTable[typeName];
     62            if (otherType != formatter.Type) {
     63              typeNameTable.Remove(typeName);
     64              typeNameTable.Add(otherType.FullName, otherType);
     65              typeName = formatter.Type.FullName;
     66              typeNameTable.Add(typeName, formatter.Type);
     67            }
     68          } else {
     69            typeNameTable.Add(typeName, formatter.Type);
     70          }         
     71        }
     72        foreach (var formatter in formats.Value) {         
     73          string formatterName =
     74            formatterTable.ContainsKey(formatter.GetType().Name) ?
     75            formatter.GetType().Name :
     76            formatter.GetType().FullName;
     77          string typeName =
     78            typeNameTable.ContainsKey(formatter.Type.Name) ?
     79            formatter.Type.Name :
     80            formatter.Type.FullName;         
     81          if (!formatterMap.ContainsKey(typeName))
     82            formatterMap.Add(typeName, new List<string>());
     83          formatterMap[typeName].Add(formatterName);
    4984        }
    5085        foreach ( var formatterMapping in formatterMap ) {
    5186          var row = gridView.Rows[gridView.Rows.Add()];
    52           row.Cells[0].Value = formatterMapping.Key.SimpleFullName();
    53           row.Cells[0].ToolTipText = formatterMapping.Key.AssemblyQualifiedName;
     87          row.Cells[0].Value = formatterMapping.Key;
     88          row.Cells[0].ToolTipText = formatterMapping.Key;
    5489          row.Cells[1].Value = true;
    55           var comboBoxCell = (DataGridViewComboBoxCell) row.Cells[2];
    56           //comboBoxCell.ValueType = typeof(IFormatter);         
    57           foreach ( var formatter in formatterMapping.Value ) {           
    58             comboBoxCell.Items.Add(formatter.GetType().Name);
     90          var comboBoxCell = (DataGridViewComboBoxCell) row.Cells[2];         
     91          foreach ( var formatter in formatterMapping.Value ) {
     92            comboBoxCell.Items.Add(formatter);
    5993          }         
    6094          comboBoxCell.Value = comboBoxCell.Items[0];         
     
    68102    }
    69103
    70     void gridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) {
    71       e.Value = e.Value.ToString();
    72       e.FormattingApplied = true;
     104    void gridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) {
     105      UpdatePreview();
    73106    }   
    74107
     
    105138        i++;
    106139      }
    107       Update();
     140      UpdatePreview();
    108141    }
    109142
     
    121154    }
    122155
    123     private void Update() {
    124       checkbox.Items.Clear();
     156    private void UpdatePreview() {
     157      checkbox.Items.Clear();     
    125158      foreach (var decomposer in GetDecomposers())
    126         checkbox.Items.Add(decomposer.GetType().Name);     
     159        checkbox.Items.Add(decomposer.GetType().Name + " (D)");
     160      IFormat activeFormat = (IFormat) formatterTabs.SelectedTab.Tag;
     161      if (activeFormat != null) {
     162        foreach (var formatter in GetCurrentConfiguration(activeFormat).Formatters) {
     163          checkbox.Items.Add(formatter.GetType().Name + " (F)");
     164        }
     165      }
    127166    }
    128167
    129168    private void decomposerList_ItemChecked(object sender, ItemCheckedEventArgs e) {
    130       Update();
     169      UpdatePreview();
     170    }
     171
     172    public Configuration GetCurrentConfiguration(IFormat format) {     
     173      Dictionary<Type, IFormatter> formatters = new Dictionary<Type, IFormatter>();
     174      foreach ( TabPage page in formatterTabs.TabPages ) {
     175        if ( page.Text == format.Name ) {
     176          Control[] controls = page.Controls.Find("GridView", false);
     177          if (controls.Length == 1) {
     178            foreach (DataGridViewRow row in ((DataGridView) controls[0]).Rows) {
     179              if ( row.Cells[1].Value != null &&
     180                row.Cells[0].Value != null &&
     181                row.Cells[2].Value != null &&
     182                (bool)row.Cells[1].Value == true ) {               
     183                formatters.Add(
     184                  typeNameTable[(string)row.Cells[0].Value],                 
     185                  formatterTable[(string)row.Cells[2].Value]);
     186              }
     187            }
     188          }
     189        }
     190      }
     191      return new Configuration(formatters, GetDecomposers());
    131192    }
    132193   
  • branches/New Persistence Exploration/Persistence/HeuristicLab.Persistence.GUI/PersistenceConfigurationForm.resx

    r1382 r1398  
    130130    <value>True</value>
    131131  </metadata>
     132  <metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     133    <value>True</value>
     134  </metadata>
     135  <metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     136    <value>True</value>
     137  </metadata>
     138  <metadata name="Column3.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     139    <value>True</value>
     140  </metadata>
    132141</root>
  • branches/New Persistence Exploration/Persistence/Persistence/Core/PersistenceConfiguration.cs

    r1373 r1398  
    11using System;
     2using System.Collections;
    23using System.Collections.Generic;
    34using System.Reflection;
     
    2526      this.decomposers = new List<IDecomposer>(decomposers);
    2627      decomposerCache = new Dictionary<Type, IDecomposer>();     
    27     }   
     28    }
     29
     30    public IEnumerable Formatters {
     31      get { return formatters.Values; }
     32    }
    2833
    2934    public IFormatter GetFormatter(Type type) {
Note: See TracChangeset for help on using the changeset viewer.