Preferences - Code Generation

This page is used to control various code generation styles.

Use the existing creation style when it can be deduced

This preference determines whether Designer attempts to use the existing code creation style already in a file to generate code.  The Designer checks a file when it is opened in the editor to see if one style or the other is used.  If only one of the styles is being used in a file, it will continue generating code in that style, regardless of what the "Create every component in its own block" or "Create Swing components stored in fields in an accessor method" settings are set to.  If no style is detected (no controls have been created yet) or if more than one style is detected, the Designer will generate code as set in the "Create every component in its own block" and "Create Swing components stored in fields in an accessor method" settings.

Create every component in its own block

When this preference is selected, the Designer generates code using block style: a control is declared and instantiated inside its own block of code.  All of the control"s properties are placed in the block.  The block is surrounded by opening and closing braces.  Child controls are nested in their parent"s blocks.  When a control is declared inside its block of code, it is visible only to its children and itself.  A control can be made visible to the rest of the class using the "Convert local to field" button.  Below is a simple example of what the block style looks like.

       {
              final Button button = new Button(shell, SWT.NONE);
              button.setText("button");
       }

When this preference is not selected, the Designer generates code using the flat style: all controls are created in the same scope in a method making the controls visible anywhere in a method after they have been declared.

Create every non-visual bean as a field by default

This preference determines whether all non-visual beans are automatically created as a field in the class. Turn on this option to emulate the style used by other popular GUI builder. When this option is turned off, non-visual beans will be created as fields depending upon whether they are listed on the Type Specific preference page. 

Create every component as a field by default

This preference determines whether all created controls are automatically created as a field in the class. Turn on this option to emulate the style used by other popular GUI builder. When this option is turned off, controls will be created as fields depending upon whether they are listed on the Type Specific preference page. 

Create Swing component fields in accessor methods 

This preference determines whether all field-based Swing components are created in accessor methods. Turning this option will emulate the VisualAge Java / Eclipse VE code generation style. A drop down list allows you to choose the visibility of the generated accessors: private, package private, protected or public.

Create Swing component fields in initializers 

This preference determines whether all field-based Swing components are created in initializers. Turning this option will emulate the JBuilder code generation style.

Prefix each component creation code by 

This preference determines whether the text field below it is enabled.  If the text field is left blank, every new control created will have a blank line above it in the source code.  You can also place a custom one-line comment before each new control by putting the comment in the text field.  The text field must be blank, start with "//", or start with "/*" and end with "*/".

Method name for new statements

This preference determines which method components will be created in by default in the event that a suitable method has not already be defined for the current class. If the method does not exist, it will be created and a call to it added to the constructor for the class. Various default choices are provided to match the code generation patterns of other GUI builders.

Surround method invocation code with try{}catch{}

This preference determines whether the component creation method will be surrounded with try{}catch{}.