KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > sharedfolder > gui > actions > MoveAction


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2005 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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.ManagedWindow;
22 import org.lucane.client.widgets.DialogBox;
23 import org.lucane.applications.sharedfolder.gui.FolderTreeModel;
24 import org.lucane.applications.sharedfolder.gui.FolderTreeRenderer;
25 import org.lucane.applications.sharedfolder.gui.FolderTableModel;
26 import org.lucane.applications.sharedfolder.SharedFolderPlugin;
27 import org.lucane.applications.sharedfolder.model.SharedItem;
28 import org.lucane.applications.sharedfolder.model.FolderInfo;
29 import org.lucane.applications.sharedfolder.model.FileInfo;
30
31 import javax.swing.*;
32 import java.awt.event.ActionEvent JavaDoc;
33 import java.awt.event.ActionListener JavaDoc;
34 import java.awt.*;
35
36 public class MoveAction extends PerformableAction
37 {
38     private SharedFolderPlugin plugin;
39     private JTable table;
40     private boolean history;
41
42     public MoveAction(SharedFolderPlugin plugin, JTable table, boolean history)
43     {
44         this.plugin = plugin;
45         this.table = table;
46         this.history = history;
47
48         putValue(Action.SMALL_ICON, plugin.getImageIcon("actions/move.png"));
49         putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip.move"));
50     }
51
52     public boolean isPerformable()
53     {
54         int row = table.getSelectedRow();
55         if(row < 0 || history)
56             return false;
57
58         FolderTableModel model = (FolderTableModel)table.getModel();
59         SharedItem item = model.getItemAt(row);
60         return item.isWritable();
61     }
62
63     public void actionPerformed(ActionEvent JavaDoc ae)
64     {
65         if(!isPerformable())
66             return;
67
68         int row = table.getSelectedRow();
69         FolderTableModel model = (FolderTableModel)table.getModel();
70         final SharedItem item = model.getItemAt(row);
71
72
73         final JTree tree = new JTree(new FolderTreeModel(plugin));
74         tree.setCellRenderer(new FolderTreeRenderer(plugin));
75
76         String JavaDoc title = plugin.tr("window.move") + ' ' + item.getName();
77         final ManagedWindow window = new ManagedWindow(plugin, title);
78         window.setName("explore");
79
80         JButton btnMove = new JButton(plugin.tr("btn.moveItem"));
81         btnMove.addActionListener(new ActionListener JavaDoc() {
82             public void actionPerformed(ActionEvent JavaDoc ae) {
83                 if(tree.getSelectionCount() != 1)
84                     return;
85
86                 FolderInfo folder = (FolderInfo)tree.getSelectionPath().getLastPathComponent();
87                 if(!folder.isWritable())
88                 {
89                     DialogBox.error(plugin.tr("msg.unwritableDestinationFolder"));
90                     return;
91                 }
92
93                 item.setParentId(folder.getId());
94
95                 try {
96                     if(item.isFolder())
97                         plugin.updateFolder((FolderInfo)item);
98                     else
99                         plugin.updateFile((FileInfo)item);
100                 } catch(Exception JavaDoc e) {
101                     DialogBox.error(e.getMessage());
102                     e.printStackTrace();
103                 }
104
105                 table.clearSelection();
106                 new RefreshAction(plugin, table, history).actionPerformed(ae);
107                 window.dispose();
108             }
109         });
110
111         window.getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
112         window.getContentPane().add(btnMove, BorderLayout.SOUTH);
113         window.setPreferredSize(new Dimension(200, 300));
114         window.show();
115     }
116 }
Popular Tags