I have been trying to get Visual Inheritance working correctly, and am almost there. The last problem that i am trying to get around, is that in the designer, in the subclass, i can't seem to manipulate any of the widgets that were created in the super class. They can be manipulated in the code, and the window will render them correctly.
The bigger problem with this is that if there is a composite of some kind defined in the super class, controls can't be added to it in the subclass. I can add the control in the code by hand, and it runs correctly, however the designer won't render the control at all.
i have included the code samples:
- Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
public class Shell1 extends Shell {
protected Group mainFormGroup;
public Shell1(Display display, int style) {
super(display, style);
setLayout(new FormLayout());
setText("SWT Application");
setSize(492, 341);
mainFormGroup = new Group(this, SWT.NONE);
final FormData fd_mainFormGroup = new FormData();
fd_mainFormGroup.left = new FormAttachment(0, 5);
fd_mainFormGroup.bottom = new FormAttachment(0, 336);
fd_mainFormGroup.right = new FormAttachment(0, 389);
mainFormGroup.setLayoutData(fd_mainFormGroup);
mainFormGroup.setLayout(new FormLayout());
Group group;
group = new Group(this, SWT.NONE);
group.setLayout(new FormLayout());
fd_mainFormGroup.top = new FormAttachment(group, 0, SWT.TOP);
final FormData fd_group = new FormData();
fd_group.right = new FormAttachment(0, 485);
fd_group.bottom = new FormAttachment(0, 336);
fd_group.top = new FormAttachment(0, 13);
fd_group.left = new FormAttachment(0, 395);
group.setLayoutData(fd_group);
final Button okButton = new Button(group, SWT.NONE);
final FormData fd_okButton = new FormData();
fd_okButton.bottom = new FormAttachment(0, 37);
fd_okButton.top = new FormAttachment(0, 8);
fd_okButton.right = new FormAttachment(0, 77);
fd_okButton.left = new FormAttachment(0, 8);
okButton.setLayoutData(fd_okButton);
okButton.setText("OK");
final Button cancelButton = new Button(group, SWT.NONE);
final FormData fd_cancelButton = new FormData();
fd_cancelButton.bottom = new FormAttachment(0, 72);
fd_cancelButton.top = new FormAttachment(0, 43);
fd_cancelButton.right = new FormAttachment(0, 77);
fd_cancelButton.left = new FormAttachment(0, 8);
cancelButton.setLayoutData(fd_cancelButton);
cancelButton.setText("Cancel");
}
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}
and the subclass
- Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
public class Shell2 extends Shell1 {
public static void main(String args[]) {
try {
Display display = Display.getDefault();
Shell2 shell = new Shell2(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public Shell2(Display display, int style) {
super(display, style);
setText("SWT Application - Shell2");
setSize(492, 341);
Button button = new Button(mainFormGroup, SWT.NONE);
button.setText("Test Button");
}
}
Any help is appreciated,
Jamie