Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] IOptionApplicability

> I'm trying to implement an IOptionApplicability class for an option
> which should be enabled depending on the state of another (enum) option.
> 
> This is the method which tries to determine the state of the enum option:
> 
>>     private final boolean usingCustomLibraryConfig(IHoldsOptions holder,
>>             IOption option)
>>     {
>>         IOption o = holder.getOptionById(OptionConstants.LIB_CONFIG_OPTION);
>>         assert o != null;
>>         try {
>>             String s = o.getSelectedEnum();
>> 
>>             System.err.println("Selected enum: " + s);
>> 
>>             if (s.equals(OptionConstants.LIB_CONFIG_CUSTOM)) {
>>                 return true;
>>             } else {
>>                 return false;
>>             }
>> 
>>         } catch (BuildException e) {
>>             e.printStackTrace();
>>         }
>>         return false;
>> 
>>     }
>
> The problem is that the return value from getSelectedEnum() is always
> the default value (which is != LIB_CONFIG_CUSTOM in this case),
> regardless of the actual state of the combobox in the UI. So the method
> always returns false, and the option is therefore always disabled.

I think the problem is in:
   IOption o = holder.getOptionById(OptionConstants.LIB_CONFIG_OPTION);
this returns the 'original' option as defined in your manifest file,
this by definition will return its default value. Once you change an
option a new instance will be created with a new id, that is the
original id followed by some kind of random number.

As you don't know the random nr part in the id you will have to use
something like the following to get to the actual value:

  String s = null;
  for ( IOption opt : holder.getOptions() ) {
    if ( opt.isExtensionElement() ) {
      // option as loaded from the manifest file
      if ( opt.getId().
              equals(OptionConstants.LIB_CONFIG_CUSTOM)) {
        s = opt.getSelectedEnum();
        break;
      }
    } else {
      // 'changed' option, check its superclass id
      if ( opt.getSuperClass().getId().
              equals(OptionConstants.LIB_CONFIG_CUSTOM)) {
        s = opt.getSelectedEnum();
        break;
      }
    } 
  }

Hope this helps,
  Wieant


Back to the top