5
// Gabriel Burt <gburt@novell.com>
7
// Copyright (C) 2008 Novell, Inc.
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
using System.Collections.Generic;
35
namespace Hyena.Query.Gui
37
public abstract class QueryValueEntry : HBox
39
private static Dictionary<Type, Type> types = new Dictionary<Type, Type> ();
41
protected int DefaultWidth {
45
public QueryValueEntry () : base ()
50
public abstract QueryValue QueryValue { get; set; }
52
public static QueryValueEntry Create (QueryValue qv)
54
Type qv_type = qv.GetType ();
55
Type entry_type = null;
57
foreach (KeyValuePair<Type, Type> pair in types) {
58
if (pair.Value == qv_type) {
59
entry_type = pair.Key;
64
// If we don't have an entry type that's exactly for our type, take a more generic one
65
if (entry_type == null) {
66
foreach (KeyValuePair<Type, Type> pair in types) {
67
if (qv_type.IsSubclassOf (pair.Value)) {
68
entry_type = pair.Key;
74
if (entry_type != null) {
75
QueryValueEntry entry = Activator.CreateInstance (entry_type) as QueryValueEntry;
76
entry.QueryValue = qv;
83
public static void AddSubType (Type entry_type, Type query_value_type)
85
types[entry_type] = query_value_type;
88
public static Type GetValueType (QueryValueEntry entry)
90
return types [entry.GetType ()];
93
static QueryValueEntry () {
94
AddSubType (typeof(StringQueryValueEntry), typeof(StringQueryValue));
95
AddSubType (typeof(IntegerQueryValueEntry), typeof(IntegerQueryValue));
96
AddSubType (typeof(DateQueryValueEntry), typeof(DateQueryValue));
97
AddSubType (typeof(FileSizeQueryValueEntry), typeof(FileSizeQueryValue));
98
AddSubType (typeof(TimeSpanQueryValueEntry), typeof(TimeSpanQueryValue));
99
AddSubType (typeof(RelativeTimeSpanQueryValueEntry), typeof(RelativeTimeSpanQueryValue));
100
AddSubType (typeof(NullQueryValueEntry), typeof(NullQueryValue));