Module: Rubeus::Extensions::Javax::Swing::Table::DefaultTableModel::ClassMethods

Defined in:
lib/rubeus/extensions/javax/swing/table/default_table_model.rb

Instance Method Summary collapse

Instance Method Details

#new_with_rubeus(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubeus/extensions/javax/swing/table/default_table_model.rb', line 25

def new_with_rubeus(*args)
  if args.length == 1
    obj = args.first
    if obj.is_a?(Array)
      if obj.first.is_a?(Array)
        data = vectorize_if_array(obj.map{|row| vectorize_if_array(row)})
        column_names = vectorize_if_array((1..obj.first.size).entries)
        return new_without_rubeus(data, column_names)
      else
        column_names = vectorize_if_array(obj)
        return new_without_rubeus(column_names, 0)
      end
    elsif obj.is_a?(Hash)
      options = obj
      rows = options[:data] || options[:rows]
      cols = options[:column_names] || options[:columns]
      if rows.nil? or cols.nil?
        raise ArgumentError, "DefaultTableModel needs (:data or :rows) and (:column_names or :columns) but options was #{options}"
      end
      data = vectorize_if_array(rows.map{|row| vectorize_if_array(row)})
      column_names = vectorize_if_array(cols)
      return new_without_rubeus(data, column_names)
    end
  elsif (args.length == 2) and (args.first.class.name == 'REXML::Document' and args.last.is_a?(Hash))
    result = new_without_rubeus(vectorize_if_array(args.last[:column_paths]), 0)
    result.load_from_xml(*args)
    return result
  end
  return new_without_rubeus(*args)
end

#vectorize_if_array(value) ⇒ Object



21
22
23
# File 'lib/rubeus/extensions/javax/swing/table/default_table_model.rb', line 21

def vectorize_if_array(value)
  value.is_a?(Array) ? java.util.Vector.new(value) : value
end