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.FolderInfo; 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 import java.util.Iterator ; 31 32 public class UploadAction extends PerformableAction 33 { 34 private SharedFolderPlugin plugin; 35 private JTable table; 36 private boolean history; 37 38 public UploadAction(SharedFolderPlugin plugin, JTable table, boolean history) 39 { 40 this.plugin = plugin; 41 this.table = table; 42 this.history = history; 43 44 putValue(Action.SMALL_ICON, plugin.getImageIcon("actions/upload.png")); 45 putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip.upload")); 46 } 47 48 public boolean isPerformable() 49 { 50 FolderTableModel model = (FolderTableModel)table.getModel(); 51 return !history && model.getCurrentFolder().isWritable(); 52 } 53 54 public void actionPerformed(ActionEvent ae) 55 { 56 if(!isPerformable()) 57 return; 58 59 JFileChooser jfc = new JFileChooser(); 60 int res = jfc.showDialog(null, plugin.tr("btn.upload")); 61 if(res != JFileChooser.APPROVE_OPTION) 62 return; 63 64 File file = jfc.getSelectedFile(); 65 FolderTableModel model = (FolderTableModel)table.getModel(); 66 FolderInfo current = model.getCurrentFolder(); 67 int version = FileInfo.FIRST_VERSION; 68 int id = FileInfo.NEW_ID; 69 70 try { 71 plugin.uploadFile(current.getId(), id, file.getName(), version, file); 72 new RefreshAction(plugin, table, history).actionPerformed(ae); 73 } catch(Exception e) { 74 DialogBox.error(e.getMessage()); 75 e.printStackTrace(); 76 } 77 } 78 } | Popular Tags |