001: package net.sourceforge.squirrel_sql.client.plugin;
002:
003: /*
004: * Copyright (C) 2001-2004 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.awt.BorderLayout;
022: import java.awt.Container;
023: import java.awt.Frame;
024: import java.awt.event.ActionEvent;
025: import java.awt.event.ActionListener;
026: import java.awt.event.KeyEvent;
027:
028: import javax.swing.AbstractAction;
029: import javax.swing.BorderFactory;
030: import javax.swing.JButton;
031: import javax.swing.JComponent;
032: import javax.swing.JDialog;
033: import javax.swing.JFrame;
034: import javax.swing.JLabel;
035: import javax.swing.JPanel;
036: import javax.swing.JScrollPane;
037: import javax.swing.KeyStroke;
038:
039: import net.sourceforge.squirrel_sql.client.IApplication;
040: import net.sourceforge.squirrel_sql.client.util.ApplicationFiles;
041: import net.sourceforge.squirrel_sql.fw.datasetviewer.DataSetException;
042: import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
043: import net.sourceforge.squirrel_sql.fw.util.StringManager;
044: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
045:
046: /**
047: * This dialog displays a summary of all plugins.
048: *
049: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
050: */
051: public class PluginSummaryDialog extends JDialog {
052: private static final long serialVersionUID = 1L;
053:
054: /** Internationalized strings for this class. */
055: private static final StringManager s_stringMgr = StringManagerFactory
056: .getStringManager(PluginSummaryDialog.class);
057:
058: transient private final IApplication _app;
059:
060: private PluginSummaryTable _pluginPnl;
061:
062: static interface i18n {
063: //i18n[PluginSummaryDialog.unload=Unload]
064: String UNLOAD_LABEL = s_stringMgr
065: .getString("PluginSummaryDialog.unload");
066: }
067:
068: public PluginSummaryDialog(IApplication app, Frame owner)
069: throws DataSetException {
070: super (owner, s_stringMgr.getString("PluginSummaryDialog.title"));
071: _app = app;
072: createGUI();
073: }
074:
075: private void saveSettings() {
076: _app.getPluginManager().setPluginStatuses(
077: _pluginPnl.getPluginStatus());
078: }
079:
080: private void createGUI() throws DataSetException {
081: setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
082:
083: // final SquirrelResources rsrc = _app.getResources();
084: // final ImageIcon icon = rsrc.getIcon(SquirrelResources.IImageNames.PLUGINS);
085: // if (icon != null)
086: // {
087: // setIconImage(icon.getImage());
088: // }
089:
090: final Container contentPane = getContentPane();
091: contentPane.setLayout(new BorderLayout());
092:
093: // Label containing the location of the plugins at top of dialog.
094: final JLabel pluginLoc = new JLabel(s_stringMgr.getString(
095: "PluginSummaryDialog.pluginloc", new ApplicationFiles()
096: .getPluginsDirectory().getAbsolutePath()));
097: pluginLoc
098: .setBorder(BorderFactory.createEmptyBorder(1, 4, 1, 4));
099:
100: contentPane.add(pluginLoc, BorderLayout.NORTH);
101:
102: // Table of loaded plugins in centre of dialog.
103: final PluginManager pmgr = _app.getPluginManager();
104: final PluginInfo[] pluginInfo = pmgr.getPluginInformation();
105: final PluginStatus[] pluginStatus = pmgr.getPluginStatuses();
106: _pluginPnl = new PluginSummaryTable(pluginInfo, pluginStatus);
107: contentPane.add(new JScrollPane(_pluginPnl),
108: BorderLayout.CENTER);
109:
110: final JPanel btnsPnl = new JPanel();
111: final JButton okBtn = new JButton(s_stringMgr
112: .getString("PluginSummaryDialog.ok"));
113: okBtn.addActionListener(new ActionListener() {
114: public void actionPerformed(ActionEvent evt) {
115: saveSettings();
116: dispose();
117: }
118: });
119: btnsPnl.add(okBtn);
120: final JButton unloadButton = new JButton(i18n.UNLOAD_LABEL);
121: unloadButton.addActionListener(new ActionListener() {
122: public void actionPerformed(ActionEvent evt) {
123: int[] rows = _pluginPnl.getSelectedRows();
124: if (rows.length == 0) {
125: // no rows selected.
126: return;
127: }
128: for (int row : rows) {
129: // column 1 is internal name
130: String internalName = (String) _pluginPnl
131: .getModel().getValueAt(row, 1);
132: _app.getPluginManager().unloadPlugin(internalName);
133: // column 3 is loaded status
134: _pluginPnl.setValueAt("false", row, 3);
135: }
136: _pluginPnl.repaint();
137: }
138: });
139: btnsPnl.add(unloadButton);
140: final JButton closeBtn = new JButton(s_stringMgr
141: .getString("PluginSummaryDialog.close"));
142: closeBtn.addActionListener(new ActionListener() {
143: public void actionPerformed(ActionEvent evt) {
144: dispose();
145: }
146: });
147: btnsPnl.add(closeBtn);
148: contentPane.add(btnsPnl, BorderLayout.SOUTH);
149:
150: AbstractAction closeAction = new AbstractAction() {
151: private static final long serialVersionUID = 1L;
152:
153: public void actionPerformed(ActionEvent actionEvent) {
154: setVisible(false);
155: dispose();
156: }
157: };
158: KeyStroke escapeStroke = KeyStroke.getKeyStroke(
159: KeyEvent.VK_ESCAPE, 0);
160: getRootPane().getInputMap(
161: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
162: escapeStroke, "CloseAction");
163: getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
164: .put(escapeStroke, "CloseAction");
165: getRootPane().getInputMap(JComponent.WHEN_FOCUSED).put(
166: escapeStroke, "CloseAction");
167: getRootPane().getActionMap().put("CloseAction", closeAction);
168:
169: pack();
170: setSize(655, 500);
171: GUIUtils.centerWithinParent(this );
172: setResizable(true);
173:
174: }
175: }
|