Class BaseOptionTemplateSection

java.lang.Object
org.eclipse.pde.ui.templates.AbstractTemplateSection
org.eclipse.pde.ui.templates.BaseOptionTemplateSection
All Implemented Interfaces:
ITemplateSection, IVariableProvider
Direct Known Subclasses:
OptionTemplateSection

public abstract class BaseOptionTemplateSection extends AbstractTemplateSection
This class adds a notion of options to the default template section implementation. Options have values and visual presence that allows users to change them. When a section is configured with a number of options, they become available to the code generator and can take part in conditional code emitting.

This class is typically used in conjunction with OptionTemplateWizardPage . The later is capable of creating UI based on the list of options it was given, thus simplifying new template section creation.

Since:
2.0
  • Constructor Details

    • BaseOptionTemplateSection

      public BaseOptionTemplateSection()
  • Method Details

    • addOption

      protected TemplateOption addOption(String name, String label, boolean value, int pageIndex)
      Adds a boolean option with a provided name, label and initial value.
      Parameters:
      name - the unique name of the option (can be used as a variable in conditional code emitting and variable substitution)
      label - presentable name of the option
      value - initial value of the option
      pageIndex - a zero-based index of a page where this option should appear
      Returns:
      the newly created option
    • addOption

      protected TemplateOption addOption(String name, String label, String value, int pageIndex)
      Adds a string option with a provided name, label and initial value.
      Parameters:
      name - the unique name of the option (can be used as a variable in conditional code emitting and variable substitution)
      label - presentable name of the option
      value - initial value of the option
      pageIndex - a zero-based index of a page where this option should appear
      Returns:
      the newly created option
    • addOption

      protected TemplateOption addOption(String name, String label, String[][] choices, String value, int pageIndex)
      Adds a choice option with a provided name, label, list of choices and the initial value (choice).
      Parameters:
      name - the unique name of the option (can be used as a variable in conditional code emitting and variable substitution)
      label - presentable name of the option
      choices - an array of choices that the user will have when setting the value of the option. Each array position should accept an array of String objects of size 2, the first being the unique name and the second the presentable label of the choice.
      value - initial value (choice) of the option
      pageIndex - a zero-based index of a page where this option should appear
      Returns:
      the newly created option
    • addComboChoiceOption

      protected ComboChoiceOption addComboChoiceOption(String name, String label, String[][] choices, String value, int pageIndex)
      Force a combo choice representation. Radio buttons look bad - even if only two options specified.
      Parameters:
      name - the unique name
      label - the presentable label
      choices - the list of choices from which the value can be chosen. Each array entry should be an array of size 2, where position 0 will be interpeted as the choice unique name, and position 1 as the choice presentable label.
      value - registerOption
      pageIndex - the page index to which this option belongs
      Returns:
      the newly created option
    • addBlankField

      protected TemplateOption addBlankField(int pageIndex)
      Adds a blank field with a default height to provide spacing.
      Parameters:
      pageIndex - a zero-based index of a page where this option should appear
      Returns:
      the newly created option
    • addBlankField

      protected TemplateOption addBlankField(int height, int pageIndex)
      Adds a blank field with a specific height to provide spacing.
      Parameters:
      height - specifies the height of the blank field in pixels
      pageIndex - a zero-based index of a page where this option should appear
      Returns:
      the newly created option
    • initializeOption

      protected void initializeOption(String name, Object value)
      Initializes the option with a given unique name with the provided value. The value will be set only if the option has not yet been initialized.
      Parameters:
      name - option unique name
      value - the initial value of the option
    • getStringOption

      public String getStringOption(String name)
      Returns a string value of the option with a given name. The option with that name must exist and must be registered as a string option to begin with.
      Parameters:
      name - the unique name of the option
      Returns:
      the string value of the option with a given name or null if not found.
    • getBooleanOption

      public boolean getBooleanOption(String key)
      Returns a boolean value of the option with a given name. The option with that name must exist and must be registered as a boolean option to begin with.
      Parameters:
      key - the unique name of the option
      Returns:
      the boolean value of the option with a given name or null if not found.
    • setOptionEnabled

      public void setOptionEnabled(String name, boolean enabled)
      Enables the option with a given name. The exact effect of the method depends on the option type, but the end-result should always be the same - users should not be able to modify values of disabled options. This method has no effect if the option with a given name is not found.
      Parameters:
      name - the unique name of the option
      enabled - the enable state that the option should have
    • getValue

      public Object getValue(String name)
      Returns the value of the option with a given name. The actual type of the returned object depends on the option type.
      Specified by:
      getValue in interface IVariableProvider
      Overrides:
      getValue in class AbstractTemplateSection
      Parameters:
      name - the name of the option
      Returns:
      the current value of the option with a specified name or null if not found or not applicable.
    • isDependentOnParentWizard

      public boolean isDependentOnParentWizard()
      Returns true if this template depends on values set in the parent wizard. Values in the parent wizard include plug-in id, plug-in name, plug-in class name, plug-in provider etc. If the template does depend on these values, initializeFields will be called when the page is made visible in the forward direction (going from the first page to the pages owned by this template). If the page is never shown (Finish is pressed before the page is made visible at least once), initializeFields will be called with the model object instead during template execution. The same method will also be called when the template is created within the context of the plug-in manifest editor, because plug-in model already exists at that time.
      Returns:
      true if this template depends on the data set in the parent wizard, false otherwise.
    • initializeFields

      protected void initializeFields(IFieldData data)
      Initializes options in the wizard page using the data provided by the method parameters. Some options may depend on the user selection in the common wizard pages before template page has been shown (for example, plug-in ID, plug-in name etc.). This method allows options to initialize in respect to these values.

      The method is called before the actual plug-in has been built.

      Parameters:
      data - plug-in data as defined in the common plug-in project wizard pages
    • initializeFields

      public void initializeFields(IPluginModelBase model)
      Initializes options in the wizard page using the data provided by the method parameters. Some options may depend on the user selection in the common wizard pages before template page has been shown (for example, plug-in ID, plug-in name etc.). This method allows options to initialize in respect to these values.

      This method is called after the plug-in has already been created or as part of new extension creation (inside the manifest editor). Either way, the plug-in properties in the model have been fully set and the model can be used to initialize options that cannot be initialized independently.

      Parameters:
      model - the model of the plug-in manifest file.
    • validateOptions

      public abstract void validateOptions(TemplateOption changed)
      Subclasses must implement this method in order to validate options whose value have been changed by the user. The subclass can elect to validate the option on its own, or to also check validity of other options in relation to the new value of this one.
      Parameters:
      changed - the option whose value has been changed by the user
    • getReplacementString

      public String getReplacementString(String fileName, String key)
      Expands variable substitution to include all string options defined in this template.
      Specified by:
      getReplacementString in interface ITemplateSection
      Overrides:
      getReplacementString in class AbstractTemplateSection
      Parameters:
      fileName - the name of the file in which the key was found. You can use it to return different values for different files.
      key - the replacement key found in the template file
      Returns:
      replacement string for the provided key, or the key itself if not found.
      See Also:
    • execute

      public void execute(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException
      Description copied from class: AbstractTemplateSection
      The default implementation of the interface method. It will generate required files found in the template location and then call updateModel to add the required manifest entires.
      Specified by:
      execute in interface ITemplateSection
      Overrides:
      execute in class AbstractTemplateSection
      Parameters:
      project - the workspace project that contains the plug-in
      model - structured representation of the plug-in manifest
      monitor - progress monitor to indicate execution progress
      Throws:
      CoreException - if there is a problem generating resources
    • registerOption

      protected void registerOption(TemplateOption option, Object value, int pageIndex)
      Registers the provided option and sets the initial value.
      Parameters:
      option - the option to register
      value - the initial value
      pageIndex - the page index to which this option belongs