Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/30/16 16:33:05 (7 years ago)
Author:
bburlacu
Message:

#2710: Offer the user the option to provide the variable name when the symbol does not contain a list of available variable names. In this case the combo box is replaced by a text box.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeVariableNodeEditDialog.cs

    r14185 r14432  
    2222using System;
    2323using System.ComponentModel;
     24using System.Linq;
    2425using System.Text;
    2526using System.Windows.Forms;
     
    4041    }
    4142
     43    public string SelectedVariableName {
     44      get { return variableNamesCombo.Visible ? variableNamesCombo.Text : variableNameTextBox.Text; }
     45    }
     46
    4247    public VariableNodeEditDialog(ISymbolicExpressionTreeNode node) {
    4348      InitializeComponent();
    4449      oldValueTextBox.TabStop = false; // cannot receive focus using tab key
    45 
    4650      NewNode = (VariableTreeNode)node; // will throw an invalid cast exception if node is not of the correct type
    4751      InitializeFields();
     
    5761        variableNameLabel.Visible = true;
    5862        variableNamesCombo.Visible = true;
    59         foreach (var name in variableTreeNode.Symbol.VariableNames) variableNamesCombo.Items.Add(name);
    60         variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variableTreeNode.VariableName);
     63        if (variableTreeNode.Symbol.VariableNames.Any()) {
     64          foreach (var name in variableTreeNode.Symbol.VariableNames)
     65            variableNamesCombo.Items.Add(name);
     66          variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variableTreeNode.VariableName);
     67          variableNamesCombo.Visible = true;
     68          variableNameTextBox.Visible = false;
     69        } else {
     70          variableNamesCombo.Visible = false;
     71          variableNameTextBox.Visible = true;
     72        }
    6173      }
    6274    }
     
    93105    #region combo box validation and events
    94106    private void variableNamesCombo_Validating(object sender, CancelEventArgs e) {
     107      if (variableNamesCombo.Items.Count == 0) return;
    95108      if (variableNamesCombo.Items.Contains(variableNamesCombo.SelectedItem)) return;
    96109      e.Cancel = true;
     
    119132    private void OnDialogValidated(object sender, EventArgs e) {
    120133      double weight = double.Parse(newValueTextBox.Text);
    121       var variableName = (string)variableNamesCombo.SelectedItem;
    122134      // we impose an extra validation condition: that the weight/value be different than the original ones
     135      var variableName = SelectedVariableName;
    123136      if (variableTreeNode.Weight.Equals(weight) && variableTreeNode.VariableName.Equals(variableName)) return;
    124137      variableTreeNode.Weight = weight;
Note: See TracChangeset for help on using the changeset viewer.