Search in sources :

Example 1 with ParameterRepository

use of com.biglybt.pifimpl.local.ui.config.ParameterRepository in project BiglyBT by BiglySoftware.

the class ConfigSectionPlugins method initPluginSubSections.

public void initPluginSubSections() {
    // Create subsections for plugins that used the PluginConfigModel object
    // =====================================================================
    TreeItem treePlugins = configView.findTreeItem(ConfigSection.SECTION_PLUGINS);
    ParameterRepository repository = ParameterRepository.getInstance();
    String[] names = repository.getNames();
    Arrays.sort(names);
    for (int i = 0; i < names.length; i++) {
        String pluginName = names[i];
        Parameter[] parameters = repository.getParameterBlock(pluginName);
        // Note: 2070's plugin documentation for PluginInterface.addConfigUIParameters
        // said to pass <"ConfigView.plugins." + displayName>.  This was
        // never implemented in 2070.  2070 read the key <displayName> without
        // the prefix.
        // 
        // 2071+ uses <sSectionPrefix ("ConfigView.section.plugins.") + pluginName>
        // and falls back to <displayName>.  Since
        // <"ConfigView.plugins." + displayName> was never implemented in the
        // first place, a check for it has not been created
        boolean bUsePrefix = MessageText.keyExists(ConfigView.sSectionPrefix + "plugins." + pluginName);
        Composite pluginGroup = configView.createConfigSection(treePlugins, pluginName, -2, bUsePrefix);
        GridLayout pluginLayout = new GridLayout();
        pluginLayout.numColumns = 3;
        pluginGroup.setLayout(pluginLayout);
        Map parameterToPluginParameter = new HashMap();
        // Add all parameters
        for (int j = 0; j < parameters.length; j++) {
            Parameter parameter = parameters[j];
            parameterToPluginParameter.put(parameter, new PluginParameter(pluginGroup, parameter));
        }
        // Check for dependencies
        for (int j = 0; j < parameters.length; j++) {
            Parameter parameter = parameters[j];
            if (parameter instanceof BooleanParameterImpl) {
                List parametersToEnable = ((BooleanParameterImpl) parameter).getEnabledOnSelectionParameters();
                List controlsToEnable = new ArrayList();
                Iterator iter = parametersToEnable.iterator();
                while (iter.hasNext()) {
                    Parameter parameterToEnable = (Parameter) iter.next();
                    PluginParameter pp = (PluginParameter) parameterToPluginParameter.get(parameterToEnable);
                    Control[] controls = pp.getControls();
                    Collections.addAll(controlsToEnable, controls);
                }
                List parametersToDisable = ((BooleanParameterImpl) parameter).getDisabledOnSelectionParameters();
                List controlsToDisable = new ArrayList();
                iter = parametersToDisable.iterator();
                while (iter.hasNext()) {
                    Parameter parameterToDisable = (Parameter) iter.next();
                    PluginParameter pp = (PluginParameter) parameterToPluginParameter.get(parameterToDisable);
                    Control[] controls = pp.getControls();
                    Collections.addAll(controlsToDisable, controls);
                }
                Control[] ce = new Control[controlsToEnable.size()];
                Control[] cd = new Control[controlsToDisable.size()];
                if (ce.length + cd.length > 0) {
                    IAdditionalActionPerformer ap = new DualChangeSelectionActionPerformer((Control[]) controlsToEnable.toArray(ce), (Control[]) controlsToDisable.toArray(cd));
                    PluginParameter pp = (PluginParameter) parameterToPluginParameter.get(parameter);
                    pp.setAdditionalActionPerfomer(ap);
                }
            }
        }
    }
}
Also used : IAdditionalActionPerformer(com.biglybt.ui.swt.config.IAdditionalActionPerformer) ParameterRepository(com.biglybt.pifimpl.local.ui.config.ParameterRepository) GridLayout(org.eclipse.swt.layout.GridLayout) DualChangeSelectionActionPerformer(com.biglybt.ui.swt.config.DualChangeSelectionActionPerformer) PluginParameter(com.biglybt.ui.swt.config.plugins.PluginParameter) Parameter(com.biglybt.pif.ui.config.Parameter) List(java.util.List) PluginParameter(com.biglybt.ui.swt.config.plugins.PluginParameter) BooleanParameterImpl(com.biglybt.pifimpl.local.ui.config.BooleanParameterImpl)

Aggregations

Parameter (com.biglybt.pif.ui.config.Parameter)1 BooleanParameterImpl (com.biglybt.pifimpl.local.ui.config.BooleanParameterImpl)1 ParameterRepository (com.biglybt.pifimpl.local.ui.config.ParameterRepository)1 DualChangeSelectionActionPerformer (com.biglybt.ui.swt.config.DualChangeSelectionActionPerformer)1 IAdditionalActionPerformer (com.biglybt.ui.swt.config.IAdditionalActionPerformer)1 PluginParameter (com.biglybt.ui.swt.config.plugins.PluginParameter)1 List (java.util.List)1 GridLayout (org.eclipse.swt.layout.GridLayout)1