PageRenderTime 30ms CodeModel.GetById 1ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package org.gjt.sp.jedit.pluginmgr;
  23. //{{{ Imports
  24. import com.microstar.xml.XmlException;
  25. import javax.swing.border.*;
  26. import javax.swing.event.*;
  27. import javax.swing.table.*;
  28. import javax.swing.*;
  29. import java.awt.event.*;
  30. import java.awt.*;
  31. import java.util.*;
  32. import org.gjt.sp.jedit.gui.*;
  33. import org.gjt.sp.jedit.io.VFSManager;
  34. import org.gjt.sp.jedit.msg.*;
  35. import org.gjt.sp.jedit.options.*;
  36. import org.gjt.sp.jedit.*;
  37. import org.gjt.sp.util.Log;
  38. import org.gjt.sp.util.WorkRequest;
  39. //}}}
  40. public class PluginManager extends JFrame implements EBComponent
  41. {
  42. //{{{ getInstance() method
  43. /**
  44. * Returns the currently visible plugin manager window, or null.
  45. * @since jEdit 4.2pre2
  46. */
  47. public static PluginManager getInstance()
  48. {
  49. return instance;
  50. } //}}}
  51. //{{{ dispose() method
  52. public void dispose()
  53. {
  54. GUIUtilities.saveGeometry(this,"plugin-manager");
  55. instance = null;
  56. EditBus.removeFromBus(this);
  57. super.dispose();
  58. } //}}}
  59. //{{{ handleMessage() method
  60. public void handleMessage(EBMessage message)
  61. {
  62. // Force the install tab to refresh for possible
  63. // change of mirror
  64. if (message instanceof PropertiesChanged)
  65. {
  66. pluginList = null;
  67. updatePluginList();
  68. if(tabPane.getSelectedIndex() != 0)
  69. {
  70. installer.updateModel();
  71. updater.updateModel();
  72. }
  73. }
  74. else if (message instanceof PluginUpdate)
  75. {
  76. if(!queuedUpdate)
  77. {
  78. SwingUtilities.invokeLater(new Runnable()
  79. {
  80. public void run()
  81. {
  82. queuedUpdate = false;
  83. manager.update();
  84. }
  85. });
  86. queuedUpdate = true;
  87. }
  88. }
  89. } //}}}
  90. //{{{ showPluginManager() method
  91. public static void showPluginManager(Frame frame)
  92. {
  93. if (instance == null)
  94. instance = new PluginManager(frame);
  95. else
  96. {
  97. instance.toFront();
  98. return;
  99. }
  100. } //}}}
  101. //{{{ ok() method
  102. public void ok()
  103. {
  104. dispose();
  105. } //}}}
  106. //{{{ cancel() method
  107. public void cancel()
  108. {
  109. dispose();
  110. } //}}}
  111. //{{{ getPluginList() method
  112. public PluginList getPluginList()
  113. {
  114. return pluginList;
  115. } //}}}
  116. //{{{ Private members
  117. private static PluginManager instance;
  118. //{{{ Instance variables
  119. private JTabbedPane tabPane;
  120. private JButton done;
  121. private JButton mgrOptions;
  122. private JButton pluginOptions;
  123. private InstallPanel installer;
  124. private InstallPanel updater;
  125. private ManagePanel manager;
  126. private PluginList pluginList;
  127. private boolean queuedUpdate;
  128. private boolean downloadingPluginList;
  129. //}}}
  130. //{{{ PluginManager constructor
  131. private PluginManager(Frame frame)
  132. {
  133. super(jEdit.getProperty("plugin-manager.title"));
  134. EditBus.addToBus(this);
  135. /* Setup panes */
  136. JPanel content = new JPanel(new BorderLayout(12,12));
  137. content.setBorder(new EmptyBorder(12,12,12,12));
  138. setContentPane(content);
  139. tabPane = new JTabbedPane();
  140. tabPane.addTab(jEdit.getProperty("manage-plugins.title"),
  141. manager = new ManagePanel(this));
  142. tabPane.addTab(jEdit.getProperty("update-plugins.title"),
  143. updater = new InstallPanel(this,true));
  144. tabPane.addTab(jEdit.getProperty("install-plugins.title"),
  145. installer = new InstallPanel(this,false));
  146. content.add(BorderLayout.CENTER,tabPane);
  147. tabPane.addChangeListener(new ListUpdater());
  148. /* Create the buttons */
  149. Box buttons = new Box(BoxLayout.X_AXIS);
  150. ActionListener al = new ActionHandler();
  151. mgrOptions = new JButton(jEdit.getProperty("plugin-manager.mgr-options"));
  152. mgrOptions.addActionListener(al);
  153. pluginOptions = new JButton(jEdit.getProperty("plugin-manager.plugin-options"));
  154. pluginOptions.addActionListener(al);
  155. done = new JButton(jEdit.getProperty("plugin-manager.done"));
  156. done.addActionListener(al);
  157. buttons.add(Box.createGlue());
  158. buttons.add(mgrOptions);
  159. buttons.add(Box.createHorizontalStrut(6));
  160. buttons.add(pluginOptions);
  161. buttons.add(Box.createHorizontalStrut(6));
  162. buttons.add(done);
  163. buttons.add(Box.createGlue());
  164. getRootPane().setDefaultButton(done);
  165. content.add(BorderLayout.SOUTH,buttons);
  166. setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  167. setIconImage(GUIUtilities.getPluginIcon());
  168. pack();
  169. GUIUtilities.loadGeometry(this,"plugin-manager");
  170. show();
  171. } //}}}
  172. //{{{ updatePluginList() method
  173. private void updatePluginList()
  174. {
  175. if(jEdit.getSettingsDirectory() == null
  176. && jEdit.getJEditHome() == null)
  177. {
  178. GUIUtilities.error(this,"no-settings",null);
  179. return;
  180. }
  181. else if(pluginList != null || downloadingPluginList)
  182. {
  183. return;
  184. }
  185. final Exception[] exception = new Exception[1];
  186. VFSManager.runInWorkThread(new WorkRequest()
  187. {
  188. public void run()
  189. {
  190. try
  191. {
  192. downloadingPluginList = true;
  193. setStatus(jEdit.getProperty(
  194. "plugin-manager.list-download"));
  195. pluginList = new PluginList();
  196. }
  197. catch(Exception e)
  198. {
  199. exception[0] = e;
  200. }
  201. finally
  202. {
  203. downloadingPluginList = false;
  204. }
  205. }
  206. });
  207. VFSManager.runInAWTThread(new Runnable()
  208. {
  209. public void run()
  210. {
  211. if(exception[0] instanceof XmlException)
  212. {
  213. XmlException xe = (XmlException)
  214. exception[0];
  215. int line = xe.getLine();
  216. String path = jEdit.getProperty(
  217. "plugin-manager.export-url");
  218. String message = xe.getMessage();
  219. Log.log(Log.ERROR,this,path + ":" + line
  220. + ": " + message);
  221. String[] pp = { path,
  222. String.valueOf(line),
  223. message };
  224. GUIUtilities.error(PluginManager.this,
  225. "plugin-list.xmlerror",pp);
  226. }
  227. else if(exception[0] != null)
  228. {
  229. Exception e = exception[0];
  230. Log.log(Log.ERROR,this,e);
  231. String[] pp = { e.toString() };
  232. String ok = jEdit.getProperty(
  233. "common.ok");
  234. String proxyButton = jEdit.getProperty(
  235. "plugin-list.ioerror.proxy-servers");
  236. int retVal =
  237. JOptionPane.showOptionDialog(
  238. PluginManager.this,
  239. jEdit.getProperty("plugin-list.ioerror.message",pp),
  240. jEdit.getProperty("plugin-list.ioerror.title"),
  241. JOptionPane.YES_NO_OPTION,
  242. JOptionPane.ERROR_MESSAGE,
  243. null,
  244. new Object[] {
  245. proxyButton,
  246. ok
  247. },
  248. ok);
  249. if(retVal == 0)
  250. {
  251. new GlobalOptions(
  252. PluginManager.this,
  253. "firewall");
  254. }
  255. }
  256. }
  257. });
  258. } //}}}
  259. //}}}
  260. //{{{ Inner classes
  261. //{{{ ActionHandler class
  262. class ActionHandler implements ActionListener
  263. {
  264. public void actionPerformed(ActionEvent evt)
  265. {
  266. Object source = evt.getSource();
  267. if(source == done)
  268. ok();
  269. else if (source == mgrOptions)
  270. new GlobalOptions(PluginManager.this,"plugin-manager");
  271. else if (source == pluginOptions)
  272. new PluginOptions(PluginManager.this);
  273. }
  274. } //}}}
  275. //{{{ ListUpdater class
  276. class ListUpdater implements ChangeListener
  277. {
  278. public void stateChanged(ChangeEvent e)
  279. {
  280. final Component selected = tabPane.getSelectedComponent();
  281. if(selected == installer || selected == updater)
  282. {
  283. updatePluginList();
  284. installer.updateModel();
  285. updater.updateModel();
  286. }
  287. else if(selected == manager)
  288. manager.update();
  289. }
  290. } //}}}
  291. //}}}
  292. }