📄 callviewpanel.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.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.beans.*;import java.io.*;import javax.swing.border.*;import java.applet.*;import java.net.*;/** The panel that displays a list of calls for the user. It is designed to be extensible, * allowing for displaying both limited (smaller) list for the HomePanel and the full extended * list. */public class CallViewPanel extends CRMSPanel implements CallbackDestination { JPanel titlePanel = new JPanel(); CRMSButtonBar buttonBar = new CRMSButtonBar(); CRMSPanel bodyPanel = CRMSPanel.getEmptyPanel(); int companyID = -1; JLabel lblMessage = new JLabel("Loading message details..."); CallDataTableModel tableModel = new CallDataTableModel(); //TableSorter sorter = new TableSorter(tableModel); JTable viewCallsTable = new JTable(tableModel) { public TableCellRenderer getCellRenderer(int row, int column) { final Call call = tableModel.getCall(row); return new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component parent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,column); if (!call.getOwnerHasRead()) { parent.setFont(parent.getFont().deriveFont(Font.BOLD)); } return parent; } }; } }; JScrollPane scrollPane = new JScrollPane(viewCallsTable); JLabel headingLabel = new JLabel(); public static SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); public static SimpleDateFormat tf = new SimpleDateFormat("h:mm a"); /** Creates a new instance of CallViewPanel */ boolean restrictCallCount = false; private ArrayList searchResults = null; public CallViewPanel() { } public CallViewPanel(int companyID ) { this.companyID = companyID; } public CallViewPanel(boolean restrictCallCount) { this.restrictCallCount = restrictCallCount; } public CallViewPanel(java.util.List searchResults) { this.searchResults = (ArrayList) searchResults; } public void init() { final CallbackDestination thisobj = this; setLayout(new BorderLayout()); setBackground(Color.WHITE); // put in an entry lblMessage.setForeground(Color.GRAY); lblMessage.setForeground(Color.GRAY); lblMessage.setVerticalAlignment(JLabel.TOP); lblMessage.setHorizontalAlignment(JLabel.CENTER); // setup automatic refresh java.util.Timer timer = new java.util.Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { refreshData(); } }, 100, 1000 * 60 * 15); headingLabel.setFont(new java.awt.Font("Serif", 1, 18)); if (searchResults == null) { headingLabel.setText("Messages"); } else { headingLabel.setText("Message Search Results"); } headingLabel.setBackground(Color.WHITE); headingLabel.setHorizontalAlignment(JLabel.CENTER); titlePanel.setLayout(new BorderLayout()); titlePanel.add(headingLabel, BorderLayout.CENTER); titlePanel.setBackground(Color.WHITE); add(titlePanel, BorderLayout.NORTH); viewCallsTable.setAutoCreateColumnsFromModel(true); viewCallsTable.setBackground(Color.WHITE); // replace the headings with icons TableCellRenderer rend = new DefaultTableCellRenderer() { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { String file = null; String tip = null; if (value == "U") { file = "urgent"; tip = "Message has been marked URGENT"; } else if (value == "W") { file = "willcall"; tip = "Message indicates the caller will return the call"; } else if (value == "C") { file = "pleasecall"; tip = "Please call the person back"; } else { return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } URL url = getClass().getResource("/images/" + file + ".png"); ImageIcon icon = new ImageIcon(url); JLabel label = new JLabel(icon); label.setToolTipText(tip); //Border b = new BevelBorder(BevelBorder.RAISED); //label.setBorder(b); return label; } }; TableColumn col = null; for (int i = 0; i <= 7; i++) { col = viewCallsTable.getColumnModel().getColumn(i); if (i >= 5) { col.setHeaderRenderer(rend); col.setPreferredWidth(30); col.setMinWidth(30); col.setMaxWidth(30); } else if (i == 4) { col.setMinWidth(270); } else if (i == 2) { col.setMinWidth(120); } } scrollPane.getViewport().setBackground(Color.WHITE); viewCallsTable.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent ev) { if (ev.getClickCount() == 2) { processCallSelected(); } } }); bodyPanel.setLayout(new BorderLayout()); bodyPanel.setBackground(Color.WHITE); // this happens on refreshdata bodyPanel.add(scrollPane, BorderLayout.CENTER); bodyPanel.add(lblMessage, BorderLayout.CENTER); bodyPanel.setBorder(new EmptyBorder(0,10,0,10)); // prepare the button panel buttonBar.setBackground(Color.WHITE); //if (!restrictCallCount) { if (true) { /* JButton backButton = new JButton("Back"); backButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (companyID >= 0) { PanelManager.getInstance().activatePanel(new CompanyEditPanel(PANEL_TYPE_EDIT, companyID)); } else { PanelManager.getInstance().activatePanel(new HomePanel()); } } } ); */ JButton buttonLog = new JButton("Log"); buttonLog.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //CallEditPanel panel = new CallEditPanel(); //PanelManager.getInstance().activatePanel(panel); MessageEditWindow window = new MessageEditWindow(); window.setDestination(thisobj); window.display(); } } ); JButton buttonSearch = new JButton("Search"); buttonSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CallSearchPanel panel = new CallSearchPanel(); PanelManager.getInstance().activatePanel(panel); } } ); /*JButton editButton = new JButton("Edit"); editButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { processCallSelected(); } } );*/ JButton exportButton = new JButton("Export"); exportButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { processExport(); } } ); buttonBar.addButton(CRMSButtonBar.RIGHT, buttonLog); //buttonBar.addButton(CRMSButtonBar.RIGHT, editButton); //buttonBar.addButton(CRMSButtonBar.RIGHT, buttonSearch); buttonBar.addButton(CRMSButtonBar.RIGHT, exportButton); } add(bodyPanel, BorderLayout.CENTER); add(buttonBar, BorderLayout.SOUTH); //setCurrentPanel(bodyPanel); } public CRMSButtonBar getButtonBar() { return buttonBar; } public void updateList() { if (lblMessage != null) { bodyPanel.remove(lblMessage); lblMessage = null; bodyPanel.add(scrollPane, BorderLayout.CENTER); bodyPanel.revalidate(); } viewCallsTable.tableChanged(new TableModelEvent(tableModel)); } public void processCallSelected() { int selected = viewCallsTable.getSelectedRow(); if (selected < 0) { JOptionPane.showMessageDialog(this, "Please select a message to edit.", "Message List", JOptionPane.WARNING_MESSAGE); return; } // get the call and mark as read Call call = tableModel.getCall(selected); call.setOwnerHasRead(true); updateList(); // create and display the view window MessageEditWindow window = new MessageEditWindow(); window.setDestination(this); window.setMessage(call); window.display(); } public void processExport() { PanelManager manager = 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.CALL_EXPORT.getCode()); if (companyID > 0) { urlString.append("&compid="); urlString.append(companyID); } toURL = new URL(urlString.toString()); } catch (MalformedURLException ex) { ex.printStackTrace(); } context.showDocument(toURL); } public void callback(Object source, int mode, Object data) { if (source instanceof MessageEditWindow) { if (mode == MessageEditWindow.MESSAGE_ADD) { java.util.List callList = tableModel.getCalls(); callList.add(0, (Call)data); tableModel.setCalls(callList); updateList(); } else if (mode == MessageEditWindow.MESSAGE_DELETE) { System.out.println("CallViewPanel -- DELETING Message " + source + " mode " + mode + " data " + data); java.util.List callList = tableModel.getCalls(); System.out.println("Call count: " + callList.size()); Iterator i = callList.iterator(); while (i.hasNext()) { Call call = (Call)i.next(); if (call.getCallID() == ((Integer)data).intValue()) { i.remove(); // remove this item break; } } tableModel.setCalls(callList); updateList(); } } } public void refreshData() { ArrayList callList = null; if (searchResults == null) { // Normal use of the screen, ask server for call list Server server = ServerFactory.getInstance().getServer(); ServerCommand command = new ServerCommand(CallModule.CALLS_SHOW); if (!restrictCallCount) { command.setParameter(CallModule.PARAM_CALL_SHOW_ALL, "true"); } if (companyID > 0) { command.setParameter(CallModule.PARAM_COMPANY_ID, new Integer(companyID)); } ServerResponse response = server.sendCommand(command); callList = (ArrayList)response.getPart("calls"); } else { callList = searchResults; } tableModel.clear(); if (callList.size() == 0) { lblMessage.setText("There are no messages for you."); return; } tableModel.setCalls(callList); viewCallsTable.setModel(tableModel); // swap to the table when ready updateList(); //CRMSUtil.resizeTable(viewCallsTable); } public Class getPanel(int i) { return null; } protected class CallDataTableModel implements TableModel { ArrayList listeners = new ArrayList(); ArrayList calls = new ArrayList(); ArrayList contacts = new ArrayList(); String headings[] = { "Date", //"Time", "Company", "From", "Number", "Message", "U", "W", "C", }; public void setCalls(java.util.List calls) { //System.out.println("Updating calls: before = " + this.calls.size()); this.calls = (ArrayList) calls; System.out.println("Updating calls: after = " + this.calls.size()); } public java.util.List getCalls() { return calls; } public void setContacts(java.util.List contacts) { this.contacts = (ArrayList) contacts; } 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) { Call call = (Call) calls.get(rowIndex); switch(columnIndex) { case 0: return df.format(call.getDate()) + " " + tf.format(call.getDate()); case 1: //return Integer.toString(call.getCompanyID()); Company company = call.getCompany(); if (company != null) return company.getCompanyName(); else return "Not Set"; case 2: return call.getFromFirstName() + " " + call.getFromLastName(); case 3: return call.getNumber(); case 4: return call.getNote(); case 5: return call.checkFlag(Call.CALL_FLAG_URGENT) ? "Y": ""; case 6: return call.checkFlag(Call.CALL_FLAG_CALLBACK) ? "Y" : ""; case 7: return call.checkFlag(Call.CALL_FLAG_PLEASECALL) ? "Y" : ""; default: //Nasty } return null; } public int getRowCount() { return calls.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 addCall(Call call) { calls.add(call); } public void clear() { calls = new ArrayList(); } public Call getCall(int i) { return (Call) calls.get(i); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -