1 19 package org.lucane.applications.sharedfolder.gui.actions; 20 21 import org.lucane.client.widgets.DialogBox; 22 import org.lucane.applications.sharedfolder.gui.FolderTableModel; 23 import org.lucane.applications.sharedfolder.model.SharedItem; 24 import org.lucane.applications.sharedfolder.model.FileInfo; 25 import org.lucane.applications.sharedfolder.SharedFolderPlugin; 26 27 import javax.swing.*; 28 import java.awt.event.ActionEvent ; 29 import java.io.File ; 30 31 public class DownloadAction extends PerformableAction 32 { 33 private SharedFolderPlugin plugin; 34 private JTable table; 35 36 public DownloadAction(SharedFolderPlugin plugin, JTable table, boolean history) 37 { 38 this.plugin = plugin; 39 this.table = table; 40 41 putValue(Action.SMALL_ICON, plugin.getImageIcon("actions/download.png")); 42 putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip.download")); 43 } 44 45 public boolean isPerformable() 46 { 47 int row = table.getSelectedRow(); 48 if(row < 0) 49 return false; 50 51 FolderTableModel model = (FolderTableModel)table.getModel(); 52 SharedItem item = model.getItemAt(row); 53 if(item.isFolder() || !item.isReadable()) 54 return false; 55 56 return true; 57 } 58 59 public void actionPerformed(ActionEvent ae) 60 { 61 if(!isPerformable()) 62 return; 63 64 int row = table.getSelectedRow(); 65 FolderTableModel model = (FolderTableModel)table.getModel(); 66 FileInfo item = (FileInfo)model.getItemAt(row); 67 68 JFileChooser jfc = new JFileChooser(); 69 jfc.setSelectedFile(new File (item.getName())); 70 int res = jfc.showSaveDialog(null); 71 if(res != JFileChooser.APPROVE_OPTION) 72 return; 73 74 File file = jfc.getSelectedFile(); 75 try { 76 plugin.downloadFile(item.getId(), item.getVersion(), file); 77 } catch(Exception e) { 78 DialogBox.error(e.getMessage()); 79 e.printStackTrace(); 80 } 81 } 82 } | Popular Tags |