コード例 #1
0
 protected TranslatorConfigurationDialog(
     Shell parentShell,
     // String translatorCategory,
     // Map<String, ConfigurationOption> config,
     ITranslator _translator,
     IConfigurationManagerForIDE configurationManager2) {
   super(parentShell);
   this.translator = _translator;
   this.translatorCategory = this.translator.getConfigurationCategory();
   this.config = this.translator.getTranslatorConfigurationOptions();
   //		this.translatorCategory = translatorCategory;
   //		this.config = config;
   configurationManager = configurationManager2;
   processConfigurationOptions();
   currentConfig = new HashMap<String, Object>();
   String[] catHier = new String[1];
   catHier[0] = this.translatorCategory;
   try {
     List<ConfigurationItem> cis = configurationManager.getConfiguration(catHier, true);
     if (cis != null && cis.size() > 0) {
       ConfigurationItem ci = cis.get(0);
       List<ConfigurationItem.NameValuePair> nvPairs = ci.getNameValuePairs();
       for (ConfigurationItem.NameValuePair nv : nvPairs) {
         currentConfig.put(nv.getName(), nv.getValue());
       }
     }
   } catch (ConfigurationException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
コード例 #2
0
 private void updateConfigurationOptions(ConfigurationItem configItem) {
   if (configItem == null) {
     return;
   }
   try {
     configurationManager.updateConfiguration(configItem);
     configurationManager.saveConfiguration();
   } catch (ConfigurationException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
コード例 #3
0
  private ConfigurationItem constructConfigurationOptions() {
    String[] categoryHierarchy = new String[1];
    categoryHierarchy[0] = this.translatorCategory;
    List<ConfigurationItem> configItems = null;
    try {
      configItems = configurationManager.getConfiguration(categoryHierarchy, true);
    } catch (ConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    logger.debug("Size of configItem = " + (configItems != null ? configItems.size() : 0));
    if (config == null) {
      return null;
    }

    ConfigurationItem configItem;
    if (configItems != null) {
      configItem = configItems.get(0);
    } else {
      configItem = new ConfigurationItem(categoryHierarchy);
    }
    configItem.clearNameValuePairs();
    for (Map.Entry<String, ConfigurationOption> entry : config.entrySet()) {
      String key = entry.getKey();
      ConfigurationOption option = entry.getValue();
      if (key.equalsIgnoreCase("builtin")) {
        continue;
      }
      String optionName = option.getName();
      Object optionValue = option.getValue();
      if (optionValue.getClass().getName().equalsIgnoreCase("java.lang.String")) {
        optionValue = this.rcps.getString(key);
      } else if (optionValue.getClass().getName().equalsIgnoreCase("java.lang.Double")) {
        optionValue = this.rcps.getDouble(key);
      } else if (optionValue.getClass().getName().equalsIgnoreCase("java.lang.Integer")) {
        optionValue = this.rcps.getInt(key);
      } else if (optionValue.getClass().getName().equalsIgnoreCase("java.lang.Boolean")) {
        optionValue = this.rcps.getBoolean(key);
      } else {
        logger.debug(
            "Error saving configuration option, "
                + optionName
                + ", of type "
                + optionValue.getClass().getName());
      }
      logger.debug("Setting " + optionName + " to " + optionValue.toString());
      ConfigurationItem.NameValuePair nv = configItem.new NameValuePair(optionName, optionValue);
      nv.setConfigType(ConfigurationItem.ConfigurationType.SingleValue);
      configItem.addNameValuePair(nv);
    }
    return configItem;
  }