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.model.SharedItem; 26 import org.lucane.applications.sharedfolder.SharedFolderPlugin; 27 28 import javax.swing.*; 29 import java.awt.event.ActionEvent ; 30 import java.io.File ; 31 32 public class NewVersionAction extends PerformableAction 33 { 34 private SharedFolderPlugin plugin; 35 private JTable table; 36 private boolean history; 37 38 public NewVersionAction(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/newversion.png")); 45 putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip.newVersion")); 46 } 47 48 public boolean isPerformable() 49 { 50 int row = table.getSelectedRow(); 51 if(history || row < 0) 52 return false; 53 54 FolderTableModel model = (FolderTableModel)table.getModel(); 55 SharedItem item = model.getItemAt(row); 56 return item.isWritable() && !item.isFolder(); 57 } 58 59 public void actionPerformed(ActionEvent ae) 60 { 61 if(!isPerformable()) 62 return; 63 64 JFileChooser jfc = new JFileChooser(); 65 int res = jfc.showDialog(null, plugin.tr("btn.upload")); 66 if(res != JFileChooser.APPROVE_OPTION) 67 return; 68 69 File file = jfc.getSelectedFile(); 70 FolderTableModel model = (FolderTableModel)table.getModel(); 71 FolderInfo current = model.getCurrentFolder(); 72 73 int row = table.getSelectedRow(); 74 FileInfo item = (FileInfo)model.getItemAt(row); 75 int version = item.getVersion()+1; 76 int id = item.getId(); 77 78 try { 79 plugin.uploadFile(current.getId(), id, file.getName(), version, file); 80 new RefreshAction(plugin, table, history).actionPerformed(ae); 81 } catch(Exception e) { 82 DialogBox.error(e.getMessage()); 83 e.printStackTrace(); 84 } 85 } 86 } | Popular Tags |