private void HandleFieldChanged(object o, EventArgs args)
        {
            if (field_chooser.Active < 0 || field_chooser.Active >= sorted_fields.Length)
            {
                return;
            }

            QueryField field = sorted_fields [field_chooser.Active];

            // Leave everything as is unless the new field is a different type
            if (this.field != null && (field.ValueTypes.Length == 1 && this.field.ValueTypes.Length == 1 && field.ValueTypes[0] == this.field.ValueTypes[0]))
            {
                this.field = field;
                return;
            }

            op_chooser.Changed -= HandleOperatorChanged;

            this.field = field;

            // Remove old type's operators
            while (op_chooser.Model.IterNChildren() > 0)
            {
                op_chooser.RemoveText(0);
            }

            // Add new field's operators
            int val_count = 0;

            value_entries.Clear();
            operators.Clear();
            operator_entries.Clear();
            foreach (QueryValue val in this.field.CreateQueryValues())
            {
                QueryValueEntry entry = QueryValueEntry.Create(val);
                value_entries.Add(entry);

                if (val_count++ > 0)
                {
                    op_chooser.AppendText(String.Empty);
                    operators.Add(null);
                }

                foreach (Operator op in val.OperatorSet)
                {
                    op_chooser.AppendText(op.Label);
                    operators.Add(op);
                    operator_entries [op] = entry;
                }
            }

            SetValueEntry(value_entries[0]);

            // TODO: If we have the same operator that was previously selected, select it
            op_chooser.Changed += HandleOperatorChanged;
            op_chooser.Active   = 0;
        }
        private void SetValueEntry(QueryValueEntry entry)
        {
            if (first)
            {
                first = false;
            }
            else
            {
                value_box.Remove(value_box.Children [0]);
            }

            current_value_entry = entry;
            value_box.PackStart(current_value_entry, false, true, 0);
            current_value_entry.ShowAll();
        }
        public static QueryValueEntry Create(QueryValue qv)
        {
            Type qv_type    = qv.GetType();
            Type entry_type = null;

            foreach (KeyValuePair <Type, Type> pair in types)
            {
                if (pair.Value == qv_type)
                {
                    entry_type = pair.Key;
                    break;
                }
            }

            // If we don't have an entry type that's exactly for our type, take a more generic one
            if (entry_type == null)
            {
                foreach (KeyValuePair <Type, Type> pair in types)
                {
                    if (qv_type.IsSubclassOf(pair.Value))
                    {
                        entry_type = pair.Key;
                        break;
                    }
                }
            }

            if (entry_type != null)
            {
                QueryValueEntry entry = Activator.CreateInstance(entry_type) as QueryValueEntry;
                entry.QueryValue = qv;
                return(entry);
            }

            return(null);
        }
Exemple #4
0
        private void SetValueEntry (QueryValueEntry entry)
        {
            if (first) {
                first = false;
            } else {
                value_box.Remove (value_box.Children [0]);
            }

            current_value_entry = entry;
            value_box.PackStart (current_value_entry, false, true, 0);
            current_value_entry.ShowAll ();
        }
Exemple #5
0
 public static Type GetValueType (QueryValueEntry entry)
 {
     return types [entry.GetType ()];
 }
 public static Type GetValueType(QueryValueEntry entry)
 {
     return(types [entry.GetType()]);
 }