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.DialogBox;
022: import org.lucane.client.widgets.ManagedWindow;
023: import org.lucane.applications.sharedfolder.gui.FolderTableModel;
024: import org.lucane.applications.sharedfolder.gui.FolderTableRenderer;
025: import org.lucane.applications.sharedfolder.gui.ActionToolBar;
026: import org.lucane.applications.sharedfolder.gui.FolderTableListener;
027: import org.lucane.applications.sharedfolder.model.SharedItem;
028: import org.lucane.applications.sharedfolder.model.FileInfo;
029: import org.lucane.applications.sharedfolder.model.FolderInfo;
030: import org.lucane.applications.sharedfolder.SharedFolderPlugin;
031:
032: import javax.swing.*;
033: import java.awt.event.ActionEvent;
034: import java.awt.*;
035: import java.util.ArrayList;
036:
037: public class HistoryAction extends PerformableAction {
038: private SharedFolderPlugin plugin;
039: private JTable table;
040: private boolean history;
041:
042: public HistoryAction(SharedFolderPlugin plugin, JTable table,
043: boolean history) {
044: this .plugin = plugin;
045: this .table = table;
046: this .history = history;
047:
048: putValue(Action.SMALL_ICON, plugin
049: .getImageIcon("actions/history.png"));
050: putValue(Action.SHORT_DESCRIPTION, plugin.tr("tip.history"));
051: }
052:
053: public boolean isPerformable() {
054: int row = table.getSelectedRow();
055: if (row < 0 || history)
056: return false;
057:
058: FolderTableModel model = (FolderTableModel) table.getModel();
059: SharedItem item = model.getItemAt(row);
060: if (item.isFolder() || !item.isReadable())
061: return false;
062:
063: return true;
064: }
065:
066: public void actionPerformed(ActionEvent ae) {
067: if (!isPerformable())
068: return;
069:
070: int row = table.getSelectedRow();
071: FolderTableModel model = (FolderTableModel) table.getModel();
072: FolderInfo folder = model.getCurrentFolder();
073: FileInfo item = (FileInfo) model.getItemAt(row);
074: table.clearSelection();
075:
076: try {
077: ArrayList versions = plugin.listFileVersions(item.getId());
078: model = new FolderTableModel(plugin);
079:
080: JTable table = new JTable(model);
081: table.setDefaultRenderer(String.class,
082: new FolderTableRenderer());
083: table.getColumnModel().getColumn(0).setMinWidth(16);
084: table.getColumnModel().getColumn(0).setMaxWidth(20);
085: table.setRowHeight(18);
086: table.setRowSelectionAllowed(true);
087:
088: ActionToolBar toolbar = new ActionToolBar(plugin, table,
089: true);
090: FolderTableListener listener = new FolderTableListener(
091: plugin, table, toolbar);
092: table.addMouseListener(listener);
093: table.addKeyListener(listener);
094: table.getSelectionModel()
095: .addListSelectionListener(listener);
096: model.addTableModelListener(listener);
097:
098: model.setItems(folder, versions);
099:
100: String title = plugin.tr("window.history") + ' '
101: + item.getName();
102: ManagedWindow window = new ManagedWindow(plugin, title);
103: window.setName("history");
104: window.getContentPane().add(new JScrollPane(table),
105: BorderLayout.CENTER);
106: window.setPreferredSize(new Dimension(500, 200));
107: window.show();
108: } catch (Exception e) {
109: DialogBox.error(e.getMessage());
110: e.printStackTrace();
111: }
112: }
113: }
|