001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2005 Vincent Fiack <vfiack@mail15.com>
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package org.lucane.applications.sharedfolder.gui.actions;
020:
021: import org.lucane.client.widgets.ManagedWindow;
022: import org.lucane.client.widgets.DialogBox;
023: import org.lucane.applications.sharedfolder.gui.FolderTreeModel;
024: import org.lucane.applications.sharedfolder.gui.FolderTreeRenderer;
025: import org.lucane.applications.sharedfolder.gui.FolderTableModel;
026: import org.lucane.applications.sharedfolder.SharedFolderPlugin;
027: import org.lucane.applications.sharedfolder.model.SharedItem;
028: import org.lucane.applications.sharedfolder.model.FolderInfo;
029: import org.lucane.applications.sharedfolder.model.FileInfo;
030:
031: import javax.swing.*;
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034: import java.awt.*;
035:
036: public class MoveAction extends PerformableAction {
037: private SharedFolderPlugin plugin;
038: private JTable table;
039: private boolean history;
040:
041: public MoveAction(SharedFolderPlugin plugin, JTable table,
042: boolean history) {
043: this .plugin = plugin;
044: this .table = table;
045: this .history = history;
046:
047: putValue(Action.SMALL_ICON, plugin
048: .getImageIcon("actions/move.png"));
049: putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip.move"));
050: }
051:
052: public boolean isPerformable() {
053: int row = table.getSelectedRow();
054: if (row < 0 || history)
055: return false;
056:
057: FolderTableModel model = (FolderTableModel) table.getModel();
058: SharedItem item = model.getItemAt(row);
059: return item.isWritable();
060: }
061:
062: public void actionPerformed(ActionEvent ae) {
063: if (!isPerformable())
064: return;
065:
066: int row = table.getSelectedRow();
067: FolderTableModel model = (FolderTableModel) table.getModel();
068: final SharedItem item = model.getItemAt(row);
069:
070: final JTree tree = new JTree(new FolderTreeModel(plugin));
071: tree.setCellRenderer(new FolderTreeRenderer(plugin));
072:
073: String title = plugin.tr("window.move") + ' ' + item.getName();
074: final ManagedWindow window = new ManagedWindow(plugin, title);
075: window.setName("explore");
076:
077: JButton btnMove = new JButton(plugin.tr("btn.moveItem"));
078: btnMove.addActionListener(new ActionListener() {
079: public void actionPerformed(ActionEvent ae) {
080: if (tree.getSelectionCount() != 1)
081: return;
082:
083: FolderInfo folder = (FolderInfo) tree
084: .getSelectionPath().getLastPathComponent();
085: if (!folder.isWritable()) {
086: DialogBox.error(plugin
087: .tr("msg.unwritableDestinationFolder"));
088: return;
089: }
090:
091: item.setParentId(folder.getId());
092:
093: try {
094: if (item.isFolder())
095: plugin.updateFolder((FolderInfo) item);
096: else
097: plugin.updateFile((FileInfo) item);
098: } catch (Exception e) {
099: DialogBox.error(e.getMessage());
100: e.printStackTrace();
101: }
102:
103: table.clearSelection();
104: new RefreshAction(plugin, table, history)
105: .actionPerformed(ae);
106: window.dispose();
107: }
108: });
109:
110: window.getContentPane().add(new JScrollPane(tree),
111: BorderLayout.CENTER);
112: window.getContentPane().add(btnMove, BorderLayout.SOUTH);
113: window.setPreferredSize(new Dimension(200, 300));
114: window.show();
115: }
116: }
|