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.SharedItem;
24: import org.lucane.applications.sharedfolder.model.FolderInfo;
25: import org.lucane.applications.sharedfolder.model.FileInfo;
26: import org.lucane.applications.sharedfolder.SharedFolderPlugin;
27:
28: import javax.swing.*;
29: import java.awt.event.ActionEvent;
30:
31: public class RenameAction extends PerformableAction {
32: private SharedFolderPlugin plugin;
33: private JTable table;
34: private boolean history;
35:
36: public RenameAction(SharedFolderPlugin plugin, JTable table,
37: boolean history) {
38: this .plugin = plugin;
39: this .table = table;
40: this .history = history;
41:
42: putValue(Action.SMALL_ICON, plugin
43: .getImageIcon("actions/rename.png"));
44: putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip.rename"));
45: }
46:
47: public boolean isPerformable() {
48: int row = table.getSelectedRow();
49: if (row < 0 || history)
50: return false;
51:
52: FolderTableModel model = (FolderTableModel) table.getModel();
53: SharedItem item = model.getItemAt(row);
54: return item.isWritable();
55: }
56:
57: public void actionPerformed(ActionEvent ae) {
58: if (!isPerformable())
59: return;
60:
61: int row = table.getSelectedRow();
62: FolderTableModel model = (FolderTableModel) table.getModel();
63: SharedItem item = model.getItemAt(row);
64: String name = DialogBox.input(plugin.tr("tip.rename"), plugin
65: .tr("msg.enterNewName"), item.getName());
66: if (name == null || name.length() == 0
67: || name.equals(item.getName()))
68: return;
69:
70: item.setName(name);
71:
72: try {
73: if (item.isFolder())
74: plugin.updateFolder((FolderInfo) item);
75: else
76: plugin.updateFile((FileInfo) item);
77:
78: new RefreshAction(plugin, table, history)
79: .actionPerformed(ae);
80: } catch (Exception e) {
81: DialogBox.error(e.getMessage());
82: e.printStackTrace();
83: }
84: }
85: }
|