Class: Clevic::ClevicTable

Inherits:
Object show all
Defined in:
lib/clevic/swing/table_view.rb

Overview

TODO make sure JTable doesn’t grab Ctrl-C and do its own copy routine. TODO make sure Delegates use the correct copy routines.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#table_viewObject

Returns the value of attribute table_view.



21
22
23
# File 'lib/clevic/swing/table_view.rb', line 21

def table_view
  @table_view
end

Instance Method Details

#editCellAt(row, column, event = nil) ⇒ Object

for mouse events, only edit if the cell is already selected provided it isn’t a combo box, in which case show the drop-down arrow, but not the drop-down itself.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/clevic/swing/table_view.rb', line 69

def editCellAt( row, column, event = nil )
  if event
    index = table_view.model.create_index(row,column)
    edit_ok =
    if event.is_a?( java.awt.event.MouseEvent ) && index.field.delegate.needs_pre_selection?
      # the table_view selection model is mine. The JTable one is not.
      # Maybe that's weird.
      table_view.selection_model.with do |sm|
        sm.single_cell? && sm.selected?( row, column )
      end
    else
      true
    end

    # must call superclass here to do the edit rather than
    # just returning whether it should be edited. Java. tsk tsk.
    if edit_ok
      super
    else
      false
    end
  else
    # no event, so do whatever JTable does, which seems to work OK.
    super
  end
end

#getCellEditor(row_index, column_index) ⇒ Object

override to make things simpler



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/clevic/swing/table_view.rb', line 43

def getCellEditor( row_index, column_index )
  index = table_view.model.create_index( row_index, column_index )

  # Basically, this is for boolean editing. Number of mouse
  # clicks and so on is horribly complicated, so just let the
  # code in javax.swing.whatever handle it.
  # It has to go here and not in CellEditor, otherwise
  # listeners and things are wrong.
  if data_class = index.field.delegate.native
    # use the default editor for this class of object
    getDefaultEditor( data_class )
  else
    # use the Clevic CellEditor
    @cell_editor ||= CellEditor.new( self )
  end
rescue
  puts "#{__FILE__}:#{__LINE__}:$!.message: #{$!.message}"
  puts $!.backtrace
  puts index.entity.inspect
  nil
end

#processKeyBinding(key_stroke, key_event, condition, pressed) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/clevic/swing/table_view.rb', line 23

def processKeyBinding( key_stroke, key_event, condition, pressed )
  # don't auto-start if it's a Ctrl, or Alt-modified key
  # or a function key. Hopefully this doesn't get checked
  # for every single keystroke while editing - those should
  # be captured by the cell editor.
  if key_event.alt? || key_event.ctrl? || key_event.meta? || key_event.fx? || key_event.del? || key_event.esc?
    put_client_property( "JTable.autoStartsEdit", false )
  end

  # do what JTable normally does with keys
  super
rescue Exception => e
  puts e.message
  puts e.backtrace
  table_view.model.emit_data_error( table_view.current_index, nil, e.message )
ensure
  put_client_property( "JTable.autoStartsEdit", true )
end