clevic 0.13.0.b9 → 0.13.0.b10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -0
- data/lib/clevic/action_builder.rb +16 -16
- data/lib/clevic/ar_methods.rb +22 -22
- data/lib/clevic/attribute_list.rb +5 -5
- data/lib/clevic/cache_table.rb +18 -18
- data/lib/clevic/dataset_roller.rb +3 -3
- data/lib/clevic/default_view.rb +4 -4
- data/lib/clevic/delegate.rb +8 -8
- data/lib/clevic/delegates/combo_delegate.rb +22 -22
- data/lib/clevic/delegates/distinct_delegate.rb +5 -5
- data/lib/clevic/delegates/relational_delegate.rb +6 -6
- data/lib/clevic/delegates/set_delegate.rb +3 -3
- data/lib/clevic/dirty.rb +1 -1
- data/lib/clevic/emitter.rb +3 -3
- data/lib/clevic/extensions.rb +4 -4
- data/lib/clevic/field.rb +68 -68
- data/lib/clevic/field_valuer.rb +26 -26
- data/lib/clevic/filter_command.rb +6 -6
- data/lib/clevic/framework.rb +3 -3
- data/lib/clevic/generic_format.rb +2 -2
- data/lib/clevic/many_field.rb +3 -3
- data/lib/clevic/model_builder.rb +88 -84
- data/lib/clevic/model_column.rb +13 -13
- data/lib/clevic/ordered_dataset.rb +7 -7
- data/lib/clevic/qt/action_builder.rb +3 -3
- data/lib/clevic/qt/browser.rb +28 -28
- data/lib/clevic/qt/clipboard.rb +5 -5
- data/lib/clevic/qt/combo_delegate.rb +12 -12
- data/lib/clevic/qt/distinct_delegate.rb +1 -1
- data/lib/clevic/qt/extensions.rb +4 -4
- data/lib/clevic/qt/qt_combo_box.rb +7 -7
- data/lib/clevic/qt/relational_delegate.rb +5 -5
- data/lib/clevic/qt/search_dialog.rb +15 -15
- data/lib/clevic/qt/simplest_delegate.rb +2 -2
- data/lib/clevic/qt/table_model.rb +46 -46
- data/lib/clevic/qt/table_view.rb +48 -48
- data/lib/clevic/qt/text_delegate.rb +9 -9
- data/lib/clevic/rails_models_loaders.rb +3 -3
- data/lib/clevic/record.rb +8 -8
- data/lib/clevic/sampler.rb +6 -6
- data/lib/clevic/sequel_ar_adapter.rb +22 -22
- data/lib/clevic/sequel_clevic.rb +10 -10
- data/lib/clevic/sequel_meta.rb +5 -5
- data/lib/clevic/sequel_naked.rb +4 -4
- data/lib/clevic/swing/action.rb +20 -20
- data/lib/clevic/swing/action_builder.rb +2 -2
- data/lib/clevic/swing/boolean_delegate.rb +3 -3
- data/lib/clevic/swing/browser.rb +37 -37
- data/lib/clevic/swing/cell_editor.rb +13 -13
- data/lib/clevic/swing/cell_renderer.rb +7 -7
- data/lib/clevic/swing/clipboard.rb +19 -19
- data/lib/clevic/swing/combo_delegate.rb +26 -26
- data/lib/clevic/swing/confirm_dialog.rb +7 -7
- data/lib/clevic/swing/delegate.rb +4 -4
- data/lib/clevic/swing/extensions.rb +24 -24
- data/lib/clevic/swing/field.rb +1 -1
- data/lib/clevic/swing/relational_delegate.rb +2 -2
- data/lib/clevic/swing/row_header.rb +32 -32
- data/lib/clevic/swing/search_dialog.rb +31 -31
- data/lib/clevic/swing/selection_model.rb +12 -12
- data/lib/clevic/swing/swing_table_index.rb +6 -6
- data/lib/clevic/swing/table_model.rb +30 -30
- data/lib/clevic/swing/table_view.rb +54 -54
- data/lib/clevic/swing/table_view_focus.rb +4 -4
- data/lib/clevic/swing/tag_delegate.rb +14 -14
- data/lib/clevic/swing/tag_editor.rb +4 -4
- data/lib/clevic/swing/text_area_delegate.rb +6 -6
- data/lib/clevic/swing/text_delegate.rb +4 -4
- data/lib/clevic/table_index.rb +14 -14
- data/lib/clevic/table_model.rb +30 -30
- data/lib/clevic/table_searcher.rb +19 -19
- data/lib/clevic/table_view.rb +92 -92
- data/lib/clevic/table_view_paste.rb +19 -19
- data/lib/clevic/version.rb +1 -1
- data/lib/clevic/view.rb +22 -22
- data/models/accounts_models.rb +10 -10
- data/models/examples.rb +2 -2
- data/models/times_models.rb +32 -32
- data/models/values_models.rb +2 -2
- data/test/test_cache_table.rb +15 -15
- data/test/test_helper.rb +7 -7
- data/test/test_model_index_extensions.rb +6 -6
- data/test/test_table_model.rb +6 -6
- data/test/test_table_searcher.rb +25 -25
- metadata +33 -35
data/lib/clevic/sampler.rb
CHANGED
@@ -80,7 +80,7 @@ class Sampler
|
|
80
80
|
def string_sample
|
81
81
|
'N' * ( entity_class.max( :length.sql_function( field_name ) ).andand.to_i || 20 )
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def sample_date_time
|
85
85
|
ds = entity_class \
|
86
86
|
.filter( ~{ field_name => nil } ) \
|
@@ -90,33 +90,33 @@ class Sampler
|
|
90
90
|
# isn't called unless we access the value via the entity object
|
91
91
|
ds.first.send( field_name )
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
def date_time_sample
|
95
95
|
# replace all letters with 'N'
|
96
96
|
# and numbers with 8
|
97
97
|
do_format( sample_date_time || Date.today ).andand.gsub( /[[:alpha:]]/, 'N' ).gsub( /\d/, '8' )
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
def numeric_sample
|
101
101
|
max = entity_class.max( field_name )
|
102
102
|
min = entity_class.min( field_name )
|
103
103
|
max_length = [ do_format( min ).to_s, do_format( max ).to_s ].map( &:length ).max
|
104
104
|
'9' * ( max_length || 5 )
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
# Hmm. The first reified exemplar of a relational nested Field
|
108
108
|
class VirtualField
|
109
109
|
def initialize( entity_class, display )
|
110
110
|
@entity_class, @display = entity_class, display
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
def entity_class; @entity_class; end
|
114
114
|
def attribute; @display; end
|
115
115
|
def display; nil; end
|
116
116
|
def meta; @entity_class.meta[attribute]; end
|
117
117
|
def set; nil; end
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
def related_sample
|
121
121
|
if display.respond_to?( :to_sym )
|
122
122
|
Sampler.new( VirtualField.new( eval( meta.class_name ), display.to_sym ), &@format_block ).compute
|
@@ -10,48 +10,48 @@ module Clevic
|
|
10
10
|
@entity_class = entity_class
|
11
11
|
@entity_class.plugin :ar_methods
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def quoted_false
|
15
15
|
@entity_class.dataset.boolean_constant_sql( false )
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def quoted_true
|
19
19
|
@entity_class.dataset.boolean_constant_sql( true )
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def count( *args )
|
23
23
|
@entity_class.count_ar( *args )
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def find( *args )
|
27
27
|
@entity_class.find_ar( *args )
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def attribute_list( attribute, attribute_value, by_description, by_frequency, find_options, &block )
|
31
31
|
lister = AttributeList.new( @entity_class, attribute, attribute_value, find_options )
|
32
32
|
ds = lister.dataset( by_description, by_frequency )
|
33
33
|
ds.map( &block )
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
class ActiveRecordAdaptor
|
38
38
|
def initialize( entity_class )
|
39
39
|
@entity_class = entity_class
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def quoted_false
|
43
43
|
@entity_class.connection.quoted_false
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def quoted_true
|
47
47
|
@entity_class.connection.quoted_true
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
# options is a hash
|
51
51
|
def count( attribute = nil, options = {} )
|
52
52
|
@entity_class.count( attribute, options )
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def find( options )
|
56
56
|
@entity_class.find( :all, options )
|
57
57
|
end
|
@@ -65,7 +65,7 @@ module Clevic
|
|
65
65
|
order by lower(#{attribute.to_s})
|
66
66
|
EOF
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def query_order_frequency( attribute, attribute_value, find_options )
|
70
70
|
<<-EOF
|
71
71
|
select distinct #{attribute.to_s}, count(#{attribute.to_s})
|
@@ -76,7 +76,7 @@ module Clevic
|
|
76
76
|
order by count(#{attribute.to_s}) desc
|
77
77
|
EOF
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
# values are passed as row objects to block
|
81
81
|
def attribute_list( attribute, attribute_value, by_description, by_frequency, find_options, &block )
|
82
82
|
query =
|
@@ -88,7 +88,7 @@ module Clevic
|
|
88
88
|
else
|
89
89
|
entity_class.adaptor.query_order_frequency( attribute, attribute_value, find_options )
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
entity_class.connection.execute( query ).each( &block )
|
93
93
|
end
|
94
94
|
end
|
@@ -108,11 +108,11 @@ if defined? ActiveRecord
|
|
108
108
|
false
|
109
109
|
end
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def self.attribute_names
|
113
113
|
( column_names + reflections.keys.map {|sym| sym.to_s} ).sort
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
def adaptor
|
117
117
|
@adaptor ||= Clevic::ActiveRecordAdaptor.new( self )
|
118
118
|
end
|
@@ -127,12 +127,12 @@ module Sequel
|
|
127
127
|
def translate_options( options )
|
128
128
|
options[:key] = options[:foreign_key].andand.to_sym
|
129
129
|
options.delete( :foreign_key )
|
130
|
-
|
130
|
+
|
131
131
|
options[:class] = options[:class_name].andand.to_sym
|
132
132
|
options.delete( :class_name )
|
133
133
|
options
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
def belongs_to( name, options = nil, &block )
|
137
137
|
# work around possible Sequel bug
|
138
138
|
if options.nil?
|
@@ -141,7 +141,7 @@ module Sequel
|
|
141
141
|
many_to_one( name, translate_options( options ), &block )
|
142
142
|
end
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
def has_many( name, options = nil, &block )
|
146
146
|
# work around possible Sequel bug
|
147
147
|
if options.nil?
|
@@ -150,11 +150,11 @@ module Sequel
|
|
150
150
|
one_to_many( name, translate_options( options ), &block )
|
151
151
|
end
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
def columns_hash
|
155
155
|
db_schema
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
# return a class containing various db methods. Not sure
|
159
159
|
# if this is the right way to do it, but at least this way
|
160
160
|
# the model class namespace doesn't get filled up with crud
|
@@ -162,14 +162,14 @@ module Sequel
|
|
162
162
|
@adaptor ||= Clevic::SequelAdaptor.new( self )
|
163
163
|
end
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
module Associations
|
167
167
|
class ManyToOneAssociationReflection
|
168
168
|
# return class for this side of the association
|
169
169
|
def class_name
|
170
170
|
self[:class_name]
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
# return class for the other side of the association
|
174
174
|
def klass
|
175
175
|
eval class_name
|
data/lib/clevic/sequel_clevic.rb
CHANGED
@@ -11,49 +11,49 @@ module Sequel
|
|
11
11
|
# store model-related stuff here
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
module ClassMethods
|
16
16
|
# Copy the necessary class instance variables to the subclass.
|
17
17
|
def inherited(subclass)
|
18
18
|
super
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
# This doesn't really belong here, but I don't want to make
|
22
22
|
# a whole new plugin.
|
23
23
|
def table_exists?
|
24
24
|
db.table_exists?( implicit_table_name )
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
# Hmm, maybe these need to go in a different plugin
|
28
28
|
def column_names
|
29
29
|
columns
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# Getting heavy enough, yet?
|
33
33
|
def reflections
|
34
34
|
association_reflections
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def attribute_names
|
38
38
|
columns + reflections.keys
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def has_attribute?( attribute )
|
42
42
|
attribute_names.include?( attribute )
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
module InstanceMethods
|
48
48
|
# This should also go in another plugin
|
49
49
|
def changed?
|
50
50
|
modified?
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def readonly?
|
54
54
|
false
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def new_record?
|
58
58
|
new?
|
59
59
|
end
|
data/lib/clevic/sequel_meta.rb
CHANGED
@@ -13,7 +13,7 @@ module Sequel
|
|
13
13
|
# store model-related stuff here
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
module ClassMethods
|
18
18
|
def meta
|
19
19
|
if @meta.nil?
|
@@ -21,20 +21,20 @@ module Sequel
|
|
21
21
|
db_schema.each do |key,value|
|
22
22
|
@meta[key] = ModelColumn.new( key, value.merge( :association => false ) )
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
association_reflections.each do |key,value|
|
26
26
|
@meta[key] = ModelColumn.new( key, value.merge( :association => true ) )
|
27
27
|
end
|
28
28
|
end
|
29
29
|
@meta
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# reload from current metadata
|
33
33
|
def meta!
|
34
34
|
@meta = nil
|
35
35
|
meta
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
# column and relations, but not keys for defined relations
|
39
39
|
def attributes
|
40
40
|
meta.reject do |column,model_column|
|
@@ -43,7 +43,7 @@ module Sequel
|
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
module InstanceMethods
|
48
48
|
end
|
49
49
|
end
|
data/lib/clevic/sequel_naked.rb
CHANGED
@@ -12,17 +12,17 @@ module Sequel
|
|
12
12
|
# store model-related stuff here
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
module ClassMethods
|
17
17
|
def inherited(subclass)
|
18
18
|
super
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def naked( *args )
|
22
|
-
|
22
|
+
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
module InstanceMethods
|
27
27
|
end
|
28
28
|
end
|
data/lib/clevic/swing/action.rb
CHANGED
@@ -6,7 +6,7 @@ class Action
|
|
6
6
|
include Gather
|
7
7
|
property :shortcut, :method, :handler, :tool_tip, :visible
|
8
8
|
property :name, :text, :checkable, :enabled
|
9
|
-
|
9
|
+
|
10
10
|
# Needed to enable / disable accelerators on the fly.
|
11
11
|
def enabled=( bool )
|
12
12
|
# test for @menu_item instead of the method to
|
@@ -14,24 +14,24 @@ class Action
|
|
14
14
|
menu_item.enabled = bool unless @menu_item.nil?
|
15
15
|
@enabled = bool
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def initialize( parent, options = {}, &block )
|
19
19
|
@parent = parent
|
20
20
|
@enabled = true
|
21
|
-
|
21
|
+
|
22
22
|
# work around the Swing Stupidity detailed in enabled=
|
23
23
|
gather( options, &block )
|
24
24
|
end
|
25
25
|
attr_reader :parent, :menu_item
|
26
|
-
|
26
|
+
|
27
27
|
def plain_text
|
28
28
|
text.gsub( /&/, '' )
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def object_name
|
32
32
|
name.to_s
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
# find the java.awt.event.KeyEvent::VK constant
|
36
36
|
# for the letter after the &. Then set it on the item's
|
37
37
|
# mnemonic. Because JMenuItem.setMnemonic won't take a nil
|
@@ -47,7 +47,7 @@ class Action
|
|
47
47
|
end
|
48
48
|
@mnemonic
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
def menu_item
|
52
52
|
if @menu_item.nil?
|
53
53
|
@menu_item =
|
@@ -56,13 +56,13 @@ class Action
|
|
56
56
|
else
|
57
57
|
javax.swing.JMenuItem.new
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
# Menu item always enabled, until later.
|
61
61
|
# Otherwise it prevents the assignment
|
62
62
|
# of an accelerator key. So we have to
|
63
63
|
# work around yet another Swing stupidity.
|
64
64
|
menu_item.enabled = true
|
65
|
-
|
65
|
+
|
66
66
|
menu_item.text = plain_text
|
67
67
|
menu_item.mnemonic = mnemonic if mnemonic
|
68
68
|
menu_item.accelerator = parse_shortcut( shortcut ) unless shortcut.nil?
|
@@ -70,14 +70,14 @@ class Action
|
|
70
70
|
menu_item.add_action_listener do |event|
|
71
71
|
handler.call( event )
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
# Put this at the end so it doesn't interfere with the
|
75
75
|
# keystroke assignment Swing Stupidity.
|
76
76
|
menu_item.enabled = enabled
|
77
77
|
end
|
78
78
|
@menu_item
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
# parse a Qt-style Ctrl+D shortcut specification
|
82
82
|
# and return a javax.swing.KeyStroke
|
83
83
|
def parse_shortcut( sequence )
|
@@ -86,7 +86,7 @@ class Action
|
|
86
86
|
# Yes, the space MUST be last in the charset, otherwise Ctrl-" fails
|
87
87
|
modifiers = sequence.split( /[-+ ]/ )
|
88
88
|
last = modifiers.pop
|
89
|
-
|
89
|
+
|
90
90
|
modifier_mask = modifiers.inject(0) do |mask,value|
|
91
91
|
mask |
|
92
92
|
if value =~ /ctrl/i
|
@@ -95,27 +95,27 @@ class Action
|
|
95
95
|
eval( "java.awt.event.InputEvent::#{value.upcase}_DOWN_MASK" )
|
96
96
|
end
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
keystroke =
|
100
100
|
if last.length == 1
|
101
101
|
case last
|
102
102
|
# these two seem to break the KeyStroke parsing algorithm
|
103
103
|
when "'"
|
104
104
|
javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent::VK_QUOTE, modifier_mask )
|
105
|
-
|
105
|
+
|
106
106
|
when '"'
|
107
107
|
javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent::VK_QUOTE, modifier_mask | java.awt.event.InputEvent::SHIFT_DOWN_MASK )
|
108
|
-
|
108
|
+
|
109
109
|
# the conversion in else doesn't work for these
|
110
110
|
when '['
|
111
111
|
javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent::VK_OPEN_BRACKET, modifier_mask )
|
112
|
-
|
112
|
+
|
113
113
|
when ']'
|
114
114
|
javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent::VK_CLOSE_BRACKET, modifier_mask )
|
115
|
-
|
115
|
+
|
116
116
|
when ';'
|
117
117
|
javax.swing.KeyStroke.getKeyStroke( java.awt.event.KeyEvent::VK_SEMICOLON, modifier_mask )
|
118
|
-
|
118
|
+
|
119
119
|
else
|
120
120
|
keystring = javax.swing.KeyStroke.getKeyStroke( java.lang.Character.new( last.to_char ), modifier_mask ).toString
|
121
121
|
# have to do this conversion for Mac OS X
|
@@ -137,11 +137,11 @@ class Separator < Action
|
|
137
137
|
def initialize
|
138
138
|
super(nil)
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
def shortcut
|
142
142
|
nil
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
def menu_item
|
146
146
|
end
|
147
147
|
end
|