Eclipse JDT
2.0

org.eclipse.jdt.ui.wizards
Class NewTypeWizardPage

java.lang.Object
  |
  +--org.eclipse.jface.dialogs.DialogPage
        |
        +--org.eclipse.jface.wizard.WizardPage
              |
              +--org.eclipse.jdt.ui.wizards.NewElementWizardPage
                    |
                    +--org.eclipse.jdt.ui.wizards.NewContainerWizardPage
                          |
                          +--org.eclipse.jdt.ui.wizards.NewTypeWizardPage
All Implemented Interfaces:
IDialogPage, IMessageProvider, IWizardPage
Direct Known Subclasses:
NewClassWizardPage, NewInterfaceWizardPage

public abstract class NewTypeWizardPage
extends NewContainerWizardPage

The class NewTypeWizardPage contains controls and validation routines for a 'New Type WizardPage'. Implementors decide which components to add and to enable. Implementors can also customize the validation code. NewTypeWizardPage is intended to serve as base class of all wizards that create types like applets, servlets, classes, interfaces, etc.

See NewClassWizardPage or NewInterfaceWizardPage for an example usage of NewTypeWizardPage.

Since:
2.0
See Also:
NewClassWizardPage, NewInterfaceWizardPage

Nested Class Summary
static class NewTypeWizardPage.ImportsManager
          Class used in stub creation routines to add needed imports to a compilation unit.
 
Field Summary
protected static String ENCLOSING
          Field ID of the eclosing type input field
protected static String ENCLOSINGSELECTION
          Field ID of the enclosing type checkbox
 int F_ABSTRACT
          Abstract property flag.
 int F_FINAL
          Final access flag.
 int F_PRIVATE
          Private access flag.
 int F_PROTECTED
          Protected access flag.
 int F_PUBLIC
          Public access flag.
 int F_STATIC
          Static access flag.
protected  IStatus fEnclosingTypeStatus
           
protected  IStatus fModifierStatus
           
protected  IStatus fPackageStatus
           
protected  IStatus fSuperClassStatus
           
protected  IStatus fSuperInterfacesStatus
           
protected  IStatus fTypeNameStatus
           
protected static String INTERFACES
          Field ID of the super interfaces input field
protected static String METHODS
          Field ID of the method stubs checkboxes
protected static String MODIFIERS
          Field ID of the modifier checkboxes
protected static String PACKAGE
          Field ID of the package input field
protected static String SUPER
          Field ID of the super type input field
protected static String TYPENAME
          Field ID of the type name input field
 
Fields inherited from class org.eclipse.jdt.ui.wizards.NewContainerWizardPage
CONTAINER, fContainerStatus
 
Fields inherited from interface org.eclipse.jface.dialogs.IMessageProvider
ERROR, INFORMATION, NONE, WARNING
 
Constructor Summary
NewTypeWizardPage(boolean isClass, String pageName)
          Creates a new NewTypeWizardPage
 
Method Summary
protected  void createEnclosingTypeControls(Composite composite, int nColumns)
          Creates the controls for the enclosing type name field.
protected  IMethod[] createInheritedMethods(IType type, boolean doConstructors, boolean doUnimplementedMethods, org.eclipse.jdt.internal.corext.codemanipulation.IImportsStructure imports, IProgressMonitor monitor)
          Deprecated. Use createInheritedMethods(IType,boolean,boolean,IImportsManager,IProgressMonitor)
protected  IMethod[] createInheritedMethods(IType type, boolean doConstructors, boolean doUnimplementedMethods, NewTypeWizardPage.ImportsManager imports, IProgressMonitor monitor)
          Creates the bodies of all unimplemented methods and constructors and adds them to the type.
protected  void createModifierControls(Composite composite, int nColumns)
          Creates the controls for the modifiers radio/ceckbox buttons.
protected  void createPackageControls(Composite composite, int nColumns)
          Creates the controls for the package name field.
protected  void createSeparator(Composite composite, int nColumns)
          Creates a separator line.
protected  void createSuperClassControls(Composite composite, int nColumns)
          Creates the controls for the superclass name field.
protected  void createSuperInterfacesControls(Composite composite, int nColumns)
          Creates the controls for the superclass name field.
 void createType(IProgressMonitor monitor)
          Creates the new type using the entered field values.
protected  void createTypeMembers(IType newType, org.eclipse.jdt.internal.corext.codemanipulation.IImportsStructure imports, IProgressMonitor monitor)
          Deprecated. Overwrite createTypeMembers(IType, IImportsManager, IProgressMonitor) instead
protected  void createTypeMembers(IType newType, NewTypeWizardPage.ImportsManager imports, IProgressMonitor monitor)
          Hook method that gets called from createType to support adding of unanticipated methods, fields, and inner types to the created type.
protected  void createTypeNameControls(Composite composite, int nColumns)
          Creates the controls for the type name field.
protected  IStatus enclosingTypeChanged()
          Hook method that gets called when the enclosing type name has changed.
 IType getCreatedType()
          Returns the created type.
 IType getEnclosingType()
          Returns the enclosing type corresponding to the current input.
 String getEnclosingTypeText()
          Returns the text of the enclosing type input field.
protected  String getFileComment(ICompilationUnit parentCU)
          Hook mathod that gets called from createType to retrieve a file comment.
 int getModifiers()
          Returns the selected modifiers.
 IPackageFragment getPackageFragment()
          Returns the package fragment corresponding to the current input.
 String getPackageText()
          Returns the text of the package input field.
 IRunnableWithProgress getRunnable()
          Returns the runnable that creates the type using the current settings.
 String getSuperClass()
          Returns the content of the superclass input field.
 List getSuperInterfaces()
          Returns the chosen super interfaces.
protected  String getTemplate(String name, ICompilationUnit parentCU)
          Deprecated. Use getTemplate(String,ICompilationUnit,int)
protected  String getTemplate(String name, ICompilationUnit parentCU, int pos)
          Returns the string resulting from evaluation the given template in the context of the given compilation unit.
protected  String getTypeComment(ICompilationUnit parentCU)
          Hook method that gets called from createType to retrieve a type comment.
 String getTypeName()
          Returns the type name entered into the type input field.
protected  void handleFieldChanged(String fieldName)
          Hook method that gets called when a field on this page has changed.
protected  void initTypePage(IJavaElement elem)
          Initializes all fields provided by the page with a given selection.
 boolean isEnclosingTypeSelected()
          Returns the selection state of the enclosing type checkbox.
protected  IStatus modifiersChanged()
          Hook method that gets called when the modifiers have changed.
protected  IStatus packageChanged()
          A hook method that gets called when the package field has changed.
 void setEnclosingType(IType type, boolean canBeModified)
          Sets the enclosing type.
 void setEnclosingTypeSelection(boolean isSelected, boolean canBeModified)
          Sets the enclosing type checkbox's selection state.
protected  void setFocus()
          Sets the focus on the type name input field.
 void setModifiers(int modifiers, boolean canBeModified)
          Sets the modifiers.
 void setPackageFragment(IPackageFragment pack, boolean canBeModified)
          Sets the package fragment to the given value.
 void setSuperClass(String name, boolean canBeModified)
          Sets the super class name.
 void setSuperInterfaces(List interfacesNames, boolean canBeModified)
          Sets the super interfaces.
 void setTypeName(String name, boolean canBeModified)
          Sets the type name input field's text to the given value.
protected  IStatus superClassChanged()
          Hook method that gets called when the superclass name has changed.
protected  IStatus superInterfacesChanged()
          Hook method that gets called when the list of super interface has changed.
protected  IStatus typeNameChanged()
          Hook method that gets called when the type name has changed.
 
Methods inherited from class org.eclipse.jdt.ui.wizards.NewContainerWizardPage
containerChanged, createContainerControls, getInitialJavaElement, getMaxFieldWidth, getPackageFragmentRoot, getPackageFragmentRootText, getWorkspaceRoot, initContainerPage, setFocusOnContainer, setPackageFragmentRoot
 
Methods inherited from class org.eclipse.jdt.ui.wizards.NewElementWizardPage
setVisible, updateStatus, updateStatus
 
Methods inherited from class org.eclipse.jface.wizard.WizardPage
canFlipToNextPage, getContainer, getDialogSettings, getImage, getName, getNextPage, getPreviousPage, getShell, getWizard, isCurrentPage, isPageComplete, setDescription, setErrorMessage, setImageDescriptor, setMessage, setPageComplete, setPreviousPage, setTitle, setWizard, toString
 
Methods inherited from class org.eclipse.jface.dialogs.DialogPage
convertHeightInCharsToPixels, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, convertWidthInCharsToPixels, createControl, dispose, getControl, getDescription, getDialogFontName, getErrorMessage, getFont, getMessage, getMessageType, getTitle, getToolTipText, initializeDialogUnits, isControlCreated, performHelp, setControl, setMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.dialogs.IDialogPage
createControl, dispose, getControl, getDescription, getErrorMessage, getMessage, getTitle, performHelp
 

Field Detail

F_PUBLIC

public int F_PUBLIC
Public access flag. See The Java Virtual Machine Specification for more details.


F_PRIVATE

public int F_PRIVATE
Private access flag. See The Java Virtual Machine Specification for more details.


F_PROTECTED

public int F_PROTECTED
Protected access flag. See The Java Virtual Machine Specification for more details.


F_STATIC

public int F_STATIC
Static access flag. See The Java Virtual Machine Specification for more details.


F_FINAL

public int F_FINAL
Final access flag. See The Java Virtual Machine Specification for more details.


F_ABSTRACT

public int F_ABSTRACT
Abstract property flag. See The Java Virtual Machine Specification for more details.


PACKAGE

protected static final String PACKAGE
Field ID of the package input field

See Also:
Constant Field Values

ENCLOSING

protected static final String ENCLOSING
Field ID of the eclosing type input field

See Also:
Constant Field Values

ENCLOSINGSELECTION

protected static final String ENCLOSINGSELECTION
Field ID of the enclosing type checkbox

See Also:
Constant Field Values

TYPENAME

protected static final String TYPENAME
Field ID of the type name input field

See Also:
Constant Field Values

SUPER

protected static final String SUPER
Field ID of the super type input field

See Also:
Constant Field Values

INTERFACES

protected static final String INTERFACES
Field ID of the super interfaces input field

See Also:
Constant Field Values

MODIFIERS

protected static final String MODIFIERS
Field ID of the modifier checkboxes

See Also:
Constant Field Values

METHODS

protected static final String METHODS
Field ID of the method stubs checkboxes

See Also:
Constant Field Values

fEnclosingTypeStatus

protected IStatus fEnclosingTypeStatus

fPackageStatus

protected IStatus fPackageStatus

fTypeNameStatus

protected IStatus fTypeNameStatus

fSuperClassStatus

protected IStatus fSuperClassStatus

fModifierStatus

protected IStatus fModifierStatus

fSuperInterfacesStatus

protected IStatus fSuperInterfacesStatus
Constructor Detail

NewTypeWizardPage

public NewTypeWizardPage(boolean isClass,
                         String pageName)
Creates a new NewTypeWizardPage

Parameters:
isClass - true if a new class is to be created; otherwise an interface is to be created
pageName - the wizard page's name
Method Detail

initTypePage

protected void initTypePage(IJavaElement elem)
Initializes all fields provided by the page with a given selection.

Parameters:
elem - the selection used to intialize this page or null if no selection was available

createSeparator

protected void createSeparator(Composite composite,
                               int nColumns)
Creates a separator line. Expects a GridLayout with at least 1 column.

Parameters:
composite - the parent composite
nColumns - number of columns to span

createPackageControls

protected void createPackageControls(Composite composite,
                                     int nColumns)
Creates the controls for the package name field. Expects a GridLayout with at least 4 columns.

Parameters:
composite - the parent composite
nColumns - number of columns to span

createEnclosingTypeControls

protected void createEnclosingTypeControls(Composite composite,
                                           int nColumns)
Creates the controls for the enclosing type name field. Expects a GridLayout with at least 4 columns.

Parameters:
composite - the parent composite
nColumns - number of columns to span

createTypeNameControls

protected void createTypeNameControls(Composite composite,
                                      int nColumns)
Creates the controls for the type name field. Expects a GridLayout with at least 2 columns.

Parameters:
composite - the parent composite
nColumns - number of columns to span

createModifierControls

protected void createModifierControls(Composite composite,
                                      int nColumns)
Creates the controls for the modifiers radio/ceckbox buttons. Expects a GridLayout with at least 3 columns.

Parameters:
composite - the parent composite
nColumns - number of columns to span

createSuperClassControls

protected void createSuperClassControls(Composite composite,
                                        int nColumns)
Creates the controls for the superclass name field. Expects a GridLayout with at least 3 columns.

Parameters:
composite - the parent composite
nColumns - number of columns to span

createSuperInterfacesControls

protected void createSuperInterfacesControls(Composite composite,
                                             int nColumns)
Creates the controls for the superclass name field. Expects a GridLayout with at least 3 columns.

Parameters:
composite - the parent composite
nColumns - number of columns to span

setFocus

protected void setFocus()
Sets the focus on the type name input field.


handleFieldChanged

protected void handleFieldChanged(String fieldName)
Description copied from class: NewContainerWizardPage
Hook method that gets called when a field on this page has changed. For this page the method gets called when the source folder field changes.

Every sub type is responsible to call this method when a field on its page has changed. Subtypes override (extend) the method to add verification when a own field has a dependency to an other field. For example the class name input must be verified again when the package field changes (check for duplicated class names).

Overrides:
handleFieldChanged in class NewContainerWizardPage
Parameters:
fieldName - The name of the field that has changed (field id). For the source folder the field id is CONTAINER

getPackageText

public String getPackageText()
Returns the text of the package input field.

Returns:
the text of the package input field

getEnclosingTypeText

public String getEnclosingTypeText()
Returns the text of the enclosing type input field.

Returns:
the text of the enclosing type input field

getPackageFragment

public IPackageFragment getPackageFragment()
Returns the package fragment corresponding to the current input.

Returns:
a package fragement or null if the input could not be resolved.

setPackageFragment

public void setPackageFragment(IPackageFragment pack,
                               boolean canBeModified)
Sets the package fragment to the given value. The method updates the model and the text of the control.

Parameters:
pack - the package fragement to be set
canBeModified - if true the package fragment is editable; otherwise it is read-only.

getEnclosingType

public IType getEnclosingType()
Returns the enclosing type corresponding to the current input.

Returns:
the enclosing type or null if the enclosing type is not selected or the input could not be resolved

setEnclosingType

public void setEnclosingType(IType type,
                             boolean canBeModified)
Sets the enclosing type. The method updates the underlying model and the text of the control.

Parameters:
type - the enclosing type
canBeModified - if true the enclosing type field is editable; otherwise it is read-only.

isEnclosingTypeSelected

public boolean isEnclosingTypeSelected()
Returns the selection state of the enclosing type checkbox.

Returns:
the seleciton state of the enclosing type checkbox

setEnclosingTypeSelection

public void setEnclosingTypeSelection(boolean isSelected,
                                      boolean canBeModified)
Sets the enclosing type checkbox's selection state.

Parameters:
isSelected - the checkbox's selection state
canBeModified - if true the enclosing type checkbox is modifiable; otherwise it is read-only.

getTypeName

public String getTypeName()
Returns the type name entered into the type input field.

Returns:
the type name

setTypeName

public void setTypeName(String name,
                        boolean canBeModified)
Sets the type name input field's text to the given value. Method doesn't update the model.

Parameters:
name - the new type name
canBeModified - if true the enclosing type name field is editable; otherwise it is read-only.

getModifiers

public int getModifiers()
Returns the selected modifiers.

Returns:
the selected modifiers
See Also:
Flags

setModifiers

public void setModifiers(int modifiers,
                         boolean canBeModified)
Sets the modifiers.

Parameters:
modifiers - F_PUBLIC, F_PRIVATE, F_PROTECTED, F_ABSTRACT, F_FINAL or F_STATIC or, a valid combination.
canBeModified - if true the modifier fields are editable; otherwise they are read-only
See Also:
Flags

getSuperClass

public String getSuperClass()
Returns the content of the superclass input field.

Returns:
the superclass name

setSuperClass

public void setSuperClass(String name,
                          boolean canBeModified)
Sets the super class name.

Parameters:
name - the new superclass name
canBeModified - if true the superclass name field is editable; otherwise it is read-only.

getSuperInterfaces

public List getSuperInterfaces()
Returns the chosen super interfaces.

Returns:
a list of chosen super interfaces. The list's elements are of type String

setSuperInterfaces

public void setSuperInterfaces(List interfacesNames,
                               boolean canBeModified)
Sets the super interfaces.

Parameters:
interfacesNames - a list of super interface. The method requires that the list's elements are of type String
canBeModified - if true the super interface field is editable; otherwise it is read-only.

packageChanged

protected IStatus packageChanged()
A hook method that gets called when the package field has changed. The method validates the package name and returns the status of the validation. The validation also updates the package fragment model.

Subclasses may extend this method to perform their own validation.

Returns:
the status of the validation

enclosingTypeChanged

protected IStatus enclosingTypeChanged()
Hook method that gets called when the enclosing type name has changed. The method validates the enclosing type and returns the status of the validation. It also updates the enclosing type model.

Subclasses may extend this method to perform their own validation.

Returns:
the status of the validation

typeNameChanged

protected IStatus typeNameChanged()
Hook method that gets called when the type name has changed. The method validates the type name and returns the status of the validation.

Subclasses may extend this method to perform their own validation.

Returns:
the status of the validation

superClassChanged

protected IStatus superClassChanged()
Hook method that gets called when the superclass name has changed. The method validates the superclass name and returns the status of the validation.

Subclasses may extend this method to perform their own validation.

Returns:
the status of the validation

superInterfacesChanged

protected IStatus superInterfacesChanged()
Hook method that gets called when the list of super interface has changed. The method validates the superinterfaces and returns the status of the validation.

Subclasses may extend this method to perform their own validation.

Returns:
the status of the validation

modifiersChanged

protected IStatus modifiersChanged()
Hook method that gets called when the modifiers have changed. The method validates the modifiers and returns the status of the validation.

Subclasses may extend this method to perform their own validation.

Returns:
the status of the validation

createType

public void createType(IProgressMonitor monitor)
                throws CoreException,
                       InterruptedException
Creates the new type using the entered field values.

Parameters:
monitor - a progress monitor to report progress. The progress monitor must not be null
CoreException
InterruptedException

getCreatedType

public IType getCreatedType()
Returns the created type. The method only returns a valid type after createType has been called.

Returns:
the created type
See Also:
createType(IProgressMonitor)

createTypeMembers

protected void createTypeMembers(IType newType,
                                 org.eclipse.jdt.internal.corext.codemanipulation.IImportsStructure imports,
                                 IProgressMonitor monitor)
                          throws CoreException
Deprecated. Overwrite createTypeMembers(IType, IImportsManager, IProgressMonitor) instead

CoreException

createTypeMembers

protected void createTypeMembers(IType newType,
                                 NewTypeWizardPage.ImportsManager imports,
                                 IProgressMonitor monitor)
                          throws CoreException
Hook method that gets called from createType to support adding of unanticipated methods, fields, and inner types to the created type.

Implementers can use any methods defined on IType to manipulate the new type.

The source code of the new type will be formtted using the platform's formatter. Needed imports are added by the wizard at the end of the type creation process using the given import manager.

Parameters:
newType - the new type created via createType
imports - an import manager which can be used to add new imports
monitor - a progress monitor to report progress. Must not be null
CoreException
See Also:
createType(IProgressMonitor)

getFileComment

protected String getFileComment(ICompilationUnit parentCU)
Hook mathod that gets called from createType to retrieve a file comment. This default implementation returns the content of the 'filecomment' template.

Returns:
the file comment or null if a file comment is not desired

getTypeComment

protected String getTypeComment(ICompilationUnit parentCU)
Hook method that gets called from createType to retrieve a type comment. This default implementation returns the content of the 'typecomment' template.

Returns:
the type comment or null if a type comment is not desired

getTemplate

protected String getTemplate(String name,
                             ICompilationUnit parentCU)
Deprecated. Use getTemplate(String,ICompilationUnit,int)


getTemplate

protected String getTemplate(String name,
                             ICompilationUnit parentCU,
                             int pos)
Returns the string resulting from evaluation the given template in the context of the given compilation unit.

Parameters:
name - the template to be evaluated
parentCU - the templates evaluation context
pos - a source offset into the parent compilation unit. The template is evalutated at the given source offset

createInheritedMethods

protected IMethod[] createInheritedMethods(IType type,
                                           boolean doConstructors,
                                           boolean doUnimplementedMethods,
                                           org.eclipse.jdt.internal.corext.codemanipulation.IImportsStructure imports,
                                           IProgressMonitor monitor)
                                    throws CoreException
Deprecated. Use createInheritedMethods(IType,boolean,boolean,IImportsManager,IProgressMonitor)

CoreException

createInheritedMethods

protected IMethod[] createInheritedMethods(IType type,
                                           boolean doConstructors,
                                           boolean doUnimplementedMethods,
                                           NewTypeWizardPage.ImportsManager imports,
                                           IProgressMonitor monitor)
                                    throws CoreException
Creates the bodies of all unimplemented methods and constructors and adds them to the type. Method is typically called by implementers of NewTypeWizardPage to add needed method and constructors.

Parameters:
type - the type for which the new methods and constructor are to be created
doConstructors - if true unimplemented constructors are created
doUnimplementedMethods - if true unimplemented methods are created
imports - an import manager to add all neded import statements
monitor - a progress monitor to report progress
CoreException

getRunnable

public IRunnableWithProgress getRunnable()
Returns the runnable that creates the type using the current settings. The returned runnable must be executed in the UI thread.

Returns:
the runnable to create the new type

Eclipse JDT
2.0

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