Class: SWT::ChildCommand

Inherits:
ContainerTreeCommand show all
Defined in:
lib/swt.rb

Instance Method Summary collapse

Methods inherited from ContainerTreeCommand

#accept, #to_s

Methods inherited from TreeCommand

#accept, #stacktrace

Constructor Details

#initialize(parent) ⇒ ChildCommand

Returns a new instance of ChildCommand


78
79
80
# File 'lib/swt.rb', line 78

def initialize(parent)
  super(parent)
end

Instance Method Details

#invoke(origstack) ⇒ Object


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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/swt.rb', line 82

def invoke(origstack)
  stack=origstack.dup
  last=origstack.last
  expand=lambda do
    res=TreeItem.new last,Builder::RealSWT::NONE
    res.setData("object",last.getData("object"))
    #puts "In Child.invoke: res:#{res.hashCode} data: #{last.getData("object").id}"
    stack.push(res)

    #puts "Stack: #{stack} last:#{stack.last.hashCode} objectid:#{stack.last.getData("object").hashCode}"
    @children.each do |x|
      x.invoke stack
    end
    stack.pop
    res
  end

  parent=origstack.last

  unless parent.is_a? TreeItem
    expand.call
    return
  end

  dummy=parent.getData("dummy")
  unless dummy
    dummy=TreeItem.new parent,Builder::RealSWT::NONE
    dummy.setText "dummy"
    parent.setData("dummy",dummy)
  end

  li=TreeListener.new
  class <<li
    def treeExpanded(e)
      @block.call e
    end
    def treeCollapsed(e)
    end
    def set_info(&block)
      @block=block
    end
  end
  li.set_info do |e|
    if e.item==parent
      unless dummy.isDisposed
        dummy.dispose
      end

      res=expand.call
      e.widget.getColumn(0).pack if e.widget.getColumnCount>0
      res.getParent.removeTreeListener li
    end
  end
  parent.getParent.addTreeListener li
end