Class: Watobo::Gui::ChecksPolicyFrame

Inherits:
FXVerticalFrame
  • Object
show all
Defined in:
lib/watobo/gui/checks_policy_frame.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent, policy = nil) ⇒ ChecksPolicyFrame

Returns a new instance of ChecksPolicyFrame.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
# File 'lib/watobo/gui/checks_policy_frame.rb', line 63

def initialize(parent, policy=nil)
  # Invoke base class initialize function first
  super(parent, :opts => LAYOUT_FILL_X| LAYOUT_FILL_Y, :padding => 0)

   @checks = Watobo::ActiveModules.to_a
  #@checks = Watobo.active_checks
=begin        
  @policy_list = policy.is_a?(Hash) ? policy : default_policy(checks)         # policy settings

  policy_frame = FXHorizontalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_SIDE_TOP)

  policy_name = @policy_list[:default_policy] if @policy_list.has_key? :default_policy
  @current_policy = @policy_list[policy_name] if @policy_list.has_key? policy_name

  policy_count = ( @policy_list.is_a? Hash ) ? @policy_list.length : 0

  @policyCombo = FXComboBox.new(policy_frame, policy_count, nil, 0,
  COMBOBOX_INSERT_LAST|FRAME_SUNKEN|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X)

  @policyCombo.numVisible = policy_count
 # @policyCombo.connect(SEL_COMMAND, method(:onPolicyChanged))
=end        
   quickSelectFrame = FXHorizontalFrame.new(self, LAYOUT_FILL_X)
  @sel_all_btn = FXButton.new(quickSelectFrame, "Select All", nil, nil, 0, FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X)
  @sel_all_btn.connect(SEL_COMMAND){ 
    @tree.checkAll
    @tree.update
  }
  
#  @sel_all_btn.setFocus()
#  @sel_all_btn.setDefault()
  
  @desel_all_btn = FXButton.new(quickSelectFrame, "Deselect All", nil, nil, 0, FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_X)
  @desel_all_btn.connect(SEL_COMMAND){ 
    @tree.uncheckAll
    @tree.update 
  } 

  tree_frame = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_GROOVE)
  @tree = CheckBoxTreeList.new(tree_frame)

  #if @policy_list
  #  @policy_list.each do |pname, p|
  #    next if pname.is_a? Symbol
  #    @policyCombo.appendItem(pname, p)
  #  end
  # # select policy
  #  index = @policyCombo.findItem(policy_name)
  #  if index >= 0 then
  #  @policyCombo.setCurrentItem(index)
  #  end
  #applyPolicy(@current_policy)
  #end
  #applyPolicy()
  set_checks @checks
end

Instance Method Details

#applyPolicy(policy = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/watobo/gui/checks_policy_frame.rb', line 12

def applyPolicy(policy=nil)
  #return false if policy.nil?
  tree_elements = []
  @checks.each do |check|
    status = true
    begin
    #  status = policy[check.class.to_s]
    status = false
    rescue
    puts "unknown policy or unknown test [#{@policy}] - [#{check.class.to_s}"
    end
    a = {
      :name => "#{check.check_group}|#{check.check_name}",
      :enabled => status,
      :data => check
    }
    tree_elements.push a
  end

  showTree(tree_elements)
end

#getSelectedModulesObject



57
58
59
60
61
# File 'lib/watobo/gui/checks_policy_frame.rb', line 57

def getSelectedModules()
  sel = @tree.getCheckedData

#sel.map { |i| p i.class }
end

#onPolicyChanged(sender, sel, item) ⇒ Object

attr :policy_name



6
7
8
9
10
# File 'lib/watobo/gui/checks_policy_frame.rb', line 6

def onPolicyChanged(sender, sel, item)
  @policy_name = @policyCombo.getItemText(@policyCombo.currentItem)
  policy = @policyCombo.getItemData(@policyCombo.currentItem)
  applyPolicy(policy)
end

#set_checks(elements, policy = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/watobo/gui/checks_policy_frame.rb', line 34

def set_checks(elements, policy={})
  tree_elements = []
  @checks.each do |check|
    a = {
      :name => "#{check.check_group}|#{check.check_name}",
      :enabled => false,
      :data => check
    }
    puts a[:name]
    tree_elements.push a
  end

  showTree(tree_elements)
end

#showInfo(check) ⇒ Object



49
50
51
# File 'lib/watobo/gui/checks_policy_frame.rb', line 49

def showInfo(check)

end

#showTree(elements) ⇒ Object



53
54
55
# File 'lib/watobo/gui/checks_policy_frame.rb', line 53

def showTree(elements)
  @tree.elements = elements
end