Created
May 13, 2009 17:52
-
-
Save alpengeist/111159 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'gui/main_model' | |
require 'gui/main_view' | |
require 'gui/graph_controller' | |
require 'gui/log_controller' | |
module TestTool::GUI | |
class MainController < Monkeybars::Controller | |
E_UPDATE = 0 | |
include Logging | |
set_model 'TestTool::GUI::MainModel' | |
set_view 'TestTool::GUI::MainView' | |
set_close_action :exit | |
add_listener :type=>:list_selection, :components=>{"usecaseTable.selectionModel" => "usecase_table"} | |
add_listener :type=>:table_model, :components=>{"usecaseTable.model" => "usecase_table"} | |
add_listener :type=>:list_selection, :components=>{"testcaseTable.selectionModel" => "testcase_table"} | |
add_listener :type=>:table_model, :components=>{"testcaseTable.model" => "testcase_table"} | |
add_listener :type=>:list_selection, :components=>{"testcaseSelection.selectionModel" => "testcase_selection"} | |
def reset | |
@session = @load_proc.call | |
model.session = session | |
@running = false | |
end | |
def open | |
reset | |
super | |
end | |
def load_proc(&block) | |
@load_proc = block | |
end | |
# TableModelListener | |
def usecase_table_table_changed(event) | |
if event.type == E_UPDATE && event.column == 1 | |
#log_debug "usecaseTable/table changed, type=#{event.type}, first_row=#{event.first_row}, column=#{event.column}" | |
row = event.first_row | |
transfer[:uc_row] = row | |
signal :uc_table_changed | |
update_view | |
end | |
end | |
def testcase_table_table_changed(event) | |
if event.type == E_UPDATE && event.column == 0 | |
#log_debug "testcaseTable/table changed, type=#{event.type}, first_row=#{event.first_row}, column=#{event.column}" | |
row = event.first_row | |
transfer[:tc_row] = row | |
signal :tc_table_changed | |
update_view | |
end | |
end | |
# SelectionModel listener | |
def usecase_table_value_changed(event) | |
unless event.getValueIsAdjusting | |
#log_debug "usecase table value changed" | |
signal :uc_value_changed | |
update_view | |
end | |
end | |
def testcase_table_value_changed(event) | |
unless event.getValueIsAdjusting || event.firstIndex == -1 | |
#log_debug "testcase table value changed" | |
signal :tc_value_changed | |
update_view | |
end | |
end | |
def testcase_selection_value_changed(event) | |
unless event.getValueIsAdjusting || event.firstIndex == -1 | |
signal :tc_selection_value_changed | |
# view updates itself | |
end | |
end | |
# RUN/STOP Button | |
def run_btn_action_performed(event) | |
if (@running) | |
log_info "*** STOPPED by user ***" | |
# tell the View that it must finish the signal handling | |
# for the :run_testcases signal | |
signal :cancel | |
else | |
# The signal processing is done in a background thread | |
repaint_while do | |
@running = true | |
signal :run_testcases | |
# we get here when the View finishes the signal handling | |
@running = false | |
end | |
end | |
end | |
# RELOAD button | |
def reload_btn_action_performed(event) | |
begin | |
signal :log_on | |
reset | |
signal :lock | |
signal :reload | |
rescue => e | |
log_error e.message + "\n" + e.backtrace.join("\n") | |
signal :log_off | |
transfer[:message] = "Error occured while loading suite file, please see log for details" | |
signal :popup | |
ensure | |
transfer[:state] = true | |
signal :lock | |
end | |
update_view | |
end | |
# Reset Button | |
def reset_btn_action_performed(event) | |
model.reset_testcases | |
signal :filter_reset | |
signal :log_clear | |
update_view | |
end | |
# Diff Button | |
def diff_btn_action_performed(event) | |
if model.last_compared_files | |
# Run the DIFF program in the background to avoid blocking the GUI | |
Thread.new do | |
if ! system($DIFF_PROGRAM, model.last_compared_files.ref_file, model.last_compared_files.file) | |
transfer[:message]="Could not run the DIFF program" | |
signal :popup | |
end | |
Thread.current.exit | |
end | |
else | |
transfer[:message]="No Testcase highlighted or Testcase has not compared any files recently" | |
signal :popup | |
end | |
end | |
# Filter Buttons | |
def all_filter_btn_action_performed(event) | |
model.set_filter(:all) | |
signal :filter_changed | |
update_view | |
end | |
def success_filter_btn_action_performed(event) | |
model.set_filter(:success) | |
signal :filter_changed | |
update_view | |
end | |
def failed_filter_btn_action_performed(event) | |
model.set_filter(:failed) | |
signal :filter_changed | |
update_view | |
end | |
def not_run_filter_btn_action_performed(event) | |
model.set_filter(:norun) | |
signal :filter_changed | |
update_view | |
end | |
# Select Buttons | |
def select_all_btn_action_performed(event) | |
model.select_usecase | |
signal :uc_table_changed | |
signal :filter_reset | |
update_view | |
end | |
def unselect_all_btn_action_performed(event) | |
model.unselect_usecase | |
signal :uc_table_changed | |
signal :filter_reset | |
update_view | |
end | |
def show_log_btn_action_performed(event) | |
LogController.instance.open | |
end | |
# message verification check box | |
def verification_check_item_state_changed(event) | |
model.message_verification=state_change_to_boolean(event.getStateChange) | |
end | |
# display graph button | |
def graph_btn_action_performed(event) | |
GraphController.instance.open | |
end | |
# graph drawing check box | |
def draw_graph_check_item_state_changed(event) | |
model.draw_graph=state_change_to_boolean(event.getStateChange) | |
end | |
# Java Swing ItemEvent mapping | |
def state_change_to_boolean(s) | |
case s | |
when 2 then false # java.awt.event.ItemEvent.SELECTED | |
when 1 then true # java.awt.event.ItemEvent.DESELECTED | |
else false | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment