01: /*
02: * Lucane - a collaborative platform
03: * Copyright (C) 2005 Vincent Fiack <vfiack@mail15.com>
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
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: private SharedFolderPlugin plugin;
34: private JTable table;
35: private boolean history;
36:
37: public NewVersionAction(SharedFolderPlugin plugin, JTable table,
38: boolean history) {
39: this .plugin = plugin;
40: this .table = table;
41: this .history = history;
42:
43: putValue(Action.SMALL_ICON, plugin
44: .getImageIcon("actions/newversion.png"));
45: putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip.newVersion"));
46: }
47:
48: public boolean isPerformable() {
49: int row = table.getSelectedRow();
50: if (history || row < 0)
51: return false;
52:
53: FolderTableModel model = (FolderTableModel) table.getModel();
54: SharedItem item = model.getItemAt(row);
55: return item.isWritable() && !item.isFolder();
56: }
57:
58: public void actionPerformed(ActionEvent ae) {
59: if (!isPerformable())
60: return;
61:
62: JFileChooser jfc = new JFileChooser();
63: int res = jfc.showDialog(null, plugin.tr("btn.upload"));
64: if (res != JFileChooser.APPROVE_OPTION)
65: return;
66:
67: File file = jfc.getSelectedFile();
68: FolderTableModel model = (FolderTableModel) table.getModel();
69: FolderInfo current = model.getCurrentFolder();
70:
71: int row = table.getSelectedRow();
72: FileInfo item = (FileInfo) model.getItemAt(row);
73: int version = item.getVersion() + 1;
74: int id = item.getId();
75:
76: try {
77: plugin.uploadFile(current.getId(), id, file.getName(),
78: version, file);
79: new RefreshAction(plugin, table, history)
80: .actionPerformed(ae);
81: } catch (Exception e) {
82: DialogBox.error(e.getMessage());
83: e.printStackTrace();
84: }
85: }
86: }
|