Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-core-dev] Dynamic Plug-in


I'm trying to roll my own configurator, that will load a bundle(s).  I think I'm getting through the load process clean but the bundles extensions, menus, views, help, contributions are not updated in the UI.  Is there some trick to forcing the framework to parse the new plug-in stuff dynamically.

Here is a simplified bit of code, gleaned from the update ConfigurationActivator.


 public void run(IAction action) {
    List toRefresh = getUnresolvedBundles(); //Get all unresolved bundles
    Bundle target;
    try {
      URL bundleURL = new URL(
          "reference:file:"
              + "D:/I0529/JDG2EBonusPack/plugins/com.ibm.jdg2e.mini.workplace.bonus_pack_3.0.0");
      target = ConfiguratorPlugin
          .getDefault()
          .getPluginContext()
          .installBundle(
              "D:/I0529/eclipse/workspace/com.ibm.jdg2e.mini.workplace.bonus_pack/",
              bundleURL.openStream());
      toRefresh.add(target); // any new bundle should be refreshed as well
      refreshPackages((Bundle[]) toRefresh
          .toArray(new Bundle[toRefresh.size()])); //refresh all the bundles
      // specified and their
      // dependents.
    } catch (Exception e) {
      e.printStackTrace();
    }
    MessageDialog.openInformation(window.getShell(),
        "Configurator Plug-in", "Bonus pack bundle was added");
  }
  private List getUnresolvedBundles() {
    Bundle[] allBundles = ConfiguratorPlugin.getDefault()
        .getPluginContext().getBundles();
    List unresolved = new ArrayList();
    for (int i = 0; i < allBundles.length; i++)
      if (allBundles[i].getState() == Bundle.INSTALLED)
        unresolved.add(allBundles[i]);
    return unresolved;
  }
  private void refreshPackages(Bundle[] bundles) {
    if (bundles.length == 0)
      return;
    ServiceReference packageAdminRef = ConfiguratorPlugin
        .getDefault().getPluginContext().getServiceReference(
            PackageAdmin.class.getName());
    PackageAdmin packageAdmin = null;
    if (packageAdminRef != null) {
      packageAdmin = (PackageAdmin) ConfiguratorPlugin
          .getDefault().getPluginContext().getService(
              packageAdminRef);
      if (packageAdmin == null)
        return;
    }

    final boolean[] flag = new boolean[]{false};
    FrameworkListener listener = new FrameworkListener() {
      public void frameworkEvent(FrameworkEvent event) {
        if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED)
          synchronized (flag) {
            flag[0] = true;
            flag.notifyAll();
          }
      }
    };
    ConfiguratorPlugin.getDefault().getPluginContext()
        .addFrameworkListener(listener);
    packageAdmin.refreshPackages(bundles);
    synchronized (flag) {
      while (!flag[0]) {
        try {
          flag.wait();
        } catch (InterruptedException e) {
        }
      }
    }
    ConfiguratorPlugin.getDefault().getPluginContext()
        .removeFrameworkListener(listener);
    ConfiguratorPlugin.getDefault().getPluginContext()
        .ungetService(packageAdminRef);
  }


   

Thanks,
Scott Fairbrother
Eclipse/WebSphere Studio Jumpstart Team
607 Pinewood Dr
Apex , NC 27502

Voice : 919-367-9345  TL:  223-7851

The Java Developer's Guide to Eclipse - http://www.aw.com/catalog/academic/product/1,4096,0321159640,00.html?type=PRE
WebSphere Studio - http://www.ibm.com/software/ad/adstudio
Ready for WebSphere Studio partner program - http://www.developer.ibm.com/websphere/ready.html

Back to the top