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