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 Summary
Modifier and TypeFieldDescriptionstatic final String
The key for the simple class name of a bundle activator (value="activator")static final String
The key for the package name that will be created by this template (value="packageName").static final String
The key for the main plug-in class of the plug-in that the template is used for (value="pluginClass").static final String
The key for the plug-in id of the plug-in that the template is used for (value="pluginId").static final String
The key for the plug-in name of the plug-in that the template is used for (value="pluginName").protected IPluginModelBase
The plug-in model.protected IProject
The project handle. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds template-related pages to the wizard.protected IPluginExtension
createExtension
(String pointId, boolean reuse) A utility method to create an extension object for the plug-in model from the provided extension point id.void
execute
(IProject project, IPluginModelBase model, IProgressMonitor monitor) The default implementation of the interface method.protected void
generateFiles
(IProgressMonitor monitor) Generates files as part of the template execution.protected void
generateFiles
(IProgressMonitor monitor, URL locationUrl) Generates files as part of the template execution.getDependencies
(String schemaVersion) Provides the list of template dependencies.Returns a description of the section.protected String
getManifestHeader
(String name) Gets a header from within the plug-in's underlying manifest header, if it has one.int
The default implementation of the interface method.boolean
Tests whether this template have had a chance to create its pages.protected abstract ResourceBundle
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 the translated version of the resource string represented by the provided key.getReplacementString
(String fileName, String key) The default implementation of this method provides values of the following keys: pluginClass , pluginId and pluginName .protected IFolder
getSourceFolder
(IProgressMonitor monitor) Returns the folder with Java files in the target project.protected double
Returns the URL of the zip file containing template files and directories that will be created in the plug-in project.Returns the value of the variable with a given name.protected boolean
Determines whether this plug-in has a manifest on which to set/get headers.protected boolean
isOkToCreateFile
(File sourceFile) Tests if the file found in the template location should be created in the target project.protected boolean
isOkToCreateFolder
(File sourceFolder) Tests if the folder found in the template location should be created in the target project.protected void
Marks that pages have been added to the wizard by this template.protected void
setManifestHeader
(String name, String value) Sets a header within the plug-in's underlying manifest header, if it has one.protected abstract void
updateModel
(IProgressMonitor monitor) Subclass must implement this method to add the required entries in the plug-in model.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.pde.ui.templates.ITemplateSection
getLabel, getNewFiles, getPage, getPageCount, getUsedExtensionPoint
-
Field Details
-
project
The project handle. -
model
The plug-in model. -
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:
-
KEY_ACTIVATOR_SIMPLE
The key for the simple class name of a bundle activator (value="activator")- Since:
- 3.3
- See Also:
-
KEY_PLUGIN_ID
The key for the plug-in id of the plug-in that the template is used for (value="pluginId").- See Also:
-
KEY_PLUGIN_NAME
The key for the plug-in name of the plug-in that the template is used for (value="pluginName").- See Also:
-
KEY_PACKAGE_NAME
The key for the package name that will be created by this template (value="packageName").- See Also:
-
-
Constructor Details
-
AbstractTemplateSection
public AbstractTemplateSection()
-
-
Method Details
-
getReplacementString
The default implementation of this method provides values of the following keys: pluginClass , pluginId and pluginName .- Specified by:
getReplacementString
in interfaceITemplateSection
- 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.
-
getValue
Description copied from interface:IVariableProvider
Returns the value of the variable with a given name.- Specified by:
getValue
in interfaceIVariableProvider
- Parameters:
key
- the name of the variable- Returns:
- the value of the specified variable
-
getTemplateLocation
Description copied from interface:ITemplateSection
Returns 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:
getTemplateLocation
in interfaceITemplateSection
- Returns:
- a template location URL
-
getDescription
Description copied from interface:ITemplateSection
Returns 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:
getDescription
in interfaceITemplateSection
- Returns:
- a template description
-
getPluginResourceString
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
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.
-
addPages
Description copied from interface:ITemplateSection
Adds template-related pages to the wizard. A typical section implementation contributes one page, but complex sections may span several pages.- Specified by:
addPages
in interfaceITemplateSection
- Parameters:
wizard
- the host wizard to add pages into
-
getPagesAdded
public boolean getPagesAdded()Description copied from interface:ITemplateSection
Tests whether this template have had a chance to create its pages. This method returns true after 'addPages' has been called.- Specified by:
getPagesAdded
in interfaceITemplateSection
- Returns:
- true if wizard pages have been created by this template.
-
markPagesAdded
protected void markPagesAdded()Marks that pages have been added to the wizard by this template. Call this method in 'addPages'.- See Also:
-
getNumberOfWorkUnits
public int getNumberOfWorkUnits()The default implementation of the interface method. The returned value is 1.- Specified by:
getNumberOfWorkUnits
in interfaceITemplateSection
- Returns:
- the number of work units
-
getDependencies
Description copied from interface:ITemplateSection
Provides 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:
getDependencies
in interfaceITemplateSection
- 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
-
getSourceFolder
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.
-
generateFiles
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
-
generateFiles
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 progresslocationUrl
- a url pointing to a file/directory that will be copied into the template- Throws:
CoreException
- Since:
- 3.3
-
isOkToCreateFolder
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:
true
if the provided folder should be created in the workspace,false
if the values of the substitution variables indicate otherwise.
-
isOkToCreateFile
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 .
-
updateModel
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
-
execute
public 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:
execute
in interfaceITemplateSection
- Parameters:
project
- the workspace project that contains the plug-inmodel
- structured representation of the plug-in manifestmonitor
- progress monitor to indicate execution progress- Throws:
CoreException
- if there is a problem generating resources
-
createExtension
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 pointreuse
- 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
-
getTargetVersion
protected double getTargetVersion() -
setManifestHeader
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 setvalue
- The value of the header- Since:
- 3.4
- See Also:
-
getManifestHeader
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
-
hasBundleManifest
protected 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
-