KickJava   Java API By Example, From Geeks To Geeks.

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


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.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.SharedFolderPlugin;
26
27 import javax.swing.*;
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.util.ArrayList JavaDoc;
30
31 public class OpenFolderAction extends PerformableAction
32 {
33     private SharedFolderPlugin plugin;
34     private JTable table;
35
36     public OpenFolderAction(SharedFolderPlugin plugin, JTable table, boolean history)
37     {
38         this.plugin = plugin;
39         this.table = table;
40
41         putValue(Action.SMALL_ICON, plugin.getImageIcon("actions/openfolder.png"));
42         putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip.openFolder"));
43     }
44
45     public boolean isPerformable()
46     {
47         int row = table.getSelectedRow();
48         if(row < 0)
49             return false;
50
51         FolderTableModel model = (FolderTableModel)table.getModel();
52         SharedItem item = model.getItemAt(row);
53         return item.isFolder() && item.isReadable();
54     }
55
56     public void actionPerformed(ActionEvent JavaDoc ae)
57     {
58         if(!isPerformable())
59             return;
60
61         int row = table.getSelectedRow();
62         FolderTableModel model = (FolderTableModel)table.getModel();
63         SharedItem item = model.getItemAt(row);
64
65         ArrayList JavaDoc items = new ArrayList JavaDoc();
66         try {
67             items.addAll(plugin.listFolders(item.getId()));
68             items.addAll(plugin.listFiles(item.getId()));
69         } catch(Exception JavaDoc e) {
70             DialogBox.error(e.getMessage());
71             e.printStackTrace();
72         }
73         table.getSelectionModel().clearSelection();
74         model.setItems((FolderInfo)item, items);
75     }
76 }
Popular Tags