package test; import org.eclipse.jface.dialogs.*; import org.eclipse.jface.window.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.*; import org.eclipse.swt.events.*; /** * @author Web Performance, Inc. *
Copyright 2006 */ public class NestedGridTitleDialog extends ApplicationWindow implements SelectionListener { public static void main(String[] args) { NestedGridTitleDialog window = new NestedGridTitleDialog(); window.run(); } public NestedGridTitleDialog() { super(null); } public void run() { setBlockOnOpen(true); open(); Display.getCurrent().dispose(); } protected Control createContents(Composite parent) { Button button = new Button(parent, SWT.PUSH); button.setText("push me"); button.addSelectionListener(this); return button; } public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { MyDialog dialog = new MyDialog(getShell()); dialog.open(); } } class MyDialog extends TitleAreaDialog { public MyDialog(Shell shell) { super(shell); setShellStyle(getShellStyle() | SWT.RESIZE); } protected Control createDialogArea(Composite parent) { setTitle("Title of the dialog"); setMessage("Long message instrucing the user what to do.\nIt required two lines."); Composite background_area = new Composite(parent, SWT.NONE); background_area.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED)); FillLayout layout = new FillLayout(); layout.marginHeight = 5; layout.marginWidth = 5; background_area.setLayout(layout); GridData layout_data = new GridData(GridData.FILL_BOTH); layout_data.widthHint=300; background_area.setLayoutData(layout_data); _outer_panel = new OuterPanel(background_area, SWT.NONE); return background_area; } OuterPanel _outer_panel; public final static String LONG_STRING = "A;LKFDA;KLJWA;OEJI;WE;FOIJASDKJSALKDFJ;AEJFAWNELFIUAWBEFLIAUEHOI78OI3LU4HO349TY3Q098H3LIUFBOQ349H7TROQ398HRTQ9P328RBLQIURBLQ23IH8R2Q3NR982390RQ2V39082Q0938Y50Q987RYQ0923RYQ20N3980C2Q9R898FHAOWI8HRO8EF7AHWON9E7NY2Q093R8Q2039R8YQ2039R82QNY9R8Q29P83N9Q283A;LKFDA;KLJWA;OEJI;WE;FOIJASDKJSALKDFJ;AEJFAWNELFIUAWBEFLIAUEHOI78OI3LU4HO349TY3Q098H3LIUFBOQ349H7TROQ398HRTQ9P328RBLQIURBLQ23IH8R2Q3NR982390RQ2V39082Q0938Y50Q987RYQ0923RYQ20N3980C2Q9R898FHAOWI8HRO8EF7AHWON9E7NY2Q093R8Q2039R8YQ2039R82QNY9R8Q29P83N9Q283A;LKFDA;KLJWA;OEJI;WE;FOIJASDKJSALKDFJ;AEJFAWNELFIUAWBEFLIAUEHOI78OI3LU4HO349TY3Q098H3LIUFBOQ349H7TROQ398HRTQ9P328RBLQIURBLQ23IH8R2Q3NR982390RQ2V39082Q0938Y50Q987RYQ0923RYQ20N3980C2Q9R898FHAOWI8HRO8EF7AHWON9E7NY2Q093R8Q2039R8YQ2039R82QNY9R8Q29P83N9Q283"; } class OuterPanel extends Composite implements SelectionListener { public OuterPanel(Composite parent, int style) { super(parent, style); setLayout(new GridLayout(2, false)); Label label1 = new Label(this, SWT.NONE); label1.setText("label 1 in outer panel"); Text text1 = new Text(this, SWT.BORDER); text1.setText("some text goes in here."); text1.setEditable(false); text1.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); Label label2 = new Label(this, SWT.NONE); label2.setText("label 2 in outer panel"); Text text2 = new Text(this, SWT.BORDER); text2.setText("asdfasdf"); text2.setEditable(false); text2.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); _inner_panel = new InnerPanel(this, SWT.NONE); // use this line to see the bug _inner_panel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1)); // use this line for it to work correctly. // _inner_panel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1)); Button button = new Button(this, SWT.PUSH); button.setText("show sizes..."); button.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false, 1, 1)); button.addSelectionListener(this); } public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { System.out.println("OuterPanel width=" + getSize().x); System.out.println("InnerPanel width=" + _inner_panel.getSize().x); } InnerPanel _inner_panel; } class InnerPanel extends Composite { public InnerPanel(Composite parent, int style) { super(parent, style); setLayout(new GridLayout(2, false)); setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_YELLOW)); Label label1 = new Label(this, SWT.NONE); label1.setText("label 1 in inner panel"); Text text1 = new Text(this, SWT.BORDER); text1.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); text1.setText("really long string in here: " + MyDialog.LONG_STRING); text1.setEnabled(false); Label label2 = new Label(this, SWT.NONE); label2.setText("label 2 in inner panel"); Text text2 = new Text(this, SWT.BORDER); text2.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); } }