require 'eclipse' # RUBY REGION DELIMITER require 'rdtHelpers' # RUBY REGION DELIMITER include_class "org.eclipse.swt.widgets.List" include_class "org.eclipse.swt.widgets.Label" include_class "org.eclipse.swt.layout.FillLayout" include_class "org.eclipse.swt.widgets.Composite" include_class "org.eclipse.swt.widgets.Group" include_class "org.eclipse.swt.events.SelectionListener" # RUBY REGION DELIMITER view = createScratchPadView("DemoClassBrowser") # RUBY REGION DELIMITER $comp = view.getComponent() # RUBY REGION DELIMITER syncExec{ $comp.setLayout(FillLayout.new()) } # RUBY REGION DELIMITER syncExec{ $classesGroup = Group.new($comp, 8) $classesGroup.setText("Classes") } # RUBY REGION DELIMITER syncExec{ $methodsGroup = Group.new($comp, 8) $methodsGroup.setText("Methods") } # RUBY REGION DELIMITER syncExec{ $classesGroup.setLayout(FillLayout.new()) } # RUBY REGION DELIMITER syncExec{ $methodsGroup.setLayout(FillLayout.new()) } # RUBY REGION DELIMITER syncExec{ $classesList = List.new($classesGroup, 0) $classesList.add("Classes") } # RUBY REGION DELIMITER syncExec{ $methodsList = List.new($methodsGroup, 0) $methodsList.add("Methods") } # RUBY REGION DELIMITER # OK... all set; how about we get some RDT data and hook this thing up # RUBY REGION DELIMITER include RDT initRdtCore() # RUBY REGION DELIMITER # I have a few projects in my Workspace, let's take one... $zen = asRubyProject(rubyProjects[3]) # RUBY REGION DELIMITER $zen.open(nil) # RUBY REGION DELIMITER # the $mod is an object of RubyProjectModel, a simple wrapper around RDT Ruby Projects $mod = RDT::RubyProjectModel.new($zen) # RUBY REGION DELIMITER # So, get all the classes from the project and fill the classes List with them syncExec{ types = $mod.typeDefs $classesList.removeAll types.each{|t| $classesList.add(t[0]) } } # RUBY REGION DELIMITER # OK, class list for the project all set up... # But now we want to see a classes method when we select a class, # a Job for a Selection Listener # RUBY REGION DELIMITER # sets up a SelectionListener object and defines its methods # the widgetSelect simply checks what class was selected, gets its methods # and adds them to the methods list. There are probably cleaner ways, but # this is just a demo... $classListener = SelectionListener.new class << $classListener def widgetSelected(ev) syncExec{ sel = ev.widget.getSelection selType = "" if sel.length > 0 selType = sel[0] end $methodsList.removeAll types = $mod.typeDefs pt = types.values.first types.keys.each{|currType| if selType.include?(currType) pt = types[currType] end } pt.methodDefs.each{|m| $methodsList.add(m[1].to_s) } } end def widgetDefaultSelected(ev) end end # RUBY REGION DELIMITER # register the listener syncExec{ $classesList.addSelectionListener($classListener) } # RUBY REGION DELIMITER # RUBY REGION DELIMITER # RUBY REGION DELIMITER