예제 #1
0
  private void loadPlugIns(WorkbenchProperties props) {
    PlugInContext pc = context.createPlugInContext();
    // List<String> classNames = props.getPlugInClassNames();
    Map<String, Map<String, String>> pluginSettings =
        props.getSettings(new String[] {WorkbenchProperties.KEY_PLUGIN});
    int i = 0;
    for (String className : pluginSettings.keySet()) {
      //        System.out.println(i++ + "/"+ className);
      String initSetting = pluginSettings.get(className).get(WorkbenchProperties.ATTR_INITIALIZE);
      if (initSetting instanceof String && initSetting.equals(WorkbenchProperties.ATTR_VALUE_FALSE))
        continue;

      monitor.report(LOADING + " " + className);

      Class plugInClass = null;
      try {
        long start = secondsSince(0);
        plugInClass = Class.forName(className);
        PlugIn plugIn = (PlugIn) plugInClass.newInstance();
        plugIn.initialize(pc);

        // get plugin's menu settings
        Map<String, Map> menuSettings =
            props.getSettings(
                new String[] {
                  WorkbenchProperties.KEY_PLUGIN, className, WorkbenchProperties.KEY_MENUS
                });

        // interpret menu settings
        for (Map.Entry<String, Map> entry : menuSettings.entrySet()) {

          String menuKey = entry.getKey();
          if (pc.getFeatureInstaller().fetchMenuForKey(menuKey) == null) continue;

          // install me to menu?
          String installSetting =
              props.getSetting(
                  new String[] {
                    WorkbenchProperties.KEY_PLUGIN,
                    className,
                    WorkbenchProperties.KEY_MENUS,
                    menuKey,
                    WorkbenchProperties.ATTR_INSTALL
                  });
          //            String orderSetting = props.getSetting(new String[] {
          //                WorkbenchProperties.KEY_PLUGIN, className,
          //                WorkbenchProperties.KEY_MENUS,
          //                menuKey,
          //                WorkbenchProperties.ATTR_ORDERID});
          // log (order) info
          //            context
          //                .getWorkbench()
          //                .getFrame()
          //                .log(
          //                    "install " + className + " to " + menuKey + " = "
          //                        + installSetting + " with orderid = " + orderSetting);
          // install, or not
          if (installSetting.equals(WorkbenchProperties.ATTR_VALUE_TRUE))
            pc.getFeatureInstaller().addMenuPlugin(menuKey, plugIn);
        }

        // register shortcuts of plugins
        AbstractPlugIn.registerShortcuts(plugIn);

        context
            .getWorkbench()
            .getFrame()
            .log("Loading " + className + " took " + secondsSinceString(start) + "s");

      } catch (Throwable e) {
        context.getErrorHandler().handleThrowable(e);
        context.getWorkbench().getFrame().log(className + " " + NOT_INITIALIZED, this.getClass());
      }
    }
  }