KickJava   Java API By Example, From Geeks To Geeks.

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


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.client.widgets.ManagedWindow;
23 import org.lucane.applications.sharedfolder.gui.FolderTableModel;
24 import org.lucane.applications.sharedfolder.gui.FolderTableRenderer;
25 import org.lucane.applications.sharedfolder.gui.ActionToolBar;
26 import org.lucane.applications.sharedfolder.gui.FolderTableListener;
27 import org.lucane.applications.sharedfolder.model.SharedItem;
28 import org.lucane.applications.sharedfolder.model.FileInfo;
29 import org.lucane.applications.sharedfolder.model.FolderInfo;
30 import org.lucane.applications.sharedfolder.SharedFolderPlugin;
31
32 import javax.swing.*;
33 import java.awt.event.ActionEvent JavaDoc;
34 import java.awt.*;
35 import java.util.ArrayList JavaDoc;
36
37 public class HistoryAction extends PerformableAction
38 {
39     private SharedFolderPlugin plugin;
40     private JTable table;
41     private boolean history;
42
43     public HistoryAction(SharedFolderPlugin plugin, JTable table, boolean history)
44     {
45         this.plugin = plugin;
46         this.table = table;
47         this.history = history;
48
49         putValue(Action.SMALL_ICON, plugin.getImageIcon("actions/history.png"));
50         putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip.history"));
51     }
52
53     public boolean isPerformable()
54     {
55         int row = table.getSelectedRow();
56         if(row < 0 || history)
57             return false;
58
59         FolderTableModel model = (FolderTableModel)table.getModel();
60         SharedItem item = model.getItemAt(row);
61         if(item.isFolder() || !item.isReadable())
62             return false;
63
64         return true;
65     }
66
67     public void actionPerformed(ActionEvent JavaDoc ae)
68     {
69         if(!isPerformable())
70             return;
71
72         int row = table.getSelectedRow();
73         FolderTableModel model = (FolderTableModel)table.getModel();
74         FolderInfo folder = model.getCurrentFolder();
75         FileInfo item = (FileInfo)model.getItemAt(row);
76         table.clearSelection();
77
78         try {
79             ArrayList JavaDoc versions = plugin.listFileVersions(item.getId());
80             model = new FolderTableModel(plugin);
81
82             JTable table = new JTable(model);
83             table.setDefaultRenderer(String JavaDoc.class, new FolderTableRenderer());
84             table.getColumnModel().getColumn(0).setMinWidth(16);
85             table.getColumnModel().getColumn(0).setMaxWidth(20);
86             table.setRowHeight(18);
87             table.setRowSelectionAllowed(true);
88
89             ActionToolBar toolbar = new ActionToolBar(plugin, table, true);
90             FolderTableListener listener = new FolderTableListener(plugin, table, toolbar);
91             table.addMouseListener(listener);
92             table.addKeyListener(listener);
93             table.getSelectionModel().addListSelectionListener(listener);
94             model.addTableModelListener(listener);
95
96             model.setItems(folder, versions);
97
98             String JavaDoc title = plugin.tr("window.history") + ' ' + item.getName();
99             ManagedWindow window = new ManagedWindow(plugin, title);
100             window.setName("history");
101             window.getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
102             window.setPreferredSize(new Dimension(500, 200));
103             window.show();
104         } catch(Exception JavaDoc e) {
105             DialogBox.error(e.getMessage());
106             e.printStackTrace();
107         }
108     }
109 }
Popular Tags