/** * Method to return an array list containing plugins of a certain editor type and category * * @param editorType The editor type * @param category The category * @return An array list of any plugins found */ public ArrayList<ATPlugin> getEmbeddedEditorPlugins(String editorType, String category) { ArrayList<ATPlugin> foundPlugins = new ArrayList<ATPlugin>(); try { Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator(); while (it.hasNext()) { PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next(); String id = pluginDescriptor.getId(); ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id); String cat = plugin.getCategory(); String et = plugin.getEditorType(); // check to make sure that the plugin is of the right category and // editor type and that it has a panel that can be embedded into // the resource editor panel if (cat.indexOf(category) != -1 && et.indexOf(editorType) != -1 && plugin.getEmbeddedPanels() != null) { foundPlugins.add(plugin); } } } catch (Exception e) { e.printStackTrace(); } return foundPlugins; }
/** * Method to return the name of all plugins in a particular category. It is used to add plugins to * plugin menu in the main application frame * * @return HashMap containing the names and ids of all the plugins found */ public HashMap getPluginNamesByCategory(String inCategory) { HashMap<String, String> pluginNames = new HashMap<String, String>(); try { Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator(); while (it.hasNext()) { PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next(); String id = pluginDescriptor.getId(); ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id); String name = plugin.getName(); String category = plugin.getCategory(); if (category.indexOf(inCategory) != -1) { if (plugin.getTaskList() == null) { // no list of task so just return the id and name pluginNames.put(id, name); } else { // list of task so return the name::task1::task2::task3 etc ... String nameWithTask = getNameWithTask(name, plugin.getTaskList()); pluginNames.put(id, nameWithTask); } } } } catch (Exception e) { e.printStackTrace(); } if (pluginNames.size() == 0) { return null; // no plugins in this category so return null } else { return pluginNames; } }
/** * Method to return the ATPlugin for a particular and domain object * * @param domainObject The domain object to find a plugin for * @param category The category to find a domain object for * @return The plugin found or null if none can be located. */ private ATPlugin getATPlugin(DomainObject domainObject, String category) { String editorType = getEditorTypeForDomainObject(domainObject); if (editorType != null) { ATPlugin foundPlugin = null; try { Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator(); while (it.hasNext()) { PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next(); String id = pluginDescriptor.getId(); ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id); String cat = plugin.getCategory(); String et = plugin.getEditorType(); if (cat.indexOf(category) != -1 && et.indexOf(editorType) != -1) { foundPlugin = plugin; break; } } } catch (Exception e) { e.printStackTrace(); } return foundPlugin; } else { return null; } }
/** * Method to return a plugin given an id. If it can't be found then null is returned * * @param id The id of the plugin to return * @return The ATPlugin found or null */ public ATPlugin getPlugin(String id) { try { return (ATPlugin) pluginManager.getPlugin(id); } catch (Exception e) { e.printStackTrace(); return null; } }
public PluginEvent(String pluginName) { _parentPlugins = new ArrayList<String>(); for (Extension parent : PluginManager.lookup(this).getRegistry().getPluginDescriptor(pluginName).getExtensions()) { _parentPlugins.add(parent.getExtendedPluginId() + "@" + parent.getExtendedPointId()); } _plugin = pluginName; }
/** * Method to return an list of all the plugin names and ids in a hasmap * * @return HashMap containing the names and ids of all the plugins found */ public HashMap getPluginNames() { HashMap<String, String> pluginNames = new HashMap<String, String>(); try { Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator(); while (it.hasNext()) { PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next(); String id = pluginDescriptor.getId(); ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id); String name = plugin.getName(); pluginNames.put(id, name); } } catch (Exception e) { e.printStackTrace(); } if (pluginNames.size() == 0) { return null; // no plugins found so return null } else { return pluginNames; } }
/** * Method that loadsany plugins found in the plugin directory * * @return boolean indicating f any plugins were found */ public boolean parsePluginDirectory() { File pluginDirectory = new File("plugins"); if (!pluginDirectory .exists()) { // check to see if the directory actually exist before continuing return false; } // get any files which are zip and return those File[] plugins = pluginDirectory.listFiles( new FilenameFilter() { public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".zip"); } }); // load the plugins now pluginManager = ObjectFactory.newInstance().createManager(); try { PluginLocation[] locations = new PluginLocation[plugins.length]; for (int i = 0; i < plugins.length; i++) { locations[i] = StandardPluginLocation.create(plugins[i]); } pluginManager.publishPlugins(locations); } catch (Exception e) { System.out.println("Error loading plugins ..."); e.printStackTrace(); return false; } if (plugins.length > 0) { // check to see if any plugins were in the directory return true; } else { return false; } }
public void drawWindow() { HashSet<SettingsExtension> set = new HashSet<SettingsExtension>(); try { for (Extension e : ext.getAvailableExtensions()) { PluginDescriptor pd = e.getDeclaringPluginDescriptor(); // if(manager.isPluginActivated(pd)){ Plugin plugin = manager.getPlugin(pd.getId()); if (plugin instanceof SettingsExtension) { set.add((SettingsExtension) plugin); } // } } } catch (PluginLifecycleException x) { x.printStackTrace(); } set.add(new NTorrentPlugins()); SettingsExtension[] array = new SettingsExtension[set.size()]; set.toArray(array); SettingsWindow window = new SettingsWindow(array); window.validate(); window.pack(); window.setSize(640, 480); window.setVisible(true); }
public SettingsController() { this.manager = NtorrentApplication.MANAGER; this.ext = manager.getRegistry().getExtensionPoint("ntorrent@SettingsExtension"); }