indexing description : "Main window for this application" legal: "See notice at end of class." status: "See notice at end of class." author : "Generated by the New Vision2 Application Wizard." date : "$Date$" revision : "1.0.0" class MAIN_WINDOW inherit EV_TITLED_WINDOW redefine initialize, is_in_default_state end INTERFACE_NAMES export {NONE} all undefine default_create, copy end create default_create feature {NONE} -- Initialization initialize is -- Build the interface for this window. do Precursor {EV_TITLED_WINDOW} -- Create and add the menu bar. build_standard_menu_bar set_menu_bar (standard_menu_bar) -- Create and add the toolbar. upper_bar.extend (create {EV_HORIZONTAL_SEPARATOR}) -- Create and add the status bar. build_standard_status_bar lower_bar.extend (standard_status_bar) build_main_container extend (main_container) -- Set the title of the window set_title (Window_title) -- Set the initial size of the window set_size (Window_width, Window_height) -- Destroy application on closing close_request_actions.extend (agent ((create {EV_ENVIRONMENT}).application).destroy) end is_in_default_state: BOOLEAN is -- Is the window in its default state -- (as stated in `initialize') do Result := (width = Window_width) and then (height = Window_height) and then (title.is_equal (Window_title)) end feature {NONE} -- Menu Implementation standard_menu_bar: EV_MENU_BAR -- Standard menu bar for this window. file_menu: EV_MENU -- "File" menu for this window (contains New, Open, Close, Exit...) help_menu: EV_MENU -- "Help" menu for this window (contains About...) build_standard_menu_bar is -- Create and populate `standard_menu_bar'. require menu_bar_not_yet_created: standard_menu_bar = Void do -- Create the menu bar. create standard_menu_bar -- Add the "File" menu build_file_menu standard_menu_bar.extend (file_menu) -- Add the "Help" menu build_help_menu standard_menu_bar.extend (help_menu) ensure menu_bar_created: standard_menu_bar /= Void and then not standard_menu_bar.is_empty end build_file_menu is -- Create and populate `file_menu'. require file_menu_not_yet_created: file_menu = Void local menu_item: EV_MENU_ITEM do create file_menu.make_with_text (Menu_file_item) create menu_item.make_with_text (Menu_file_new_item) --| TODO: Add the action associated with "New" here. file_menu.extend (menu_item) create menu_item.make_with_text (Menu_file_open_item) --| TODO: Add the action associated with "Open" here. file_menu.extend (menu_item) create menu_item.make_with_text (Menu_file_save_item) --| TODO: Add the action associated with "Save" here. file_menu.extend (menu_item) create menu_item.make_with_text (Menu_file_saveas_item) --| TODO: Add the action associated with "Save As..." here. file_menu.extend (menu_item) create menu_item.make_with_text (Menu_file_close_item) --| TODO: Add the action associated with "Close" here. file_menu.extend (menu_item) file_menu.extend (create {EV_MENU_SEPARATOR}) -- Create the File/Exit menu item and make it call -- `{EV_APPLICATION}.destroy' when it is selected. create menu_item.make_with_text (Menu_file_exit_item) menu_item.select_actions.extend (agent ((create {EV_ENVIRONMENT}).application).destroy) file_menu.extend (menu_item) ensure file_menu_created: file_menu /= Void and then not file_menu.is_empty end build_help_menu is -- Create and populate `help_menu'. require help_menu_not_yet_created: help_menu = Void local menu_item: EV_MENU_ITEM do create help_menu.make_with_text (Menu_help_item) create menu_item.make_with_text (Menu_help_contents_item) --| TODO: Add the action associated with "Contents and Index" here. help_menu.extend (menu_item) create menu_item.make_with_text (Menu_help_about_item) menu_item.select_actions.extend (agent on_about) help_menu.extend (menu_item) ensure help_menu_created: help_menu /= Void and then not help_menu.is_empty end feature {NONE} -- StatusBar Implementation standard_status_bar: EV_STATUS_BAR -- Standard status bar for this window standard_status_label: EV_LABEL -- Label situated in the standard status bar. -- -- Note: Call `standard_status_label.set_text (...)' to change the text -- displayed in the status bar. build_standard_status_bar is -- Create and populate the standard toolbar. require status_bar_not_yet_created: standard_status_bar = Void and then standard_status_label = Void do -- Create the status bar. create standard_status_bar standard_status_bar.set_border_width (2) -- Populate the status bar. create standard_status_label standard_status_label.align_text_left standard_status_bar.extend (standard_status_label) ensure status_bar_created: standard_status_bar /= Void and then standard_status_label /= Void end feature {NONE} -- About Dialog Implementation on_about is -- Display the About dialog. local about_dialog: ABOUT_DIALOG do create about_dialog about_dialog.show_modal_to_window (Current) end feature {NONE} -- Implementation main_container: EV_VERTICAL_BOX -- Main container (contains all widgets displayed in this window) data_grid: WINFORMS_DATA_GRID -- Data grid server_field, database_field: EV_TEXT_FIELD build_main_container is -- Create and populate `main_container'. require main_container_not_yet_created: main_container = Void local winform_container: EV_WINFORM_CONTAINER l_vbox: EV_VERTICAL_BOX l_hbox: EV_HORIZONTAL_BOX l_label: EV_LABEL l_button: EV_BUTTON do create main_container create l_vbox create l_hbox create l_label.make_with_text ("SQL Server: ") l_hbox.extend (l_label) l_hbox.disable_item_expand (l_label) create server_field.make_with_text ("localhost") server_field.key_press_actions.extend (agent process_key) server_field.set_minimum_width (100) l_hbox.extend (server_field) l_hbox.extend (create {EV_CELL}) create l_label.make_with_text ("Database: ") l_hbox.extend (l_label) l_hbox.disable_item_expand (l_label) create database_field.make_with_text ("Northwind") database_field.set_minimum_width (100) l_hbox.extend (database_field) l_hbox.extend (create {EV_CELL}) create l_button.make_with_text_and_action ("Populate grid", agent populate_grid) l_hbox.extend (l_button) l_hbox.disable_item_expand (l_button) l_hbox.set_padding_width (8) l_hbox.set_border_width (5) l_vbox.extend (l_hbox) l_vbox.disable_item_expand (l_hbox) create winform_container create data_grid.make data_grid.set_caption_text ("Winform data grid inside a Vision2 container") winform_container.extend (data_grid) l_vbox.extend (winform_container) main_container.extend (l_vbox) ensure main_container_created: main_container /= Void end feature {NONE} -- Implementation / Constants Window_title: STRING is "ADO Application" -- Title of the window. Window_width: INTEGER is 400 -- Initial width for this window. Window_height: INTEGER is 400 -- Initial height for this window. feature -- Database code populate_grid is -- Populate data grid from DB. do standard_status_label.set_text ("Populating data grid...") (create {EV_ENVIRONMENT}).application.process_events do_populate data_grid.set_data_binding (data_set, "Suppliers") standard_status_label.set_text ("Data grid populated.") end process_key (a_key: EV_KEY) is -- do if a_key.code = {EV_KEY_CONSTANTS}.Key_enter then populate_grid end end feature {NONE} -- Implementation data_set: DATA_DATA_SET -- Associated data set of `data_grid'. do_populate is local northwind_connection: DATA_SQL_CONNECTION suppliers_adapter: DATA_SQL_DATA_ADAPTER products_adapter: DATA_SQL_DATA_ADAPTER data_relation: DATA_DATA_RELATION data_column_1: DATA_DATA_COLUMN data_column_2: DATA_DATA_COLUMN command_on_suppliers: DATA_SQL_COMMAND command_on_products: DATA_SQL_COMMAND a_mapping: DATA_DATA_TABLE_MAPPING l_count: INTEGER connection_string: STRING do -- create a DATA_SQL_CONNECTION from the given connection string. -- Change the data source value to the name of your computer. connection_string := "server=" connection_string.append (server_field.text) connection_string.append (";Trusted_Connection=yes;database=") connection_string.append (database_field.text) create northwind_connection.make (connection_string) -- Create a DATA_SQL_DATA_ADAPTER for the Suppliers table. create suppliers_adapter.make -- A table mapping tells the adapter what to call the table. a_mapping := suppliers_adapter.table_mappings.add ("Table", "Suppliers") northwind_connection.open create command_on_suppliers.make ("SELECT * FROM Suppliers", northwind_connection) command_on_suppliers.set_command_type ({DATA_COMMAND_TYPE}.Text) suppliers_adapter.set_select_command (command_on_suppliers) create data_set.make ("Customers") l_count := suppliers_adapter.fill_data_set (data_set) -- Create a second DATA_SQL_DATA_ADAPTER and DATA_SQL_COMMAND to get -- the Products table, a child table of Suppliers. create products_adapter.make a_mapping := products_adapter.table_mappings.add ("Table", "Products") create command_on_products.make ("SELECT * FROM Products", northwind_connection) products_adapter.set_select_command (command_on_products) l_count := products_adapter.fill_data_set (data_set) northwind_connection.Close -- You must create a DATA_DATA_RELATION to link the two tables. -- Get the parent and child columns of the two tables. data_column_1 := data_set.tables.item ("Suppliers").columns.item ("SupplierID") data_column_2 := data_set.tables.item ("Products").columns.item ("SupplierID") create data_relation.make ("suppliers2products", data_column_1, data_column_2) data_set.relations.add (data_relation) end indexing copyright: "Copyright (c) 1984-2006, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software 356 Storke Road, Goleta, CA 93117 USA Telephone 805-685-1006, Fax 805-685-6869 Website http://www.eiffel.com Customer support http://support.eiffel.com ]" end -- class MAIN_WINDOW