Package org.eclipse.pde.ui.templates
Class AbstractTemplateSection
- java.lang.Object
- 
- org.eclipse.pde.ui.templates.AbstractTemplateSection
 
- 
- All Implemented Interfaces:
- ITemplateSection,- IVariableProvider
 - Direct Known Subclasses:
- BaseOptionTemplateSection
 
 public abstract class AbstractTemplateSection extends Object implements ITemplateSection, IVariableProvider Common function for template sections. It is recommended to subclass this class rather than implementing ITemplateSection directly when providing extension templates.- Since:
- 2.0
 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringKEY_ACTIVATOR_SIMPLEThe key for the simple class name of a bundle activator (value="activator")static StringKEY_PACKAGE_NAMEThe key for the package name that will be created by this template (value="packageName").static StringKEY_PLUGIN_CLASSThe key for the main plug-in class of the plug-in that the template is used for (value="pluginClass").static StringKEY_PLUGIN_IDThe key for the plug-in id of the plug-in that the template is used for (value="pluginId").static StringKEY_PLUGIN_NAMEThe key for the plug-in name of the plug-in that the template is used for (value="pluginName").protected IPluginModelBasemodelThe plug-in model.protected IProjectprojectThe project handle.
 - 
Constructor SummaryConstructors Constructor Description AbstractTemplateSection()
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddPages(Wizard wizard)Adds template-related pages to the wizard.protected IPluginExtensioncreateExtension(String pointId, boolean reuse)A utility method to create an extension object for the plug-in model from the provided extension point id.voidexecute(IProject project, IPluginModelBase model, IProgressMonitor monitor)The default implementation of the interface method.protected voidgenerateFiles(IProgressMonitor monitor)Generates files as part of the template execution.protected voidgenerateFiles(IProgressMonitor monitor, URL locationUrl)Generates files as part of the template execution.IPluginReference[]getDependencies(String schemaVersion)Provides the list of template dependencies.StringgetDescription()Returns a description of the section.protected StringgetManifestHeader(String name)Gets a header from within the plug-in's underlying manifest header, if it has one.intgetNumberOfWorkUnits()The default implementation of the interface method.booleangetPagesAdded()Tests whether this template have had a chance to create its pages.protected abstract ResourceBundlegetPluginResourceBundle()An abstract method that returns the resource bundle that corresponds to the best match of plugin.properties file for the current locale (in case of fragments, the file is fragment.properties ).StringgetPluginResourceString(String key)Returns the translated version of the resource string represented by the provided key.StringgetReplacementString(String fileName, String key)The default implementation of this method provides values of the following keys: pluginClass , pluginId and pluginName .protected IFoldergetSourceFolder(IProgressMonitor monitor)Returns the folder with Java files in the target project.protected doublegetTargetVersion()URLgetTemplateLocation()Returns the URL of the zip file containing template files and directories that will be created in the plug-in project.ObjectgetValue(String key)Returns the value of the variable with a given name.protected booleanhasBundleManifest()Determines whether this plug-in has a manifest on which to set/get headers.protected booleanisOkToCreateFile(File sourceFile)Tests if the file found in the template location should be created in the target project.protected booleanisOkToCreateFolder(File sourceFolder)Tests if the folder found in the template location should be created in the target project.protected voidmarkPagesAdded()Marks that pages have been added to the wizard by this template.protected voidsetManifestHeader(String name, String value)Sets a header within the plug-in's underlying manifest header, if it has one.protected abstract voidupdateModel(IProgressMonitor monitor)Subclass must implement this method to add the required entries in the plug-in model.- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.eclipse.pde.ui.templates.ITemplateSectiongetLabel, getNewFiles, getPage, getPageCount, getUsedExtensionPoint
 
- 
 
- 
- 
- 
Field Detail- 
projectprotected IProject project The project handle.
 - 
modelprotected IPluginModelBase model The plug-in model.
 - 
KEY_PLUGIN_CLASSpublic static final String KEY_PLUGIN_CLASS The key for the main plug-in class of the plug-in that the template is used for (value="pluginClass"). The return value is a fully-qualified class name.- See Also:
- Constant Field Values
 
 - 
KEY_ACTIVATOR_SIMPLEpublic static final String KEY_ACTIVATOR_SIMPLE The key for the simple class name of a bundle activator (value="activator")- Since:
- 3.3
- See Also:
- Constant Field Values
 
 - 
KEY_PLUGIN_IDpublic static final String KEY_PLUGIN_ID The key for the plug-in id of the plug-in that the template is used for (value="pluginId").- See Also:
- Constant Field Values
 
 - 
KEY_PLUGIN_NAMEpublic static final String KEY_PLUGIN_NAME The key for the plug-in name of the plug-in that the template is used for (value="pluginName").- See Also:
- Constant Field Values
 
 - 
KEY_PACKAGE_NAMEpublic static final String KEY_PACKAGE_NAME The key for the package name that will be created by this template (value="packageName").- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getReplacementStringpublic String getReplacementString(String fileName, String key) The default implementation of this method provides values of the following keys: pluginClass , pluginId and pluginName .- Specified by:
- getReplacementStringin interface- ITemplateSection
- 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.
 
 - 
getValuepublic Object getValue(String key) Description copied from interface:IVariableProviderReturns the value of the variable with a given name.- Specified by:
- getValuein interface- IVariableProvider
- Parameters:
- key- the name of the variable
- Returns:
- the value of the specified variable
 
 - 
getTemplateLocationpublic URL getTemplateLocation() Description copied from interface:ITemplateSectionReturns the URL of the zip file containing template files and directories that will be created in the plug-in project. If URL protocol is 'file', and the URL ends with a trailing file separator, an attempt will be made to treat the URL as a root directory and iterate using standard Java I/O classes. If template files are stored in a ZIP or JAR archive, the name of the archive must be part of the URL.- Specified by:
- getTemplateLocationin interface- ITemplateSection
- Returns:
- a template location URL
 
 - 
getDescriptionpublic String getDescription() Description copied from interface:ITemplateSectionReturns a description of the section. The description should explain what extension will be used, what classes will be generated and how to test that the generated code works properly.- Specified by:
- getDescriptionin interface- ITemplateSection
- Returns:
- a template description
 
 - 
getPluginResourceStringpublic String getPluginResourceString(String key) Returns the translated version of the resource string represented by the provided key.- Parameters:
- key- the key of the required resource string
- Returns:
- the translated version of the required resource string
- See Also:
- getPluginResourceBundle()
 
 - 
getPluginResourceBundleprotected abstract ResourceBundle getPluginResourceBundle() An abstract method that returns the resource bundle that corresponds to the best match of plugin.properties file for the current locale (in case of fragments, the file is fragment.properties ).- Returns:
- resource bundle for plug-in properties file or null if not found.
 
 - 
addPagespublic void addPages(Wizard wizard) Description copied from interface:ITemplateSectionAdds template-related pages to the wizard. A typical section implementation contributes one page, but complex sections may span several pages.- Specified by:
- addPagesin interface- ITemplateSection
- Parameters:
- wizard- the host wizard to add pages into
 
 - 
getPagesAddedpublic boolean getPagesAdded() Description copied from interface:ITemplateSectionTests whether this template have had a chance to create its pages. This method returns true after 'addPages' has been called.- Specified by:
- getPagesAddedin interface- ITemplateSection
- Returns:
- true if wizard pages have been created by this template.
 
 - 
markPagesAddedprotected void markPagesAdded() Marks that pages have been added to the wizard by this template. Call this method in 'addPages'.- See Also:
- addPages(Wizard)
 
 - 
getNumberOfWorkUnitspublic int getNumberOfWorkUnits() The default implementation of the interface method. The returned value is 1.- Specified by:
- getNumberOfWorkUnitsin interface- ITemplateSection
- Returns:
- the number of work units
 
 - 
getDependenciespublic IPluginReference[] getDependencies(String schemaVersion) Description copied from interface:ITemplateSectionProvides the list of template dependencies. A template may generate a number of Java classes that reference classes and interfaces from other plug-ins. By providing this list, a template enables the template wizard to create the correct Java build path so that these classes and interfaces are correctly resolved.- Specified by:
- getDependenciesin interface- ITemplateSection
- Parameters:
- schemaVersion- version of the target manifest, or null if older manifest (prior to 3.0) will be created. Depending on the manifest version, the list of dependencies may vary.
- Returns:
- an array of template dependencies
 
 - 
getSourceFolderprotected IFolder getSourceFolder(IProgressMonitor monitor) Returns the folder with Java files in the target project. The default implementation looks for source folders in the classpath of the target folders and picks the first one encountered. Subclasses may override this behaviour.- Parameters:
- monitor- progress monitor to use
- Returns:
- source folder that will be used to generate Java files or null if none found.
 
 - 
generateFilesprotected void generateFiles(IProgressMonitor monitor) throws CoreException Generates files as part of the template execution. The default implementation uses template location as a root of the file templates.generateFiles(IProgressMonitor monitor, URL locationUrl)on how the location gets processed.- Parameters:
- monitor- progress monitor to use to indicate generation progress
- Throws:
- CoreException
 
 - 
generateFilesprotected void generateFiles(IProgressMonitor monitor, URL locationUrl) throws CoreException Generates files as part of the template execution. The files found in the location are processed in the following way:- Files and folders found in the directory bin are copied into the target project without modification.
- Files found in the directory java are copied into the Java source folder by creating the folder structure that corresponds to the package name (variable packageName ). Java files are subject to conditional generation and variable replacement.
- All other files and folders are copied directly into the target folder with the conditional generation and variable replacement for files. Variable replacement also includes file names.
 - Parameters:
- monitor- progress monitor to use to indicate generation progress
- locationUrl- a url pointing to a file/directory that will be copied into the template
- Throws:
- CoreException
- Since:
- 3.3
 
 - 
isOkToCreateFolderprotected boolean isOkToCreateFolder(File sourceFolder) Tests if the folder found in the template location should be created in the target project. Subclasses may use this method to conditionally block the creation of entire directories (subject to user choices).- Parameters:
- sourceFolder- the folder that is tested
- Returns:
- trueif the provided folder should be created in the workspace,- falseif the values of the substitution variables indicate otherwise.
 
 - 
isOkToCreateFileprotected boolean isOkToCreateFile(File sourceFile) Tests if the file found in the template location should be created in the target project. Subclasses may use this method to conditionally block creation of the file (subject to user choices).- Parameters:
- sourceFile- the file found in the template location that needs to be created.
- Returns:
- true if the specified file should be created in the project or false to skip it. The default implementation is true .
 
 - 
updateModelprotected abstract void updateModel(IProgressMonitor monitor) throws CoreException Subclass must implement this method to add the required entries in the plug-in model.- Parameters:
- monitor- the progress monitor to be used
- Throws:
- CoreException
 
 - 
executepublic void execute(IProject project, IPluginModelBase model, IProgressMonitor monitor) throws CoreException 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:
- executein interface- ITemplateSection
- 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
 
 - 
createExtensionprotected IPluginExtension createExtension(String pointId, boolean reuse) throws CoreException A utility method to create an extension object for the plug-in model from the provided extension point id.- Parameters:
- pointId- the identifier of the target extension point
- reuse- if true, new extension object will be created only if an extension with the same Id does not exist.
- Returns:
- an existing extension (if exists and reuse is true ), or a new extension object otherwise.
- Throws:
- CoreException
 
 - 
getTargetVersionprotected double getTargetVersion() 
 - 
setManifestHeaderprotected void setManifestHeader(String name, String value) Sets a header within the plug-in's underlying manifest header, if it has one. It the plug-in doesn't have a manifest, this method does nothing. It's expected that this method will only be called by sub-classes during execution of the template (i.e. during the sub-class's updateModel(...) method).
 For example:- setManifestHeader(Constants.BUNDLE_LOCALIZATION, "plugin")
 - Parameters:
- name- The name of the header to set
- value- The value of the header
- Since:
- 3.4
- See Also:
- Constants
 
 - 
getManifestHeaderprotected String getManifestHeader(String name) Gets a header from within the plug-in's underlying manifest header, if it has one. If the plug-in doesn't have a manifest, this method returns null. It's expected that this method will only be called by sub-classes during execution of the template (i.e. during the sub-class's updateModel(...) method).- Parameters:
- name- The name of the header to fetch
- Returns:
- The value of the manifest header, if available, otherwise null
- Since:
- 3.4
 
 - 
hasBundleManifestprotected boolean hasBundleManifest() Determines whether this plug-in has a manifest on which to set/get headers. This method will return false if the plug-in doesn't have a manifest (e.g. it's a v3.0 plug-in) or if the method is called before the model has been set on the template. It's expected that this method will only be called by sub-classes during execution of the template (i.e. during the sub-class's updateModel(...) method).- Returns:
- true if the plug-in has a manifest, false otherwise
- Since:
- 3.4
 
 
- 
 
-