Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/23/09 17:13:25 (15 years ago)
Author:
epitzer
Message:

Recfactoring of Persistence GUI.

Location:
branches/New Persistence Exploration/Persistence/HeuristicLab.Persistence.GUI
Files:
3 edited

Legend:

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

    r1398 r1399  
    2525    private void InitializeComponent() {
    2626      System.Windows.Forms.TabPage nullFormatterConfig;
    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");
     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");
    3030      this.dataGridView1 = new System.Windows.Forms.DataGridView();
    3131      this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
     
    3636      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
    3737      this.splitContainer2 = new System.Windows.Forms.SplitContainer();
    38       this.checkbox = new System.Windows.Forms.CheckedListBox();
    3938      this.formatterTabs = new System.Windows.Forms.TabControl();
     39      this.checkBox = new System.Windows.Forms.ListBox();
    4040      nullFormatterConfig = new System.Windows.Forms.TabPage();
    4141      nullFormatterConfig.SuspendLayout();
     
    100100      this.decomposerList.GridLines = true;
    101101      this.decomposerList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
    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;
     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;
    109109      this.decomposerList.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
    110             listViewItem4,
    111             listViewItem5,
    112             listViewItem6});
     110            listViewItem1,
     111            listViewItem2,
     112            listViewItem3});
    113113      this.decomposerList.Location = new System.Drawing.Point(0, 0);
    114114      this.decomposerList.Name = "decomposerList";
     
    159159      // splitContainer2.Panel2
    160160      //
    161       this.splitContainer2.Panel2.Controls.Add(this.checkbox);
     161      this.splitContainer2.Panel2.Controls.Add(this.checkBox);
    162162      this.splitContainer2.Size = new System.Drawing.Size(199, 580);
    163163      this.splitContainer2.SplitterDistance = 290;
    164164      this.splitContainer2.TabIndex = 1;
    165       //
    166       // checkbox
    167       //
    168       this.checkbox.Dock = System.Windows.Forms.DockStyle.Fill;
    169       this.checkbox.Enabled = false;
    170       this.checkbox.FormattingEnabled = true;
    171       this.checkbox.Location = new System.Drawing.Point(0, 0);
    172       this.checkbox.Name = "checkbox";
    173       this.checkbox.Size = new System.Drawing.Size(199, 274);
    174       this.checkbox.TabIndex = 1;
    175       this.checkbox.ThreeDCheckBoxes = true;
    176165      //
    177166      // formatterTabs
     
    184173      this.formatterTabs.Size = new System.Drawing.Size(394, 580);
    185174      this.formatterTabs.TabIndex = 0;
     175      //
     176      // checkBox
     177      //
     178      this.checkBox.Dock = System.Windows.Forms.DockStyle.Fill;
     179      this.checkBox.FormattingEnabled = true;
     180      this.checkBox.Location = new System.Drawing.Point(0, 0);
     181      this.checkBox.Name = "checkBox";
     182      this.checkBox.Size = new System.Drawing.Size(199, 277);
     183      this.checkBox.TabIndex = 0;
    186184      //
    187185      // PersistenceConfigurationForm
     
    211209    private System.Windows.Forms.ColumnHeader DecomposersColumn;
    212210    private System.Windows.Forms.SplitContainer splitContainer1;
    213     private System.Windows.Forms.CheckedListBox checkbox;
    214211    private System.Windows.Forms.SplitContainer splitContainer2;
    215212    private System.Windows.Forms.TabControl formatterTabs;
     
    218215    private System.Windows.Forms.DataGridViewCheckBoxColumn Column2;
    219216    private System.Windows.Forms.DataGridViewComboBoxColumn Column3;
     217    private System.Windows.Forms.ListBox checkBox;
    220218  }
    221219}
  • branches/New Persistence Exploration/Persistence/HeuristicLab.Persistence.GUI/PersistenceConfigurationForm.cs

    r1398 r1399  
    1313
    1414    private readonly Dictionary<string, IFormatter> formatterTable;
    15     private readonly Dictionary<string, Type> typeNameTable;   
     15    private readonly Dictionary<IFormatter, string> reverseFormatterTable;   
     16    private readonly Dictionary<string, Type> typeNameTable;
     17    private readonly Dictionary<Type, string> reverseTypeNameTable;
    1618
    1719    public PersistenceConfigurationForm() {
    1820      InitializeComponent();
    1921      formatterTable = new Dictionary<string, IFormatter>();
     22      reverseFormatterTable = new Dictionary<IFormatter, string>();
    2023      typeNameTable = new Dictionary<string, Type>();
     24      reverseTypeNameTable = new Dictionary<Type, string>();
     25      initializeDecomposerList();
     26      initializeFormatterPages();
     27    }
     28
     29    private void initializeFormatterPages() {
     30      formatterTabs.TabPages.Clear();
     31      foreach ( var formats in ConfigurationService.Instance.AllFormatters ) {
     32        TabPage page = new TabPage(formats.Key.Name) {Tag = formats.Key};
     33        formatterTabs.TabPages.Add(page);
     34        DataGridView gridView = new DataGridView {
     35                                                   Dock = DockStyle.Fill,
     36                                                   EditMode = DataGridViewEditMode.EditOnEnter,
     37                                                   AllowUserToAddRows = false,
     38                                                   AllowUserToDeleteRows = false,
     39                                                   AllowUserToResizeRows = false,
     40                                                   Name = "GridView",
     41                                                 };
     42        gridView.CellValueChanged += gridView_CellValueChanged;
     43        gridView.Columns.Add(new DataGridViewTextBoxColumn {
     44          Name = "Type", ReadOnly = true,
     45          AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
     46        });
     47        gridView.Columns.Add(new DataGridViewCheckBoxColumn {
     48          AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells});
     49        gridView.Columns.Add(new DataGridViewComboBoxColumn {
     50          AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill});
     51        page.Controls.Add(gridView);
     52        fillDataGrid(gridView, formats.Value);
     53      }
     54    }
     55
     56    private void fillDataGrid(DataGridView gridView, IEnumerable<IFormatter> formatters) {     
     57      updateNameTables(formatters);
     58      Dictionary<string, List<string>> formatterMap = createFormatterMap(formatters);
     59      foreach ( var formatterMapping in formatterMap ) {
     60        var row = gridView.Rows[gridView.Rows.Add()];
     61        row.Cells[0].Value = formatterMapping.Key;
     62        row.Cells[0].ToolTipText = formatterMapping.Key;
     63        row.Cells[1].Value = true;
     64        var comboBoxCell = (DataGridViewComboBoxCell) row.Cells[2];         
     65        foreach ( var formatter in formatterMapping.Value ) {
     66          comboBoxCell.Items.Add(formatter);
     67        }         
     68        comboBoxCell.Value = comboBoxCell.Items[0];         
     69        comboBoxCell.ToolTipText = comboBoxCell.Items[0].ToString();
     70        if (comboBoxCell.Items.Count == 1) {
     71          comboBoxCell.ReadOnly = true;
     72          comboBoxCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
     73        }     
     74      }
     75    }
     76
     77    private Dictionary<string, List<string>> createFormatterMap(IEnumerable<IFormatter> formatters) {
     78      var formatterMap = new Dictionary<string, List<string>>();     
     79      foreach (var formatter in formatters) {
     80        string formatterName = reverseFormatterTable[formatter];
     81        string typeName = reverseTypeNameTable[formatter.Type];         
     82        if (!formatterMap.ContainsKey(typeName))
     83          formatterMap.Add(typeName, new List<string>());
     84        formatterMap[typeName].Add(formatterName);
     85      }
     86      return formatterMap;
     87    }
     88
     89    private void updateNameTables(IEnumerable<IFormatter> formatters) {
     90      foreach (var formatter in formatters) {
     91        string formatterName = formatter.GetType().Name;
     92        if (formatterTable.ContainsKey(formatterName)) {
     93          IFormatter otherFormatter = formatterTable[formatterName];
     94          formatterTable.Remove(formatterName);
     95          reverseFormatterTable.Remove(otherFormatter);
     96          formatterTable.Add(otherFormatter.GetType().FullName, otherFormatter);
     97          reverseFormatterTable.Add(otherFormatter, otherFormatter.GetType().FullName);
     98          formatterName = formatter.GetType().FullName;
     99        }
     100        formatterTable.Add(formatterName, formatter);
     101        reverseFormatterTable.Add(formatter, formatterName);
     102
     103        string typeName = formatter.Type.IsGenericType ?
     104          formatter.Type.SimpleFullName() :
     105          formatter.Type.Name;
     106        if (typeNameTable.ContainsKey(typeName)) {
     107          Type otherType = typeNameTable[typeName];
     108          if (otherType != formatter.Type) {
     109            typeNameTable.Remove(typeName);
     110            reverseTypeNameTable.Remove(otherType);
     111            typeNameTable.Add(otherType.FullName, otherType);
     112            reverseTypeNameTable.Add(otherType, otherType.FullName);
     113            typeName = formatter.Type.FullName;
     114            typeNameTable.Add(typeName, formatter.Type);
     115            reverseTypeNameTable.Add(formatter.Type, typeName);
     116          }
     117        } else {
     118          typeNameTable.Add(typeName, formatter.Type);
     119          reverseTypeNameTable.Add(formatter.Type, typeName);
     120        }         
     121      }
     122    }
     123
     124    private void initializeDecomposerList() {
    21125      decomposerList.Items.Clear();
    22126      foreach ( IDecomposer decomposer in ConfigurationService.Instance.AllDecomposers ) {
     
    24128        item.Checked = true;
    25129        item.Tag = decomposer;
    26       }
    27 
    28       foreach ( var formats in ConfigurationService.Instance.AllFormatters ) {
    29         TabPage page = new TabPage(formats.Key.Name) {Tag = formats.Key};
    30         formatterTabs.TabPages.Add(page);
    31         DataGridView gridView = new DataGridView {
    32           Dock = DockStyle.Fill,
    33           EditMode = DataGridViewEditMode.EditOnEnter,
    34           AllowUserToAddRows = false,
    35           AllowUserToDeleteRows = false,
    36           AllowUserToResizeRows = false,
    37           Name = "GridView",
    38         };
    39         gridView.CellValueChanged += gridView_CellValueChanged;
    40         page.Controls.Add(gridView);       
    41         gridView.Columns.Add(new DataGridViewTextBoxColumn {
    42           Name = "Type", ReadOnly = true,
    43           AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
    44         });
    45         gridView.Columns.Add(new DataGridViewCheckBoxColumn
    46           { AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells });
    47         gridView.Columns.Add(new DataGridViewComboBoxColumn
    48           { AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill });               
    49         var formatterMap = new Dictionary<string, List<string>>();
    50         foreach (var formatter in formats.Value) {
    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);
    84         }
    85         foreach ( var formatterMapping in formatterMap ) {
    86           var row = gridView.Rows[gridView.Rows.Add()];
    87           row.Cells[0].Value = formatterMapping.Key;
    88           row.Cells[0].ToolTipText = formatterMapping.Key;
    89           row.Cells[1].Value = true;
    90           var comboBoxCell = (DataGridViewComboBoxCell) row.Cells[2];         
    91           foreach ( var formatter in formatterMapping.Value ) {
    92             comboBoxCell.Items.Add(formatter);
    93           }         
    94           comboBoxCell.Value = comboBoxCell.Items[0];         
    95           comboBoxCell.ToolTipText = comboBoxCell.Items[0].ToString();
    96           if (comboBoxCell.Items.Count == 1) {
    97             comboBoxCell.ReadOnly = true;
    98             comboBoxCell.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
    99           }     
    100         }     
    101130      }
    102131    }
     
    155184
    156185    private void UpdatePreview() {
    157       checkbox.Items.Clear();     
    158       foreach (var decomposer in GetDecomposers())
    159         checkbox.Items.Add(decomposer.GetType().Name + " (D)");
    160       IFormat activeFormat = (IFormat) formatterTabs.SelectedTab.Tag;
     186      checkBox.Items.Clear();
     187      IFormat activeFormat = (IFormat)formatterTabs.SelectedTab.Tag;
    161188      if (activeFormat != null) {
    162189        foreach (var formatter in GetCurrentConfiguration(activeFormat).Formatters) {
    163           checkbox.Items.Add(formatter.GetType().Name + " (F)");
    164         }
    165       }
     190          checkBox.Items.Add(formatter.GetType().Name + " (F)");
     191        }
     192      }
     193      foreach (var decomposer in GetDecomposers())
     194        checkBox.Items.Add(decomposer.GetType().Name + " (D)");     
    166195    }
    167196
     
    177206          if (controls.Length == 1) {
    178207            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 ) {               
     208              if ( row.Cells[0].Value != null &&
     209                   row.Cells[1].Value != null &&
     210                   row.Cells[2].Value != null &&
     211                   (bool)row.Cells[1].Value == true ) {
    183212                formatters.Add(
    184213                  typeNameTable[(string)row.Cells[0].Value],                 
     
    206235    public object Parse(object o) {
    207236      return null;
    208     }
    209    
    210   }
    211 
    212   public class FormatterWrapper {
    213     public IFormatter Formatter;
    214     public FormatterWrapper(IFormatter f) {
    215       Formatter = f;
    216     }
    217     public override string ToString() {
    218       return Formatter.GetType().Name;
     237    }   
     238  } 
     239
     240  public class Int2XmlFormatter: IFormatter {
     241    public Type Type { get { return typeof (int);  } }
     242    public IFormat Format { get { return XmlFormat.Instance; } }
     243    public object DoFormat(object o) {
     244      return null;
     245    }
     246    public object Parse(object o) {
     247      return null;
    219248    }
    220249  }
  • branches/New Persistence Exploration/Persistence/HeuristicLab.Persistence.GUI/PersistenceConfigurationForm.resx

    r1398 r1399  
    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>
    141132</root>
Note: See TracChangeset for help on using the changeset viewer.