Class: Cheri::JRuby::Explorer::SearchDialog

Inherits:
Object
  • Object
show all
Includes:
Swing
Defined in:
lib/cheri/jruby/explorer/dialogs.rb

Constant Summary

Constants included from Swing

Swing::SwingConnecter

Instance Method Summary collapse

Constructor Details

#initialize(main) ⇒ SearchDialog

Returns a new instance of SearchDialog.



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 135

def initialize(main)
  swing[:auto=>true]
  @main = main
  @main_frame = main.main_frame
  @dialog = dialog @main_frame, 'Search ObjectSpace', true do |d|
    box_layout d, :Y_AXIS
    size 400,300
    default_close_operation :HIDE_ON_CLOSE
    y_glue
    x_panel do
      x_spacer 4
      label 'Instance:'
      x_spacer 10
      @instance_list = combo_box instance_list do
        editable false
      end
      x_spacer 4 
    end
    y_glue
    x_panel do
      compound_border( 
        titled_border('Find specific object') { etched_border :LOWERED },
        empty_border(4,8,4,8)
      )
      y_box do
        label 'Object id:'        
      end
      x_spacer 10
      y_box do
        y_glue
        @object_id = text_field do
           columns 16
           fixed_size 100,24
        end
        y_glue
      end
      x_glue
      y_box do
        y_glue
        button 'Find' do
          on_click do
            id = nil_if_empty(@object_id.text)
            id = Integer(id) rescue nil if id
            if !id
              JOptionPane.show_message_dialog(@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
        end
        y_glue
      end
    end

    y_glue

    y_panel do
      compound_border( 
        titled_border('Search for instances by type and optional variable/value') { etched_border :LOWERED },
        empty_border(4,8,4,8)
      )
     x_panel do
      y_box do
        y_glue
        label 'Class or Module:' 
        y_glue
        label 'Variable name:'
        y_glue
        label 'Search string or /regexp/:'
        y_glue
      end
      x_spacer 6
      y_box do
        y_glue
        label '@'
        y_glue        
      end
      y_box do
        y_glue
        @clazz = text_field do
           columns 20
           fixed_size 200,24
        end
        y_glue
        @name1 = text_field do
           columns 20
           fixed_size 200,24
        end
        y_glue
        @value1 = text_field do
           columns 20
           fixed_size 200,24
        end
        y_glue
      end
      x_glue
      y_box do
        button 'Find' do
          on_click do
            clazz = nil_if_empty(@clazz.text)
            name = nil_if_empty(@name1.text)
            value = @value1.text
            value = nil if value.empty?
            if !clazz
              JOptionPane.show_message_dialog(@dialog,"Please enter a Class or Module name",
                'Search Error', JOptionPane::ERROR_MESSAGE)
            elsif clazz !~ /^([A-Z])((\w|::[A-Z])*)$/
              JOptionPane.show_message_dialog(@dialog,"Invalid Class or Module name, please re-enter",
                'Search Error', JOptionPane::ERROR_MESSAGE)
            elsif name && name !~ /^([A-Za-z_])(\w*)$/
              JOptionPane.show_message_dialog(@dialog,"Invalid variable name, please re-enter",
                '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(@instances[@instance_list.selected_index],clazz,name,value,gc)
              end
            end
          end
        end
      end
     end
     x_panel do
      @gc = check_box 'GC target instance before search'
     end
    end
    y_glue
      x_box do
        x_glue
        button 'Cancel' do
          on_click do
          @dialog.visible = false
          end
        end
        x_glue
      end
    y_glue
  end

  @main.center(@main_frame,@dialog)
end

Instance Method Details

#hideObject



314
315
316
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 314

def hide
  @dialog.visible = false  
end

#instance_listObject



318
319
320
321
322
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 318

def instance_list
  @instances = @main.instance_list
  arr = Array.new(@instances.length) {|i| @instances[i].name}
  arr.to_java
end

#nil_if_empty(val) ⇒ Object



288
289
290
291
292
293
294
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 288

def nil_if_empty(val)
  if val
    val.strip!
    val = nil if val.empty?
  end
  val  
end

#show(clazz = nil) ⇒ Object



308
309
310
311
312
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 308

def show(clazz = nil)
  @clazz.text = clazz if clazz
  update_instance_list
  @dialog.visible = true  
end

#update_instance_listObject



324
325
326
327
328
329
330
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 324

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

#valueObject



304
305
306
# File 'lib/cheri/jruby/explorer/dialogs.rb', line 304

def value
  @dialog  
end