[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [albireo-dev] SWT size/layout management

Gordon Hirsch wrote:

I think I can construct an example that will show why getParent().layout() is not adequate and why we will have to defer to the application in this case. I'll try to add it to our examples in the next day or two.


I changed RelayoutExampleView to add more nesting. The current nesting is

parent
  composite
    leftComposite    <-- new
      SWT label      <-- new
      Swing Control
    buttonList composite

With the default controlResized() implementation (getParent().layout()) the original problem with "..." is back again. The solution is to override controlResized() to layout the grandparent instead of the parent.

Having the ability to override controlResized() is great, but it's my strong belief that there is no implementation of this method that is good enough to serve as a default. It would be better to make the method abstract so that all clients are clearly aware that they need to decide how and when to layout.

### Eclipse Workspace Patch 1.0
#P org.eclipse.albireo.examples.plugin
Index: src/org/eclipse/albireo/examples/plugin/views/RelayoutExampleView.java
===================================================================
RCS file: /cvsroot/technology/org.eclipse.albireo/org.eclipse.albireo.examples.plugin/src/org/eclipse/albireo/examples/plugin/views/RelayoutExampleView.java,v
retrieving revision 1.4
diff -u -r1.4 RelayoutExampleView.java
--- src/org/eclipse/albireo/examples/plugin/views/RelayoutExampleView.java	8 Feb 2008 20:55:49 -0000	1.4
+++ src/org/eclipse/albireo/examples/plugin/views/RelayoutExampleView.java	11 Feb 2008 20:33:28 -0000
@@ -21,6 +21,7 @@
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.part.ViewPart;
 
 
@@ -49,13 +50,32 @@
         GridLayout layout = new GridLayout();
         layout.numColumns = 2;
         composite.setLayout(layout);
-        swingControl = new SwingControl(composite, SWT.NONE) {
+        
+        
+        Composite leftComposite = new Composite(composite, SWT.NONE);
+        GridData data = new GridData();
+        data.horizontalAlignment = SWT.CENTER;
+        data.verticalAlignment = SWT.CENTER;
+        data.grabExcessHorizontalSpace = true;
+        data.grabExcessVerticalSpace = true;
+        leftComposite.setLayoutData(data);
+        leftComposite.setLayout(new GridLayout());  // single column grid
+        
+        Label label = new Label(leftComposite, SWT.NONE);
+        label.setText("Top SWT Label");
+        data = new GridData();
+        data.horizontalAlignment = SWT.CENTER;
+        data.verticalAlignment = SWT.CENTER;
+        data.grabExcessHorizontalSpace = true;
+        label.setLayoutData(data);
+
+        swingControl = new SwingControl(leftComposite, SWT.NONE) {
             protected JComponent createSwingComponent() {
                 addSwingWidgets();
                 return panel;
             }
         };
-        GridData data = new GridData();
+        data = new GridData();
         data.horizontalAlignment = SWT.CENTER;
         data.verticalAlignment = SWT.CENTER;
         data.grabExcessHorizontalSpace = true;