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
@@ -10,140 +10,140 @@ module Clevic
|
|
10
10
|
else
|
11
11
|
super()
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
init_controls
|
15
15
|
init_layout
|
16
|
-
|
16
|
+
|
17
17
|
self.default_close_operation = javax.swing.WindowConstants::HIDE_ON_CLOSE
|
18
18
|
self.name = "SearchDialog"
|
19
19
|
self.modal = modal
|
20
20
|
self.title = "Search"
|
21
|
-
|
21
|
+
|
22
22
|
# Enter triggers Ok button
|
23
23
|
root_pane.default_button = ok_button
|
24
|
-
|
24
|
+
|
25
25
|
# TODO finish this for Esc key to close dialog
|
26
26
|
#~ esc = javax.swing.KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 )
|
27
27
|
#~ root_pane.registerKeyboardAction( actionListener, stroke, javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW )
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# after the dialog, this will be either accepted or rejected
|
31
31
|
attr_reader :status
|
32
|
-
|
32
|
+
|
33
33
|
def from_start?
|
34
34
|
from_start.selected
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def from_start=( value )
|
38
38
|
from_start.selected = value
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def regex?
|
42
42
|
regex.selected
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def whole_words?
|
46
46
|
whole_words.selected
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def forwards?
|
50
50
|
forwards.selected
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def backwards?
|
54
54
|
backwards.selected
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# return either :backwards or :forwards
|
58
58
|
def direction
|
59
59
|
return :forwards if forwards?
|
60
60
|
return :backwards if backwards?
|
61
61
|
raise "direction not known"
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
# show the dialog, wait for close,
|
65
65
|
# return an object that understands rejected? and accepted?
|
66
66
|
def exec( text = '' )
|
67
67
|
self.search_text = text
|
68
68
|
search_combo.request_focus
|
69
69
|
search_combo.editor.select_all
|
70
|
-
|
70
|
+
|
71
71
|
# modal dialog, so this will wait
|
72
72
|
show
|
73
|
-
|
73
|
+
|
74
74
|
# remember previous searches
|
75
75
|
unless search_combo.include?( search_text )
|
76
76
|
search_combo << search_text
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
self
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def search_text=( value )
|
83
83
|
search_combo.editor.item = value.to_s
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
def search_text
|
87
87
|
search_combo.editor.item
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
def accepted?
|
91
91
|
status == :accept
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
def accept!
|
95
95
|
@status = :accept
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
def rejected?
|
99
99
|
status == :reject
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def reject!
|
103
103
|
@status = :reject
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
attr_reader :search_label, :search_combo
|
107
107
|
attr_reader :from_start, :whole_words, :regex
|
108
108
|
attr_reader :forwards, :backwards
|
109
109
|
attr_reader :ok_button, :cancel_button
|
110
|
-
|
110
|
+
|
111
111
|
def init_controls
|
112
112
|
@search_label = javax.swing.JLabel.new( "Search" ).tap do |search_label|
|
113
113
|
search_label.text = "Search"
|
114
114
|
search_label.name = "search_label"
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
@search_combo = javax.swing.JComboBox.new.tap do |search_combo|
|
118
118
|
search_combo.editable = true
|
119
119
|
search_combo.name = "search_combo"
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
@from_start = javax.swing.JCheckBox.new.tap do |from_start|
|
123
123
|
from_start.mnemonic = 'S'
|
124
124
|
from_start.text = "From Start"
|
125
125
|
from_start.name = "from_start"
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
@regex = javax.swing.JCheckBox.new.tap do |regex|
|
129
129
|
regex.mnemonic = 'R'
|
130
130
|
regex.text = "Regular Expression"
|
131
131
|
regex.name = "regex"
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
@whole_words = javax.swing.JCheckBox.new.tap do |whole_words|
|
135
135
|
whole_words.mnemonic = 'W'
|
136
136
|
whole_words.text = "Whole words"
|
137
137
|
whole_words.name = "whole_words"
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
@forwards = javax.swing.JRadioButton.new.tap do |forwards|
|
141
141
|
forwards.mnemonic = 'F'
|
142
142
|
forwards.text = "Forwards"
|
143
143
|
forwards.name = "forwards"
|
144
144
|
forwards.selected = true
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
@backwards = javax.swing.JRadioButton.new.tap do |backwards|
|
148
148
|
backwards.mnemonic = 'B'
|
149
149
|
backwards.text = "Backwards"
|
@@ -170,7 +170,7 @@ module Clevic
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
end
|
173
|
-
|
173
|
+
|
174
174
|
# this was originally Java from NetBeans, so it's really ugly.
|
175
175
|
# Note that for 1.5 compatibility, we have to use org.jdesktop.layout.GroupLayout
|
176
176
|
# and include swing-layout-1.0.3.jar
|
@@ -14,19 +14,19 @@ class SelectionRange
|
|
14
14
|
@row_range = row_range
|
15
15
|
@column_range = column_range
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def height
|
19
19
|
@row_range.distance
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def width
|
23
23
|
@column_range.distance
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def top_left
|
27
27
|
SwingTableIndex.new( nil, @row_range.first, @column_range.first )
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def bottom_right
|
31
31
|
SwingTableIndex.new( nil, @row_range.last, @column_range.last )
|
32
32
|
end
|
@@ -36,13 +36,13 @@ class SelectionModel
|
|
36
36
|
def initialize( table_view )
|
37
37
|
@table_view = table_view
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
attr_reader :table_view
|
41
|
-
|
41
|
+
|
42
42
|
def jtable
|
43
43
|
@table_view.jtable
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
# return a collection of selection ranges
|
47
47
|
def ranges
|
48
48
|
rv = []
|
@@ -53,27 +53,27 @@ class SelectionModel
|
|
53
53
|
end
|
54
54
|
rv
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def single_cell?
|
58
58
|
jtable.selected_row_count == 1 && jtable.selected_column_count == 1
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def selected?( row, column )
|
62
62
|
selected_indexes.first.with do |index|
|
63
63
|
index.row == row &&
|
64
64
|
index.column == column
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
# return an array of integer indexes for currently selected rows
|
69
69
|
def row_indexes
|
70
70
|
jtable.selected_rows.to_a
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
def clear
|
74
74
|
jtable.clear_selection
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
# return the full set of selected indexes, ordered
|
78
78
|
# by row then column
|
79
79
|
def selected_indexes
|
@@ -5,17 +5,17 @@ module Clevic
|
|
5
5
|
class SwingTableIndex
|
6
6
|
include TableIndex
|
7
7
|
include Gather
|
8
|
-
|
8
|
+
|
9
9
|
def initialize( model, row, column )
|
10
10
|
@model, @row, @column = model, row.to_i, column.to_i
|
11
11
|
end
|
12
12
|
attr_accessor :model
|
13
13
|
property :row, :column
|
14
|
-
|
14
|
+
|
15
15
|
def valid?
|
16
16
|
row != -1 && column != -1 && model != nil
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def self.invalid
|
20
20
|
new( nil, -1, -1 )
|
21
21
|
end
|
@@ -23,14 +23,14 @@ module Clevic
|
|
23
23
|
def choppy( *args, &block )
|
24
24
|
return self unless self.valid?
|
25
25
|
copied = clone.gather( *args, &block )
|
26
|
-
|
26
|
+
|
27
27
|
# TODO this is mostly shared with Qt
|
28
|
-
|
28
|
+
|
29
29
|
# convert a column name to a column index
|
30
30
|
unless copied.column.is_a?( Numeric )
|
31
31
|
copied.column = model.field_column( copied.column )
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# return an invalid index if it's out of bounds,
|
35
35
|
# or the copied index if it's OK.
|
36
36
|
if copied.row >= model.row_count || copied.column >= model.column_count
|
@@ -19,45 +19,45 @@ including the Clevic::Record module in a Sequel::Model subclass.
|
|
19
19
|
=end
|
20
20
|
class TableModel < javax.swing.table.AbstractTableModel
|
21
21
|
include Emitter
|
22
|
-
|
22
|
+
|
23
23
|
# index, value, message
|
24
24
|
emitter :data_error
|
25
|
-
|
25
|
+
|
26
26
|
def initialize
|
27
27
|
super()
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def create_index( row, column )
|
31
31
|
SwingTableIndex.new( self, row, column )
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# add a new item, and set defaults from the Clevic::View
|
35
35
|
def add_new_item_start
|
36
36
|
# don't need to do anything
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def add_new_item_end
|
40
40
|
fireTableRowsInserted( collection.size, collection.size )
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def remove_notify( rows, &block )
|
44
44
|
# no need to do anything before removing rows
|
45
45
|
yield
|
46
46
|
# tell the views
|
47
47
|
fireTableRowsDeleted( rows.first, rows.last )
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
# Tell the UI we had a major data change
|
51
51
|
def reset
|
52
52
|
# could also use fireTableStructureChanged(), but it doesn't seem necessary
|
53
53
|
fireTableDataChanged
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
# override TableModel method
|
57
57
|
def getRowCount
|
58
58
|
collection.size
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
# make it ruby-nice
|
62
62
|
alias_method :row_count, :getRowCount
|
63
63
|
|
@@ -65,15 +65,15 @@ class TableModel < javax.swing.table.AbstractTableModel
|
|
65
65
|
def getColumnCount
|
66
66
|
fields.size
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
# make it ruby-nice
|
70
70
|
alias_method :column_count, :getColumnCount
|
71
|
-
|
71
|
+
|
72
72
|
# override TableModel method
|
73
73
|
def getColumnName( column_index )
|
74
74
|
fields[column_index].label
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
# override TableModel method
|
78
78
|
def getColumnClass( column_index )
|
79
79
|
if fields[column_index].meta.type == :boolean || fields[column_index].delegate.is_a?( BooleanDelegate )
|
@@ -84,35 +84,35 @@ class TableModel < javax.swing.table.AbstractTableModel
|
|
84
84
|
java.lang.Object
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def isCellEditable( row_index, column_index )
|
89
89
|
index = create_index( row_index, column_index )
|
90
90
|
!( index.field.read_only? || index.entity.andand.readonly? || read_only? )
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
def valuer_for( index )
|
94
94
|
case
|
95
95
|
# pull values from entity at index
|
96
96
|
when index.field.entity_class == entity_class
|
97
97
|
index
|
98
|
-
|
98
|
+
|
99
99
|
# pull values from the Clevic::View class
|
100
100
|
when entity_view.class.ancestors.include?( Clevic::View )
|
101
101
|
#~ entity_view.entity = index.entity
|
102
102
|
FieldValuer.valuer( index.field, entity_view )
|
103
|
-
|
103
|
+
|
104
104
|
else
|
105
105
|
raise "No valuer for #{index.inspect}"
|
106
106
|
end
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
# Provide raw value to renderers
|
110
110
|
def getValueAt( row_index, column_index )
|
111
111
|
index = create_index( row_index, column_index )
|
112
|
-
|
112
|
+
|
113
113
|
#~ valuer = valuer_for( index )
|
114
114
|
valuer = index
|
115
|
-
|
115
|
+
|
116
116
|
if index.field.delegate.native
|
117
117
|
valuer.display_value
|
118
118
|
else
|
@@ -124,16 +124,16 @@ class TableModel < javax.swing.table.AbstractTableModel
|
|
124
124
|
puts $!.backtrace
|
125
125
|
nil
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
def setValueAt( value, row_index, column_index )
|
129
129
|
index = create_index( row_index, column_index )
|
130
130
|
#~ puts "setting index: #{index.inspect} to #{value.inspect}"
|
131
131
|
#~ valuer = valuer_for( index )
|
132
132
|
valuer = index
|
133
|
-
|
133
|
+
|
134
134
|
# Don't allow the primary key to be changed
|
135
135
|
return if index.attribute == entity_class.primary_key.to_sym
|
136
|
-
|
136
|
+
|
137
137
|
# translate the value from the ui to something that
|
138
138
|
# the DB entity will understand
|
139
139
|
begin
|
@@ -143,19 +143,19 @@ class TableModel < javax.swing.table.AbstractTableModel
|
|
143
143
|
# more specific descendant first
|
144
144
|
when java.util.Time
|
145
145
|
Time.new( value.hour, value.min, value.sec )
|
146
|
-
|
146
|
+
|
147
147
|
when java.util.Date
|
148
148
|
Date.new( value.year, value.month, value.day )
|
149
|
-
|
149
|
+
|
150
150
|
else
|
151
151
|
raise "don't know how to convert a #{value.class.name}:#{value.inspect}"
|
152
152
|
end
|
153
153
|
else
|
154
154
|
valuer.edit_value = value
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
valuer.entity.save
|
158
|
-
|
158
|
+
|
159
159
|
data_changed( index )
|
160
160
|
rescue Exception => e
|
161
161
|
puts "#{__FILE__}:#{__LINE__}:e.message: #{e.message}"
|
@@ -163,7 +163,7 @@ class TableModel < javax.swing.table.AbstractTableModel
|
|
163
163
|
emit_data_error( index, value, e.message )
|
164
164
|
end
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
# A rubyish way of doing dataChanged
|
168
168
|
# - if args has one element, it's either a single ModelIndex
|
169
169
|
# or something that understands top_left and bottom_right. These
|
@@ -181,10 +181,10 @@ class TableModel < javax.swing.table.AbstractTableModel
|
|
181
181
|
# assume it's a ModelIndex, so one cell was updated
|
182
182
|
fireTableCellUpdated( arg.row, arg.column )
|
183
183
|
end
|
184
|
-
|
184
|
+
|
185
185
|
when 2
|
186
186
|
fireTableRowsUpdated( args.first.row, args.last.row )
|
187
|
-
|
187
|
+
|
188
188
|
else
|
189
189
|
unless block.nil?
|
190
190
|
change = DataChange.new
|
@@ -194,7 +194,7 @@ class TableModel < javax.swing.table.AbstractTableModel
|
|
194
194
|
end
|
195
195
|
end
|
196
196
|
end
|
197
|
-
|
197
|
+
|
198
198
|
end
|
199
199
|
|
200
200
|
end #module
|