Class: Clevic::DistinctDelegate

Inherits:
ComboDelegate show all
Includes:
SimplestDelegate
Defined in:
lib/clevic/swing/distinct_delegate.rb,
lib/clevic/qt/distinct_delegate.rb,
lib/clevic/delegates/distinct_delegate.rb

Overview

Provide a list of all values in this field, and allow new values to be entered. :frequency can be set as an option. Boolean. If it’s true the options are sorted in order of most frequently used first.

Instance Attribute Summary

Attributes inherited from ComboDelegate

#editor

Attributes inherited from Delegate

#entity, #field, #parent

Instance Method Summary collapse

Methods included from SimplestDelegate

#editor_to_item, #item_to_editor

Methods inherited from ComboDelegate

#allow_null?, #autocomplete, #combo_class, #configure_editable, #configure_prefix, #createEditor, #create_combo_box, #dump_editor_state, #empty_set?, #filter_prefix, #framework_setup, #full_edit, #getListCellRendererComponent, #hint_string, #if_empty_message, #init_component, #initialize, #is_combo?, #line_editor, #minimal_edit, #needs_pre_selection?, #repopulate, #restricted?, #setEditorData, #setModelData, #updateEditorGeometry, #value

Methods inherited from Delegate

#attribute, #editorEvent, #entity_class, #full_edit, #initialize, #inspect, #is_combo?, #minimal_edit, #native, #needs_pre_selection?, #show_message, #updateEditorGeometry

Methods included from FieldValuer

#attribute_value, #attribute_value=, #display_value, #edit_value, #edit_value=, #find_related, #raw_value, #text_value=, #tooltip, valuer, #valuer, #writer

Constructor Details

This class inherits a constructor from Clevic::ComboDelegate

Instance Method Details

#datasetObject

TODO move away from ar_methods. Partly done. TODO ordering by either recentness, or frequency. OR both. TODO make sure nil is in the list. And the current item is at the top. TODO and the current item is in the list, even if it’s older we only use the first column, so use the second column to sort by, since SQL requires the order by clause to be in the select list where distinct is involved



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

def dataset
  base_dataset =
  unless field.find_options.empty?
    puts "#{field.entity_class.name}:#{field.attribute} conditions and order are deprecated. Use dataset instead."
    puts caller
    require 'clevic/ar_methods'
    field.entity_class.plugin :ar_methods
    field.entity_class.translate( field.find_options )
  else
    field.dataset_roller.dataset
  end

  # now pull out the field and the distinct values
  base_dataset. \
    distinct. \
    select( field.attribute ). \
    order( field.attribute ). \
    naked
end

#display_for(model_value) ⇒ Object

strings are stored in the model



11
12
13
# File 'lib/clevic/swing/distinct_delegate.rb', line 11

def display_for( model_value )
  model_value
end

#needs_combo?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/clevic/delegates/distinct_delegate.rb', line 11

def needs_combo?
  # works except when there is a null in the column
  dataset.count > 0
end

#populationObject



43
44
45
# File 'lib/clevic/delegates/distinct_delegate.rb', line 43

def population
  dataset.map( field.attribute )
end

#translate_from_editor_text(editor, text) ⇒ Object

This might be unnecessary.



10
11
12
# File 'lib/clevic/qt/distinct_delegate.rb', line 10

def translate_from_editor_text( editor, text )
  text
end