Class: Cheri::JRuby::Explorer::SearchDialog
- Inherits:
-
Object
- Object
- Cheri::JRuby::Explorer::SearchDialog
- Includes:
- Swing
- Defined in:
- lib/cheri/jruby/explorer/dialogs.rb,
lib/cheri/jruby/explorer/dialogs-old.rb
Constant Summary
Constants included from Swing
Instance Method Summary collapse
- #find_by_id ⇒ Object
- #find_by_type ⇒ Object
- #hide ⇒ Object
-
#initialize(main) ⇒ SearchDialog
constructor
A new instance of SearchDialog.
- #instance_list ⇒ Object
- #nil_if_empty(val) ⇒ Object
- #show(clazz = nil) ⇒ Object
- #update_instance_list ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(main) ⇒ SearchDialog
Returns a new instance of SearchDialog.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 105 def initialize(main) swing[:auto=>true] @main = main @main_frame = main.main_frame @dialog = dialog @main_frame, 'Search ObjectSpace', true do |dlg| grid_table_layout dlg, :a=>:nw, :wx=>0.1, :wy=>0.1, :f=>:h empty_border 4,4,4,4 size 400,350 default_close_operation :HIDE_ON_CLOSE grid_row{grid_table{ defaults :a=>:w, :i=>[4,2] compound_border titled_border('Select instance') {etched_border :LOWERED}, empty_border(2,2,2,2) grid_row {label 'Instance:'; @instance_list = combo_box(instance_list,:f=>:h,:wx=>0.1) {editable false}} }} grid_row{grid_table{ defaults :a=>:w,:i=>[4,2] compound_border titled_border('Find specific object') {etched_border :LOWERED}, empty_border(2,2,2,2) grid_row { label 'Object id:' @object_id = text_field(:wx=>0.1) {columns 16} ('Find') {on_click {find_by_id}} } }} grid_row{grid_table{ defaults :a=>:w,:i=>[4,2] compound_border titled_border('Search for instances by type and optional variable/value') {etched_border :LOWERED}, empty_border(2,2,2,2) grid_row { label 'Class or Module:', :w=>2 @clazz = text_field(:wx=>0.1,:f=>:h) {columns 16} ('Find', :h=>3,:a=>:c) {on_click {find_by_type}} } grid_row {label 'Variable name:'; label '@',:i=>0,:a=>:e; @name1 = text_field(:wx=>0.1,:f=>:h) {columns 16}} grid_row {label 'Search string or /regexp/:',:w=>2; @value1 = text_field(:wx=>0.1,:f=>:h) {columns 16}} grid_row {@gc = check_box 'GC target instance before search', :a=>:c, :w=>4} }} grid_row {('Cancel', :a=>:c, :wx=>0.1, :f=>:none) {on_click {@dialog.visible = false; reset_fields}}} end @main.center(@main_frame,@dialog) end |
Instance Method Details
#find_by_id ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 146 def find_by_id id = nil_if_empty(@object_id.text) id = Integer(id) rescue nil if id if !id JOptionPane.(@dialog,"Please enter a valid id", 'Search Error', JOptionPane::ERROR_MESSAGE) else @dialog.visible = false @object_id.text = '' @main.new_find(@instances[@instance_list.selected_index],id) end end |
#find_by_type ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 159 def find_by_type clazz = nil_if_empty(@clazz.text) name = nil_if_empty(@name1.text) value = @value1.text value = nil if value.empty? instance = @instances[@instance_list.selected_index] if !clazz JOptionPane.(@dialog,"Please enter a Class or Module name", 'Search Error', JOptionPane::ERROR_MESSAGE) elsif clazz !~ /^([A-Z])((\w|::[A-Z])*)$/ JOptionPane.(@dialog,"Invalid Class or Module name, please re-enter", 'Search Error', JOptionPane::ERROR_MESSAGE) elsif name && name !~ /^([A-Za-z_])(\w*)$/ JOptionPane.(@dialog,"Invalid variable name, please re-enter", 'Search Error', JOptionPane::ERROR_MESSAGE) elsif !instance.proxy.object_space? && clazz != 'Class' JOptionPane.(@dialog,"Only class 'Class' supported when ObjectSpace disabled", 'Search Error', JOptionPane::ERROR_MESSAGE) else if value && value.strip.length != value.length rsp = JOptionPane.show_confirm_dialog(@main_frame, "Value contains leading/trailing whitespace -- continue?") else rsp = nil end unless rsp && rsp != JOptionPane::YES_OPTION @dialog.visible = false gc = @gc.selected reset_fields @main.new_search(instance,clazz,name,value,gc) end end end |
#hide ⇒ Object
219 220 221 |
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 219 def hide @dialog.visible = false end |
#instance_list ⇒ Object
223 224 225 226 227 228 229 230 231 |
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 223 def instance_list @instances = @main.instance_list arr = Array.new(@instances.length) {|i| instance = @instances[i] pfx = instance.proxy.object_space? ? 'en' : 'dis' "#{instance.name} [#{pfx}abled]" } arr.to_java end |
#nil_if_empty(val) ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 193 def nil_if_empty(val) if val val.strip! val = nil if val.empty? end val end |
#show(clazz = nil) ⇒ Object
213 214 215 216 217 |
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 213 def show(clazz = nil) @clazz.text = clazz if clazz update_instance_list @dialog.visible = true end |
#update_instance_list ⇒ Object
233 234 235 236 237 238 239 |
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 233 def update_instance_list new_list = instance_list @instance_list.remove_all_items new_list.each do |name| @instance_list.add_item name end end |
#value ⇒ Object
209 210 211 |
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 209 def value @dialog end |