com.bea.workshop.controls.ui.actions
Class DefaultControlInsertionDelegate

java.lang.Object
  extended by com.bea.workshop.controls.ui.actions.DefaultControlInsertionDelegate
All Implemented Interfaces:
com.bea.workshop.controls.core.model.IControlInsertionDelegate
Direct Known Subclasses:
InsertGenericControlDelegate

public class DefaultControlInsertionDelegate
extends Object
implements com.bea.workshop.controls.core.model.IControlInsertionDelegate


Nested Class Summary
static class DefaultControlInsertionDelegate.AnnotationInfo
          Describes an annotation to be added to a generated control field.
 
Constructor Summary
DefaultControlInsertionDelegate()
           
 
Method Summary
protected  boolean copyJarIfNecessary(com.bea.workshop.controls.core.model.IControlInsertionDelegateContext ctx, File file, String targetFileName)
          Copy the given file into the appropriate library location in the project.
protected  String getDefaultControlDeclarationFieldName(IType primaryType, String shortTypeName)
          By overriding this method, subclasses can provide their own field name.
protected  File getFileFromPlugin(Plugin plugin, String pluginRelativePath)
          Convenience method for retrieving a File from a plugin.
 IJavaElement insertControl(com.bea.workshop.controls.core.model.IControlInsertionDelegateContext context)
          This default implementation does only the work of inserting a control field into the compilation unit's primary type.
 IJavaElement insertControl(com.bea.workshop.controls.core.model.IControlInsertionDelegateContext context, List<DefaultControlInsertionDelegate.AnnotationInfo> extraAnnotations)
          Insert a control reference, as described in insertControl(IControlInsertionDelegateContext), with an option to add configuration information in the form of extra annotations.
 IJavaElement insertControl(com.bea.workshop.controls.core.model.IControlInsertionDelegateContext context, String annotationName, Map<String,String> annotationAttrs)
          Convenience method to insert a control with a single configuration annotation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultControlInsertionDelegate

public DefaultControlInsertionDelegate()
Method Detail

insertControl

public IJavaElement insertControl(com.bea.workshop.controls.core.model.IControlInsertionDelegateContext context)
This default implementation does only the work of inserting a control field into the compilation unit's primary type. It does not show any wizard dialog or do anything else to collect user input. Subclassers may do so if they choose, and can continue to delegate to this class to do the field insertion if they wish. The example output of calling this is:

import org.apache.beehive.controls.api.bean.Control;
import com.somecontrolprovider.AnExampleControl;

...

@Control
private AnExampleControl control1;

Specified by:
insertControl in interface com.bea.workshop.controls.core.model.IControlInsertionDelegate
Parameters:
context - the IControlInsertionDelegateContext that provides contextual information for the control insertion, and also allows some parameterization of the insertion.
Returns:
a reference to the newly inserted Java element or null if the control insertion was not successful.

insertControl

public IJavaElement insertControl(com.bea.workshop.controls.core.model.IControlInsertionDelegateContext context,
                                  String annotationName,
                                  Map<String,String> annotationAttrs)
Convenience method to insert a control with a single configuration annotation. This annotation will be passed to insertControl(IControlInsertionDelegateContext, List).


insertControl

public IJavaElement insertControl(com.bea.workshop.controls.core.model.IControlInsertionDelegateContext context,
                                  List<DefaultControlInsertionDelegate.AnnotationInfo> extraAnnotations)
Insert a control reference, as described in insertControl(IControlInsertionDelegateContext), with an option to add configuration information in the form of extra annotations.

If any extra annotations are provided, they will be added to the new control reference field. All attributes must be provided as strings, but they will be rendered as the types that they are declared on the annotation definition. (i.e. without quotes where necessary) This can be used for configuring a new control, and will produce something like:

@ExampleSettings( someKey="someValue", someOtherKey=true ) @Control
private AnExampleControl control1;


getDefaultControlDeclarationFieldName

protected final String getDefaultControlDeclarationFieldName(IType primaryType,
                                                             String shortTypeName)
By overriding this method, subclasses can provide their own field name.

Parameters:
shortTypeName - The type name to use for the field, which would normally be the unqualified control type
primaryType - the primary (outermost) type for the compilation unit in which the control field is being inserted.

copyJarIfNecessary

protected boolean copyJarIfNecessary(com.bea.workshop.controls.core.model.IControlInsertionDelegateContext ctx,
                                     File file,
                                     String targetFileName)
                              throws FileNotFoundException,
                                     CoreException
Copy the given file into the appropriate library location in the project. If the project is a web project, this will be the WEB-INF/lib of the project. If it's not a Web Project, it will be the APP-INF/lib of a referencing EAR project. If it's in multiple EAR projects, the first one will be used. If the file already exists, this will no-op.
After copying the file, this will cause the project to refresh so that any types in the jar will be available.
To copy a file that lives in a plugin, getFileFromPlugin(Plugin, String) can be used to get a java.io.File reference to it to pass to this method.

Parameters:
ctx - The IControlInsertionDelegateContext for this insertion delegate
file - The file to copy
targetFileName - The name to give the file after copying
Returns:
true if the jar was copied, false if it already existed
Throws:
FileNotFoundException - if the file to copy does not exist
CoreException - if an error occurs while copying the file
IllegalArgumentException - if the current project is not a valid web or ear project

getFileFromPlugin

protected File getFileFromPlugin(Plugin plugin,
                                 String pluginRelativePath)
                          throws CoreException
Convenience method for retrieving a File from a plugin. This can be used when calling copyJarIfNecessary(IControlInsertionDelegateContext, File, String) to copy a jar that lives in a plugin.

Parameters:
plugin - The Plugin that contains the file
pluginRelativePath - The path to the file, relative to the plugin root
Returns:
a File object for that file
Throws:
IllegalArgumentException - if the file does not exist
CoreException - if there is a problem retrieving the file