Class: Clevic::CellEditor
Overview
This is the glue class that interfaces with JTable’s API There’s usually only ever one of them for any given JTable, so it’s created once, and then re-used repeatedly. Must inherit from JComponent so that it gets focus when the editing starts
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#listeners ⇒ Object
Returns the value of attribute listeners.
Instance Method Summary collapse
-
#addCellEditorListener(cell_editor_listener) ⇒ Object
Adds a listener to the list that’s notified when the editor stops, or cancels editing.
-
#cancelCellEditing ⇒ Object
Tells the editor to cancel editing and not accept any partially edited value.
- #change_event ⇒ Object
- #delegate ⇒ Object
-
#getCellEditorValue ⇒ Object
Returns the value contained in the editor.
-
#getTableCellEditorComponent(jtable, value, selected, row_index, column_index) ⇒ Object
override TableCellEditor methods basically, initialize a component to send back to the JTable, and store a bunch of state information.
-
#initialize(table_view) ⇒ CellEditor
constructor
A new instance of CellEditor.
-
#isCellEditable(event_object) ⇒ Object
Asks the editor if it can start editing using anEvent.
-
#removeCellEditorListener(cell_editor_listener) ⇒ Object
Removes a listener from the list that’s notified.
-
#shouldSelectCell(event_object) ⇒ Object
Docs say not used, as of Java-1.2.
-
#stopCellEditing ⇒ Object
Tells the editor to stop editing and accept any partially edited value as the value of the editor true if editing was stopped, false otherwise.
Constructor Details
#initialize(table_view) ⇒ CellEditor
Returns a new instance of CellEditor.
11 12 13 14 15 |
# File 'lib/clevic/swing/cell_editor.rb', line 11 def initialize( table_view ) super() @table_view = table_view @listeners = [] end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
18 19 20 |
# File 'lib/clevic/swing/cell_editor.rb', line 18 def index @index end |
#listeners ⇒ Object
Returns the value of attribute listeners.
17 18 19 |
# File 'lib/clevic/swing/cell_editor.rb', line 17 def listeners @listeners end |
Instance Method Details
#addCellEditorListener(cell_editor_listener) ⇒ Object
Adds a listener to the list that’s notified when the editor stops, or cancels editing.
41 42 43 |
# File 'lib/clevic/swing/cell_editor.rb', line 41 def addCellEditorListener(cell_editor_listener) listeners << cell_editor_listener end |
#cancelCellEditing ⇒ Object
Tells the editor to cancel editing and not accept any partially edited value.
50 51 52 53 54 |
# File 'lib/clevic/swing/cell_editor.rb', line 50 def cancelCellEditing listeners.each do |listener| listener.editingCancelled( change_event ) end end |
#change_event ⇒ Object
45 46 47 |
# File 'lib/clevic/swing/cell_editor.rb', line 45 def change_event @change_event ||= javax.swing.event.ChangeEvent.new( self ) end |
#delegate ⇒ Object
20 21 22 |
# File 'lib/clevic/swing/cell_editor.rb', line 20 def delegate index.field.delegate end |
#getCellEditorValue ⇒ Object
Returns the value contained in the editor.
57 58 59 |
# File 'lib/clevic/swing/cell_editor.rb', line 57 def getCellEditorValue delegate.value end |
#getTableCellEditorComponent(jtable, value, selected, row_index, column_index) ⇒ Object
override TableCellEditor methods basically, initialize a component to send back to the JTable, and store a bunch of state information
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/clevic/swing/cell_editor.rb', line 27 def getTableCellEditorComponent(jtable, value, selected, row_index, column_index) # remember index for later. The delegate and the editor and the value # all come from it. @index = @table_view.model.create_index( row_index, column_index ) # use the delegate's component. It actually comes from the index, which # is a bit weird. But anyway. delegate.entity = @index.entity # need self so combo boxes can get back here and stop editing when enter is pressed delegate.init_component( self ) delegate.editor end |
#isCellEditable(event_object) ⇒ Object
Asks the editor if it can start editing using anEvent.
62 63 64 |
# File 'lib/clevic/swing/cell_editor.rb', line 62 def isCellEditable(event_object) true end |
#removeCellEditorListener(cell_editor_listener) ⇒ Object
Removes a listener from the list that’s notified
67 68 69 |
# File 'lib/clevic/swing/cell_editor.rb', line 67 def removeCellEditorListener(cell_editor_listener) listeners.delete cell_editor_listener end |
#shouldSelectCell(event_object) ⇒ Object
Docs say not used, as of Java-1.2. But it is used. Not sure what to do with it, really.
73 74 75 |
# File 'lib/clevic/swing/cell_editor.rb', line 73 def shouldSelectCell(event_object) true end |
#stopCellEditing ⇒ Object
Tells the editor to stop editing and accept any partially edited value as the value of the editor true if editing was stopped, false otherwise
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/clevic/swing/cell_editor.rb', line 79 def stopCellEditing listeners.each do |listener| listener.editingStopped( change_event ) end # can return false here if editing should not stop # for some reason, ie validation didn't succeed true rescue puts puts $!.backtrace puts "returning false from stopCellEditing" false end |