Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » need help tweaking a layout on preference page
need help tweaking a layout on preference page [message #325394] Sat, 16 February 2008 18:47 Go to next message
Eclipse UserFriend
Originally posted by: marc_e.ye.olde.spam.buster.cablespeed.com

Greetings all. I've got a preference page that extends
FieldEditorPreferencePage.

I'm have only a few preferences, but they naturally fit into groups so I'd
like to group them with a Group().

Everything works fine when I use stringfieldeditor. That is to say, the
label lines up nicely on the left and the string field sits to the right..
Everything appears to be a nice 2-column grid layout.

However, I have one group that takes a DirectoryFieldEditor. When I call
addField() with this editor, it completely screws up the layout for the
previous field editors. What happens is that the label for those previous
ones now sits on top of the string fields. So instead of:


Username: -------------------------
Password: -------------------------
Directory: ----------------------------------------------- Browse

I now get


Username:
-----------------------
Password:
-----------------------
Directory -------------------------------------------------Browse

I'm admittedly still just learning layouts, and I'm hoping its that n00b
misunderstanding that's causing me to miss something obvious. I've tried
all kinds of combinations with spans and Layout cols, but to no avail.

Any help is MOST appreciated!!!

Thanks so much.

Here's my code:

public void createFieldEditors() {
Composite container = new
Composite(this.getFieldEditorParent(),SWT.NONE);
GridData containerData = new
GridData(GridData.FILL,GridData.FILL,true,false);
containerData.horizontalSpan = 1;

container.setLayoutData(containerData);
GridLayout layout = new GridLayout(1,false);
container.setLayout(layout);

//first group
Group urlGroup = new Group(container,SWT.NONE);
urlGroup.setText("Test Runner URL");
GridData gd = new GridData(GridData.FILL,GridData.FILL,true,false);
gd.horizontalSpan = 2;
urlGroup.setLayoutData(gd);
urlGroup.setLayout(new GridLayout(2,false));

addField(new StringFieldEditor(MXUnitPreferenceConstants.P_USERNAME, "
&Username:", 20, urlGroup));
addField(new StringFieldEditor(MXUnitPreferenceConstants.P_PASSWORD, "
&Password:", 20, urlGroup));

//second group
Group webrootGroup = new Group(container, SWT.NONE);
webrootGroup.setText("Your web root");
GridData gd3 = new GridData(GridData.FILL,GridData.FILL,true,false);
gd3.horizontalSpan = 3;
webrootGroup.setLayoutData(gd3);
webrootGroup.setLayout(new GridLayout(3,false));


DirectoryFieldEditor webrootDir = new
DirectoryFieldEditor(MXUnitPreferenceConstants.P_WEBROOTPATH ,
" &Web root directory:", webrootGroup);
addField(webrootDir);
}
Re: need help tweaking a layout on preference page [message #325395 is a reply to message #325394] Sun, 17 February 2008 15:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tskaufma.gmail.com

Hey Marc,

It appears there is some magic going on.

When you create the FieldEditors, they are setting the layout on the
parent. Your layouts get ignored. Also, after the createFieldEditors method
another method is called in which all the field editors adjust their size to
fill the space.

I am not sure what the best possible solution is, but in your specific case,
getting the layout from group and adjusting its numColumns got the result
you were looking for.

After adding the two StringFieldEditors do this:

GridLayout urlLayout = (GridLayout) urlGroup.getLayout();
urlLayout.numColumns = 3;

This works, but I am not sure its the best way to go about this. If anyone
else has a better solution, please comment, I am interested in seeing the
answer.

Hope this helps,
Trevor Kaufman

"Marc E" <marc_e@ye.olde.spam.buster.cablespeed.com> wrote in message
news:fp7snm$uih$1@build.eclipse.org...
> Greetings all. I've got a preference page that extends
> FieldEditorPreferencePage.
>
> I'm have only a few preferences, but they naturally fit into groups so I'd
> like to group them with a Group().
>
> Everything works fine when I use stringfieldeditor. That is to say, the
> label lines up nicely on the left and the string field sits to the right..
> Everything appears to be a nice 2-column grid layout.
>
> However, I have one group that takes a DirectoryFieldEditor. When I call
> addField() with this editor, it completely screws up the layout for the
> previous field editors. What happens is that the label for those previous
> ones now sits on top of the string fields. So instead of:
>
>
> Username: -------------------------
> Password: -------------------------
> Directory: ----------------------------------------------- Browse
>
> I now get
>
>
> Username:
> -----------------------
> Password:
> -----------------------
> Directory -------------------------------------------------Browse
>
> I'm admittedly still just learning layouts, and I'm hoping its that n00b
> misunderstanding that's causing me to miss something obvious. I've tried
> all kinds of combinations with spans and Layout cols, but to no avail.
>
> Any help is MOST appreciated!!!
>
> Thanks so much.
>
> Here's my code:
>
> public void createFieldEditors() {
> Composite container = new
> Composite(this.getFieldEditorParent(),SWT.NONE);
> GridData containerData = new
> GridData(GridData.FILL,GridData.FILL,true,false);
> containerData.horizontalSpan = 1;
>
> container.setLayoutData(containerData);
> GridLayout layout = new GridLayout(1,false);
> container.setLayout(layout);
>
> //first group
> Group urlGroup = new Group(container,SWT.NONE);
> urlGroup.setText("Test Runner URL");
> GridData gd = new GridData(GridData.FILL,GridData.FILL,true,false);
> gd.horizontalSpan = 2;
> urlGroup.setLayoutData(gd);
> urlGroup.setLayout(new GridLayout(2,false));
>
> addField(new StringFieldEditor(MXUnitPreferenceConstants.P_USERNAME, "
> &Username:", 20, urlGroup));
> addField(new StringFieldEditor(MXUnitPreferenceConstants.P_PASSWORD, "
> &Password:", 20, urlGroup));
>
> //second group
> Group webrootGroup = new Group(container, SWT.NONE);
> webrootGroup.setText("Your web root");
> GridData gd3 = new GridData(GridData.FILL,GridData.FILL,true,false);
> gd3.horizontalSpan = 3;
> webrootGroup.setLayoutData(gd3);
> webrootGroup.setLayout(new GridLayout(3,false));
>
>
> DirectoryFieldEditor webrootDir = new
> DirectoryFieldEditor(MXUnitPreferenceConstants.P_WEBROOTPATH ,
> " &Web root directory:", webrootGroup);
> addField(webrootDir);
> }
>
Re: need help tweaking a layout on preference page [message #325406 is a reply to message #325395] Mon, 18 February 2008 04:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marc_e.ye.olde.spam.buster.cablespeed.com

Un-be-liev-able.

dude, i spent hours monkeying with this. trying to set the griddata
separately on the label and text fields, etc. your two lines did the trick.
funny thing is i had added that exact code *before* the addField but never
thought to try adding it after. Duh.

That said, i still don't understand exactly what was going on. I understand
addField was modifying the layout, but i don't understand specifically why
it was creating the effect it did, i.e. why the label was taking up the
entire row and pushing my text fields down a row.

Could you take a few minutes and explain that?

Thanks!

Marc

"Trevor Kaufman" <tskaufma@gmail.com> wrote in message
news:fpa45l$8kl$1@build.eclipse.org...
> Hey Marc,
>
> It appears there is some magic going on.
>
> When you create the FieldEditors, they are setting the layout on the
> parent. Your layouts get ignored. Also, after the createFieldEditors
> method another method is called in which all the field editors adjust
> their size to fill the space.
>
> I am not sure what the best possible solution is, but in your specific
> case, getting the layout from group and adjusting its numColumns got the
> result you were looking for.
>
> After adding the two StringFieldEditors do this:
>
> GridLayout urlLayout = (GridLayout) urlGroup.getLayout();
> urlLayout.numColumns = 3;
>
> This works, but I am not sure its the best way to go about this. If anyone
> else has a better solution, please comment, I am interested in seeing the
> answer.
>
> Hope this helps,
> Trevor Kaufman
>
> "Marc E" <marc_e@ye.olde.spam.buster.cablespeed.com> wrote in message
> news:fp7snm$uih$1@build.eclipse.org...
>> Greetings all. I've got a preference page that extends
>> FieldEditorPreferencePage.
>>
>> I'm have only a few preferences, but they naturally fit into groups so
>> I'd like to group them with a Group().
>>
>> Everything works fine when I use stringfieldeditor. That is to say, the
>> label lines up nicely on the left and the string field sits to the
>> right.. Everything appears to be a nice 2-column grid layout.
>>
>> However, I have one group that takes a DirectoryFieldEditor. When I call
>> addField() with this editor, it completely screws up the layout for the
>> previous field editors. What happens is that the label for those previous
>> ones now sits on top of the string fields. So instead of:
>>
>>
>> Username: -------------------------
>> Password: -------------------------
>> Directory: ----------------------------------------------- Browse
>>
>> I now get
>>
>>
>> Username:
>> -----------------------
>> Password:
>> -----------------------
>> Directory -------------------------------------------------Browse
>>
>> I'm admittedly still just learning layouts, and I'm hoping its that n00b
>> misunderstanding that's causing me to miss something obvious. I've tried
>> all kinds of combinations with spans and Layout cols, but to no avail.
>>
>> Any help is MOST appreciated!!!
>>
>> Thanks so much.
>>
>> Here's my code:
>>
>> public void createFieldEditors() {
>> Composite container = new
>> Composite(this.getFieldEditorParent(),SWT.NONE);
>> GridData containerData = new
>> GridData(GridData.FILL,GridData.FILL,true,false);
>> containerData.horizontalSpan = 1;
>>
>> container.setLayoutData(containerData);
>> GridLayout layout = new GridLayout(1,false);
>> container.setLayout(layout);
>>
>> //first group
>> Group urlGroup = new Group(container,SWT.NONE);
>> urlGroup.setText("Test Runner URL");
>> GridData gd = new GridData(GridData.FILL,GridData.FILL,true,false);
>> gd.horizontalSpan = 2;
>> urlGroup.setLayoutData(gd);
>> urlGroup.setLayout(new GridLayout(2,false));
>>
>> addField(new StringFieldEditor(MXUnitPreferenceConstants.P_USERNAME, "
>> &Username:", 20, urlGroup));
>> addField(new StringFieldEditor(MXUnitPreferenceConstants.P_PASSWORD, "
>> &Password:", 20, urlGroup));
>>
>> //second group
>> Group webrootGroup = new Group(container, SWT.NONE);
>> webrootGroup.setText("Your web root");
>> GridData gd3 = new GridData(GridData.FILL,GridData.FILL,true,false);
>> gd3.horizontalSpan = 3;
>> webrootGroup.setLayoutData(gd3);
>> webrootGroup.setLayout(new GridLayout(3,false));
>>
>>
>> DirectoryFieldEditor webrootDir = new
>> DirectoryFieldEditor(MXUnitPreferenceConstants.P_WEBROOTPATH ,
>> " &Web root directory:", webrootGroup);
>> addField(webrootDir);
>> }
>>
Re: need help tweaking a layout on preference page [message #325433 is a reply to message #325406] Mon, 18 February 2008 12:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: tskaufma.gmail.com

Hey Marc,

I'll do my best to explain it here.

When you create and add your FieldEditors they set the layout on their
parent. In your case, that is the group. After createFieldEditor returns,
another method gets called if the layout style is GRID. This method
readjusts all the FieldEditors to fit given the largest FieldEditor. In your
case, the largest has 3 controls, which is the DirectoryFieldEditor. This
information is passed to your StringFieldEditors and they decide to make the
text control have a horizontal span of 2 columns. Since your group
containing the StringFieldEditors only has 2 columns, the text control jumps
down to the next line to satisfy its column span of 2.

There appears to be an assumption that ALL the FieldEditors share a common
parent, namely the one returned by getFieldEditorParent(), and so the
automatic layout adjustments are all tuned for that. This assumption is not
true in your case and is causing odd behaviour.

I hope this clarifies what is going on,

Trevor Kaufman

"Marc E" <marc_e@ye.olde.spam.buster.cablespeed.com> wrote in message
news:fpbkkd$fu2$1@build.eclipse.org...
> Un-be-liev-able.
>
> dude, i spent hours monkeying with this. trying to set the griddata
> separately on the label and text fields, etc. your two lines did the
> trick. funny thing is i had added that exact code *before* the addField
> but never thought to try adding it after. Duh.
>
> That said, i still don't understand exactly what was going on. I
> understand addField was modifying the layout, but i don't understand
> specifically why it was creating the effect it did, i.e. why the label was
> taking up the entire row and pushing my text fields down a row.
>
> Could you take a few minutes and explain that?
>
> Thanks!
>
> Marc
>
> "Trevor Kaufman" <tskaufma@gmail.com> wrote in message
> news:fpa45l$8kl$1@build.eclipse.org...
>> Hey Marc,
>>
>> It appears there is some magic going on.
>>
>> When you create the FieldEditors, they are setting the layout on the
>> parent. Your layouts get ignored. Also, after the createFieldEditors
>> method another method is called in which all the field editors adjust
>> their size to fill the space.
>>
>> I am not sure what the best possible solution is, but in your specific
>> case, getting the layout from group and adjusting its numColumns got the
>> result you were looking for.
>>
>> After adding the two StringFieldEditors do this:
>>
>> GridLayout urlLayout = (GridLayout) urlGroup.getLayout();
>> urlLayout.numColumns = 3;
>>
>> This works, but I am not sure its the best way to go about this. If
>> anyone else has a better solution, please comment, I am interested in
>> seeing the answer.
>>
>> Hope this helps,
>> Trevor Kaufman
>>
>> "Marc E" <marc_e@ye.olde.spam.buster.cablespeed.com> wrote in message
>> news:fp7snm$uih$1@build.eclipse.org...
>>> Greetings all. I've got a preference page that extends
>>> FieldEditorPreferencePage.
>>>
>>> I'm have only a few preferences, but they naturally fit into groups so
>>> I'd like to group them with a Group().
>>>
>>> Everything works fine when I use stringfieldeditor. That is to say, the
>>> label lines up nicely on the left and the string field sits to the
>>> right.. Everything appears to be a nice 2-column grid layout.
>>>
>>> However, I have one group that takes a DirectoryFieldEditor. When I call
>>> addField() with this editor, it completely screws up the layout for the
>>> previous field editors. What happens is that the label for those
>>> previous ones now sits on top of the string fields. So instead of:
>>>
>>>
>>> Username: -------------------------
>>> Password: -------------------------
>>> Directory: ----------------------------------------------- Browse
>>>
>>> I now get
>>>
>>>
>>> Username:
>>> -----------------------
>>> Password:
>>> -----------------------
>>> Directory -------------------------------------------------Browse
>>>
>>> I'm admittedly still just learning layouts, and I'm hoping its that n00b
>>> misunderstanding that's causing me to miss something obvious. I've
>>> tried all kinds of combinations with spans and Layout cols, but to no
>>> avail.
>>>
>>> Any help is MOST appreciated!!!
>>>
>>> Thanks so much.
>>>
>>> Here's my code:
>>>
>>> public void createFieldEditors() {
>>> Composite container = new
>>> Composite(this.getFieldEditorParent(),SWT.NONE);
>>> GridData containerData = new
>>> GridData(GridData.FILL,GridData.FILL,true,false);
>>> containerData.horizontalSpan = 1;
>>>
>>> container.setLayoutData(containerData);
>>> GridLayout layout = new GridLayout(1,false);
>>> container.setLayout(layout);
>>>
>>> //first group
>>> Group urlGroup = new Group(container,SWT.NONE);
>>> urlGroup.setText("Test Runner URL");
>>> GridData gd = new GridData(GridData.FILL,GridData.FILL,true,false);
>>> gd.horizontalSpan = 2;
>>> urlGroup.setLayoutData(gd);
>>> urlGroup.setLayout(new GridLayout(2,false));
>>>
>>> addField(new StringFieldEditor(MXUnitPreferenceConstants.P_USERNAME,
>>> " &Username:", 20, urlGroup));
>>> addField(new StringFieldEditor(MXUnitPreferenceConstants.P_PASSWORD,
>>> " &Password:", 20, urlGroup));
>>>
>>> //second group
>>> Group webrootGroup = new Group(container, SWT.NONE);
>>> webrootGroup.setText("Your web root");
>>> GridData gd3 = new GridData(GridData.FILL,GridData.FILL,true,false);
>>> gd3.horizontalSpan = 3;
>>> webrootGroup.setLayoutData(gd3);
>>> webrootGroup.setLayout(new GridLayout(3,false));
>>>
>>>
>>> DirectoryFieldEditor webrootDir = new
>>> DirectoryFieldEditor(MXUnitPreferenceConstants.P_WEBROOTPATH ,
>>> " &Web root directory:", webrootGroup);
>>> addField(webrootDir);
>>> }
>>>
>
>
Re: need help tweaking a layout on preference page [message #325436 is a reply to message #325433] Mon, 18 February 2008 15:12 Go to previous message
Eclipse UserFriend
Originally posted by: marc_e.ye.olde.spam.buster.cablespeed.com

perfect. thanks!

"Trevor Kaufman" <tskaufma@gmail.com> wrote in message
news:fpcfne$ljb$1@build.eclipse.org...
> Hey Marc,
>
> I'll do my best to explain it here.
>
> When you create and add your FieldEditors they set the layout on their
> parent. In your case, that is the group. After createFieldEditor returns,
> another method gets called if the layout style is GRID. This method
> readjusts all the FieldEditors to fit given the largest FieldEditor. In
> your case, the largest has 3 controls, which is the DirectoryFieldEditor.
> This information is passed to your StringFieldEditors and they decide to
> make the text control have a horizontal span of 2 columns. Since your
> group containing the StringFieldEditors only has 2 columns, the text
> control jumps down to the next line to satisfy its column span of 2.
>
> There appears to be an assumption that ALL the FieldEditors share a common
> parent, namely the one returned by getFieldEditorParent(), and so the
> automatic layout adjustments are all tuned for that. This assumption is
> not true in your case and is causing odd behaviour.
>
> I hope this clarifies what is going on,
>
> Trevor Kaufman
>
> "Marc E" <marc_e@ye.olde.spam.buster.cablespeed.com> wrote in message
> news:fpbkkd$fu2$1@build.eclipse.org...
>> Un-be-liev-able.
>>
>> dude, i spent hours monkeying with this. trying to set the griddata
>> separately on the label and text fields, etc. your two lines did the
>> trick. funny thing is i had added that exact code *before* the addField
>> but never thought to try adding it after. Duh.
>>
>> That said, i still don't understand exactly what was going on. I
>> understand addField was modifying the layout, but i don't understand
>> specifically why it was creating the effect it did, i.e. why the label
>> was taking up the entire row and pushing my text fields down a row.
>>
>> Could you take a few minutes and explain that?
>>
>> Thanks!
>>
>> Marc
>>
>> "Trevor Kaufman" <tskaufma@gmail.com> wrote in message
>> news:fpa45l$8kl$1@build.eclipse.org...
>>> Hey Marc,
>>>
>>> It appears there is some magic going on.
>>>
>>> When you create the FieldEditors, they are setting the layout on the
>>> parent. Your layouts get ignored. Also, after the createFieldEditors
>>> method another method is called in which all the field editors adjust
>>> their size to fill the space.
>>>
>>> I am not sure what the best possible solution is, but in your specific
>>> case, getting the layout from group and adjusting its numColumns got the
>>> result you were looking for.
>>>
>>> After adding the two StringFieldEditors do this:
>>>
>>> GridLayout urlLayout = (GridLayout) urlGroup.getLayout();
>>> urlLayout.numColumns = 3;
>>>
>>> This works, but I am not sure its the best way to go about this. If
>>> anyone else has a better solution, please comment, I am interested in
>>> seeing the answer.
>>>
>>> Hope this helps,
>>> Trevor Kaufman
>>>
>>> "Marc E" <marc_e@ye.olde.spam.buster.cablespeed.com> wrote in message
>>> news:fp7snm$uih$1@build.eclipse.org...
>>>> Greetings all. I've got a preference page that extends
>>>> FieldEditorPreferencePage.
>>>>
>>>> I'm have only a few preferences, but they naturally fit into groups so
>>>> I'd like to group them with a Group().
>>>>
>>>> Everything works fine when I use stringfieldeditor. That is to say, the
>>>> label lines up nicely on the left and the string field sits to the
>>>> right.. Everything appears to be a nice 2-column grid layout.
>>>>
>>>> However, I have one group that takes a DirectoryFieldEditor. When I
>>>> call addField() with this editor, it completely screws up the layout
>>>> for the previous field editors. What happens is that the label for
>>>> those previous ones now sits on top of the string fields. So instead
>>>> of:
>>>>
>>>>
>>>> Username: -------------------------
>>>> Password: -------------------------
>>>> Directory: ----------------------------------------------- Browse
>>>>
>>>> I now get
>>>>
>>>>
>>>> Username:
>>>> -----------------------
>>>> Password:
>>>> -----------------------
>>>> Directory -------------------------------------------------Browse
>>>>
>>>> I'm admittedly still just learning layouts, and I'm hoping its that
>>>> n00b misunderstanding that's causing me to miss something obvious.
>>>> I've tried all kinds of combinations with spans and Layout cols, but to
>>>> no avail.
>>>>
>>>> Any help is MOST appreciated!!!
>>>>
>>>> Thanks so much.
>>>>
>>>> Here's my code:
>>>>
>>>> public void createFieldEditors() {
>>>> Composite container = new
>>>> Composite(this.getFieldEditorParent(),SWT.NONE);
>>>> GridData containerData = new
>>>> GridData(GridData.FILL,GridData.FILL,true,false);
>>>> containerData.horizontalSpan = 1;
>>>>
>>>> container.setLayoutData(containerData);
>>>> GridLayout layout = new GridLayout(1,false);
>>>> container.setLayout(layout);
>>>>
>>>> //first group
>>>> Group urlGroup = new Group(container,SWT.NONE);
>>>> urlGroup.setText("Test Runner URL");
>>>> GridData gd = new GridData(GridData.FILL,GridData.FILL,true,false);
>>>> gd.horizontalSpan = 2;
>>>> urlGroup.setLayoutData(gd);
>>>> urlGroup.setLayout(new GridLayout(2,false));
>>>>
>>>> addField(new StringFieldEditor(MXUnitPreferenceConstants.P_USERNAME,
>>>> " &Username:", 20, urlGroup));
>>>> addField(new StringFieldEditor(MXUnitPreferenceConstants.P_PASSWORD,
>>>> " &Password:", 20, urlGroup));
>>>>
>>>> //second group
>>>> Group webrootGroup = new Group(container, SWT.NONE);
>>>> webrootGroup.setText("Your web root");
>>>> GridData gd3 = new GridData(GridData.FILL,GridData.FILL,true,false);
>>>> gd3.horizontalSpan = 3;
>>>> webrootGroup.setLayoutData(gd3);
>>>> webrootGroup.setLayout(new GridLayout(3,false));
>>>>
>>>>
>>>> DirectoryFieldEditor webrootDir = new
>>>> DirectoryFieldEditor(MXUnitPreferenceConstants.P_WEBROOTPATH ,
>>>> " &Web root directory:", webrootGroup);
>>>> addField(webrootDir);
>>>> }
>>>>
>>
>>
Previous Topic:ntlm authentication question
Next Topic:[DataBinding] Relation of JavaBeans and JFace DB
Goto Forum:
  


Current Time: Sun May 11 10:09:20 EDT 2025

Powered by FUDForum. Page generated in 0.04369 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top