Опытный
 
Профиль
Группа: Участник
Сообщений: 327
Регистрация: 30.10.2004
Репутация: 7 Всего: 21
|
Хм, а куда делся исходник класса formEmployees? Итак: 1. Main_KHR не менял 2. Изменный formEmployees привожу полностью, потому как не помню, где именно делал изменения, а сравнивать не с чем  . 3. В DB привожу изменные куски 4. Хранимую эмулировал при помощи таблицы Test_Table, создал ее из первых 10 столбцов длинного списка, все столбцы типа Number (ломко было создавать все по уму  ) В результате удалось вывести ВСЁ подмножество столбцов и ВСЕ строки PS: возможны проблемы, если порядок следования столбцов в columnNames отличается от такового в запросе. Тогда надо менять и columnNames. Код | package sanic;
/** * Created by IntelliJ IDEA. * User: sanik * Date: Nov 15, 2004 * Time: 1:12:41 PM * To change this template use File | Settings | File Templates. */ import java.sql.CallableStatement; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import javax.swing.*; import java.*; import java.util.ArrayList; ///import java.sql.*; import java.awt.*; import java.awt.event.*; import oracle.jdbc.OracleConnection; import oracle.jdbc.OracleDriver; import java.sql.Connection; import java.sql.DriverManager;
public class DB {
private static boolean isNeededColumn(String[] columnNames,String currentColumnName) { for (int i=0;i<columnNames.length;i++) { if (columnNames[i].equalsIgnoreCase(currentColumnName)) { return true; } } return false; }
private static Connection con = null; /// private static java.sql.Connection con = null; /// private static final String url = "jdbc:microsoft:sqlserver://"; /// private static final String serverName = "bbb9"; /// private static final String portNumber = "1433"; /// private static final String databaseName = "My_DB"; /// private static final String userName = "sanik"; /// private static final String password = "parol";
private static String url= "jdbc:oracle:thin:@localhost:1521:bank2"; private static String userName= "vingrad"; private static String password= "vingrad";
// Informs the driver to use server a side-cursor, which permits more than one active statement // on a connection.
private static final String selectMethod = "cursor";
private static String getConnectionUrl() {
/// return url + serverName + ":" + portNumber + ";databaseName=" + /// databaseName + ";selectMethod=" + selectMethod + ";"; return url; }
public static java.sql.Connection getConnection() {
try{ DriverManager.registerDriver(new OracleDriver());
/// Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); con = (OracleConnection)DriverManager.getConnection(getConnectionUrl(),userName,password); /// con = java.sql.DriverManager.getConnection(getConnectionUrl(),userName,password); if(con!=null) System.out.println("Connection Successful!"); } catch(Exception e) { e.printStackTrace(); System.out.println("Error Trace in getConnection() : " + e.getMessage()); } return con; } ...
public static Object[][] ExecStoredProc(String myOffice, String myDept, String activeStatus, String[] columnNames ) { int i = 0; int j = 0; int numColumns = 0;
ArrayList tableRow = new ArrayList(); ArrayList multiRow = new ArrayList(); Object[][] resultArray2D; /// CallableStatement cs = null;
System.out.println("activeStatus =" + activeStatus); System.out.println("myOffice =" + myOffice); System.out.println("myDept =" + myDept);
try { /*// cs = con.prepareCall("{CALL SpSelEmployees3(?,?,?,?,?,?,?,?)}"); cs.setString(1, "OfficeName"); // @strOrder char(100) = ' OfficeName, Department, Surname, W_Group, Discipline', cs.setInt(2, Integer.parseInt(myOffice)); // @office int = -1, cs.setInt(3, Integer.parseInt(myDept)); // @dept int = -1, cs.setInt(4, -1); // @position int = -1, cs.setString(5, ""); // @workgroup char(50) ='', cs.setString(6, ""); // @discipline char(50) ='', cs.setInt(7, Integer.parseInt(activeStatus)); // @terminated int = -1 cs.setString(8, ""); // @my_select varchar(1000) = '' */ /* SELECT "FirstName", "LastName", "Department", "JobTitle","Office"}; 0 - Id_Code, 1 - Surname, 2 - FirstName, 3 - MiddleName, 4 - EmployeeID, 5- Initials, 6 - MR, 7 - AccutiName, 8 - EmployeeName, 9 - Official, 10 - Id_JobTitle, ... */ Statement cs = con.createStatement(); ResultSet result = cs.executeQuery("select * from test_table");
/// ResultSet result = cs.executeQuery(); //========================================= //System.out.println("nnnnnn_nnnnnnnnnnnnn="); ResultSetMetaData rsmd = result.getMetaData();
System.out.println("number of columns="+ rsmd.getColumnCount()); //System.out.println("number of rows="+ rsmd.
/* for (i = 1; i <= rsmd.getColumnCount(); i++) { tableRow.add(rsmd.getColumnName(i)); numColumns = tableRow.size(); //resultArray2D[j][i] = rsmd.getColumnName(i); } multiRow.add(tableRow); */ tableRow = new ArrayList(); while (result.next()) { for (i = 1; i <= rsmd.getColumnCount(); i++) { if (isNeededColumn(columnNames,rsmd.getColumnName(i))) { tableRow.add(""+result.getInt(i)); // tableRow.add(result.getString(i)); } //resultArray2D[j][i] = result.getString(i); } multiRow.add(tableRow); numColumns = tableRow.size(); tableRow = new ArrayList(); } cs.close(); } catch (SQLException ex) { System.err.print("SQLException: "); System.err.println(ex.getMessage()); } System.out.println("a=" + numColumns); resultArray2D = new Object[multiRow.size() - 1][numColumns];
for (i = 1; i < multiRow.size(); i++) { tableRow = (ArrayList) multiRow.get(i); for (j = 0; j < numColumns; j++) { resultArray2D[i - 1][j] = (Object) tableRow.get(j); } tableRow = null; } System.out.println("Rows="+ i); //multiRow.size()); return resultArray2D; } //================================
... }
}
|
Код | package sanic;
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.net.URL; import java.io.IOException; import java.sql.CallableStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.Vector; import java.util.Arrays; import javax.swing.ImageIcon; import javax.swing.JTabbedPane; import javax.swing.table.JTableHeader; import javax.swing.table.DefaultTableModel; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionEvent; import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; import javax.swing.border.Border; import javax.swing.tree.*;
/** * Created by IntelliJ IDEA. * User: sanik * Date: Nov 23, 2004 * Time: 12:06:15 PM * To change this template use File | Settings | File Templates. */ public class formEmployees extends JFrame implements ActionListener { JPanel contentPane; JPanel testPanel; JPanel tab_offices; JPanel tab_lang; JPanel tab_services; JPanel tab_advFilters;
private TreeNode rootNode; private JSplitPane split_main;
private JEditorPane htmlPane; private JTree o_tree; private JTree s_tree; private JTree l_tree; private URL helpURL; private static boolean DEBUG = false;
private static int XSPACE = 2;
static final private String PREVIOUS = "previous"; static final private String UP = "up"; static final private String NEXT = "next"; static final private String SOMETHING_ELSE = "other"; static final private String TEXT_ENTERED = "text";
// private JRadioButton rb_LastName; // private JRadioButton rb_FirstName;
static String allString = "All Employees"; static String activeString = "Active Employee"; static String termString = "Terminated Employees";
DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
final static int LEVEL_ROOT = 0; final static int LEVEL_Office = 1; final static int LEVEL_Department = 2; final static short FIELD_KIND_ID = 1; final static short FIELD_KIND_NAME = 2; final static int INVALID_ID = -1;
// private Component tableEmployees; private DB myDatabase; // local databaseobject - initialized in constructor, passed from Main_KHR
private String activeStatus ="1"; private String myOffice; private String myDept; private String mylabel; String[] columnNames; Object[][] o_data; Object[][] s_data; Object[][] l_data; Object[][] e_data;
JTable tableEmployees; JButton buttonQuery; JButton buttonNewEmployee; JButton buttonShowDetails; JButton buttonExit; JButton buttonFind; JButton buttonCancel; JTextField textFind;
JPanel group_EStatus; JPanel group_Browse; JPanel group_FastFind; JTabbedPane tb_Filters; JToolBar o_toolBar; JToolBar s_toolBar; JToolBar l_toolBar; JScrollPane o_treeView; JScrollPane s_treeView; JScrollPane l_treeView; JScrollPane htmlView; JScrollPane scrollPane;
JSplitPane o_splitPane; JButton buttonExpandTree; JButton buttonSwapTree; JButton buttonApplyOffice; JButton buttonApplyService; JButton buttonApplyLang;
JLabel l_findoffice; JPanel f_Services; JPanel f_Languages; JPanel status_main; JSplitPane pan_Employees;
// ================C O N S T R U C T O R ===================================================== public formEmployees() throws Exception { BorderLayout myborderLayout = new BorderLayout(); contentPane = (JPanel)this.getContentPane(); contentPane.setLayout(myborderLayout);
JPanel top_NORTH = new JPanel();
top_NORTH.setLayout(new SpringLayout()); //========================================================================= //Put FastFind text box and the radio buttons into a panel. group_FastFind = MyPaneFastFind(); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!function //====================================================================== //Put the radio buttons in a line in a panel. group_EStatus = MyPaneActiveEmployeeStatus(); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!function //===================================================================== // Put the BIG buttons in a line in a panel. group_Browse = MyPaneBigButtons(); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!function //====================================================================== // Create tabbed panel with filters panels tb_Filters = MyLeftTabbedPane(); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!function //======================================================================
split_main= MyMainSplitPane();
//================================================================== top_NORTH.add(group_FastFind); top_NORTH.add(group_EStatus); top_NORTH.add(group_Browse); //gBrowse_Box); /// SpringUtilities.makeCompactGrid(top_NORTH, 1, top_NORTH.getComponentCount(), 6, 6, 6, 6);
status_main = new JPanel(); //-------------<----------- Employee status panel
status_main.setMinimumSize(new Dimension (1200,100)); status_main.setMaximumSize(new Dimension (200,100));
Border border = BorderFactory.createEtchedBorder(Color.white, new Color(178, 178, 178)); status_main.setBorder(border); status_main.setOpaque(true); // Make untrasparent background for the row
contentPane.add(top_NORTH, BorderLayout.NORTH); contentPane.add(split_main, BorderLayout.CENTER); // Placing status raw on a panel contentPane.add(status_main, BorderLayout.SOUTH);
//Display the window. this.setTitle("Employees"); } //======== E N D OF C O N S T R U C T O R =========================================
private void printDebugData(JTable tEmployees) { int numRows = tEmployees.getRowCount(); int numCols = tEmployees.getColumnCount(); javax.swing.table.TableModel model = tEmployees.getModel();
System.out.println("Value of data: "); for (int i = 0; i < numRows; i++) { System.out.print(" row " + i + ":"); for (int j = 0; j < numCols; j++) { System.out.print(" " + model.getValueAt(i, j)); } System.out.println(); } System.out.println("--------------------------"); }
private void buttonCancel_actionPerformed(ActionEvent e) { }
private void buttonFind_actionPerformed(ActionEvent e) { }
void buttonExit_actionPerformed(ActionEvent e) { exit(); }
void buttonShowDetails_actionPerformed(ActionEvent e) { }
protected JComponent makeTextPanel(String text) { JPanel panel = new JPanel(false); JLabel filler = new JLabel(text); filler.setHorizontalAlignment(JLabel.CENTER); panel.setLayout(new GridLayout(1, 1)); panel.add(filler); return panel; }
protected static ImageIcon createImageIcon(String path) { java.net.URL imgURL = Main_KHR.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } }
void buttonQuery_actionPerformed(ActionEvent e) { query(); }
private void query() { }
void buttonNewEmployee_actionPerformed(ActionEvent e) { //NewEmployeeForm(); }
protected void addButtons(JToolBar toolBar) { JButton button = null; //first button button = makeNavigationButton("Back24", PREVIOUS, "Back to previous something-or-other", "Previous"); toolBar.add(button); //second button button = makeNavigationButton("Up24", UP, "Up to something-or-other", "Up"); toolBar.add(button); //third button button = makeNavigationButton("Forward24", NEXT, "Forward to something-or-other", "Next"); toolBar.add(button); //separator toolBar.addSeparator(); //fourth button button = new JButton("find"); button.setActionCommand(SOMETHING_ELSE); button.setToolTipText("Something else"); //button.addActionListener(this); toolBar.add(button);
//fifth component is NOT a button! JTextField textField = new JTextField("A text field"); textField.setColumns(10); //textField.addActionListener(this); textField.setActionCommand(TEXT_ENTERED); toolBar.add(textField); }
protected JButton makeNavigationButton(String imageName, String actionCommand, String toolTipText, String altText) { //Look for the image. String imgLocation = "toolbarButtonGraphics/navigation/" + imageName + ".gif"; URL imageURL = formEmployees.class.getResource(imgLocation);
//Create and initialize the button. JButton button = new JButton(); button.setActionCommand(actionCommand); button.setToolTipText(toolTipText); //button.addActionListener(this);
if (imageURL != null) { //image found button.setIcon(new ImageIcon(imageURL, altText)); } else { //no image found button.setText(altText); System.err.println("Resource not found: " + imgLocation); } return button; }
/** Required by TreeSelectionListener interface. */ public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) o_tree.getLastSelectedPathComponent();
if (node == null) { return; }
Object nodeInfo = node.getUserObject(); if (node.isLeaf()) { BookInfo book = (BookInfo) nodeInfo; displayURL(book.bookURL); if (DEBUG) { System.out.print(book.bookURL + ": \n "); } } else { displayURL(helpURL); } if (DEBUG) { System.out.println(nodeInfo.toString()); } }
private class BookInfo { public String bookName; public URL bookURL;
public BookInfo(String book, String filename) { bookName = book; bookURL = formEmployees.class.getResource(filename); if (bookURL == null) { System.err.println("Couldn't find file: " + filename); } }
public String toString() { return bookName; } }
private void displayURL(URL url) { try { if (url != null) { htmlPane.setPage(url); } else { //null url htmlPane.setText("File Not Found"); if (DEBUG) { System.out.println("Attempted to display a null URL."); } } } catch (IOException e) { System.err.println("Attempted to read a bad URL: " + url); } }
/** Listens to the radio buttons. */ public void actionPerformed(ActionEvent e) { activeStatus = e.getActionCommand(); RefreshTable(); }
public void RefreshTable() {
columnNames = new String[] {"EmployeeID","Initials","MR","AccutiName","EmployeeName"};
/// columnNames = new String[] {"FirstName","LastName","Department","JobTitle","Office"}; e_data = DB.ExecStoredProc(myOffice, myDept, activeStatus,columnNames); // Call stored procedure SpSelectEmployees3 from SQL SERVER // tableEmployees.setAutoCreateColumnsFromModel(true); //tableEmployees = new JTable(e_data, columnNames); // populating grid with data from result set = stored procedure SpSelectEmployees3 tableEmployees = new JTable(e_data, columnNames); // populating grid with data from result set = stored procedure SpSelectEmployees3 /* tableEmployees.getTableHeader().resizeAndRepaint();
JTableHeader header = tableEmployees.getTableHeader();
SelectionListener listener = new SelectionListener(tableEmployees);
tableEmployees.getSelectionModel().addListSelectionListener(listener); tableEmployees.getColumnModel().getSelectionModel() .addListSelectionListener(listener);
testPanel.invalidate(); */ testPanel.removeAll(); /// testPanel.add(header, BorderLayout.NORTH); // Add header in NORTH slot JScrollPane scrollPane = new JScrollPane(tableEmployees);
testPanel.add(scrollPane, BorderLayout.CENTER); /* testPanel.validate(); testPanel.repaint(); testPanel.setPreferredSize(new Dimension(500, 70)); */ pack(); doLayout();
/* if (true) { tableEmployees.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { Point p = e.getPoint(); int row = tableEmployees.rowAtPoint(p); int column = tableEmployees.columnAtPoint(p); } } }); } */ }
public class SelectionListener implements ListSelectionListener { JTable tableEmployees;
// It is necessary to keep the table since it is not possible // to determine the table from the event's source SelectionListener(JTable table) { this.tableEmployees = table; } public void valueChanged(ListSelectionEvent e) { // If cell selection is enabled, both row and column change events are fired if (e.getSource() == tableEmployees.getSelectionModel() && tableEmployees.getRowSelectionAllowed()) { // Column selection changed int first = e.getFirstIndex(); int last = e.getLastIndex(); } else if (e.getSource() == tableEmployees.getColumnModel().getSelectionModel() && tableEmployees.getColumnSelectionAllowed() ) { // Row selection changed int first = e.getFirstIndex(); int last = e.getLastIndex(); }
if (e.getValueIsAdjusting()) { // The mouse button has not yet been released } } }
//================================== public void exit () { int response = JOptionPane.showConfirmDialog(formEmployees.this, "Really Quit?"); if (response == JOptionPane.YES_OPTION) this.dispose(); } //========================================================================= /* Put Employee status radiobuttons in a line in a panel. group_EStatus <----------- Employee status radiobuttons group */ private JPanel MyPaneActiveEmployeeStatus() { group_EStatus = new JPanel(); group_EStatus.setLayout(new SpringLayout());
JRadioButton allButton = new JRadioButton("All"); allButton.setMnemonic(KeyEvent.VK_L); allButton.setActionCommand("-1"); allButton.setSelected(true);
JRadioButton activeButton = new JRadioButton("Active"); activeButton.setMnemonic(KeyEvent.VK_C); activeButton.setActionCommand("1");
JRadioButton termButton = new JRadioButton("Terminated"); termButton.setMnemonic(KeyEvent.VK_T); termButton.setActionCommand("0");
ButtonGroup activStatus = new ButtonGroup(); activStatus.add(allButton); activStatus.add(activeButton); activStatus.add(termButton);
group_EStatus.add(allButton); group_EStatus.add(activeButton); group_EStatus.add(termButton); group_EStatus.add(Box.createHorizontalStrut(XSPACE));
//Register a listener for the radio buttons. allButton.addActionListener(this); activeButton.addActionListener(this); termButton.addActionListener(this); //group_EStatus.setLayout(new GridLayout(1,3)); //group_EStatus.setBorder(new TitledBorder(new EtchedBorder(), mylabel)); group_EStatus.setBorder(new TitledBorder(new EtchedBorder(), " Employee Status Filter ")); /// SpringUtilities.makeCompactGrid(group_EStatus, 1, group_EStatus.getComponentCount(), 6, 6, 6, 6); return group_EStatus; } //======================== private JPanel MyPaneBigButtons() { buttonNewEmployee = new JButton(); buttonShowDetails = new JButton(); buttonExit = new JButton();
JPanel group_Browse = new JPanel(); //-------------<-------------- Employee edit-browse box group_Browse.setLayout(new SpringLayout()); group_Browse.setBorder(new TitledBorder(new EtchedBorder(), " Edit <=> Browse Details "));
//========================================== group_Browse.add(buttonQuery, null); buttonQuery.setToolTipText("Search information by the request"); buttonQuery.setIcon(new ImageIcon(getToolkit().createImage( "images/SQLquery2.gif"))); buttonQuery.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonQuery_actionPerformed(e); } }); //================================================= group_Browse.add(buttonNewEmployee, null); buttonNewEmployee.setToolTipText("Enter information for a new Employee"); buttonNewEmployee.setIcon(new ImageIcon(getToolkit().createImage( "images/NewEmployee.gif"))); buttonNewEmployee.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonNewEmployee_actionPerformed(e); } }); group_Browse.add(buttonShowDetails, null); buttonShowDetails.setToolTipText("Edit information for an existed Employee"); buttonShowDetails.setIcon(new ImageIcon(getToolkit().createImage( "images/EditEmployee3.gif"))); buttonShowDetails.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonShowDetails_actionPerformed(e); } }); group_Browse.add(buttonExit, null); buttonExit.setToolTipText("Exit program"); buttonExit.setIcon(new ImageIcon(getToolkit().createImage("images/Door.gif"))); buttonExit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonExit_actionPerformed(e); } });
//gBrowse_Box.add(group_Browse,BorderLayout.NORTH); //gBrowse_Box.add(Box.createHorizontalStrut(XSPACE)); group_Browse.add(Box.createHorizontalStrut(XSPACE)); /// SpringUtilities.makeCompactGrid(group_Browse, 1, group_Browse.getComponentCount(), 6, 6, 6, 6);
return group_Browse; } //===================================================== // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!function /* Create Pane for FastFind components */ private JPanel MyPaneFastFind() { buttonFind = new JButton(); buttonCancel = new JButton(); buttonQuery = new JButton(); group_FastFind = new JPanel(); //-----------<-------------Fast Find box //group_FastFind.setLayout(new GridLayout(1,5)); // DONE group_FastFind.setLayout(new SpringLayout()); // DONE group_FastFind.setBorder(new TitledBorder(new EtchedBorder()," Fast Find Filter ")); //group_FastFind.setMinimumSize(new Dimension (1000,400)); //============================================================================= JPanel box_for_Text_RBs = new JPanel(); //-----------<------------- this box is for Text input window and radiobuttons box_for_Text_RBs.setLayout(new GridLayout(2, 1));
textFind = new JTextField(100); textFind.setFont(new Font("Arial", Font.BOLD, 20)); textFind.setForeground(Color.blue); textFind.setMaximumSize(new Dimension(100, 24));
buttonFind.setToolTipText("Search information by the request"); buttonFind.setIcon(new ImageIcon(getToolkit().createImage( "images/Search.gif"))); buttonFind.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonFind_actionPerformed(e); } });
buttonCancel.setToolTipText("Search information by the request"); buttonCancel.setIcon(new ImageIcon(getToolkit().createImage( "images/delete.gif"))); buttonCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonCancel_actionPerformed(e); } });
JRadioButton rb_LastName = new JRadioButton("LastName"); JRadioButton rb_FirstName = new JRadioButton("FirstName"); //============================================= ButtonGroup surname_filter = new ButtonGroup(); surname_filter.add(rb_LastName); surname_filter.add(rb_FirstName); rb_LastName.setSelected(true); //============================================= JPanel buttongroup_Box = new JPanel(); buttongroup_Box.setLayout(new GridLayout(1, 2)); buttongroup_Box.add(rb_LastName); buttongroup_Box.add(rb_FirstName); box_for_Text_RBs.add(textFind); box_for_Text_RBs.add(buttongroup_Box); box_for_Text_RBs.setMaximumSize(new Dimension(30, 30)); group_FastFind.add(box_for_Text_RBs); group_FastFind.add(Box.createHorizontalStrut(XSPACE)); group_FastFind.add(buttonFind); group_FastFind.add(buttonCancel); group_FastFind.add(Box.createHorizontalStrut(XSPACE)); /// SpringUtilities.makeCompactGrid(group_FastFind, 1, group_FastFind.getComponentCount(), 6, 6, 6, 6); return group_FastFind; } //============================== /* Create Tabbed Pane for Filters trees */ private JTabbedPane MyLeftTabbedPane() { o_toolBar = new JToolBar(); s_toolBar = new JToolBar(); l_toolBar = new JToolBar();
buttonExpandTree = new JButton(); buttonSwapTree = new JButton(); buttonApplyOffice = new JButton(); buttonApplyService = new JButton(); buttonApplyLang = new JButton(); textFind = new JTextField(); tb_Filters = new JTabbedPane(); //<---------------------------------------------------------- Tabbed Pane FILTERS //Create the HTML viewing pane. htmlPane = new JEditorPane(); htmlPane.setEditable(false); htmlView = new JScrollPane(htmlPane); o_splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); o_splitPane.setTopComponent(o_treeView); o_splitPane.setBottomComponent(htmlView); //Create the toolbar. //addButtons(o_toolBar); o_toolBar.add(buttonExpandTree, null); buttonExpandTree.setToolTipText("Search information by the request"); buttonExpandTree.setIcon(new ImageIcon(getToolkit().createImage("images/tree_expand.gif"))); buttonExpandTree.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonQuery_actionPerformed(e); } });
o_toolBar.add(buttonSwapTree, null); buttonSwapTree.setToolTipText("Search information by the request"); buttonSwapTree.setIcon(new ImageIcon(getToolkit().createImage( "images/tree_swap.gif"))); buttonSwapTree.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonQuery_actionPerformed(e); } });
//fourth button o_toolBar.add(Box.createHorizontalStrut(4)); l_findoffice = new JLabel("find"); o_toolBar.add(l_findoffice); o_toolBar.add(Box.createHorizontalStrut(XSPACE)); //fifth component is NOT a button! JTextField o_textField = new JTextField(""); o_textField.setColumns(10); o_textField.setMaximumSize(new Dimension(60, 24)); //textField.addActionListener(this); o_textField.setActionCommand(TEXT_ENTERED);
o_toolBar.add(o_textField); o_toolBar.add(Box.createHorizontalStrut(XSPACE));
o_toolBar.add(buttonApplyOffice, null); buttonApplyOffice.setToolTipText("Apply this filter to Employees table"); buttonApplyOffice.setText("Apply filter"); // buttonApplyOffice.setIcon(new ImageIcon(getToolkit().createImage( "images/tree_swap.gif"))); buttonApplyOffice.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) { /// buttonApplyOffice_actionPerformed(e); RefreshTable(); } }); o_toolBar.setFloatable(false); o_toolBar.setRollover(true); //================== OFFICES ===================== tab_offices = new JPanel(); //tab_offices.setLayout(new GridLayout(2,0)); tab_offices.setLayout(new BorderLayout()); // tb_Filters.addTab("Offices", icon1, tab_offices,"Does nothing"); tab_offices.add(o_toolBar, BorderLayout.PAGE_START); tab_offices.add(o_splitPane, BorderLayout.CENTER); tb_Filters.addTab("Offices", null, tab_offices, "Offices info tree"); tb_Filters.setMnemonicAt(0, KeyEvent.VK_O);
//================== F I L T E R S by date.etc..... tab_advFilters = new JPanel(); //makeTextPanel(""); //tb_Filters.addTab("Languages", icon3, p_Languages, "Still does nothing"); tab_advFilters.setLayout(new BorderLayout()); tb_Filters.addTab("Advanced filters", null, tab_advFilters, "Date, position, etc."); tb_Filters.setMnemonicAt(1, KeyEvent.VK_A);
//================== SERVICES ========================= // ImageIcon icon2 = createImageIcon("images/Services.gif"); tab_services = new JPanel(); //makeTextPanel(""); tab_services.setLayout(new BorderLayout()); // tb_Filters.addTab("Services", icon2, p_Services, "Does twice as much nothing"); tb_Filters.addTab("Services", null, tab_services, "Services info tree"); tb_Filters.setMnemonicAt(2, KeyEvent.VK_S);
s_toolBar.add(buttonApplyService, null); buttonApplyService.setToolTipText("Apply this filter to Employees table"); buttonApplyService.setText("Apply filter"); // buttonApplyOffice.setIcon(new ImageIcon(getToolkit().createImage( "images/tree_swap.gif"))); buttonApplyService.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonApplyService_actionPerformed(e); } });
s_toolBar.setFloatable(false); s_toolBar.setRollover(true);
tab_services.add(s_toolBar, BorderLayout.PAGE_START);
//================== LANGUAGES==================== // ImageIcon icon3 = createImageIcon("images/Languages2.gif"); tab_lang = new JPanel(); //makeTextPanel(""); tab_lang.setLayout(new BorderLayout()); //tb_Filters.addTab("Languages", icon3, p_Languages, "Still does nothing"); tb_Filters.addTab("Languages", null, tab_lang, "Languages info tree"); tb_Filters.setMnemonicAt(3, KeyEvent.VK_L); l_toolBar.add(buttonApplyLang, null); buttonApplyLang.setToolTipText("Apply this filter to Employees table"); buttonApplyLang.setText("Apply filter"); // buttonApplyOffice.setIcon(new ImageIcon(getToolkit().createImage( "images/tree_swap.gif"))); buttonApplyLang.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { buttonApplyLang_actionPerformed(e); } });
l_toolBar.setFloatable(false); l_toolBar.setRollover(true);
tab_lang.add(l_toolBar, BorderLayout.PAGE_START); //================================================= PopulateFilterTrees(); return tb_Filters; }
private void buttonApplyLang_actionPerformed(ActionEvent e) { }
private void buttonApplyService_actionPerformed(ActionEvent e) { }
private void buttonApplyOffice_actionPerformed(ActionEvent e) { }
public class OfficeInfo { int Id_Office; String OfficeName; int DepartmentCode; String Department_Name; String NodeText;
public OfficeInfo(int id_office, String officename, int id_dept, String department, String node_text) { Id_Office = id_office; OfficeName = officename; DepartmentCode= id_dept; Department_Name = department; NodeText = node_text; }
public String toString() { return NodeText;
} } //================================================== private void PopulateFilterTrees() { int i = 0; int j = 1; int myO,myS,myL;
//======================================== o_data = DB.ExecQuery_OfficesTree(); DefaultMutableTreeNode top = new DefaultMutableTreeNode(); DefaultMutableTreeNode office = null; DefaultMutableTreeNode dept = null;
top = new DefaultMutableTreeNode("Company Structure");
office = new DefaultMutableTreeNode((String) o_data[i][1]); top.add(office);
myO = Integer.parseInt( (String) o_data[i][0]); // Integer.parseInt(activeStatus)); for (i =0; i < o_data.length-1; i++ ) { if (myO != Integer.parseInt( (String) o_data[i][0])) { //office = new DefaultMutableTreeNode((String) o_data[i][1]); office = new DefaultMutableTreeNode(new OfficeInfo (Integer.parseInt( (String) o_data[i][0]), (String) o_data[i][1], Integer.parseInt( (String) o_data[i][2]),(String) o_data[i][3],(String) o_data[i][1])); top.add(office); myO = Integer.parseInt((String) o_data[i][0]); // remember NEW office for matching } //dept = new DefaultMutableTreeNode((String) o_data[i][3]); dept = new DefaultMutableTreeNode(new OfficeInfo (Integer.parseInt( (String) o_data[i][0]), (String) o_data[i][1], Integer.parseInt( (String) o_data[i][2]),(String) o_data[i][3],(String) o_data[i][3])); office.add(dept); }
o_tree = new JTree(top); o_treeView = new JScrollPane(o_tree); o_tree.getSelectionModel().setSelectionMode (TreeSelectionModel.SINGLE_TREE_SELECTION);
o_tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged (TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) o_tree.getLastSelectedPathComponent();
if (node == null) return;
Object nodeInfo = node.getUserObject(); OfficeInfo office = (OfficeInfo) nodeInfo;
//if (node.isNodeChild(top) if (node.isLeaf()) { //System.out.println(" department code="+ office.DepartmentCode); System.out.println("Office ="+office.Id_Office+" department code="+ office.DepartmentCode);
myOffice = String.valueOf(office.Id_Office); myDept = String.valueOf(office.DepartmentCode); //System.out.println("Office ="+office.Id_Office+" department code="+ office.DepartmentCode); } else { myOffice = String.valueOf(office.Id_Office); myDept = "-1"; {System.out.println("Just an office code"+office.Id_Office);} } } });
//Dimension minimumSize = new Dimension(100, 50); o_treeView.setMinimumSize(new Dimension(100, 200)); o_treeView.setMaximumSize(new Dimension(100, 500)); o_treeView.repaint(); o_splitPane.setTopComponent(o_treeView); o_splitPane.repaint();
//======================================== i=0; s_data = DB.ExecQuery_ServicesTree(); DefaultMutableTreeNode s_top = new DefaultMutableTreeNode(); DefaultMutableTreeNode service = null; //DefaultMutableTreeNode dept = null;
s_top = new DefaultMutableTreeNode("All Services");
service = new DefaultMutableTreeNode((String) s_data[i][1]); s_top.add(service);
//myOffice = (String) data[i][1]; myS = Integer.parseInt( (String) s_data[i][0]); // Integer.parseInt(activeStatus)); for (i =0; i < s_data.length-1; i++ ) { if (myS != Integer.parseInt( (String) s_data[i][0])) { service = new DefaultMutableTreeNode((String) s_data[i][1]); s_top.add(service); myS = Integer.parseInt((String) s_data[i][0]); // remember NEW office for matching } } s_tree = new JTree(s_top); s_treeView = new JScrollPane(s_tree); //Dimension minSize = new Dimension(100, 50); s_treeView.setMinimumSize(new Dimension(100, 200)); s_treeView.setMaximumSize(new Dimension(100, 500)); s_treeView.repaint();
tab_services.add(s_treeView); tab_services.repaint();
//======================================== i=0; l_data = DB.ExecQuery_LangTree(); DefaultMutableTreeNode l_top = new DefaultMutableTreeNode(); DefaultMutableTreeNode lang = null; //DefaultMutableTreeNode dept = null;
l_top = new DefaultMutableTreeNode("All Languages");
lang = new DefaultMutableTreeNode((String) l_data[i][1]); l_top.add(lang);
//myOffice = (String) data[i][1]; myL = Integer.parseInt( (String) l_data[i][0]); // Integer.parseInt(activeStatus)); for (i =0; i < l_data.length-1; i++ ) { if (myL != Integer.parseInt( (String) l_data[i][0])) { lang = new DefaultMutableTreeNode((String) l_data[i][1]); l_top.add(lang); myL = Integer.parseInt((String) l_data[i][0]); // remember NEW office for matching } } l_tree = new JTree(l_top); l_treeView = new JScrollPane(l_tree); //Dimension minSize = new Dimension(100, 50); l_treeView.setMinimumSize(new Dimension(100, 200)); l_treeView.setMaximumSize(new Dimension(100, 500)); l_treeView.repaint();
tab_lang.add(l_treeView); tab_lang.repaint();
} //========================================= Creating RIGHT split-pane private JSplitPane MyMainSplitPane() { // JScrollPane scrollPane = new JScrollPane(tableEmploy
--------------------
Хотите поговорить об этом?
|
|
|
|
Правила форума "Java" |
|
- Прежде, чем задать вопрос, прочтите это!
- Книги по Java собираются здесь.
- Документация и ресурсы по Java находятся здесь.
- Используйте теги [code=java][/code] для подсветки
кода. Используйтe чекбокс "транслит", если у Вас
нет русских шрифтов.
- Помечайте свой вопрос как решённый, если на него получен ответ. Ссылка "Пометить как решённый" находится над первым постом.
- Действия модераторов можно обсудить здесь.
- FAQ раздела лежит здесь.
Если Вам помогли, и атмосфера форума Вам понравилась, то заходите
к нам чаще! С уважением,
LSD,
AntonSaburov,
powerOn,
jk1.
|
1 Пользователей читают эту тему (1 Гостей и 0 Скрытых Пользователей)
|
0 Пользователей:
|
« Предыдущая тема | Java: GUI и Java FX приложения | Следующая тема »
|
|
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности
Powered by Invision Power Board(R) 1.3 © 2003 IPS, Inc. |
|
|