Esempio n. 1
0
  /**
   * Creates a plugin hosts given its class name. Use PluginHostManager.HOST_* constants.
   *
   * @param pluginHostClass Class name of plugin host to create.
   * @param props Properties map.
   * @throws PluginException on plugin error.
   */
  public void setPluginHost(String pluginHostClass, Map props) throws PluginException {
    boolean firstTime = (current_ == null);
    PluginHost previous = current_;

    try {
      current_ = (PluginHost) Class.forName(pluginHostClass).newInstance();
    } catch (InstantiationException e) {
      throw new PluginException(e);
    } catch (IllegalAccessException e) {
      throw new PluginException(e);
    } catch (ClassNotFoundException e) {
      throw new PluginException(e);
    }

    if (firstTime) {
      try {
        current_.initialize(props);
      } catch (ServiceException se) {
        throw new PluginException(se);
      }
    } else {
      try {
        transferAssets(previous, current_);
      } catch (ServiceException e1) {
        throw new PluginException(e1);
      }
      recepticle_.remove(previous.getView());
    }

    recepticle_.add(current_.getView());
  }
Esempio n. 2
0
    /** @see toolbox.util.ui.SmartAction#runAction( java.awt.event.ActionEvent) */
    public void runAction(ActionEvent e) throws Exception {
      String selected = newPluginHost_.getClass().getName();

      if (selected.equals(current_.getClass().getName())) {
        JSmartOptionPane.showMessageDialog(null, "Plugin host " + selected + " is already active.");
      }

      recepticle_.remove(current_.getView());
      transferAssets(current_, newPluginHost_);
      recepticle_.add(newPluginHost_.getView());
      current_ = newPluginHost_;
      recepticle_.validate();

      current_.applyPrefs(workspace_.getPreferences());
    }
Esempio n. 3
0
 /**
  * Creates an ActivatePluginHostAction.
  *
  * @param pluginHost Plugin host to activate.
  */
 ActivatePluginHostAction(PluginHost pluginHost) {
   super(pluginHost.getName(), false, null, null);
   newPluginHost_ = pluginHost;
 }
Esempio n. 4
0
  /**
   * Transfers the assets from one plugin host to another.
   *
   * @param source Plugin host to transfer assets from.
   * @param dest Plugin host to transfer assets to.
   * @throws ServiceException on error.
   */
  protected void transferAssets(PluginHost source, PluginHost dest) throws ServiceException {
    logger_.debug(
        "Transferring "
            + source.getPlugins().length
            + " plugins from "
            + source.getClass().getName()
            + " --> "
            + dest.getClass().getName());

    dest.initialize(source.getStartupConfig());

    //
    // Transfer over the plugins
    //
    IPlugin[] sourcePlugins = source.getPlugins();

    for (int i = 0; i < sourcePlugins.length; i++) {
      IPlugin plugin = sourcePlugins[i];
      source.exportPlugin(plugin);
      dest.importPlugin(plugin);
    }

    //
    // Transfer over the pluginost's listeners
    //
    PluginHostListener[] listeners = source.getPluginHostListeners();

    for (int i = 0; i < listeners.length; i++) {
      source.removePluginHostListener(listeners[i]);
      dest.addPluginHostListener(listeners[i]);
    }

    source.destroy();
  }