📄 staffmembersearchpanel.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;import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.swing.border.*;import javax.swing.event.*;import java.awt.event.*;import java.util.*;import crms.vo.*;import crms.module.*;import crms.util.*;import crms.ui.*;import java.text.*;import java.beans.*;import java.io.*;import java.text.*;/** Display panel for searching the staff database. * * @author dmurphy */public class StaffMemberSearchPanel extends CRMSPanel { JPanel titlePanel = new JPanel(); CRMSPanel bodyPanel = CRMSPanel.getEmptyPanel(); JLabel headingLabel = new JLabel(); public static SimpleDateFormat df = new SimpleDateFormat("EEEE, d MMMM, yyyy"); public static SimpleDateFormat tf = new SimpleDateFormat("h:mm a"); JButton buttonSearch = new JButton("Search"); JButton buttonReset = new JButton("Clear"); JButton buttonCancel = new JButton("Close"); JButton btnSelect = new JButton("Select"); JButton btnView = new JButton("View"); DefaultComboBoxModel departmentModel = new DefaultComboBoxModel(); JComboBox departmentCombo = new JComboBox(departmentModel); DefaultComboBoxModel locationModel = new DefaultComboBoxModel(); JComboBox locationCombo = new JComboBox(locationModel); JTextField textLastName = new JTextField(); JTextField textFirstName = new JTextField(); DefaultListModel resultsModel = new DefaultListModel(); JList resultsList = new JList(resultsModel); JScrollPane resultsScrollPane = new JScrollPane(resultsList); boolean preSearch = false; String preFirstName = ""; String preLastName = ""; public static String SOURCE_FORM_CALLS = "calls"; public static String SOURCE_FORM_REMINDERS = "reminders"; CRMSPanel defaultPanel = null; CRMSPanel cancelPanel = null; CallbackDestination destination = null; public static final int CLOSE_WINDOW = 0; public static final int STAFF_SELECTED = 1; /** Creates a new instance of CallViewPanel */ public StaffMemberSearchPanel(String title) { headingLabel.setText(title); } public StaffMemberSearchPanel(String title, CRMSPanel defaultPanel,CRMSPanel cancelPanel, String criteria) { headingLabel.setText(title); this.defaultPanel = defaultPanel; this.cancelPanel = cancelPanel; setCriteria(criteria); } public void setDestination(CallbackDestination new_destination) { destination = new_destination; btnSelect.setVisible(true); } public void setCriteria(String criteria) { System.out.println("StaffMemberSearchPanel - " + criteria); // These criteria are passed in before displaying the // form, they'll be interpreted as either "LastName, FirstName" // or "FirstName LastName" if (criteria == null || criteria.trim().length() == 0) { return; } preSearch = true; StringTokenizer tok = new StringTokenizer(criteria, ", ", false); ArrayList tokens = new ArrayList(); boolean haveComma = (criteria.indexOf(",") > -1); while (tok.hasMoreTokens()) { String token = tok.nextToken(); if (token.equals(",")) { haveComma = true; } else if (!token.equals(" ")) { tokens.add(token); } } if (haveComma || tokens.size()==1) { preLastName = (String) tokens.get(0); for (int i=1; i < tokens.size(); i++) { preFirstName = preFirstName + " " + (String) tokens.get(i); } } else { for (int i=0; i < tokens.size()-1; i++) { preFirstName = preFirstName + " " + (String) tokens.get(i); } preLastName = (String) tokens.get(tokens.size()-1); } preFirstName = preFirstName.trim(); preLastName = preLastName.trim(); textFirstName.setText(preFirstName); textLastName.setText(preLastName); } public void processStaffMemberSelect() { if (destination != null) { int index = resultsList.getSelectedIndex(); if (index >= 0) { destination.callback(this, STAFF_SELECTED, resultsModel.getElementAt(index)); } } } public void processStaffMemberView() { int index = resultsList.getSelectedIndex(); if (index >= 0) { StaffMemberWindow window = new StaffMemberWindow(); window.setStaffMember((StaffMember)resultsModel.getElementAt(index)); window.display(); } } public void init() { final Object thisobj = this; setLayout(new BorderLayout()); setBackground(Color.WHITE); headingLabel.setFont(new java.awt.Font("Serif", 1, 18)); headingLabel.setBackground(Color.WHITE); titlePanel.add(headingLabel); titlePanel.setBackground(Color.WHITE); add(titlePanel, BorderLayout.NORTH); resultsScrollPane.setBackground(Color.WHITE); EtchedBorder etched = new EtchedBorder(EtchedBorder.LOWERED); TitledBorder insideBorder = new TitledBorder( etched, "Search Results"); EmptyBorder outsideBorder = new EmptyBorder(5,5,5,5); resultsScrollPane.setBorder(new CompoundBorder(outsideBorder,insideBorder)); buttonSearch.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { searchStaff(); } }); buttonReset.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { refreshData(); } }); buttonCancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { if (destination != null) { destination.callback(thisobj, CLOSE_WINDOW, null); } else { PanelManager.getInstance().activatePanel(cancelPanel); } } }); btnView.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { processStaffMemberView(); } } ); btnSelect.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { processStaffMemberSelect(); } } ); resultsList.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent ev) { if (ev.getClickCount() == 2) { processStaffMemberSelect(); // depreciated if (defaultPanel != null && defaultPanel instanceof StaffMemberSearcher) { ((StaffMemberSearcher)defaultPanel).setStaffMemberFound((StaffMember)resultsModel.getElementAt(resultsList.getSelectedIndex())); PanelManager.getInstance().activatePanel(defaultPanel); } } } }); bodyPanel.setLayout(new GridBagLayout()); bodyPanel.setBackground(Color.WHITE); bodyPanel.setBorder(new EmptyBorder(10,10,10,10)); Insets defaultInsets = new Insets(8,10,0,0); bodyPanel.add(new JLabel("Division"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, defaultInsets, 0, 0)); bodyPanel.add(departmentCombo, new GridBagConstraints(1, 0, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); bodyPanel.add(new JLabel("Location"), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, defaultInsets, 0, 0)); bodyPanel.add(locationCombo, new GridBagConstraints(1, 1, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); bodyPanel.add(new JLabel("Last Name"), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, defaultInsets, 0, 0)); bodyPanel.add(textLastName, new GridBagConstraints(1, 2, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); bodyPanel.add(new JLabel("First Name"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, defaultInsets, 0, 0)); bodyPanel.add(textFirstName, new GridBagConstraints(1, 3, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0)); JPanel wrapperPanel = new JPanel(new BorderLayout()); wrapperPanel.setBackground(Color.WHITE); wrapperPanel.add(bodyPanel, BorderLayout.NORTH); wrapperPanel.add(resultsScrollPane, BorderLayout.CENTER); btnSelect.setVisible(false); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.setBackground(Color.WHITE); buttonPanel.add(btnSelect); buttonPanel.add(btnView); buttonPanel.add(buttonSearch); buttonPanel.add(buttonReset); buttonPanel.add(buttonCancel); add(wrapperPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); //setCurrentPanel(bodyPanel); refreshData(); if (preSearch) { searchStaff(); // if (resultsModel.size() == 1) {// if (resultsModel.getElementAt(0) instanceof StaffMember) {// ((StaffMemberSearcher)defaultPanel).setStaffMemberFound((StaffMember)resultsModel.getElementAt(0));// PanelManager.getInstance().activatePanel(defaultPanel);// }// } } } public void refreshData() { Server server = ServerFactory.getInstance().getServer(); ServerCommand command = new ServerCommand(StaffModule.STAFF_SEARCH_FORM); ServerResponse sr = server.sendCommand(command); ArrayList departments = (ArrayList) sr.getPart("departments"); departmentModel.removeAllElements(); for (int i=0; i < departments.size(); i++) { departmentModel.addElement((Department)departments.get(i)); } ArrayList locations = (ArrayList) sr.getPart("locations"); locationModel.removeAllElements(); for (int i=0; i < locations.size(); i++) { locationModel.addElement((Site)locations.get(i)); } resultsModel.removeAllElements(); resultsList.invalidate(); textFirstName.setText(""); textLastName.setText(""); } public void searchStaff() { Server server = ServerFactory.getInstance().getServer(); ServerCommand command = new ServerCommand(StaffModule.STAFF_SEARCH_SUBMIT); command.setParameter(StaffModule.PARAM_STAFF_FIRSTNAME, textFirstName.getText()); command.setParameter(StaffModule.PARAM_STAFF_LASTNAME, textLastName.getText()); if (departmentCombo.getSelectedIndex() > 0) { Department dept = (Department) departmentModel.getSelectedItem(); command.setParameter(StaffModule.PARAM_STAFF_DEPARTMENT, dept.getName()); } if (locationCombo.getSelectedIndex() > 0) { Site site = (Site) locationModel.getSelectedItem(); command.setParameter(StaffModule.PARAM_STAFF_LOCATION, site.getSiteCode()); } ServerResponse sr = server.sendCommand(command); ArrayList staff = (ArrayList) sr.getPart("staff"); if (staff == null || staff.size() == 0) { resultsModel.clear(); resultsModel.addElement("Search returned no results."); resultsList.setEnabled(false); return; } else { resultsList.setEnabled(true); } resultsModel.removeAllElements(); for (int i=0; i < staff.size(); i++) { StaffMember sm = (StaffMember) staff.get(i); resultsModel.addElement(sm); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -