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
Method Summary
|
void
|
addPages
(
Wizard wizard)
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. |
IPluginReference[]
|
getDependencies
(
String schemaVersion)
Provides the list of template dependencies. |
String
|
getDescription
()
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
|
getNumberOfWorkUnits
()
The default implementation of the interface method. |
boolean
|
getPagesAdded
()
Tests if wizard pages for this template section have been added. |
protected 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
). |
String
|
getPluginResourceString
(
String key)
Returns the translated version of the resource string represented by the
provided key. |
String
|
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
|
getTargetVersion
()
|
URL
|
getTemplateLocation
()
Returns the URL of the zip file containing template files and directories
that will be created in the plug-in project. |
Object
|
getValue
(
String key)
Returns the value of the variable with a given name. |
protected boolean
|
hasBundleManifest
()
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
|
markPagesAdded
()
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
|
project
protected
IProject project
- The project handle.
model
protected
IPluginModelBase model
- The plug-in model.
KEY_PLUGIN_CLASS
public 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_SIMPLE
public 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_ID
public 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_NAME
public 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_NAME
public 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
AbstractTemplateSection
public AbstractTemplateSection()
getReplacementString
public
String getReplacementString(
String fileName,
String key)
- The default implementation of this method provides values of the
following keys: pluginClass , pluginId and
pluginName .
-
-
Specified by:
-
getReplacementString
in 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.
-
See Also:
-
ITemplateSection.getReplacementString(String,String)
getValue
public
Object getValue(
String key)
-
Description copied from interface:
IVariableProvider
- Returns the value of the variable with a given name.
-
-
Specified by:
-
getValue
in interface
IVariableProvider
-
-
Parameters:
-
key
- the name of the variable
-
Returns:
- the value of the specified variable
-
See Also:
-
IVariableProvider.getValue(String)
getTemplateLocation
public
URL 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 interface
ITemplateSection
-
-
Returns:
- a template location URL
-
See Also:
-
ITemplateSection.getTemplateLocation()
getDescription
public
String 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 interface
ITemplateSection
-
-
Returns:
- a template description
-
See Also:
-
ITemplateSection.getDescription()
getPluginResourceString
public
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()
getPluginResourceBundle
protected 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.
addPages
public void addPages(
Wizard wizard)
-
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 interface
ITemplateSection
-
-
Parameters:
-
wizard
- the host wizard to add pages into
getPagesAdded
public boolean getPagesAdded()
- Tests if wizard pages for this template section have been added.
-
-
Specified by:
-
getPagesAdded
in interface
ITemplateSection
-
-
Returns:
-
true
if wizard pages for this section have been
added, false
otherwise.
markPagesAdded
protected void markPagesAdded()
- Marks that pages have been added to the wizard by this template. Call
this method in 'addPages'.
-
-
-
See Also:
-
addPages(Wizard)
getNumberOfWorkUnits
public int getNumberOfWorkUnits()
- The default implementation of the interface method. The returned value is
1.
-
-
Specified by:
-
getNumberOfWorkUnits
in interface
ITemplateSection
-
-
Returns:
- the number of work units
-
See Also:
-
ITemplateSection.getNumberOfWorkUnits()
getDependencies
public
IPluginReference[] getDependencies(
String schemaVersion)
-
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 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
getSourceFolder
protected
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.
generateFiles
protected 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
generateFiles
protected 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
isOkToCreateFolder
protected 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:
-
true
if the provided folder should be created in
the workspace, false
if the values of the
substitution variables indicate otherwise.
isOkToCreateFile
protected 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 .
updateModel
protected 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
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 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
-
See Also:
-
ITemplateSection.execute(IProject, IPluginModelBase, IProgressMonitor)
createExtension
protected
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
getTargetVersion
protected double getTargetVersion()
-
-
setManifestHeader
protected 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
getManifestHeader
protected
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
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
Copyright (c) IBM Corp. and others 2000, 2008. All Rights Reserved.