Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[pde-ui-dev] My layouts are losing their sizes!

Hi,

I'm working on the plugin. Part of the UI is a Button (the ADD Button 
below in the ASCII art) that has a listener that adds Groups (B1 and
B2 below) dynamically to another part of the parent composite (Group
groups below). The problem
is that when I click the ADD button the Composite and everything below 
it loses their layout settings. Ideally I'd like everything in the
TabItem to be filled out to the maximum available space. But when the
groups are added, it goes haywire.

This is driving me crazy. I'm sure there's some small something that I'm 
missing, but I'm either too new at SWT or I'm too close to the code. Any 
help would be greatly appreciated.

Here's the code:

public void createPartControl(Composite parent) {
     tabFolder = new TabFolder(parent, SWT.TOP);
     GridLayout tabFolderLayout = new GridLayout();
     tabFolderLayout.numColumns = 1;
     tabFolder.setLayout(tabFolderLayout);

     tabItem = new TabItem(tabFolder, SWT.NONE);
     tabItem.setText("tabItem");
     composite = new Composite (tabFolder, SWT.NONE);
     GridData compositeLayoutData = new GridData();
     compositeLayoutData.grabExcessHorizontalSpace = true;
     compositeLayoutData.grabExcessVerticalSpace = true;
     compositeLayoutData.horizontalAlignment = SWT.FILL;
     compositeLayoutData.verticalAlignment = SWT.FILL;
     composite.setLayoutData(compositeLayoutData);
     tabItem.setControl(composite);
     composite.setLayout(new FormLayout());

     Button GENButton = new Button(composite,SWT.PUSH);
     GENButton.setText("Gen");
     FormData GENButtonLayoutData = new FormData();
     GENButtonLayoutData.right = new FormAttachment(100,-5);
     GENButtonLayoutData.bottom = new FormAttachment(100,-5);
     GENButton.setLayoutData(GENButtonLayoutData);
     GENButton.addSelectionListener(new GENListener());

     Button addButton = new Button(composite,SWT.PUSH);
     addButton.setText("Add");
     FormData addButtonLayoutData = new FormData();
     addButtonLayoutData.right = new FormAttachment(GENButton,-5);
     addButtonLayoutData.bottom = new FormAttachment(100,-5);
     addButton.setLayoutData(addButtonLayoutData);
     addButton.addSelectionListener(new AddListener());

     groupA = new Composite(composite,SWT.NONE);
     FormData groupALayoutData = new FormData();
     groupALayoutData.top = new FormAttachment(0,5);
     groupALayoutData.left = new FormAttachment(0,5);
     groupALayoutData.right = new FormAttachment(100,-5);
     groupALayoutData.bottom = new FormAttachment(GENButton, -5);
     RowLayout groupALayout = new RowLayout();
     groupALayout.fill = true;
     groupALayout.pack = false;
     groupALayout.type = SWT.VERTICAL;
     groupA.setLayout(groupALayout);

     groupA.pack();
     composite.pack();
}
private void buildPagesTab (DataObject dataObject) {
     String foo = null;
     String bar = null;

     // iterate through groups in dataObject
     for (int i = 0; i < dataObject.pages.size(); i++) {
         pagefoo = dataObject.getPage(i).getfoo();
         pagebar = dataObject.getPage(i).getbar();

         // add new page group
         Group group = new Group(groups,SWT.NONE);
         FormLayout groupLayout = new FormLayout();
         group.setLayout(groupLayout);

         Text groupName = new Text(group,SWT.SINGLE);
         groupName.setText(pagefoo);
         FormData fooLayoutData = new FormData();
         fooLayoutData.top = new FormAttachment(0,5);
         fooLayoutData.left = new FormAttachment(0,5);
         fooLayoutData.right = new FormAttachment(100,-5);
         foo.setLayoutData(fooLayoutData);

         Button deleteGroupButton = new Button(group,SWT.NONE);
         deleteGroupButton.setText("Delete this page");
         FormData deleteGroupButtonLayoutData = new FormData();
         deleteGroupButtonLayoutData.bottom = new FormAttachment(100,-5);
         deleteGroupButtonLayoutData.right = new FormAttachment(100,-5);
         deleteGroupButton.setLayoutData(deleteGroupButtonLayoutData);

         // TODO Add "Move Page Up" button
         // TODO Add "Move Page Down" button

         SashForm sashForm = new SashForm(group,SWT.HORIZONTAL);
         FormData sashFormLayoutData = new FormData();
         sashFormLayoutData.top = new FormAttachment(foo,5);
         sashFormLayoutData.left = new FormAttachment(0,5);
         sashFormLayoutData.bottom = new 
FormAttachment(deleteGroupButton,-5);
         sashFormLayoutData.right = new FormAttachment(100,-5);
         sashForm.setLayoutData(sashFormLayoutData);

         Text foo = new Text(sashForm,SWT.MULTI | SWT.BORDER);
         foo.setText(pagebar);

         TableViewer tableViewer = new TableViewer(sashForm);

         sashForm.pack();
         group.pack();
     }
     groups.pack();

}


private class AddListener implements SelectionListener {
     public void widgetSelected(SelectionEvent e) {
         String foo = "Group " + Integer.toString(dataObject.groups.size());
         String bar = DateFormat.getDateTimeInstance(DateFormat.FULL, 
DateFormat.FULL).format(new Date());
         dataObject.addGroup(pageName, pageDescription);
         buildUI(dataObject);
         composite.pack();
     }

     public void widgetDefaultSelected(SelectionEvent e) {
         //nop
     }
}

private void buildUI (DataObject dataObject) {
     String foo = null;
     String bar = null;

     // iterate through groups in dataObject
     for (int i = 0; i < dataObject.pages.size(); i++) {
         pagefoo = dataObject.getPage(i).getfoo();
         pagebar = dataObject.getPage(i).getbar();

         // add new page group
         Group group = new Group(groups,SWT.NONE);
         FormLayout groupLayout = new FormLayout();
         group.setLayout(groupLayout);

         Text groupName = new Text(group,SWT.SINGLE);
         groupName.setText(pagefoo);
         FormData fooLayoutData = new FormData();
         fooLayoutData.top = new FormAttachment(0,5);
         fooLayoutData.left = new FormAttachment(0,5);
         fooLayoutData.right = new FormAttachment(100,-5);
         foo.setLayoutData(fooLayoutData);

         Button deleteGroupButton = new Button(group,SWT.NONE);
         deleteGroupButton.setText("Delete this page");
         FormData deleteGroupButtonLayoutData = new FormData();
         deleteGroupButtonLayoutData.bottom = new FormAttachment(100,-5);
         deleteGroupButtonLayoutData.right = new FormAttachment(100,-5);
         deleteGroupButton.setLayoutData(deleteGroupButtonLayoutData);

         // TODO Add "Move Page Up" button
         // TODO Add "Move Page Down" button

         SashForm sashForm = new SashForm(group,SWT.HORIZONTAL);
         FormData sashFormLayoutData = new FormData();
         sashFormLayoutData.top = new FormAttachment(foo,5);
         sashFormLayoutData.left = new FormAttachment(0,5);
         sashFormLayoutData.bottom = new 
FormAttachment(deleteGroupButton,-5);
         sashFormLayoutData.right = new FormAttachment(100,-5);
         sashForm.setLayoutData(sashFormLayoutData);

         Text foo = new Text(sashForm,SWT.MULTI | SWT.BORDER);
         foo.setText(pagebar);

         TableViewer tableViewer = new TableViewer(sashForm);

         sashForm.pack();
         group.pack();
     }
     groups.pack();

}



And here is the desired result (please pardon the ASCII art):

TabFolder tabFolder
+---------------------------------------------+
|TabItem tabItem                              |
|+-------------------------------------------+|
||Composite composite                        ||
||+-----------------------------------------+||
|||Group groups                             |||
|||+---------------------------------------+|||
||||Group B1                               ||||
||||+-------------------------------------+||||
|||||Text groupName                       |||||
|||||+-----------------------------------+|||||
||||||                                   ||||||
|||||+-----------------------------------+|||||
|||||SashForm sashForm                    |||||
|||||+-----------------------------------+|||||
||||||Text foo          TableViewer      ||||||
||||||+--------------+  +---------------+||||||
|||||||              |  |               |||||||
||||||+--------------+  +---------------+||||||
||||||                  +---------------+||||||
||||||                  |   DEL Button  |||||||
||||||                  +---------------+||||||
|||||+-----------------------------------+|||||
||||+-------------------------------------+||||
||||Group B1                               ||||
||||+-------------------------------------+||||
|||||Text groupName                       |||||
|||||+-----------------------------------+|||||
||||||                                   ||||||
|||||+-----------------------------------+|||||
|||||SashForm sashForm                    |||||
|||||+-----------------------------------+|||||
||||||Text foo          TableViewer      ||||||
||||||+--------------+  +---------------+||||||
|||||||              |  |               |||||||
||||||+--------------+  +---------------+||||||
||||||                  +---------------+||||||
||||||                  |   DEL Button  |||||||
||||||                  +---------------+||||||
|||||+-----------------------------------+|||||
||||+-------------------------------------+||||
|||+---------------------------------------+|||
|||    	   +--------------+ +--------------+|||
|||        |  GEN Button  | |  ADD Button  ||||
|||        +--------------+ +--------------+|||
||+-----------------------------------------+||
|+-------------------------------------------+|
+---------------------------------------------+


--
Howard Fore, howard.fore@xxxxxxxxx


Back to the top