PageRenderTime 80ms CodeModel.GetById 60ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/pluginmgr/PluginManager.java

#
Java | 330 lines | 244 code | 38 blank | 48 comment | 37 complexity | 4a45aec248c0249542cd6c5ad2cbab43 MD5 | raw file
  1/*
  2 * PluginManager.java - Plugin manager window
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 2002 Kris Kopicki
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package org.gjt.sp.jedit.pluginmgr;
 24
 25//{{{ Imports
 26import com.microstar.xml.XmlException;
 27import javax.swing.border.*;
 28import javax.swing.event.*;
 29import javax.swing.table.*;
 30import javax.swing.*;
 31import java.awt.event.*;
 32import java.awt.*;
 33import java.util.*;
 34import org.gjt.sp.jedit.gui.*;
 35import org.gjt.sp.jedit.io.VFSManager;
 36import org.gjt.sp.jedit.msg.*;
 37import org.gjt.sp.jedit.options.*;
 38import org.gjt.sp.jedit.*;
 39import org.gjt.sp.util.Log;
 40import org.gjt.sp.util.WorkRequest;
 41//}}}
 42
 43public class PluginManager extends JFrame implements EBComponent
 44{
 45	//{{{ getInstance() method
 46	/**
 47	 * Returns the currently visible plugin manager window, or null.
 48	 * @since jEdit 4.2pre2
 49	 */
 50	public static PluginManager getInstance()
 51	{
 52		return instance;
 53	} //}}}
 54
 55	//{{{ dispose() method
 56	public void dispose()
 57	{
 58		GUIUtilities.saveGeometry(this,"plugin-manager");
 59		instance = null;
 60		EditBus.removeFromBus(this);
 61		super.dispose();
 62	} //}}}
 63
 64	//{{{ handleMessage() method
 65	public void handleMessage(EBMessage message)
 66	{
 67		// Force the install tab to refresh for possible
 68		// change of mirror
 69		if (message instanceof PropertiesChanged)
 70		{
 71			pluginList = null;
 72			updatePluginList();
 73			if(tabPane.getSelectedIndex() != 0)
 74			{
 75				installer.updateModel();
 76				updater.updateModel();
 77			}
 78		}
 79		else if (message instanceof PluginUpdate)
 80		{
 81			if(!queuedUpdate)
 82			{
 83				SwingUtilities.invokeLater(new Runnable()
 84				{
 85					public void run()
 86					{
 87						queuedUpdate = false;
 88						manager.update();
 89					}
 90				});
 91				queuedUpdate = true;
 92			}
 93		}
 94	} //}}}
 95
 96	//{{{ showPluginManager() method
 97	public static void showPluginManager(Frame frame)
 98	{
 99		if (instance == null)
100			instance = new PluginManager(frame);
101		else
102		{
103			instance.toFront();
104			return;
105		}
106	} //}}}
107
108	//{{{ ok() method
109	public void ok()
110	{
111		dispose();
112	} //}}}
113
114	//{{{ cancel() method
115	public void cancel()
116	{
117		dispose();
118	} //}}}
119
120	//{{{ getPluginList() method
121	public PluginList getPluginList()
122	{
123		return pluginList;
124	} //}}}
125
126	//{{{ Private members
127	private static PluginManager instance;
128
129	//{{{ Instance variables
130	private JTabbedPane tabPane;
131	private JButton done;
132	private JButton mgrOptions;
133	private JButton pluginOptions;
134	private InstallPanel installer;
135	private InstallPanel updater;
136	private ManagePanel manager;
137	private PluginList pluginList;
138	private boolean queuedUpdate;
139	private boolean downloadingPluginList;
140	//}}}
141
142	//{{{ PluginManager constructor
143	private PluginManager(Frame frame)
144	{
145		super(jEdit.getProperty("plugin-manager.title"));
146
147		EditBus.addToBus(this);
148
149		/* Setup panes */
150		JPanel content = new JPanel(new BorderLayout(12,12));
151		content.setBorder(new EmptyBorder(12,12,12,12));
152		setContentPane(content);
153
154		tabPane = new JTabbedPane();
155		tabPane.addTab(jEdit.getProperty("manage-plugins.title"),
156			manager = new ManagePanel(this));
157		tabPane.addTab(jEdit.getProperty("update-plugins.title"),
158			updater = new InstallPanel(this,true));
159		tabPane.addTab(jEdit.getProperty("install-plugins.title"),
160			installer = new InstallPanel(this,false));
161
162		content.add(BorderLayout.CENTER,tabPane);
163
164		tabPane.addChangeListener(new ListUpdater());
165
166		/* Create the buttons */
167		Box buttons = new Box(BoxLayout.X_AXIS);
168
169		ActionListener al = new ActionHandler();
170		mgrOptions = new JButton(jEdit.getProperty("plugin-manager.mgr-options"));
171		mgrOptions.addActionListener(al);
172		pluginOptions = new JButton(jEdit.getProperty("plugin-manager.plugin-options"));
173		pluginOptions.addActionListener(al);
174		done = new JButton(jEdit.getProperty("plugin-manager.done"));
175		done.addActionListener(al);
176
177		buttons.add(Box.createGlue());
178		buttons.add(mgrOptions);
179		buttons.add(Box.createHorizontalStrut(6));
180		buttons.add(pluginOptions);
181		buttons.add(Box.createHorizontalStrut(6));
182		buttons.add(done);
183		buttons.add(Box.createGlue());
184
185		getRootPane().setDefaultButton(done);
186
187		content.add(BorderLayout.SOUTH,buttons);
188
189		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
190
191		setIconImage(GUIUtilities.getPluginIcon());
192
193		pack();
194		GUIUtilities.loadGeometry(this,"plugin-manager");
195		show();
196	} //}}}
197
198	//{{{ updatePluginList() method
199	private void updatePluginList()
200	{
201		if(jEdit.getSettingsDirectory() == null
202			&& jEdit.getJEditHome() == null)
203		{
204			GUIUtilities.error(this,"no-settings",null);
205			return;
206		}
207		else if(pluginList != null || downloadingPluginList)
208		{
209			return;
210		}
211
212		final Exception[] exception = new Exception[1];
213
214		VFSManager.runInWorkThread(new WorkRequest()
215		{
216			public void run()
217			{
218				try
219				{
220					downloadingPluginList = true;
221					setStatus(jEdit.getProperty(
222						"plugin-manager.list-download"));
223					pluginList = new PluginList();
224				}
225				catch(Exception e)
226				{
227					exception[0] = e;
228				}
229				finally
230				{
231					downloadingPluginList = false;
232				}
233			}
234		});
235
236		VFSManager.runInAWTThread(new Runnable()
237		{
238			public void run()
239			{
240				if(exception[0] instanceof XmlException)
241				{
242					XmlException xe = (XmlException)
243						exception[0];
244
245					int line = xe.getLine();
246					String path = jEdit.getProperty(
247						"plugin-manager.export-url");
248					String message = xe.getMessage();
249					Log.log(Log.ERROR,this,path + ":" + line
250						+ ": " + message);
251					String[] pp = { path,
252						String.valueOf(line),
253						message };
254					GUIUtilities.error(PluginManager.this,
255						"plugin-list.xmlerror",pp);
256				}
257				else if(exception[0] != null)
258				{
259					Exception e = exception[0];
260
261					Log.log(Log.ERROR,this,e);
262					String[] pp = { e.toString() };
263
264					String ok = jEdit.getProperty(
265						"common.ok");
266					String proxyButton = jEdit.getProperty(
267						"plugin-list.ioerror.proxy-servers");
268					int retVal =
269						JOptionPane.showOptionDialog(
270						PluginManager.this,
271						jEdit.getProperty("plugin-list.ioerror.message",pp),
272						jEdit.getProperty("plugin-list.ioerror.title"),
273						JOptionPane.YES_NO_OPTION,
274						JOptionPane.ERROR_MESSAGE,
275						null,
276						new Object[] {
277							proxyButton,
278							ok
279						},
280						ok);
281
282					if(retVal == 0)
283					{
284						new GlobalOptions(
285							PluginManager.this,
286							"firewall");
287					}
288				}
289			}
290		});
291	} //}}}
292
293	//}}}
294
295	//{{{ Inner classes
296
297	//{{{ ActionHandler class
298	class ActionHandler implements ActionListener
299	{
300		public void actionPerformed(ActionEvent evt)
301		{
302			Object source = evt.getSource();
303			if(source == done)
304				ok();
305			else if (source == mgrOptions)
306				new GlobalOptions(PluginManager.this,"plugin-manager");
307			else if (source == pluginOptions)
308				new PluginOptions(PluginManager.this);
309		}
310	} //}}}
311
312	//{{{ ListUpdater class
313	class ListUpdater implements ChangeListener
314	{
315		public void stateChanged(ChangeEvent e)
316		{
317			final Component selected = tabPane.getSelectedComponent();
318			if(selected == installer || selected == updater)
319			{
320				updatePluginList();
321				installer.updateModel();
322				updater.updateModel();
323			}
324			else if(selected == manager)
325				manager.update();
326		}
327	} //}}}
328
329	//}}}
330}