package package5; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import oracle.dacf.control.swing.*; import oracle.dacf.control.tdg.*; import oracle.dacf.formatter.*; import oracle.jdeveloper.layout.*; import oracle.dacf.dataset.*; import oracle.dacf.dataset.connections.*; import oracle.dacf.control.*; /** * This template contains a database-aware applet with a navigation bar * and a menu that is customised by the form generation wizard. * * @version 1.0 * @author Oracle Corp. * * Copyright (c) 1998-2000 Oracle Corporation */ public class Frame1 extends InfoFrame { //Define all the connection objects SessionInfo sessionInfo = new SessionInfo(); RowSetInfo EmpViewMasterIter = new RowSetInfo(); AttributeInfo EmpnoMasterCol = new AttributeInfo(java.sql.Types.NUMERIC); AttributeInfo EnameMasterCol = new AttributeInfo(java.sql.Types.VARCHAR); AttributeInfo JobMasterCol = new AttributeInfo(java.sql.Types.VARCHAR); AttributeInfo MgrMasterCol = new AttributeInfo(java.sql.Types.NUMERIC); AttributeInfo HiredateMasterCol = new AttributeInfo(java.sql.Types.DATE); AttributeInfo SalMasterCol = new AttributeInfo(java.sql.Types.NUMERIC); AttributeInfo CommMasterCol = new AttributeInfo(java.sql.Types.NUMERIC); AttributeInfo DeptnoMasterCol = new AttributeInfo(java.sql.Types.NUMERIC); LoginDlg loginDialog = new LoginDlg("Database Login"); String productCompany = "rtv"; String productCopyright = "Copyright (c) 2000"; String productVersion = ""; String productAuthor = "dan b"; String productName = "Your Product Name"; /** * This string is displayed by the form. It will be customised by the * form generator. * * @see #jbInit */ private String frameTitle = "Data Frame"; /** * This is the form's content pane. * * @see #jbInit */ private JPanel contentPane = new JPanel(); /** * This layout manager is used by the content pane. * * @see #jbInit */ private BorderLayout contentLayout = new BorderLayout(); /** * This panel holds the master and detail panels. * * @see #jbInit */ private JPanel formPanel = new JPanel(); /** * This layout is used by the formPanel. * * @see #jbInit */ private GridLayout formLayout = new GridLayout(0, 1); /** * This status bar is used by the form. * * @see #jbInit */ private StatusBarControl statusBar = new StatusBarControl(); /** * These controls define the menu structure of the form. * * @see #jbInit */ private JMenuBar menubarFrame = new JMenuBar(); private JMenu menuFile = new JMenu(); private JMenuItem itemFileExit = new JMenuItem(); private JMenu menuDatabase = new JMenu(); private JMenuItem itemDatabaseFirst = new JMenuItem(); private JMenuItem itemDatabasePrevious = new JMenuItem(); private JMenuItem itemDatabaseNext = new JMenuItem(); private JMenuItem itemDatabaseLast = new JMenuItem(); private JMenuItem itemDatabaseInsert = new JMenuItem(); private JMenuItem itemDatabaseDelete = new JMenuItem(); private JMenuItem itemDatabaseCommit = new JMenuItem(); private JMenuItem itemDatabaseRollback = new JMenuItem(); private JMenuItem itemFind = new JMenuItem(); private JMenu menuHelp = new JMenu(); private JMenuItem itemHelpAbout = new JMenuItem(); /** * This navigation bar is used by the master table of the form. * * @see #jbInit */ private NavigationBar masterNavBar = new NavigationBar(); /** * This panel holds the master panel and its navigation bar. */ private JPanel masterTable = new JPanel(); /** * This layout is used by the panel above. */ private BorderLayout masterTableLayout = new BorderLayout(); /** * This scroll pane is used by the master panel. */ private JScrollPane masterScroller = new JScrollPane(); /** * This panel holds the database aware controls for the master table. */ private JPanel masterPanel = new JPanel(); /** * This layout is used by the master panel. It may be modified by * the form generator. */ private GridBagLayout masterLayout = new GridBagLayout(); /** * This information will be displayed in the about box. * * @see #helpAbout */ private String[] aboutMessage = {productName, productAuthor, productVersion, productCopyright, productCompany}; private String aboutTitle = "About " + productName; //Fields to support database column: EMPNO. private JLabel labelEMPNO = new JLabel(); private TextFieldControl controlEMPNO = new TextFieldControl(); //Fields to support database column: ENAME. private JLabel labelENAME = new JLabel(); private TextFieldControl controlENAME = new TextFieldControl(); //Fields to support database column: JOB. private JLabel labelJOB = new JLabel(); private TextFieldControl controlJOB = new TextFieldControl(); //Fields to support database column: MGR. private JLabel labelMGR = new JLabel(); private TextFieldControl controlMGR = new TextFieldControl(); //Fields to support database column: HIREDATE. private JLabel labelHIREDATE = new JLabel(); private TextFieldControl controlHIREDATE = new TextFieldControl(); //Fields to support database column: SAL. private JLabel labelSAL = new JLabel(); private TextFieldControl controlSAL = new TextFieldControl(); //Fields to support database column: COMM. private JLabel labelCOMM = new JLabel(); private TextFieldControl controlCOMM = new TextFieldControl(); //Fields to support database column: DEPTNO. private JLabel labelDEPTNO = new JLabel(); private TextFieldControl controlDEPTNO = new TextFieldControl(); /** * Template's public constructor. * * @see #jbInit */ public Frame1() { try { jbInit(); if (loginDialog.showDialog() == JOptionPane.CANCEL_OPTION) { System.exit(1); } sessionInfo.publishSession(); pack(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } // This method takes care of cleaning up when closing this window, // using the window 'X' addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { processWindowClosing(e); } }); } /** * Process the windowClosing event. * * @param event WindowEvent */ private void processWindowClosing(WindowEvent e) { sessionInfo.revokeSession(); InfoBusManager.getInstance().fireReleaseResources(this, this); sessionInfo.close(); dispose(); } /** * Template's initialiser. Creates the frame's UI. * * @throw Exception if any problems occur. */ public void jbInit() throws Exception { //Set up all the session information sessionInfo.setName("Session1"); sessionInfo.setAppModuleInfo(new ModuleInfo("package4", "Package4Module")); sessionInfo.setConnectionInfo(new LocalConnection("c1")); //Set up the view usage information EmpViewMasterIter.setName("EmpView"); EmpnoMasterCol.setName("Empno"); EnameMasterCol.setName("Ename"); JobMasterCol.setName("Job"); MgrMasterCol.setName("Mgr"); HiredateMasterCol.setName("Hiredate"); SalMasterCol.setName("Sal"); CommMasterCol.setName("Comm"); DeptnoMasterCol.setName("Deptno"); EmpViewMasterIter.setAttributeInfo(new ColumnInfo[] { EmpnoMasterCol, EnameMasterCol, JobMasterCol, MgrMasterCol, HiredateMasterCol, SalMasterCol, CommMasterCol, DeptnoMasterCol}); EmpViewMasterIter.setQueryInfo(new QueryViewInfo("EmpView")); EmpViewMasterIter.setSession(sessionInfo); //Set up link association setDataItemName("infobus:/oracle/Session1"); loginDialog.setDataItemName("infobus:/oracle/Session1"); loginDialog.setShowDatabaseURL(false); loginDialog.setShowConnectionNames(true); contentPane.setLayout(contentLayout); setContentPane(contentPane); setTitle(frameTitle); setSize(new Dimension(400, 300)); /* * Build the menu. */ setJMenuBar(menubarFrame); itemFileExit.setText("Exit"); itemFileExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { fileExit(e); } }); menuFile.add(itemFileExit); menuFile.setText("File"); menubarFrame.add(menuFile); itemDatabaseFirst.setText("First"); itemDatabaseFirst.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_FIRST); } }); menuDatabase.add(itemDatabaseFirst); itemDatabasePrevious.setText("Previous"); itemDatabasePrevious.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_PREV); } }); menuDatabase.add(itemDatabasePrevious); itemDatabaseNext.setText("Next"); itemDatabaseNext.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_NEXT); } }); menuDatabase.add(itemDatabaseNext); itemDatabaseLast.setText("Last"); itemDatabaseLast.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_LAST); } }); menuDatabase.add(itemDatabaseLast); menuDatabase.addSeparator(); itemDatabaseInsert.setText("Insert"); itemDatabaseInsert.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_INSERT); } }); menuDatabase.add(itemDatabaseInsert); itemDatabaseDelete.setText("Delete"); itemDatabaseDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_DELETE); } }); menuDatabase.add(itemDatabaseDelete); menuDatabase.addSeparator(); itemDatabaseCommit.setText("Commit"); itemDatabaseCommit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_COMMIT); } }); menuDatabase.add(itemDatabaseCommit); itemDatabaseRollback.setText("Rollback"); itemDatabaseRollback.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_ROLLBACK); } }); menuDatabase.add(itemDatabaseRollback); menuDatabase.addSeparator(); itemFind.setText("Find"); itemFind.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { masterNavBar.doClick(NavigationBar.BUTTON_FIND); } }); menuDatabase.add(itemFind); menuDatabase.setText("Database"); menubarFrame.add(menuDatabase); itemHelpAbout.setText("About"); itemHelpAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { helpAbout(e); } }); menuHelp.add(itemHelpAbout); menuHelp.setText("Help"); menubarFrame.add(menuHelp); /* * Set up the panels which will hold the master and detail controls. */ formPanel.setLayout(formLayout); masterTable.setLayout(masterTableLayout); masterPanel.setLayout(masterLayout); getContentPane().add(statusBar, BorderLayout.SOUTH); getContentPane().add(formPanel, BorderLayout.CENTER); formPanel.add(masterTable, null); formPanel.setBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED)); masterTable.add(masterNavBar, BorderLayout.NORTH); masterTable.add(masterPanel, BorderLayout.CENTER); // To make the master panel scrollable, comment out the line above // and uncomment the following two lines. //masterTable.add(masterScroller, BorderLayout.CENTER); //masterScroller.getViewport().add(masterPanel); masterPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); //Code to connect the navigation bar to data. masterNavBar.setDataItemName("infobus:/oracle/Session1/EmpView"); masterNavBar.setHasInsertButton(true); masterNavBar.setHasDeleteButton(true); masterNavBar.setHasNavigationButtons(true); masterNavBar.setHasTransactionButtons(true); masterNavBar.setHasFindButton(true); //Code to support database column: EMPNO. masterPanel.add(labelEMPNO, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); labelEMPNO.setText("EMPNO:"); masterPanel.add(controlEMPNO, new GridBagConstraints2(1, 0, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); controlEMPNO.setDataItemName("infobus:/oracle/Session1/EmpView/Empno"); controlEMPNO.setColumns(15); controlEMPNO.setToolTipText("Current entry in EMPNO"); //Code to support database column: ENAME. masterPanel.add(labelENAME, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); labelENAME.setText("ENAME:"); masterPanel.add(controlENAME, new GridBagConstraints2(1, 1, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); controlENAME.setDataItemName("infobus:/oracle/Session1/EmpView/Ename"); controlENAME.setColumns(15); controlENAME.setToolTipText("Current entry in ENAME"); //Code to support database column: JOB. masterPanel.add(labelJOB, new GridBagConstraints2(0, 2, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); labelJOB.setText("JOB:"); masterPanel.add(controlJOB, new GridBagConstraints2(1, 2, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); controlJOB.setDataItemName("infobus:/oracle/Session1/EmpView/Job"); controlJOB.setColumns(15); controlJOB.setToolTipText("Current entry in JOB"); //Code to support database column: MGR. masterPanel.add(labelMGR, new GridBagConstraints2(0, 3, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); labelMGR.setText("MGR:"); masterPanel.add(controlMGR, new GridBagConstraints2(1, 3, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); controlMGR.setDataItemName("infobus:/oracle/Session1/EmpView/Mgr"); controlMGR.setColumns(15); controlMGR.setToolTipText("Current entry in MGR"); //Code to support database column: HIREDATE. masterPanel.add(labelHIREDATE, new GridBagConstraints2(0, 4, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); labelHIREDATE.setText("HIREDATE:"); masterPanel.add(controlHIREDATE, new GridBagConstraints2(1, 4, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); controlHIREDATE.setDataItemName("infobus:/oracle/Session1/EmpView/Hiredate"); controlHIREDATE.setColumns(15); controlHIREDATE.setToolTipText("Current entry in HIREDATE"); //Code to support database column: SAL. masterPanel.add(labelSAL, new GridBagConstraints2(0, 5, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); labelSAL.setText("SAL:"); masterPanel.add(controlSAL, new GridBagConstraints2(1, 5, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); controlSAL.setDataItemName("infobus:/oracle/Session1/EmpView/Sal"); controlSAL.setColumns(15); controlSAL.setToolTipText("Current entry in SAL"); //Code to support database column: COMM. masterPanel.add(labelCOMM, new GridBagConstraints2(0, 6, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); labelCOMM.setText("COMM:"); masterPanel.add(controlCOMM, new GridBagConstraints2(1, 6, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); controlCOMM.setDataItemName("infobus:/oracle/Session1/EmpView/Comm"); controlCOMM.setColumns(15); controlCOMM.setToolTipText("Current entry in COMM"); //Code to support database column: DEPTNO. masterPanel.add(labelDEPTNO, new GridBagConstraints2(0, 7, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); labelDEPTNO.setText("DEPTNO:"); masterPanel.add(controlDEPTNO, new GridBagConstraints2(1, 7, 1, 1, 0.0, 0.0,GridBagConstraints.WEST, GridBagConstraints.RELATIVE, new Insets(0, 0, 0, 5), 1, 1)); controlDEPTNO.setDataItemName("infobus:/oracle/Session1/EmpView/Deptno"); controlDEPTNO.setColumns(15); controlDEPTNO.setToolTipText("Current entry in DEPTNO"); // To make the detail panel scrollable, comment out the line above // and uncomment the following two lines. //detailTable.add(detailScroller, BorderLayout.CENTER); //detailScroller.getViewport().add(detailPanel); } /** masterTable.add(masterScroller, BorderLayout.CENTER); masterScroller.getViewport().add(masterPanel); detailTable.add(detailScroller, BorderLayout.CENTER); detailScroller.getViewport().add(detailPanel); * This method is called in response to the File|Exit menu item. * * @param e the event which caused this method to be called */ private void fileExit(ActionEvent e) { if (close()) { sessionInfo.revokeSession(); InfoBusManager.getInstance().fireReleaseResources(this, this); sessionInfo.close(); System.exit(0); } } /** * This method is called in response to the Help|About menu item. * * @param e the event which caused this method to be called */ private void helpAbout(ActionEvent e) { JOptionPane.showMessageDialog(this, aboutMessage, aboutTitle, JOptionPane.INFORMATION_MESSAGE); } }