?? contactsearchwindow.java
字號:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * CallViewPanel.java * * Created on 27 March 2003, 00:11 */package crms.applet.company;import javax.swing.*;import javax.swing.border.*;import java.awt.*;import java.awt.event.*;import javax.swing.table.*;import javax.swing.event.*;import java.util.*;import crms.vo.*;import crms.module.*;import crms.util.*;import crms.ui.*;import java.text.*;import org.w3c.dom.*;import java.net.*;import java.applet.*;/** * * @author dmurphy */public class ContactSearchWindow extends CRMSWindow implements CallbackDestination { JPanel main = new JPanel(); ContactDataListModel listModel = new ContactDataListModel(); JList viewContactList = new JList(listModel); JScrollPane scrollPane = new JScrollPane(viewContactList); JLabel headingLabel = new JLabel(); public static SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); public static SimpleDateFormat tf = new SimpleDateFormat("h:mm a"); JTextField textFirstName = new JTextField(); JTextField textLastName = new JTextField(); JTextField textCompany = new JTextField(); //int companyID = -1; Company company = null; /** Creates a new instance of CallSearchWindow * capable to filter on company id * * @param companyID */ public ContactSearchWindow() { } public void setCompany(Company company) { this.company = company; textCompany.setText(company.getCompanyName()); } public void setFirstName(String firstname) { textFirstName.setText(firstname); } public void setLastName(String lastname) { textLastName.setText(lastname); } public void init() { final Object thisobj = this; Container pane = getContentPane(); pane.setLayout(new BorderLayout()); pane.setBackground(Color.WHITE); //viewContactList.setAutoCreateColumnsFromModel(true); viewContactList.setBackground(Color.WHITE); viewContactList.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent ev) { if (ev.getClickCount() == 2) { processContactSelected(); } } }); CRMSButtonBar searchButtons = new CRMSButtonBar(); JButton buttonSearch = new JButton("Search"); buttonSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { searchContacts(); } } ); textCompany.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent k) { company = null; } } ); searchButtons.addButton(CRMSButtonBar.RIGHT, buttonSearch); JPanel searchFields = new JPanel(new GridBagLayout()); Insets defaultInsets = new Insets(4,0,0,4); searchFields.setBackground(Color.WHITE); searchFields.add(new JLabel("First Name"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, defaultInsets, 0, 0)); searchFields.add(textFirstName, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); searchFields.add(new JLabel("Last Name"), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, defaultInsets, 0, 0)); searchFields.add(textLastName, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); searchFields.add(new JLabel("Company"), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, defaultInsets, 0, 0)); searchFields.add(textCompany, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); searchFields.add(searchButtons, new GridBagConstraints(0, 3, 2, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); scrollPane.getViewport().setBackground(Color.WHITE); main.setLayout(new BorderLayout()); main.setBackground(Color.WHITE); main.setBorder(new EmptyBorder(4,4,4,4)); main.add(searchFields, BorderLayout.NORTH); main.add(scrollPane, BorderLayout.CENTER); CRMSButtonBar controlPanel = new CRMSButtonBar(); controlPanel.setBackground(Color.WHITE); JButton closeButton = new JButton("Close"); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { dispose(); } } ); JButton editButton = new JButton("Edit"); editButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { processContactSelected(); } } ); JButton addButton = new JButton("Add"); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { ContactEditWindow window = new ContactEditWindow(); window.setCallback((CallbackDestination)thisobj); if (company != null) window.setCompany(company); else window.setCompany(textCompany.getText()); window.display(); } } ); JButton exportButton = new JButton("Export"); exportButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { doDownload(); } }); controlPanel.addButton(CRMSButtonBar.LEFT, addButton); controlPanel.addButton(CRMSButtonBar.RIGHT, editButton); controlPanel.addButton(CRMSButtonBar.RIGHT, exportButton); controlPanel.addButton(CRMSButtonBar.RIGHT, closeButton); pane.add(main, BorderLayout.CENTER); pane.add(controlPanel, BorderLayout.SOUTH); } /* public void refreshData() { Server server = ServerFactory.getInstance().getServer(); ServerCommand command = new ServerCommand(ContactModule.CONTACT_SHOW); //lubo: check if we are going to filter on company id if (companyID > 0) { command.setParameter(ContactModule.PARAM_CONTACT_COMPANY_ID, new Integer(companyID)); } ServerResponse response = server.sendCommand(command); ArrayList result = (ArrayList) response.getPart("contacts"); listModel.clear(); for (int i=0; i < result.size(); i++) { Contact contact = (Contact) result.get(i); listModel.addContact(contact); } viewContactList.setModel(listModel); }*/ public void processContactSelected() { int selected = viewContactList.getSelectedIndex(); if (selected < 0) { JOptionPane.showMessageDialog(this, "Please select a contact to edit.", "Contact List", JOptionPane.WARNING_MESSAGE); return; } Contact contact = (Contact) listModel.get(selected); ContactEditWindow window = new ContactEditWindow(); window.setContact(contact); window.display(); } protected class ContactDataListModel extends DefaultListModel { ArrayList listeners = new ArrayList(); ArrayList contacts = new ArrayList(); String headings[] = { "First Name", "Last Name", "Company" }; public void setValueAt(Object aValue, int rowIndex, int columnIndex) { // Read Only } public void removeTableModelListener(TableModelListener l) { listeners.remove(l); } public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } public Object getValueAt(int rowIndex, int columnIndex) { Contact contact = (Contact) contacts.get(rowIndex); switch(columnIndex) { case 0: return contact.getFirstName(); case 1: return contact.getLastName(); case 2: return contact.getCompanyName(); default: //Nasty } return null; } public int getRowCount() { return contacts.size(); } public String getColumnName(int columnIndex) { return headings[columnIndex]; } public int getColumnCount() { return headings.length; } public Class getColumnClass(int columnIndex) { return java.lang.String.class; } public void addTableModelListener(TableModelListener l) { listeners.add(l); } public void addContact(Contact contact) { contacts.add(contact); } public void clear() { contacts= new ArrayList(); } /*public Contact get(int i) { return (Contact) contacts.get(i); }*/ } public void searchContacts() { Server server = ServerFactory.getInstance().getServer(); ServerCommand command = new ServerCommand(ContactModule.CONTACT_SEARCH_SUBMIT); command.setParameter(ContactModule.PARAM_CONTACT_COMPANY, textCompany.getText()); command.setParameter(ContactModule.PARAM_CONTACT_FIRST_NAME, textFirstName.getText()); command.setParameter(ContactModule.PARAM_CONTACT_LAST_NAME, textLastName.getText()); ServerResponse sr = server.sendCommand(command); setContacts((ArrayList)sr.getPart("contacts")); } public void setContacts(ArrayList contacts) { listModel.removeAllElements(); if (contacts == null || contacts.size() == 0) { listModel.addElement("Search returned no results."); viewContactList.setEnabled(false); } else { viewContactList.setEnabled(true); for (int i=0; i < contacts.size(); i++) { Contact c = (Contact) contacts.get(i); listModel.addElement(c); } } } public void callback(Object source, int mode, Object data) { //if (source instanceof ContactEditWindow) { searchContacts(); //} } public void doDownload() { crms.applet.PanelManager manager = crms.applet.PanelManager.getInstance(); AppletContext context = manager.getAppletContext(); if (context == null) { JOptionPane.showMessageDialog(this, "This function requires the system to be running in an applet context.", "Expore List", JOptionPane.ERROR_MESSAGE); return; } URL url = manager.getCodeBase(); URL toURL = null; FileAttachment attach = new FileAttachment(); try { StringBuffer urlString = new StringBuffer(); urlString.append("http://"); urlString.append(url.getHost()); urlString.append(":"); urlString.append(url.getPort()); urlString.append("/crms/export"); urlString.append("?user=" + ServerFactory.getInstance().getUser()); urlString.append("&type=" + EntityType.CONTACT_EXPORT.getCode()); urlString.append("&f=" + textFirstName.getText()); urlString.append("&l=" + textLastName.getText()); urlString.append("&c=" + textCompany.getText()); /*if (company != null && company.getCompanyID() > 0) { urlString.append("&compid="); urlString.append(company.getCompanyID()); }*/ toURL = new URL(urlString.toString()); } catch (MalformedURLException ex) { ex.printStackTrace(); } context.showDocument(toURL); } public void display() { init(); setSize(500,400); center(); setTitle("Contact Search"); setVisible(true); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -