Class: Watobo::Gui::CheckBoxTreeList

Inherits:
FXTreeList
  • Object
show all
Includes:
Icons
Defined in:
lib/watobo/gui/checkboxtree.rb

Constant Summary

Constants included from Icons

Icons::ICON_ADD_PROJECT, Icons::ICON_BROWSER_MEDIUM, Icons::ICON_BROWSER_SMALL, Icons::ICON_BTN_DOWN, Icons::ICON_BTN_UP, Icons::ICON_CB_CHECKED, Icons::ICON_CB_CHECKED_ORANGE, Icons::ICON_CB_UNCHECKED, Icons::ICON_CONVERSATION, Icons::ICON_DASHBOARD, Icons::ICON_DIFFER, Icons::ICON_FOLDER, Icons::ICON_FOLDER_SMALL, Icons::ICON_FUZZER, Icons::ICON_FUZZER_MEDIUM, Icons::ICON_FUZZER_SMALL, Icons::ICON_FUZZ_FILTER, Icons::ICON_FUZZ_GENERATOR, Icons::ICON_FUZZ_TAG, Icons::ICON_HINTS, Icons::ICON_HINTS_INFO, Icons::ICON_HINTS_INFO_SMALL, Icons::ICON_HINTS_SMALL, Icons::ICON_INFO, Icons::ICON_INFO_INFO, Icons::ICON_INFO_INFO_SMALL, Icons::ICON_INFO_SMALL, Icons::ICON_INFO_USER, Icons::ICON_INFO_USER_SMALL, Icons::ICON_INTERCEPTOR, Icons::ICON_LOGIN_WIZZARD, Icons::ICON_MANUAL_REQUEST, Icons::ICON_MANUAL_REQUEST_MEDIUM, Icons::ICON_MANUAL_REQUEST_SMALL, Icons::ICON_PAUSE, Icons::ICON_PLUGIN, Icons::ICON_PROJECT, Icons::ICON_PROJECT_SMALL, Icons::ICON_REPORT, Icons::ICON_REQUEST, Icons::ICON_REQUEST_SMALL, Icons::ICON_SEND_REQUEST, Icons::ICON_SITE, Icons::ICON_SITE_SMALL, Icons::ICON_START, Icons::ICON_STOP, Icons::ICON_TOKEN, Icons::ICON_TRANSCODER, Icons::ICON_VULN, Icons::ICON_VULN_BP, Icons::ICON_VULN_BP_SMALL, Icons::ICON_VULN_CRITICAL, Icons::ICON_VULN_CRITICAL_SMALL, Icons::ICON_VULN_HIGH, Icons::ICON_VULN_HIGH_SMALL, Icons::ICON_VULN_LOW, Icons::ICON_VULN_LOW_SMALL, Icons::ICON_VULN_MEDIUM, Icons::ICON_VULN_MEDIUM_SMALL, Icons::ICON_VULN_SMALL, Icons::ICON_WATOBO, Icons::SIBERAS_ICON, Icons::TBL_ICON_LOCK, Icons::WATOBO_LOGO

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ CheckBoxTreeList

Returns a new instance of CheckBoxTreeList.



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
# File 'lib/watobo/gui/checkboxtree.rb', line 211

def initialize(parent)

  @parent = parent
  super(parent, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|
  TREELIST_SHOWS_LINES|
  TREELIST_SHOWS_BOXES|
  TREELIST_ROOT_BOXES|
  #TREELIST_EXTENDEDSELECT|
  TREELIST_MULTIPLESELECT
  )
  #LAYOUT_TOP|LAYOUT_RIGHT|TREELIST_SHOWS_LINES|TREELIST_SHOWS_BOXES|TREELIST_ROOT_BOXES|TREELIST_EXTENDEDSELECT

  self.connect(SEL_COMMAND) do |sender, sel, item|
    if $DEBUG
      puts "Selected Item: #{item}"
      if item.parent
        puts "Member Of: #{item.parent}"
        puts "Has Brothers: #{item.parent.numChildren}"
      end
    end

    if self.itemLeaf?(item) then
      #toggleState(item)
      item.toggle
      updateParent(item)
    else
      data = self.getItemData(item)

      new_state = case data
      when :partly
        #  puts data
        icon = ICON_CB_UNCHECKED
        uncheckAllChildren(item)
        :none
      when :none
        #  puts data
        icon = ICON_CB_CHECKED
        checkAllChildren(item)
        :all
      when :all
        # puts data
        icon = ICON_CB_UNCHECKED
        uncheckAllChildren(item)
        :none
      end

    self.setItemData(item, new_state)
    self.setItemClosedIcon(item, icon)
    self.setItemOpenIcon(item, icon)
    end

    self.killSelection()
  end

end

Instance Method Details

#checkAllObject



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/watobo/gui/checkboxtree.rb', line 169

def checkAll
  self.each do |r|
    r.check
    setItemData(r,:all)
    r.each do |c|
      c.check
    end
    self.update
  # checkAllChildren(r)
  #   openItem(child, true)
  end
end

#checkAllChildren(parent) ⇒ Object



203
204
205
206
207
208
209
# File 'lib/watobo/gui/checkboxtree.rb', line 203

def checkAllChildren(parent)
  parent.each do |child|
  #checkItem(child)
    child.check

  end
end

#elements=(elements) ⇒ Object


C R E A T E T R E E


elements[] = [{

:name => element_name, number of subtrees controlled via pipe-char, e.g. <level1>|<level2>|item
:enabled => true|false,
:data => object|string|...
}, {..} ]


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
# File 'lib/watobo/gui/checkboxtree.rb', line 98

def elements=(elements)
  self.clearItems()
  elements.each do |e|

  # puts icon.class.to_s
    node = nil
    levels = e[:name].split('|')
  #  puts "Processing: #{e[:name]} > #{e[:data].class}" if $DEBUG
    levels.each_with_index do |l,i|
      #puts "#{l} - #{l.class}"
      item = self.findItem(l, node, SEARCH_FORWARD|SEARCH_IGNORECASE)

      if item.nil? then
        # new_item = CheckBoxTreeItem.new(l, e[:enabled], nil)
        new_item = CheckBoxTreeItem.new(l, e[:enabled], :none)
      # item = self.appendItem(node, l, ICON_CB_CHECKED, ICON_CB_CHECKED)
      item = self.appendItem(node, new_item)
      #  if e[:enabled] then
      #    self.openItem(item, false)
      #  else
      #    self.closeItem(item, false)
      #  end
      end
      node = item
      if i == levels.length-1 then
        self.setItemData(item, e[:data])
        updateParent(item)
      end

    end
  end
end

#getCheckedData(root = self) ⇒ Object



160
161
162
163
164
165
166
167
# File 'lib/watobo/gui/checkboxtree.rb', line 160

def getCheckedData(root = self)
  @selected = [] if root == self
  root.each do |c|
    getCheckedData(c) if c.numChildren > 0
    @selected << c.data if self.itemLeaf?(c) and c.checked
  end
  @selected
end

#uncheckAllObject



182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/watobo/gui/checkboxtree.rb', line 182

def uncheckAll
  self.each do |r|
  # uncheckItem(r)
    r.uncheck
    setItemData(r,:none)
    r.each do |c|
      c.uncheck
    end
    #uncheckAllChildren(r)
    self.update
  end
end

#uncheckAllChildren(parent) ⇒ Object



196
197
198
199
200
201
# File 'lib/watobo/gui/checkboxtree.rb', line 196

def uncheckAllChildren(parent)
  parent.each do |child|
  #uncheckItem(child)
    child.uncheck
  end
end

#updateParent(child) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/watobo/gui/checkboxtree.rb', line 131

def updateParent(child)
  parent = child.parent
  # count enabled childs
  return false if parent.nil?
  ec = 0
  parent.each do |item|
  #data = self.getItemData(item)
  #ec += 1 if data[:enabled]
    ec += 1 if item.checked
  end
  if ec == 0 then

    # puts "no childs selected"
    icon = ICON_CB_UNCHECKED
    self.setItemData(parent, :none)
  elsif  ec < parent.numChildren  then
    # puts "not all childs are selected"
    icon = ICON_CB_CHECKED_ORANGE
    self.setItemData(parent, :partly)
  else

  # puts "all childs have been selected"
    icon =   ICON_CB_CHECKED
    self.setItemData(parent, :all)
  end
  self.setItemOpenIcon(parent, icon)
  self.setItemClosedIcon(parent, icon)
end