Property Page: How to prevent from resizing

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Property Page: How to prevent from resizing

Postby cebarne2 » Thu Mar 11, 2004 6:20 am

I ask this here in hopes of someone who has experience with Eclipse property pages.

I use SWT designer to layout my property pages. It all looks great in the Designer, but when I actually bring up the property page in the Run-Time Workbench, the entire property dialog blows-up to screen size. All the other pages behave, but when my property page is clicked, it resizes.

Any tips on how to prevent the property page from resizing? I can confirm that my Composite's size has not changed by the time I get to the "return myComposite" command at the end of CreateControls. But, it definitely does sometime after.

My property page (Composite) contains:
-Group (several simple controls in the group)
-Tabfolder
-2 tabitems with a scrolledcomposite containing a custom field
-2 tabitems with large list boxes (grab vertical, colSpan=4) and mutiple buttons
-1 tabitem with a large Text control (grab vertical, horizontal)

Thanks
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Re: Property Page: How to prevent from resizing

Postby Eric Clayberg » Thu Mar 11, 2004 7:48 am

cebarne2 wrote:I use SWT designer to layout my property pages. It all looks great in the Designer, but when I actually bring up the property page in the Run-Time Workbench, the entire property dialog blows-up to screen size. All the other pages behave, but when my property page is clicked, it resizes.

If you are using GridLayout, trying setting the widthHint on various widgets.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby cebarne2 » Wed Jun 16, 2004 1:34 pm

Thanks for the input Eric. I have been battling this problem for a very long time now. The wHint doesn't seem to accomplish the task. I have sent email to the swt mailing list in hopes of a response. I would like to post that here in case anyone has a new opinion on the problem... thanks for your support:

[post]
I've been battling a problem for quite some time and have failed to come up with a reliable solution.

I have created a property page in Eclipse and filled it with numerous controls:

1)multiple group widgets with controls in the groups
2)a tabfolder with multiple tabs, some of which have child frames in them
3)a few other controls not in groups

The problem is when I open the project properties, and then select my property page, the entire properties window resizes to the size of the screen. I avoided this by placing a "getShell().setSize" command at the beginning of my "createContents()" method, and then a "composite.pack()" statement at the end. But, oddly enough, the size of the window AND contents is fine the first time I open the properties page, but the second time I open it (in the Eclipse session), the window is sized correctly but the contents are sized as if the window was huge again. If I resize the window at all (drag the frame), the contents resize down to the size of the window and it looks good again.

Can placing values in text boxes, values that are longer than the text box, cause the text box to expand to the screen's limits, in turn causing the properties window to expand. Can using "FILL_HORIZONTAL" cause similar problems?

I feel I am missing some basic discipline in SWT to avoid this resizing/expanding problem. Does anyone have any suggestions. I would be happy to post some code, but it is a monster createcontents() method.


Thanks,

Chad Barnes
Rockwell Collins Inc.
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Postby Eric Clayberg » Wed Jun 16, 2004 6:08 pm

cebarne2 wrote:I feel I am missing some basic discipline in SWT to avoid this resizing/expanding problem. Does anyone have any suggestions. I would be happy to post some code, but it is a monster createcontents() method.

I would suggest creating a new, small example that illustrates the problem with as few widgets as possible. Sometimes the interactions between various widgets and layout managers can seem a bit arcane (and I admit being running into some challenging cases myself in the past), so having an example to play with would help.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby cebarne2 » Thu Jun 17, 2004 5:03 am

Here is a smaller example of a property page that causes the property dialog to expand to the screen's size. I will include both my property page and a custom frame used in a scrolledComposite. The propertyPage is attached to IProject resources.

NOTE the following lines to demonstrate the "expanding behavior":

Code: Select all
//remove me to watch the property page expand when you open it
getShell().setSize(750, 675);


With this line commented out, the dialog will expand to screen size. With the line, the dialog is a managable size but the tabFolder is still to large to fit.

[SamplePropertyPage.java]
Code: Select all
package com.rockwellcollins.property.sizeTest.properties;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.PropertyPage;

public class SamplePropertyPage extends PropertyPage {

   private static final int TEXT_FIELD_WIDTH = 50;

   private Button cmdEdit;
   private Button cmdRemove;
   private List lstIncludes;
   private List lstSrcs;
   private Text txtCustomize;
   private TabFolder tabFolder;
   private FrameOne frameOne;

   public SamplePropertyPage() {
      super();
   }

   protected Control createContents(Composite parent) {
      Composite controlParent = new Composite(parent, SWT.NONE);
      final GridLayout layout = new GridLayout();
      layout.numColumns = 4;
      controlParent.setLayout(layout);
      controlParent.setLayoutData(new GridData(GridData.FILL_BOTH));
      {
         tabFolder = new TabFolder(controlParent, SWT.NONE);
         tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
         {
            final TabItem tabBuildPaths = new TabItem(tabFolder, SWT.NONE);
            tabBuildPaths.setText("Build Paths");
            {
               final ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
               tabBuildPaths.setControl(scrolledComposite);
               scrolledComposite.setLayout(new FillLayout());
               {
                  frameOne = new FrameOne(scrolledComposite, SWT.NONE);
                  frameOne.setSize(300, 300);
                  scrolledComposite.setContent(frameOne);
               }
               scrolledComposite.setExpandHorizontal(true);
               scrolledComposite.setExpandVertical(true);
               scrolledComposite.setMinSize(frameOne.computeSize(SWT.DEFAULT, SWT.DEFAULT));
            }
         }
         {
            final TabItem tabSrcs = new TabItem(tabFolder, SWT.NONE);
            tabSrcs.setText("Sources");
            {
               final Composite composite = new Composite(tabFolder, SWT.NONE);
               final GridLayout gridLayout = new GridLayout();
               gridLayout.numColumns = 2;
               composite.setLayout(gridLayout);
               tabSrcs.setControl(composite);
               {
                  lstSrcs = new List(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
                  final GridData gridData_1 = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
                  gridData_1.horizontalSpan = 2;
                  lstSrcs.setLayoutData(gridData_1);
               }
               {
                  final Button cmdClear = new Button(composite, SWT.NONE);
                  cmdClear.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END));
                  cmdClear.setText("Clear");
               }
               {
                  final Button cmdSrcs = new Button(composite, SWT.NONE);
                  cmdSrcs.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
                  cmdSrcs.setText("Select Sources");
               }
            }
         }
         {
            final TabItem tabIncludes = new TabItem(tabFolder, SWT.NONE);
            tabIncludes.setText("Include Paths");
            {
               final Composite composite = new Composite(tabFolder, SWT.NONE);
               final GridLayout gridLayout = new GridLayout();
               gridLayout.numColumns = 5;
               composite.setLayout(gridLayout);
               tabIncludes.setControl(composite);
               {
                  lstIncludes = new List(composite, SWT.BORDER | SWT.H_SCROLL | SWT.MULTI | SWT.V_SCROLL);
                  final GridData gridData_1 = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
                  gridData_1.horizontalSpan = 5;
                  lstIncludes.setLayoutData(gridData_1);
               }
               {
                  final Button cmdClear = new Button(composite, SWT.NONE);
                  cmdClear.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END));
                  cmdClear.setText("Clear");
               }
               {
                  final Button cmdFindIncludes = new Button(composite, SWT.NONE);
                  cmdFindIncludes.setText("Find");
               }
               {
                  cmdRemove = new Button(composite, SWT.NONE);
                  cmdRemove.setEnabled(false);
                  cmdRemove.setText("Remove");
               }
               {
                  final Button cmdAdd = new Button(composite, SWT.NONE);
                  cmdAdd.setText("Add");
               }
               {
                  cmdEdit = new Button(composite, SWT.NONE);
                  cmdEdit.setEnabled(false);
                  cmdEdit.setText("Edit");
               }
            }
         }
         {
            final TabItem tabCustomize = new TabItem(tabFolder, SWT.NONE);
            tabCustomize.setText("Customize Makefile");
            {
               final Composite composite = new Composite(tabFolder, SWT.NONE);
               composite.setLayout(new GridLayout());
               tabCustomize.setControl(composite);
               {
                  final Label lblCustomize = new Label(composite, SWT.NONE);
                  lblCustomize.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                  lblCustomize.setText("Please enter custom rules to add to the generated makefile:");
               }
               {
                  txtCustomize = new Text(composite, SWT.BORDER | SWT.H_SCROLL | SWT.MULTI | SWT.V_SCROLL);
                  txtCustomize.setLayoutData(new GridData(GridData.FILL_BOTH));
               }
            }
         }
      }
      //remove me to watch the property page expand when you open it
      getShell().setSize(750, 675);
      controlParent.pack();
      return controlParent;
   }
}


[FrameOne.java]
Code: Select all
/*
* Created on Jun 17, 2004
*
*/
package com.rockwellcollins.property.sizeTest.properties;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.TableColumn;

/**
* @author cebarne2
*/
public class FrameOne extends Composite {

   private Table table;
   public FrameOne(Composite parent, int style) {
      super(parent, style);
      setLayout(new GridLayout());
      {
         table = new Table(this, SWT.BORDER);
         table.setLayoutData(new GridData(GridData.FILL_BOTH));
         table.setLinesVisible(true);
         table.setHeaderVisible(true);
         for (int i = 0; i < 10; i++)
         {
            final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
            tableColumn.setWidth(100);
            tableColumn.setText("New column " + String.valueOf(i));
         }
         TableItem ti;
         for (int i = 0; i < 300; i++){
            ti = new TableItem(table,SWT.NONE);
            for (int j = 0; j < 10; j++)
               ti.setText(j, String.valueOf(i));
         }
      }
   }
   public void dispose() {
      super.dispose();
   }
   protected void checkSubclass() {}
}


Eclipse 2.1.2
Java 1.4.2_04

Thanks,
Chad
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Postby Eric Clayberg » Thu Jun 17, 2004 7:27 am

cebarne2 wrote:Here is a smaller example of a property page that causes the property dialog to expand to the screen's size.

WHat happens if you add the following to the definition of the TabFolder?
    gridData.widthHint = 300;
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby cebarne2 » Thu Jun 17, 2004 7:54 am

I added the following:

Code: Select all
GridData gd1 = new GridData(GridData.FILL_BOTH);
gd1.widthHint = 500;
gd1.heightHint = 400;
tabFolder.setLayoutData(gd1);


It managed to make the tabfolder fit inside the window... but the standard "Restore Defaults" and "Apply" buttons were off-screen. Once I resized the window (in any direction), the tabfolder resized to the window size and the standard buttons were drawn correctly.

So, the problem that the sizing is only correct after a manual resize of the window remains.

Thanks,

Chad
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Postby cebarne2 » Thu Jun 17, 2004 8:47 am

Well,

I think I found a solution but I am not completely happy with the solution, as I do not totally understand it. So, I invite anyone with a rational explanation to step forward.

Instead of using the Composite that is passed into the createContents() method, I use the getControl() method to get a composite:

The OLD way I did it:
Code: Select all
   //final Composite controlParent = new Composite(parent,

SWT.NONE);
   //final GridLayout layout = new GridLayout();
   //controlParent.setLayout(layout);
   //controlParent.setLayoutData(new GridData(GridData.FILL_BOTH));

The new way:
Code: Select all
   final Composite controlParent = (Composite)super.getControl();

With the new way, things all appear great as long as I have controlParent.pack() at the end of the method. Without it, nothing appears in the property page.

Here's the method (with some of the middle removed (...):

Code: Select all
protected Control createContents(Composite parent) {
   final Composite controlParent = (Composite)super.getControl();
   getShell().setSize(750, 675);
   //final Composite controlParent = new Composite(parent, SWT.NONE);
   //final GridLayout layout = new GridLayout();
   //controlParent.setLayout(layout);
   //controlParent.setLayoutData(new GridData(GridData.FILL_BOTH));
   {
      tabFolder = new TabFolder(controlParent, SWT.NONE);
      GridData gd1 = new GridData(GridData.FILL_BOTH);
      tabFolder.setLayoutData(gd1);
      tabFolder.layout(true);
      {
         final TabItem tabBuildPaths = new TabItem(tabFolder, SWT.NONE);
         tabBuildPaths.setText("Build Paths");
         {
            final ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
            tabBuildPaths.setControl(scrolledComposite);
            scrolledComposite.setExpandHorizontal(true);
            scrolledComposite.setExpandVertical(true);
            scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
            {
               frameOne = new FrameOne(scrolledComposite, SWT.NONE);
               frameOne.setSize(488, 265);
               scrolledComposite.setContent(frameOne);
            }
            scrolledComposite.setMinSize(0,0);
         }
      }

   {
   .
   .
   .
   }
   //if this is missing, nothing is displayed on the property page
   controlParent.pack();
   return controlParent;
}

Any thoughts on this?

Thanks,
Chad

WHOOPS! Next time I open the property page in the same Eclipse session, the tabfolder is again too large to fit in the window... This is a particularly nasty problem!
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Postby Eric Clayberg » Thu Jun 17, 2004 1:37 pm

cebarne2 wrote:I added the following:

Code: Select all
GridData gd1 = new GridData(GridData.FILL_BOTH);
gd1.widthHint = 500;
gd1.heightHint = 400;
tabFolder.setLayoutData(gd1);


It managed to make the tabfolder fit inside the window... but the standard "Restore Defaults" and "Apply" buttons were off-screen. Once I resized the window (in any direction), the tabfolder resized to the window size and the standard buttons were drawn correctly. So, the problem that the sizing is only correct after a manual resize of the window remains.

Is the behavior of the tabfolder OK based on the above? Maybe a width hint should be given to the parent composite?
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby Eric Clayberg » Thu Jun 17, 2004 1:39 pm

cebarne2 wrote:I think I found a solution but I am not completely happy with the solution, as I do not totally understand it.

I don't like that solution either. ;-)
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby cebarne2 » Thu Jun 17, 2004 6:20 pm

I've tried several techniques, all that you have recommended and some I found on eclipse.org... and the best I can do is:

1) When the property dialog is opened for the first time, the "info" page comes up. When I select my "SamplePropertyPage", it draws just fine.
2) I press OK or Cancel
3) The second time the property dialog opens, it opens right to the "SamplePropertyPage" and it is drawn incorrectly (the standard "Restore Defaults" and "Apply" buttons are off-screen and the tabfolder may be sized strangely depending on the technique I use to size it).
4) BUT, if the window is resized in any way, or I click to a different property page, and back... the "SamplePropertyPage" is again drawn correctly.

Wierd. What special event is occuring when I click back and forth between property pages that causes my property page to draw correctly?
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA

Postby cebarne2 » Fri Jun 18, 2004 10:10 am

Eureka! I missed the other changes you made (like removing the shell resize and pack commands). So, my SamplePage is now working, AND my actual property page from my original plug-in is working.

The key (in my original complex page) was to put hints on the scrolled composites, to NOT use setLayout on my tabfolder, and get rid of the pack() and getShell().setSize commands.

Thanks so much for your assistance!
cebarne2
 
Posts: 67
Joined: Tue Sep 23, 2003 10:11 am
Location: Cedar Rapids, IA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 1 guest