clevic 0.13.0.b9 → 0.13.0.b10
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -7,22 +7,22 @@ module Clevic
|
|
7
7
|
# .... and work around various other Swing stupidities
|
8
8
|
class ComboBox < javax.swing.JComboBox
|
9
9
|
attr_accessor :delegate
|
10
|
-
|
10
|
+
|
11
11
|
def initialize( field )
|
12
12
|
super()
|
13
13
|
@field = field
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# For Clevic::ComboDelegate to call
|
17
17
|
def no_insert=( bool )
|
18
18
|
# Swing doesn't have combo policies like Qt.
|
19
19
|
# From what I can see, anyway.
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
# set to true by processKeyBinding when a character
|
23
23
|
# key is pressed. Used by the autocomplete code.
|
24
24
|
attr_reader :typing
|
25
|
-
|
25
|
+
|
26
26
|
def configureEditor( combo_box_editor, item )
|
27
27
|
value =
|
28
28
|
if @field.related_class && item.is_a?( @field.related_class )
|
@@ -30,7 +30,7 @@ class ComboBox < javax.swing.JComboBox
|
|
30
30
|
else
|
31
31
|
item
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
combo_box_editor.item = value
|
35
35
|
end
|
36
36
|
|
@@ -59,38 +59,38 @@ class ComboDelegate < Delegate
|
|
59
59
|
super
|
60
60
|
@autocompleting = false
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
def combo_class
|
64
64
|
ComboBox
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
# the cell must be selected before the edit can be clicked
|
68
68
|
def needs_pre_selection?
|
69
69
|
true
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def create_combo_box( *args )
|
73
73
|
# create a new combo class each time, otherwise
|
74
74
|
# we have to get into managing cleaning out the model
|
75
75
|
# and so on
|
76
76
|
combo_class.new( field ).tap do |combo|
|
77
77
|
combo.font = Clevic.tahoma
|
78
|
-
|
78
|
+
|
79
79
|
# allow for transform of objects to their requested display values
|
80
80
|
@original_renderer = combo.renderer
|
81
81
|
combo.renderer = self
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
include javax.swing.ListCellRenderer
|
86
|
-
|
86
|
+
|
87
87
|
# return the component to render the values in the list
|
88
88
|
# we just transform the value, and pass it to the
|
89
89
|
# pre-existing renderer for the combo.
|
90
90
|
def getListCellRendererComponent(jlist, value, index, selected, cell_has_focus)
|
91
91
|
@original_renderer.getListCellRendererComponent(jlist, display_for( value ), index, selected, cell_has_focus)
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
# return a new text editor. This is for distinct_delegate when there
|
95
95
|
# are no other values to choose from.
|
96
96
|
# TODO move into distinct_delegate then?
|
@@ -99,7 +99,7 @@ class ComboDelegate < Delegate
|
|
99
99
|
line.font = Clevic.tahoma
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
# Some GUIs (Qt) can just set this. Swing can't.
|
104
104
|
def configure_prefix
|
105
105
|
# pick up events from editor
|
@@ -119,17 +119,17 @@ class ComboDelegate < Delegate
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
def framework_setup( *args )
|
124
124
|
# turn on typing the the text field of the combo
|
125
125
|
# otherwise prefix matching doesn't work
|
126
126
|
editor.editable = true
|
127
|
-
|
127
|
+
|
128
128
|
# catch the enter key action event
|
129
129
|
editor.editor.editor_component.add_action_listener do |event|
|
130
130
|
cell_editor.andand.stopCellEditing
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
133
|
# set initial focus and selection in edit part of combo
|
134
134
|
editor.editor.editor_component.with do |text_edit|
|
135
135
|
unless text_edit.text.nil?
|
@@ -141,7 +141,7 @@ class ComboDelegate < Delegate
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
# Recreate the model and fill it with anything in population that
|
146
146
|
# matches the prefix first, followed by anything in the population that
|
147
147
|
# doesn't match the prefix.
|
@@ -154,7 +154,7 @@ class ComboDelegate < Delegate
|
|
154
154
|
# save text and popup
|
155
155
|
save_item = editor.editor.item
|
156
156
|
dropdown_visible = editor.popup_visible?
|
157
|
-
|
157
|
+
|
158
158
|
# repopulate based on the prefix
|
159
159
|
prefix ||= editor.editor.item
|
160
160
|
editor.model = editor.model.class.new
|
@@ -162,13 +162,13 @@ class ComboDelegate < Delegate
|
|
162
162
|
matching, non_matching = population.partition{ |item| display_for( item ) =~ /^#{prefix}/i }
|
163
163
|
matching.each {|item| editor << item}
|
164
164
|
non_matching.each {|item| editor << item}
|
165
|
-
|
165
|
+
|
166
166
|
# restore text and popup
|
167
167
|
editor.editor.item = text || save_item
|
168
168
|
editor.popup_visible = dropdown_visible
|
169
169
|
end
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
# make sure we don't react to document change events
|
173
173
|
# while we're doing autocompletion. Reentrant
|
174
174
|
def autocomplete( &block )
|
@@ -177,7 +177,7 @@ class ComboDelegate < Delegate
|
|
177
177
|
ensure
|
178
178
|
@autocompleting = false
|
179
179
|
end
|
180
|
-
|
180
|
+
|
181
181
|
# http://www.drdobbs.com/184404457 for autocompletion steps
|
182
182
|
def filter_prefix( prefix )
|
183
183
|
# search for matching item in the UI display_for for the items in the combo model
|
@@ -188,7 +188,7 @@ class ComboDelegate < Delegate
|
|
188
188
|
autocomplete do
|
189
189
|
# set the shortlist, and the text editor value
|
190
190
|
repopulate prefix, candidate
|
191
|
-
|
191
|
+
|
192
192
|
# set the suggestion selection
|
193
193
|
editor.editor.editor_component.with do |text_edit|
|
194
194
|
# highlight the suggested match, and leave caret
|
@@ -200,7 +200,7 @@ class ComboDelegate < Delegate
|
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
203
|
-
|
203
|
+
|
204
204
|
# open the combo box, just like if F4 was pressed
|
205
205
|
# big trouble here with JComboBox firing an comboEdited action
|
206
206
|
# (probably) on focusGained
|
@@ -216,18 +216,18 @@ class ComboDelegate < Delegate
|
|
216
216
|
end
|
217
217
|
end
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
# open the combo box, just like if f4 was pressed
|
221
221
|
def minimal_edit
|
222
222
|
editor.hide_popup if is_combo?
|
223
223
|
end
|
224
|
-
|
224
|
+
|
225
225
|
def is_combo?
|
226
226
|
# Assume we're a combo if we don't have an editor yet, otherwise
|
227
227
|
# check
|
228
228
|
editor.nil? || editor.is_a?( javax.swing.JComboBox )
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
def value
|
232
232
|
# editor could be either a combo or a line (DistinctDelegate with no values yet)
|
233
233
|
if is_combo?
|
@@ -7,17 +7,17 @@ module Clevic
|
|
7
7
|
@results = []
|
8
8
|
yield self if block_given?
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
attr_accessor :names, :results, :question, :title, :dialog_result, :parent
|
12
|
-
|
12
|
+
|
13
13
|
def to_java( arg )
|
14
14
|
@options.keys.to_java( arg )
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def canonical_results
|
18
18
|
@canonical_results ||= [:accept, :reject]
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
# To create a an Ok button that has the focus, and causes
|
22
22
|
# the class to return true from accepted?
|
23
23
|
# dialog['Ok'] = :accept, true
|
@@ -31,15 +31,15 @@ module Clevic
|
|
31
31
|
results << result.to_sym
|
32
32
|
@default = name.to_s if default
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def accepted?
|
36
36
|
results[dialog_result] == :accept
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def rejected?
|
40
40
|
results[dialog_result] == :reject
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def show
|
44
44
|
self.dialog_result = javax.swing.JOptionPane.showOptionDialog(
|
45
45
|
parent,
|
@@ -7,7 +7,7 @@ module Clevic
|
|
7
7
|
@field = field
|
8
8
|
@message_receivers = Set.new
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
# FIXME this must actually show a message, and
|
12
12
|
# the Qt code must use it too
|
13
13
|
def show_message( msg, &block )
|
@@ -19,12 +19,12 @@ module Clevic
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
# workaround for broken JTable editing starts
|
24
24
|
def needs_pre_selection?
|
25
25
|
false
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
# Return something useful if this should use the default GUI framework
|
29
29
|
# mechanism for table editing. Default is false, so native framework
|
30
30
|
# won't be used. For Java/Swing, this would return the a class object
|
@@ -33,7 +33,7 @@ module Clevic
|
|
33
33
|
def native
|
34
34
|
false
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def inspect
|
38
38
|
"<#{self.class.name} native=#{native} needs_pre_selection=#{needs_pre_selection?}>"
|
39
39
|
end
|
@@ -4,7 +4,7 @@ class BlockRunner < java.lang.Thread
|
|
4
4
|
def initialize(&proc)
|
5
5
|
@p = proc
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def run
|
9
9
|
@p.call
|
10
10
|
end
|
@@ -55,13 +55,13 @@ unless defined? Component
|
|
55
55
|
case obj
|
56
56
|
when Clevic::Separator
|
57
57
|
add_separator
|
58
|
-
|
58
|
+
|
59
59
|
when Clevic::Action
|
60
60
|
add obj.menu_item
|
61
|
-
|
61
|
+
|
62
62
|
when String
|
63
63
|
add obj.to_java_string
|
64
|
-
|
64
|
+
|
65
65
|
else
|
66
66
|
add obj
|
67
67
|
end
|
@@ -88,13 +88,13 @@ unless defined? JComboBox
|
|
88
88
|
def << ( value )
|
89
89
|
model.addElement( value )
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def each
|
93
93
|
(0...model.size).each do |i|
|
94
94
|
yield model.getElementAt( i )
|
95
95
|
end
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
include Enumerable
|
99
99
|
end
|
100
100
|
end
|
@@ -103,17 +103,17 @@ unless defined? JTabbedPane
|
|
103
103
|
JTabbedPane = javax.swing.JTabbedPane
|
104
104
|
class JTabbedPane
|
105
105
|
include Enumerable
|
106
|
-
|
106
|
+
|
107
107
|
def each
|
108
108
|
(0...count).each do |index|
|
109
109
|
yield getComponentAt( index )
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
def count
|
114
114
|
getTabCount
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def current=( component )
|
118
118
|
self.selected_component = component
|
119
119
|
end
|
@@ -147,44 +147,44 @@ unless defined? KeyEvent
|
|
147
147
|
def alt?
|
148
148
|
modifiers & self.class::ALT_MASK != 0
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
def ctrl?
|
152
152
|
modifiers & self.class::CTRL_MASK != 0
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
def meta?
|
156
156
|
modifiers & self.class::META_MASK != 0
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
def self.function_keys
|
160
160
|
@function_keys ||= (1..24).map{|i| eval( "VK_F#{i}" ) }
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
def fx?
|
164
164
|
self.class.function_keys.include?( key_code )
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
def del?
|
168
168
|
key_code == VK_DELETE
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
def shift?
|
172
172
|
modifiers & self.class::SHIFT_MASK != 0
|
173
173
|
end
|
174
|
-
|
174
|
+
|
175
175
|
def plain?
|
176
176
|
modifiers == 0
|
177
177
|
end
|
178
|
-
|
178
|
+
|
179
179
|
def esc?
|
180
180
|
key_code == VK_ESCAPE
|
181
181
|
end
|
182
|
-
|
182
|
+
|
183
183
|
# a KEY_TYPED event
|
184
184
|
def typed?
|
185
185
|
getID == self.class::KEY_TYPED
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
def inspect
|
189
189
|
"<KeyEvent id=#{getID} #{self.class.getKeyText(key_code)} '#{key_char}'>"
|
190
190
|
end
|
@@ -206,15 +206,15 @@ unless defined? MouseEvent
|
|
206
206
|
def pressed?
|
207
207
|
getID == MOUSE_PRESSED
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
def released?
|
211
211
|
getID == MOUSE_RELEASED
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
def clicked?
|
215
215
|
getID == MOUSE_CLICKED
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
#~ def inspect
|
219
219
|
#~ <<EOF
|
220
220
|
|
@@ -233,7 +233,7 @@ unless defined? TableModelEvent
|
|
233
233
|
def inspect
|
234
234
|
"#<#{first_row..last_row}, #{column}, #{const_lookup( type )} >"
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
def updated?
|
238
238
|
type == self.class::UPDATE
|
239
239
|
end
|
@@ -245,7 +245,7 @@ unless defined? TableModelEvent
|
|
245
245
|
def inserted?
|
246
246
|
type == self.class::INSERT
|
247
247
|
end
|
248
|
-
|
248
|
+
|
249
249
|
# returns true if this is a notification to update all
|
250
250
|
# rows, ie a fireTableDataChanged() was called
|
251
251
|
def all_rows?
|
data/lib/clevic/swing/field.rb
CHANGED
@@ -12,13 +12,13 @@ class RelationalDelegate < ComboDelegate
|
|
12
12
|
def initialize( field )
|
13
13
|
super
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# use the Clevic::ComboBox class because JCombobox is remarkably stupid
|
17
17
|
# about far too many things.
|
18
18
|
def combo_class
|
19
19
|
ComboBox
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
# don't allow new values
|
23
23
|
def restricted?
|
24
24
|
true
|
@@ -11,18 +11,18 @@ module Clevic
|
|
11
11
|
def initialize( table_model )
|
12
12
|
super()
|
13
13
|
@table_model = table_model
|
14
|
-
|
14
|
+
|
15
15
|
# re-fire events
|
16
16
|
table_model.add_table_model_listener do |event|
|
17
17
|
fireTableChanged( event )
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
# override TableModel method
|
22
22
|
def getRowCount
|
23
23
|
@table_model.getRowCount
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# override TableModel method
|
27
27
|
def getColumnCount
|
28
28
|
1
|
@@ -32,7 +32,7 @@ module Clevic
|
|
32
32
|
def getColumnName( column_index )
|
33
33
|
"row"
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def getColumnClass( column_index )
|
37
37
|
java.lang.Object
|
38
38
|
end
|
@@ -40,11 +40,11 @@ module Clevic
|
|
40
40
|
def isCellEditable( row_index, column_index )
|
41
41
|
false
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def getValueAt( row_index, column_index )
|
45
45
|
row_index+1
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def id_value( row_index, column_index )
|
49
49
|
if @table_model.collection.cached_at?( row_index )
|
50
50
|
"#{row_index+1} [id=#{@table_model.collection[row_index].id}]"
|
@@ -52,7 +52,7 @@ module Clevic
|
|
52
52
|
row_index+1
|
53
53
|
end
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def setValueAt( value, row_index, column_index )
|
57
57
|
raise "Can't set values in the row header"
|
58
58
|
end
|
@@ -68,24 +68,24 @@ module Clevic
|
|
68
68
|
unless ancestors.include?( javax.swing.table.TableCellRenderer )
|
69
69
|
include javax.swing.table.TableCellRenderer
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
# The Clevic::TableView instance
|
73
73
|
attr_reader :table_view
|
74
|
-
|
74
|
+
|
75
75
|
# this will add a row header to the passed table_view
|
76
76
|
def initialize( table_view )
|
77
77
|
@table_view = table_view
|
78
78
|
super( RowHeaderModel.new( table_view.model ) )
|
79
79
|
self.font = table_view.font
|
80
80
|
self.grid_color = java.awt.Color::white
|
81
|
-
|
81
|
+
|
82
82
|
# user header renderer for all cells
|
83
83
|
set_default_renderer( java.lang.Object, table_header.default_renderer )
|
84
|
-
|
84
|
+
|
85
85
|
# set the width
|
86
86
|
column_width = table_view.column_width( 0, " #{row_count}" )
|
87
87
|
column_model.column( 0 ).preferred_width = column_width
|
88
|
-
|
88
|
+
|
89
89
|
# This is a workaround either for OSX, or java-1.5.0_19-b02-306
|
90
90
|
self.minimum_size = java.awt.Dimension.new( column_width, minimum_size.height )
|
91
91
|
|
@@ -94,23 +94,23 @@ module Clevic
|
|
94
94
|
count_label.font = self.font
|
95
95
|
count_label.horizontal_alignment = javax.swing.JComponent::CENTER_ALIGNMENT
|
96
96
|
table_view.set_corner( javax.swing.ScrollPaneConstants::UPPER_LEFT_CORNER, count_label )
|
97
|
-
|
97
|
+
|
98
98
|
# make sure count label is updated when the model changes
|
99
99
|
model.add_table_model_listener do |event|
|
100
100
|
count_label.text = row_count.to_s
|
101
101
|
end
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
# insert into the row header side of the scrollpane
|
105
105
|
table_view.row_header = javax.swing.JViewport.new.tap do |vp|
|
106
106
|
vp.view = self
|
107
107
|
# make sure size is passed along to viewport
|
108
108
|
vp.preferred_size = preferred_size
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
row_selection_handlers
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
# Transfer row header selection to full row selections in the main
|
115
115
|
# table. Also clear the row header selection if a main table
|
116
116
|
# selection happens.
|
@@ -119,14 +119,14 @@ module Clevic
|
|
119
119
|
selection_model.addListSelectionListener do |list_event|
|
120
120
|
process_list_selection( list_event )
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
# selections in the main table must clear any selections
|
124
124
|
# in the row header, ie self
|
125
125
|
table_view.jtable.selection_model.addListSelectionListener do |event|
|
126
126
|
selection_model.clear_selection unless row_header_selecting
|
127
127
|
end
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
# guard to make sure changes to main table selection don't feed back.
|
131
131
|
def row_header_selecting( &block )
|
132
132
|
if block_given?
|
@@ -140,68 +140,68 @@ module Clevic
|
|
140
140
|
@row_header_selecting
|
141
141
|
end
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
def process_list_selection( event )
|
145
145
|
# tell the main table handler we're busy
|
146
146
|
row_header_selecting do
|
147
147
|
# clear main table selection and start again
|
148
148
|
table_view.jtable.selection_model.clear_selection
|
149
|
-
|
149
|
+
|
150
150
|
# select the whole row in main table. Subsequent row selections will also
|
151
151
|
# select the whole row. What a broken API.
|
152
152
|
table_view.jtable.setColumnSelectionInterval( table_view.model.fields.size-1, 0 )
|
153
|
-
|
153
|
+
|
154
154
|
selected_rows.each do |row|
|
155
155
|
table_view.jtable.selection_model.addSelectionInterval( row, row )
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
# make sure the keyboard focus is on the latest selected row
|
159
159
|
table_view.jtable.selection_model.addSelectionInterval( selection_model.lead_selection_index, selection_model.lead_selection_index )
|
160
|
-
|
160
|
+
|
161
161
|
# make sure main table gets focus again
|
162
162
|
table_view.request_focus
|
163
163
|
end
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
# return self so that getTableCellRendererComponent is called
|
167
167
|
def getCellRenderer( row, column )
|
168
168
|
self
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
# Implementation of TableCellRenderer
|
172
172
|
# return renderer Component
|
173
173
|
def getTableCellRendererComponent(jtable, value,is_selected,has_focus,row,column)
|
174
174
|
item = table_view.model.collection[row]
|
175
175
|
renderer = get_default_renderer( java.lang.Object ).getTableCellRendererComponent(jtable,value,is_selected,has_focus,row,column)
|
176
|
-
|
176
|
+
|
177
177
|
case
|
178
178
|
# no highlighting for an empty item
|
179
179
|
when item.nil?
|
180
180
|
renderer.background = java.awt.Color::yellow
|
181
181
|
renderer.opaque = true
|
182
182
|
renderer.tool_tip_text = "deleted elsewhere"
|
183
|
-
|
183
|
+
|
184
184
|
# there's a validation error
|
185
185
|
when item.errors && !item.errors.empty?
|
186
186
|
renderer.background = java.awt.Color::orange
|
187
187
|
renderer.opaque = true
|
188
188
|
renderer.tool_tip_text = "validation errors"
|
189
|
-
|
189
|
+
|
190
190
|
# record isn't saved yet
|
191
191
|
when item.changed?
|
192
192
|
renderer.background = java.awt.Color::yellow
|
193
193
|
renderer.opaque = true
|
194
194
|
renderer.tool_tip_text = "row not saved"
|
195
|
-
|
195
|
+
|
196
196
|
when is_selected
|
197
197
|
renderer.background = javax.swing.UIManager.get 'Table.selectionBackground'
|
198
198
|
renderer.tool_tip_text = "id=#{item.id}"
|
199
|
-
|
199
|
+
|
200
200
|
else
|
201
201
|
renderer.tool_tip_text = "id=#{item.id}"
|
202
|
-
|
202
|
+
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
renderer
|
206
206
|
end
|
207
207
|
|