Eclipse PDE
Release 3.0

org.eclipse.pde.ui.templates
Class AbstractTemplateSection

java.lang.Object
  extended byorg.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
static String KEY_PACKAGE_NAME
          The key for the package name that will be created by this teamplate (value="packageName").
static String KEY_PLUGIN_CLASS
          The key for the main plug-in class of the plug-in that the template is used for (value="pluginClass");
static String KEY_PLUGIN_ID
          The key for the plug-in id of the plug-in that the template is used for (value="pluginId").
static String KEY_PLUGIN_NAME
          The key for the plug-in name of the plug-in that the template is used for (value="pluginName").
protected  IPluginModelBase model
          The plug-in model.
protected  IProject project
          The project handle.
 
Constructor Summary
AbstractTemplateSection()
           
 
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.
 IPluginReference[] getDependencies(String schemaVersion)
          Provides the list of template dependencies.
 String getDescription()
          Returns a description of the section.
 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.
 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 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 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 Detail

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");

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 teamplate (value="packageName").

See Also:
Constant Field Values
Constructor Detail

AbstractTemplateSection

public AbstractTemplateSection()
Method Detail

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)

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
See Also:
ITemplateSection#addPages(IBasePluginWizard)

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:
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:
See Also:
ITemplateSection#getDependencies()

getSourceFolder

protected IFolder getSourceFolder(IProgressMonitor monitor)
                           throws CoreException
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.
Throws:
CoreException

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. The files found in the location are processed in the following way:

Parameters:
monitor - progress monitor to use to indicate generation progress
Throws:
CoreException

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 creation of the entire directories (subject to user choices).

Parameters:
sourceFolder - the folder found in the template location that needs to be created.
Returns:
true if the specified folder should be created in the project, or false to skip it, including all subfolders and files it may contain. The default implementation is true .

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 createion 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

Eclipse PDE
Release 3.0

Copyright (c) IBM Corp. and others 2000, 2004. All Rights Reserved.