Class: Glimmer::SWT::TreeProxy
- Inherits:
-
WidgetProxy
- Object
- WidgetProxy
- Glimmer::SWT::TreeProxy
- Includes:
- Glimmer
- Defined in:
- lib/glimmer/swt/tree_proxy.rb
Constant Summary
Constants included from Glimmer
Constants inherited from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::DEFAULT_STYLES, WidgetProxy::KEYWORD_ALIASES
Instance Attribute Summary collapse
-
#tree_editor ⇒ Object
readonly
Returns the value of attribute tree_editor.
-
#tree_editor_text_proxy ⇒ Object
readonly
Returns the value of attribute tree_editor_text_proxy.
-
#tree_properties ⇒ Object
Returns the value of attribute tree_properties.
Attributes inherited from WidgetProxy
#drag_source_proxy, #drag_source_style, #drag_source_transfer, #drop_target_proxy, #drop_target_transfer, #finished_add_content, #parent_proxy, #swt_widget
Attributes included from Custom::Drawable
#image_double_buffered, #requires_shape_disposal
Instance Method Summary collapse
-
#all_tree_items ⇒ Object
Returns all tree items including descendants.
-
#depth_first_search(&condition) ⇒ Object
Performs depth first search for tree items matching block condition If no condition block is passed, returns all tree items Returns a Java TreeItem array to easily set as selection on org.eclipse.swt.Tree if needed.
- #edit_in_progress? ⇒ Boolean
- #edit_selected_tree_item(before_write: nil, after_write: nil, after_cancel: nil) ⇒ Object
- #edit_tree_item(tree_item, before_write: nil, after_write: nil, after_cancel: nil) ⇒ Object
-
#initialize(underscored_widget_name, parent, args) ⇒ TreeProxy
constructor
A new instance of TreeProxy.
Methods included from Glimmer
Methods inherited from WidgetProxy
#add_observer, #async_exec, #auto_exec, #can_add_observer?, #can_handle_drag_observation_request?, #can_handle_drop_observation_request?, #can_handle_observation_request?, #content, create, #dispose, #disposed?, #ensure_drag_source_proxy, #ensure_drop_target_proxy, #extract_args, #finish_add_content!, flyweight_swt_widget_classes, #get_attribute, #handle_observation_request, #has_attribute?, #has_style?, #height, #method_missing, #pack_same_size, #post_add_content, #post_initialize_child, #proxy_source_object, #remove_observer, #respond_to?, #set_attribute, swt_widget_class_for, swt_widget_class_manual_entries, #sync_exec, #timer_exec, underscored_widget_name, widget_exists?, #widget_property_listener_installers, widget_proxy_class, #width, #x, #y
Methods included from Custom::Drawable
#add_shape, #clear_shapes, #deregister_shape_painting, #expanded_shapes, #image_buffered_shapes, #paint_pixel_by_pixel, #setup_shape_painting, #shape_at_location, #shapes, #swt_drawable
Methods included from ProxyProperties
#get_attribute, #has_attribute?, #has_attribute_getter?, #has_attribute_setter?, #method_missing, #proxy_source_object, #respond_to?, #set_attribute
Methods included from Properties
attribute_getter, #attribute_getter, attribute_setter, #attribute_setter, normalized_attribute, #normalized_attribute, ruby_attribute_getter, #ruby_attribute_setter, ruby_attribute_setter
Methods included from Packages
Constructor Details
#initialize(underscored_widget_name, parent, args) ⇒ TreeProxy
Returns a new instance of TreeProxy.
32 33 34 35 36 37 38 |
# File 'lib/glimmer/swt/tree_proxy.rb', line 32 def initialize(, parent, args) super @tree_editor = TreeEditor.new() @tree_editor.horizontalAlignment = SWTProxy[:left] @tree_editor.grabHorizontal = true @tree_editor.minimumHeight = 20 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Glimmer::SWT::WidgetProxy
Instance Attribute Details
#tree_editor ⇒ Object (readonly)
Returns the value of attribute tree_editor.
29 30 31 |
# File 'lib/glimmer/swt/tree_proxy.rb', line 29 def tree_editor @tree_editor end |
#tree_editor_text_proxy ⇒ Object (readonly)
Returns the value of attribute tree_editor_text_proxy.
29 30 31 |
# File 'lib/glimmer/swt/tree_proxy.rb', line 29 def tree_editor_text_proxy @tree_editor_text_proxy end |
#tree_properties ⇒ Object
Returns the value of attribute tree_properties.
30 31 32 |
# File 'lib/glimmer/swt/tree_proxy.rb', line 30 def tree_properties @tree_properties end |
Instance Method Details
#all_tree_items ⇒ Object
Returns all tree items including descendants
51 52 53 |
# File 'lib/glimmer/swt/tree_proxy.rb', line 51 def all_tree_items depth_first_search end |
#depth_first_search(&condition) ⇒ Object
Performs depth first search for tree items matching block condition If no condition block is passed, returns all tree items Returns a Java TreeItem array to easily set as selection on org.eclipse.swt.Tree if needed
43 44 45 46 47 48 |
# File 'lib/glimmer/swt/tree_proxy.rb', line 43 def depth_first_search(&condition) found = [] first_item = DisplayProxy.instance.auto_exec { .getItems.first } recursive_depth_first_search(first_item, found, &condition) found.to_java(TreeItem) end |
#edit_in_progress? ⇒ Boolean
55 56 57 |
# File 'lib/glimmer/swt/tree_proxy.rb', line 55 def edit_in_progress? !!@edit_in_progress end |
#edit_selected_tree_item(before_write: nil, after_write: nil, after_cancel: nil) ⇒ Object
59 60 61 |
# File 'lib/glimmer/swt/tree_proxy.rb', line 59 def edit_selected_tree_item(before_write: nil, after_write: nil, after_cancel: nil) edit_tree_item(.getSelection.first, before_write: before_write, after_write: after_write, after_cancel: after_cancel) end |
#edit_tree_item(tree_item, before_write: nil, after_write: nil, after_cancel: nil) ⇒ Object
63 64 65 66 67 68 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/glimmer/swt/tree_proxy.rb', line 63 def edit_tree_item(tree_item, before_write: nil, after_write: nil, after_cancel: nil) return if tree_item.nil? content { @tree_editor_text_proxy = text { focus true text tree_item.getText action_taken = false cancel = lambda { @tree_editor_text_proxy..dispose @tree_editor_text_proxy = nil after_cancel&.call @edit_in_progress = false } action = lambda { |event| begin if !action_taken && !@edit_in_progress action_taken = true @edit_in_progress = true new_text = @tree_editor_text_proxy..getText if new_text == tree_item.getText cancel.call else before_write&.call tree_item.setText(new_text) model = tree_item.getData model.send("#{tree_properties[:text]}=", new_text) # makes tree update itself, so must search for selected tree item again edited_tree_item = depth_first_search { |ti| ti.getData == model }.first .showItem(edited_tree_item) @tree_editor_text_proxy..dispose @tree_editor_text_proxy = nil after_write&.call(edited_tree_item) @edit_in_progress = false end end rescue => e Glimmer::Config.logger.error {"Error encountered while editing tree item!\n#{e.}"} end } on_focus_lost(&action) on_key_pressed { |key_event| if key_event.keyCode == swt(:cr) action.call(key_event) elsif key_event.keyCode == swt(:esc) cancel.call end } } @tree_editor_text_proxy..selectAll } @tree_editor.setEditor(@tree_editor_text_proxy., tree_item) end |