The tool supports visual inheritance of
SWT Shells and Composites, Swing JFrames,
JDialogs, JApplets and JPanels. Visual inheritance
supports the following features:
- Inherit from any Shell, Composite,
JFrame, JDialog, JApplet or JPanel
subclass
- All inherited widgets are visible
- Access inherited widgets exposed via public or protected accessors
- Access inherited custom properties
- Inherited widgets appear in tree with the
"exposed"
decorator
The following is an example of two
Composites in an inheritance hierarchy. The first Composite uses
a GridLayout and has two Labels, two Text widgets, a
Button and an
inner Composite widget.
The inner Composite widget has been exposed as
a public component using the
Expose Component command.
Expose Component converts a component to a field and adds a public
accessor for it. Finally, the background color property of
the first Text widget and the text property of the Button have been exposed as a public properties of the
Composite using
the Expose Property command.
Expose Property adds a
pair of accessors for getting and setting the desired property of
the target widget.
- import
org.eclipse.swt.SWT;
import
org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public
class
ParentComposite
extends Composite {
private
Button
browseButton;
private
Composite
composite;
private
Text secondField;
private
Text firstField;
public
ParentComposite(Composite parent,
int
style) {
super(parent,
style);
createContents();
}
public
void
createContents() {
final
GridLayout gridLayout =
new
GridLayout();
gridLayout.numColumns
= 3;
setLayout(gridLayout);
final
Label firstFieldLabel =
new
Label(this,
SWT.NONE);
firstFieldLabel.setText("First
Field");
firstField
= new
Text(this,
SWT.BORDER);
final
GridData gd_firstField =
new
GridData(SWT.FILL,
SWT.CENTER,
true,
false);
firstField.setLayoutData(gd_firstField);
browseButton =
new
Button(this,
SWT.NONE);
browseButton.setLayoutData(new
GridData(SWT.FILL,
SWT.CENTER,
false,
false));
browseButton.setText("Browse...");
final
Label secondFieldLabel =
new
Label(this,
SWT.NONE);
secondFieldLabel.setText("Second
Field");
secondField =
new
Text(this,
SWT.BORDER);
final
GridData gd_secondField =
new
GridData(SWT.FILL,
SWT.CENTER,
true,
false,
2, 1);
secondField.setLayoutData(gd_secondField);
composite
= new
Composite(this,
SWT.NONE);
composite.setLayoutData(new
GridData(SWT.FILL,
SWT.FILL,
false,
true,
3, 1) );
}
public
Composite getComposite() {
return
composite;
}
public
String getBrowseButtonText() {
return
browseButton.getText();
}
public
void
setBrowseButtonText(String text) {
browseButton.setText(text);
}
public
Color getFirstFieldBackground() {
return
firstField.getBackground();
}
public
void
setFirstFieldBackground(Color background) {
firstField.setBackground(background);
}
}
The second Composite inherits from
the first and sets the inner Composite's layout manager via
its accessor from the superclass and then adds several new widgets
to the inner Composite. It also adds several new widgets that appear after the
inherited widgets and use the GridLayout layout manager inherited
from the superclass. Finally, it overrides the background color for
the first Text widget and the text setting of the Button using the accessors defined in the first Composite.
Note that the exposed and inherited inner Composite from the superclass
shows up in the component tree with a small
overlay icon. The
other widgets defined in the first Composite do not show up in the
tree because they are private to that Composite.
- import
org.eclipse.swt.SWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public
class
ChildComposite extends
ParentComposite {
private
List list;
private
Text sixthField;
private
Text fifthField;
private
Text fourthField;
private
Text thirdField;
public
ChildComposite(Composite parent,
int
style) {
super(parent,
style);
}
public
void
createContents() {
super.createContents();
setFirstFieldBackground(Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
setBrowseButtonText("Find...");
final
GridLayout gridLayout =
new
GridLayout();
gridLayout.numColumns
= 2;
getComposite().setLayout(gridLayout);
final
Label thirdFieldLabel =
new
Label(getComposite(), SWT.NONE);
thirdFieldLabel.setText("Third
Field");
thirdField
= new
Text(getComposite(), SWT.BORDER);
final
GridData gd_thirdField =
new
GridData(SWT.FILL,
SWT.CENTER,
true,
false);
thirdField.setLayoutData(gd_thirdField);
final
Label fourthFieldLabel =
new
Label(getComposite(), SWT.NONE);
fourthFieldLabel.setText("Fourth
Field");
fourthField
= new
Text(getComposite(), SWT.BORDER);
final
GridData gd_fourthField =
new
GridData(SWT.FILL,
SWT.CENTER,
true,
false);
fourthField.setLayoutData(gd_fourthField);
list
= new
List(getComposite(), SWT.BORDER);
list.setItems(new
String[] {"First
Item",
"Second Item"});
list.setLayoutData(new
GridData(SWT.FILL,
SWT.FILL,
false,
true,
2, 1));
final
Label fifthFieldLabel =
new
Label(this,
SWT.NONE);
fifthFieldLabel.setLayoutData(new
GridData());
fifthFieldLabel.setText("Fifth
Field");
fifthField
= new
Text(this,
SWT.BORDER);
final
GridData gd_fifthField =
new
GridData(SWT.FILL,
SWT.CENTER,
true,
false,
2, 1);
fifthField.setLayoutData(gd_fifthField);
final
Label sixthFieldLabel =
new
Label(this,
SWT.NONE);
sixthFieldLabel.setText("Sixth
Field");
sixthField
= new
Text(this,
SWT.BORDER);
final
GridData gd_sixthField =
new
GridData(SWT.FILL,
SWT.CENTER,
true,
false);
sixthField.setLayoutData(gd_sixthField);
final
Button searchButton =
new
Button(this,
SWT.NONE);
searchButton.setText("Search...");
}
}
|