/** * Restore table column positions and sizes. Note, the table must have its auto resize mode set to * off, i.e. * * @param table * @param registry prefix * @param table name * @param default column widths */ public void restoreTableMetrics(JTable table, String propertyName, int[] defaultWidths) { if (table.getAutoResizeMode() != JTable.AUTO_RESIZE_OFF) throw new IllegalArgumentException("Table AutoResizeMode must be JTable.AUTO_RESIZE_OFF"); for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { try { table.moveColumn( table.convertColumnIndexToView( Integer.parseInt( context.getPreference( propertyName + ".column." + i + ".position", String.valueOf(i)))), i); int w = Integer.parseInt( context.getPreference( propertyName + ".column." + i + ".width", String.valueOf( (defaultWidths == null) ? table.getColumnModel().getColumn(i).getPreferredWidth() : defaultWidths[i]))); table.getColumnModel().getColumn(i).setPreferredWidth(w); } catch (NumberFormatException nfe) { } } }
/** * Save table column positions and sizes. Note, the table must have its auto resize mode set to * off, i.e. * * @param table * @param registry prefix * @param table name */ private void saveTableMetrics(JTable table, String propertyName) { for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { int w = table.getColumnModel().getColumn(i).getWidth(); context.putPreference(propertyName + ".column." + i + ".width", String.valueOf(w)); context.putPreference( propertyName + ".column." + i + ".position", String.valueOf(table.convertColumnIndexToModel(i))); } }
/** * Get a list of all the plugins that are in the same resource (jar?) * * @param selRes the resource * @return all plugins in the same resource */ private Vector getAllPluginsInResource(String selRes) { // First check to see if this plugin is one of many in the same jar Vector allPlugins = new Vector(); context.log(PluginHostContext.LOG_INFORMATION, "Looking for plugins that use " + selRes); for (Enumeration e = manager.plugins(); e.hasMoreElements(); ) { Plugin p = (Plugin) e.nextElement(); Properties pr = manager.getPluginProperties(p); if (pr == null) context.log(PluginHostContext.LOG_ERROR, "No properties found for plugin?"); else if (selRes.equals(pr.getProperty(PluginManager.PLUGIN_RESOURCE))) allPlugins.addElement(p); } return allPlugins; }
/** * Mark all of the supplied jars for deletion upon the next startup. Each key in the hash map * should contain a jar name, with the value being the appropriate <code>File</code> object * * @param jars the jars to remove */ private void removeJars(HashMap removeJars) throws IOException { FileOutputStream out = null; File removeFile = new File(context.getPluginDirectory(), "ros.list"); try { out = new FileOutputStream(removeFile, true); PrintWriter w = new PrintWriter(out, true); for (Iterator i = removeJars.keySet().iterator(); i.hasNext(); ) { String n = (String) i.next(); String v = (String) removeJars.get(n); File f = new File(v); w.println(f.getAbsolutePath()); } out.close(); } finally { try { if (out != null) out.close(); } catch (IOException ioe2) { } } }
public void run() { status.setIcon(ACTIVE_ICON); updating = true; setAvailableActions(); status.setText("Contacting plugin updates site"); InputStream in = null; try { URL url = context.getPluginUpdatesResource(); URL listURL = new URL(url + "/pluginlist.properties"); in = listURL.openStream(); status.setText("Downloading list of available plugins"); Properties pluginList = new Properties(); pluginList.load(in); HashMap plugins = new HashMap(); for (Iterator i = pluginList.keySet().iterator(); i.hasNext(); ) { String key = (String) i.next(); int idx = key.indexOf('.'); if (idx != -1) { String n = key.substring(0, idx); plugins.put(n, n); } else throw new PluginException( "pluginlist.properties is in incorrect format. Please " + "contact site administrator."); } for (Iterator i = plugins.keySet().iterator(); i.hasNext(); ) { String plugin = (String) i.next(); String propertiesLocation = pluginList.getProperty(plugin + ".properties", ""); if (propertiesLocation.length() == 0) throw new PluginException( "Each plugin in pluginlist.properties must have an entry " + "<plugin-name>.properties specifying the location of the " + "properties file."); String archiveLocation = pluginList.getProperty(plugin + ".archive", ""); if (archiveLocation.length() == 0) throw new PluginException( "Each plugin in pluginlist.properties must have an entry " + "<plugin-name>.archive specifying the location of the " + "archive file."); context.log(PluginHostContext.LOG_INFORMATION, "Found plugin " + plugin); URL propURL = null; try { propURL = new URL(propertiesLocation); } catch (MalformedURLException murle) { propURL = new URL(url + "/" + propertiesLocation); } context.log( PluginHostContext.LOG_DEBUG, "Properties location is " + propURL.toExternalForm()); URL archiveURL = null; try { archiveURL = new URL(archiveLocation); } catch (MalformedURLException murle) { archiveURL = new URL(url + "/" + archiveLocation); } context.log( PluginHostContext.LOG_DEBUG, "Archive location is " + archiveURL.toExternalForm()); try { status.setText("Loading properties for archive " + plugin); HashMap props = manager.loadPluginProperties(propURL); status.setText("Checking plugin archive " + plugin); for (Iterator j = props.keySet().iterator(); j.hasNext(); ) { String name = (String) j.next(); status.setText(" Found plugin " + name); Properties p = (Properties) props.get(name); p.setProperty(PLUGIN_DOWNLOAD_LOCATION, archiveURL.toExternalForm()); model.setRemoteProperties(name, p); } } catch (PluginException pe) { context.log( PluginHostContext.LOG_ERROR, "Could not load plugin.properties for " + plugin, pe); } } status.setText("Update complete"); status.setIcon(IDLE_ICON); } catch (IOException ioe) { status.setIcon(ERROR_ICON); status.setText("Failed! " + ioe.getMessage()); } catch (PluginException pe) { status.setIcon(ERROR_ICON); status.setText("Failed! " + pe.getMessage()); } finally { PluginUtil.closeStream(in); } updating = false; setAvailableActions(); }