dialog.dispose();
}
});
downloadButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Attachment attachment = (Attachment) attachmentsList.getSelectedValue();
OutputStream stream = null;
if (attachment != null) {
try {
byte[] body = gateway.retrieveAttachment(ticketsModel.getCurrentTicketModel().getCurrentTicket().getId(), attachment.getFileName());
JFileChooser fc = new JFileChooser();
File dir = fc.getCurrentDirectory();
fc.setSelectedFile(new File(dir, attachment.getFileName()));
int save = fc.showSaveDialog(rootComponent);
if (save == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
stream = new FileOutputStream(file);
IOUtils.write(body, stream);
}
} catch (ConnectionFailedException e1) {
TracGatewayLocator.handleConnectionProblem();
} catch (IOException e1) {
logger.error("Could not save file", e1);
} finally {
IOUtils.closeQuietly(stream);
}
}
}
});
showDescriptionButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Attachment attachment = (Attachment) attachmentsList.getSelectedValue();
if (attachment != null) {
JOptionPane popup = new AttachmentDescriptionPopup(attachment.getDescription());
JDialog dialog = popup.createDialog(null, MessageFormat.format(bundle.getString("tool_window.tickets.ticket_editor.attachments.popup_title"), attachment.getFileName()));
dialog.setVisible(true);
dialog.dispose();
}
}
});
attachmentsList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
Attachment selected = (Attachment) attachmentsList.getSelectedValue();
if (selected == null) {
downloadButton.setEnabled(false);
showDescriptionButton.setEnabled(false);
} else {
downloadButton.setEnabled(true);
if (!(StringUtils.isEmpty(selected.getDescription()))) {
showDescriptionButton.setEnabled(true);
}
}
}
});