Class: JMXRefWindow
- Inherits:
-
Object
- Object
- JMXRefWindow
- Defined in:
- lib/gui/jmx_ref_window.rb
Instance Method Summary collapse
- #add_gui_jmx_ref ⇒ Object
- #add_modify_jmx_ref(add_boolean, jmx_ref_name = nil) ⇒ Object
- #clear_ls ⇒ Object
- #edit_jmx_ref(jmx_ref_name) ⇒ Object
-
#initialize ⇒ JMXRefWindow
constructor
A new instance of JMXRefWindow.
-
#populate_ls ⇒ Object
populate listview with saved values.
Constructor Details
#initialize ⇒ JMXRefWindow
Returns a new instance of JMXRefWindow.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/gui/jmx_ref_window.rb', line 15 def initialize() #save jmxref hash @jmxrefs_backup=$jmx_refs.dup @window=Gtk::Window.new @window.set_title("JMX Ref configuration") @window.set_size_request(300, 200) @window.signal_connect("key_press_event") {|w,e| if e.keyval == Gdk::Keyval::GDK_Escape @window.destroy end } frame = Gtk::Frame::new frame.border_width=5 frame.show vbox_root=Gtk::VBox::new vbox_root.show @window.add vbox_root vbox_root.add frame vbox = Gtk::VBox.new(false,0) vbox.show frame.add vbox @jmx_ref_ls = Gtk::ListStore.new(String, String) @jmx_ref_view = Gtk::TreeView.new(@jmx_ref_ls) @jmx_ref_view.show column1 = Gtk::TreeViewColumn.new("Name", Gtk::CellRendererText.new, {:text => 0}) column1.set_sort_column_id(0) column2 = Gtk::TreeViewColumn.new("Description", Gtk::CellRendererText.new, {:text => 1}) column2.set_sort_column_id(1) @jmx_ref_view.append_column(column1) @jmx_ref_view.append_column(column2) scroll = Gtk::ScrolledWindow.new(nil, nil) scroll.border_width=2 scroll.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC) scroll.add @jmx_ref_view scroll.show # Create a menu = Gtk::Menu.new item_add = Gtk::ImageMenuItem.new("Add jmx Ref") image_item_add = Gtk::Image.new() image_item_add.set_stock(Gtk::Stock::ADD) item_add.set_image(image_item_add) item_add.signal_connect("activate") { add_gui_jmx_ref() } .append(item_add) item_del = Gtk::ImageMenuItem.new("Delete selected jmx Ref") image_item_del = Gtk::Image.new() image_item_del.set_stock(Gtk::Stock::REMOVE) item_del.set_image(image_item_del) item_del.signal_connect("activate") { if @jmx_ref_view.selection.selected!=nil if JMXRef::del_jmx_ref(@jmx_ref_view.selection.selected[0]) @jmx_ref_view.model.remove(@jmx_ref_view.selection.selected) else dialog = Gtk::MessageDialog.new(@window, Gtk::Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::ERROR, Gtk::MessageDialog::BUTTONS_OK, "You can't delete! jmx Ref in use") dialog.run dialog.destroy end end } .append(item_del) item_edit = Gtk::ImageMenuItem.new("Edit jmx Ref") image_item_edit = Gtk::Image.new() image_item_edit.set_stock(Gtk::Stock::EDIT) item_edit.set_image(image_item_edit) item_edit.signal_connect("activate") { if @jmx_ref_view.selection.selected != nil edit_jmx_ref(@jmx_ref_view.selection.selected[0]) end } .append(item_edit) @jmx_ref_view.signal_connect("button_press_event") do |, event| if event.kind_of? Gdk::EventButton and event. == 3 if @jmx_ref_view.selection.selected == nil item_del.set_sensitive(false) item_edit.set_sensitive(false) else item_del.set_sensitive(true) item_edit.set_sensitive(true) end .popup(nil, nil, event., event.time) elsif (@jmx_ref_view.selection.selected != nil) && (event.event_type == Gdk::Event::BUTTON2_PRESS) edit_jmx_ref(@jmx_ref_view.selection.selected[0]) end end .show_all populate_ls() vbox.add(scroll) bbox = Gtk::HBox::new(FALSE, 10) bbox.border_width=10 bbox.show = Gtk::Button.new(Gtk::Stock::OK) .show .signal_connect("clicked") { JMXRef::write_db_jmxref() @window.destroy } = Gtk::Button.new(Gtk::Stock::CANCEL) .show .signal_connect("clicked") { $jmx_refs=@jmxrefs_backup @window.destroy } .set_flags(Gtk::Widget::CAN_DEFAULT) bbox.pack_start(, TRUE, TRUE, 0) .set_flags(Gtk::Widget::CAN_DEFAULT) bbox.pack_start(, TRUE, TRUE, 0) separator = Gtk::HSeparator::new() separator.show vbox_root.pack_start(separator, FALSE, TRUE, 0) vbox_root.pack_start(bbox, FALSE, TRUE, 0) @window.show end |
Instance Method Details
#add_gui_jmx_ref ⇒ Object
148 149 150 |
# File 'lib/gui/jmx_ref_window.rb', line 148 def add_gui_jmx_ref() add_modify_jmx_ref(true) end |
#add_modify_jmx_ref(add_boolean, jmx_ref_name = nil) ⇒ Object
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 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/gui/jmx_ref_window.rb', line 156 def add_modify_jmx_ref(add_boolean, jmx_ref_name=nil) window=Gtk::Window.new window.set_modal(true) lbl="Edit jmx Ref" if add_boolean lbl="Add jmx Ref" end window.set_title(lbl) window.set_size_request(460, 200) window.signal_connect("key_press_event") {|w,e| if e.keyval == Gdk::Keyval::GDK_Escape window.destroy end } frame = Gtk::Frame::new frame.border_width=10 frame.show vbox_root=Gtk::VBox::new vbox_root.show window.add vbox_root vbox_root.add frame vbox = Gtk::VBox.new vbox.show frame.add vbox table = Gtk::Table.new(4,2,false) table.show label_name = Gtk::Label.new "Name" label_name.show if add_boolean entry_name = Gtk::Entry.new else entry_name = Gtk::Entry.new entry_name.set_editable false entry_name.set_text(jmx_ref_name) end entry_name.show table.attach(label_name,0,1,0,1) table.attach(entry_name,1,2,0,1) entry_description = Gtk::Entry.new if !add_boolean entry_description.set_text($jmx_refs[entry_name.text()].description) unless entry_name.text() == "" end entry_description.show label_description = Gtk::Label.new "Description" label_description.show table.attach(label_description,0,1,1,2) table.attach(entry_description,1,2,1,2) entry_mbean = Gtk::Entry.new if !add_boolean entry_mbean.set_text($jmx_refs[entry_name.text()].mbean) unless entry_name.text() == "" end entry_mbean.show label_mbean = Gtk::Label.new "Object Name(s)" label_mbean.show table.attach(label_mbean,0,1,2,3) table.attach(entry_mbean,1,2,2,3) if !add_boolean entry_name.signal_connect("changed") {|e| if e.text() != "" entry_description.set_text($jmx_refs[e.text()].description) entry_mbean.set_text($jmx_refs[e.text()].mbean) entry_attr.set_text($jmx_refs[e.text()].attribute) end } end entry_attr = Gtk::Entry.new if !add_boolean entry_attr.set_text($jmx_refs[entry_name.text()].attribute) unless entry_name.text() == "" end entry_attr.show label_attr = Gtk::Label.new "Attribute Name(s)" label_attr.show table.attach(label_attr,0,1,3,4) table.attach(entry_attr,1,2,3,4) bbox =Gtk::HBox::new(FALSE, 10) bbox.border_width=10 bbox.show = Gtk::Button.new(Gtk::Stock::OK) .show .signal_connect("clicked") { if entry_name.text == "" || entry_mbean.text == "" || entry_attr.text == "" if entry_name.text == "" entry_name.grab_focus elsif entry_mbean.text == "" entry_mbean.grab_focus else entry_attr.grab_focus end else if add_boolean #new entry! if $jmx_refs[entry_name.text()] == nil JMXRef::add_jmx_ref(entry_name.text(),entry_description.text(),entry_mbean.text(),entry_attr.text()) iter = @jmx_ref_ls.append iter[0] = entry_name.text() iter[1] = entry_description.text() window.destroy else dialog = Gtk::MessageDialog.new(window, Gtk::Dialog::DESTROY_WITH_PARENT, Gtk::MessageDialog::ERROR, Gtk::MessageDialog::BUTTONS_OK, "jmx Ref '#{entry_name.text()}' already exists!") dialog.run dialog.destroy end else #modify existing entry $jmx_refs[entry_name.text()].description=entry_description.text() $jmx_refs[entry_name.text()].mbean=entry_mbean.text() $jmx_refs[entry_name.text()].attribute=entry_attr.text() @jmx_ref_ls.each do |model,path,iter| if iter[0] == entry_name.text() iter[1]=entry_description.text() break end end window.destroy end end } = Gtk::Button.new(Gtk::Stock::CANCEL) .show .signal_connect("clicked") { window.destroy } .set_flags(Gtk::Widget::CAN_DEFAULT) bbox.pack_start(, TRUE, TRUE, 0) .set_flags(Gtk::Widget::CAN_DEFAULT) bbox.pack_start(, TRUE, TRUE, 0) vbox.add(table) separator = Gtk::HSeparator::new() separator.show vbox_root.pack_start(separator, FALSE, TRUE, 0) vbox_root.pack_start(bbox, FALSE, TRUE, 0) window.show end |
#clear_ls ⇒ Object
3 4 5 |
# File 'lib/gui/jmx_ref_window.rb', line 3 def clear_ls() @jmx_ref_ls.clear() end |
#edit_jmx_ref(jmx_ref_name) ⇒ Object
152 153 154 |
# File 'lib/gui/jmx_ref_window.rb', line 152 def edit_jmx_ref(jmx_ref_name) add_modify_jmx_ref(false, jmx_ref_name) end |
#populate_ls ⇒ Object
populate listview with saved values
7 8 9 10 11 12 13 |
# File 'lib/gui/jmx_ref_window.rb', line 7 def populate_ls() $jmx_refs.each_key do |name| iter = @jmx_ref_ls.append iter[0] = name iter[1] = $jmx_refs[name].description end end |