📄 fileattachviewpanel.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 javax.swing.table.*;import java.util.*;import crms.vo.*;import crms.ui.*;import crms.module.*;import crms.util.*;import java.text.*;import java.beans.*;import java.io.*;import java.text.*;import java.applet.*;import java.net.*;/** * * @author dmurphy */public class FileAttachViewPanel extends CRMSPanel { JPanel titlePanel = new JPanel(); CRMSPanel bodyPanel = CRMSPanel.getEmptyPanel(); AttachmentTableModel tableModel = new AttachmentTableModel(); JTable attachTable = new JTable(tableModel); JScrollPane scrollPane = new JScrollPane(attachTable); JLabel headingLabel = new JLabel(); public static SimpleDateFormat df = new SimpleDateFormat("EEEE, d MMMM, yyyy"); public static SimpleDateFormat tf = new SimpleDateFormat("h:mm a"); JButton buttonAdd = new JButton("Attach File"); JButton buttonClose = new JButton("Close"); JButton buttonDownload = new JButton("Download"); JButton buttonDelete = new JButton("Delete"); JPanel buttonPanel = new JPanel(); EntityType attachType = null; int refID = -1; Permission entityPermission = null; CallbackDestination destination = null; boolean readonly = false; public FileAttachViewPanel() { } /** Creates a new instance of CallViewPanel */ public void setReference(EntityType type, int refID) { this.attachType = type; this.refID = refID; } public void setDestination(CallbackDestination new_dest) { destination = new_dest; } public void setReadonly(boolean new_read) { readonly = new_read; buttonAdd.setVisible(!readonly); buttonDelete.setVisible(!readonly); } 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);*/ buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.setBackground(Color.WHITE); buttonPanel.add(buttonAdd); buttonPanel.add(buttonDownload); buttonPanel.add(buttonDelete); buttonPanel.add(buttonClose); buttonAdd.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { //PanelManager.getInstance().activatePanel(new FileAttachPanel(attachType, Integer.parseInt(refID), entityPermission)); FileAttachAddWindow window = new FileAttachAddWindow(); window.setReference(attachType, refID); window.setDestination(destination); window.display(); } }); buttonClose.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { if (destination != null) destination.callback(thisobj, CRMSComponent.CB_CLOSE_WINDOW, null);/* CRMSPanel panel = null; if (attachType == EntityType.COMPANY) { JOptionPane.showMessageDialog(bodyPanel, "BROKEN, please fix"); //panel = new CompanyEditPanel(CompanyEditPanel.PANEL_TYPE_EDIT, Integer.parseInt(refID)); } else if (attachType == EntityType.CONTACT) { panel = new ContactEditPanel(refID, null); } else if (attachType == EntityType.CALL) { panel = new CallEditPanel(refID); } else if (attachType == EntityType.REMINDER) { panel = new ReminderEditPanel(Integer.parseInt(refID)); } PanelManager.getInstance().activatePanel(panel);*/ } }); buttonDownload.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { if (attachTable.getSelectedRowCount() == 1) { doDownload(); } } }); buttonDelete.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { if (attachTable.getSelectedRowCount() == 1) { doDelete(); } } }); attachTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if (me.getClickCount() == 2 && attachTable.getSelectedRowCount() == 1) { doDownload(); } } } ); scrollPane.getViewport().setBackground(Color.WHITE); bodyPanel.setLayout(new BorderLayout()); bodyPanel.setBackground(Color.WHITE); bodyPanel.setBorder(new EmptyBorder(0,20,0,20)); bodyPanel.add(scrollPane, BorderLayout.CENTER); add(bodyPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); setCurrentPanel(bodyPanel); refreshData(); } public void doDelete() { int selected = attachTable.getSelectedRow(); if (selected < 0) { JOptionPane.showMessageDialog(this, "Please select a file to delete.", "File Deletion", JOptionPane.INFORMATION_MESSAGE); return; } FileAttachment attach = tableModel.getAttachment(selected); int confirm = JOptionPane.showConfirmDialog(this, "Are you sure you wish to delete the file '" + attach.getLocation() + "' by " + attach.getAttachedBy() + "?", "Delete Attachment", JOptionPane.YES_NO_OPTION); if (confirm != JOptionPane.YES_OPTION) { return; } setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Server server = ServerFactory.getInstance().getServer(); ServerCommand command = new ServerCommand(FileAttachmentModule.COMMAND_DELETE_ATTACHMENT); command.setParameter(FileAttachmentModule.PARAM_ATTACHMENT, attach); ServerResponse sr = server.sendCommand(command); if (sr != null && sr.getPart("fail") != null) { JOptionPane.showMessageDialog(this, "File was unable to be deleted, please contact your System Adminstrator", "File Deletion", JOptionPane.ERROR_MESSAGE); } refreshData(); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } public void doDownload() { PanelManager manager = PanelManager.getInstance(); AppletContext context = manager.getAppletContext(); int selected = attachTable.getSelectedRow(); if (context == null) { JOptionPane.showMessageDialog(this, "File downloads can only be performed from an applet context.", "File Download", JOptionPane.INFORMATION_MESSAGE); return; } else if (selected < 0) { JOptionPane.showMessageDialog(this, "Please select a file to download.", "File Download", JOptionPane.INFORMATION_MESSAGE); return; } URL url = manager.getCodeBase(); URL toURL = null; FileAttachment attach = tableModel.getAttachment(selected); try { StringBuffer urlString = new StringBuffer(); urlString.append("http://"); urlString.append(url.getHost()); urlString.append(":"); urlString.append(url.getPort()); urlString.append("/crms/filedownload"); urlString.append("?user=user"); urlString.append("&type=" + attach.getAttachmentType().getCode()); urlString.append("&id=" + attach.getAttachmentID()); toURL = new URL(urlString.toString()); System.out.println(toURL); } catch (MalformedURLException ex) { ex.printStackTrace(); } context.showDocument(toURL); } public void refreshData() { Server server = ServerFactory.getInstance().getServer(); ServerCommand command = new ServerCommand(FileAttachmentModule.COMMAND_GET_ATTACHMENTS); command.setParameter(FileAttachmentModule.PARAM_TYPE, attachType.getCode()); command.setParameter(FileAttachmentModule.PARAM_REF_ID, Integer.toString(refID)); ServerResponse response = server.sendCommand(command); ArrayList attachments = (ArrayList) response.getPart("attachments"); tableModel.setAttachments(attachments); attachTable.setModel(tableModel); CRMSUtil.resizeTable(attachTable); } public class AttachmentTableModel extends DefaultTableModel { ArrayList attachments = new ArrayList(); String[] headings = { "File Name", "Attached By", "Description" }; public int getColumnCount() { return headings.length; } public int getRowCount() { if (attachments != null) { return attachments.size(); } return 0; } public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } public String getColumnName(int column) { return headings[column]; } public void setValueAt(Object aValue, int rowIndex, int columnIndex) { // read only } public Object getValueAt(int row, int column) { FileAttachment attach = (FileAttachment) attachments.get(row); switch(column) { case 0: return attach.getLocation(); case 1: return attach.getAttachedBy(); case 2: return attach.getDescription(); default: return null; } } public void addAttachment(FileAttachment attach) { attachments.add(attach); } public void setAttachments(ArrayList attachments) { this.attachments = attachments; } public FileAttachment getAttachment(int i) { return (FileAttachment) attachments.get(i); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -