Home » Eclipse Projects » Rich Client Platform (RCP) » Problem understanding Forms and Sections
Problem understanding Forms and Sections [message #467419] |
Thu, 03 May 2007 15:52 |
Eclipse User |
|
|
|
Originally posted by: vgap4.gmx.de
Hi altogether,
I'm frustrated. I only want to put a Section or ExpandableComposite
inside a Composite of mine.
I don't want to have a ScrolledForm, because it adds a title bar and all
this stuff. I only want a Section. But I can't use it with a FormToolkit
only, because I need ScrolledForm.reflow(true) for handling the
Expanding or Collapsing of the Section.
In all examples I have found a ScrolledForm is used when a Section is
added. Why? Does it only works with ScrolledForm? Why can I not adapt a
Section directly to the FormToolkit?
Is there some more information about Forms?
best regards
Ilja
|
|
|
Re: Problem understanding Forms and Sections [message #467423 is a reply to message #467419] |
Thu, 03 May 2007 17:04 |
Paul E. Keyser Messages: 878 Registered: July 2009 |
Senior Member |
|
|
Yeah, ExpSxn is a bit tricky, but I've gotten it to work quite well. The code below shows how I've
wrapped up the function for my convenience -- clients get the composite(), set a Layout on it, and
add children. The parent is either theForm.getBody(), or any Composite down the containment
hierarchy from that one. The Form is just a Form (no ScrolledForm's were used).
HTH,
Paul
public class ExpandableCompositeSection extends ExpansionAdapter {
/**
* Create the ExpandableCompositeSection with the given data
* @param kit FormToolkit
* @param parent Composite in some Form
* @param layoutData Object of type suitable for the Layout of the parent
* @param text String label of the ExpandableComposite
* @param style int of the ExpandableComposite: e.g., ExpandableComposite.TWISTIE
* @param expanded boolean initial expansion-state
*/
public ExpandableCompositeSection(
final FormToolkit kit, final Composite parent, final Object layoutData,
final String text, final int style, boolean expanded) {
super(); // in case we change superclass to have data
_parent = parent;
_section = kit.createExpandableComposite(parent, style);
_section.setLayoutData(layoutData);
// internally we use GridLayout:
final GridLayout gridLayout = new GridLayout();
gridLayout.marginHeight = gridLayout.marginWidth = 0;
_section.setLayout(gridLayout);
_section.addExpansionListener(this);
_section.setText(text);
_section.setExpanded(expanded);
_composite = kit.createComposite(_section, SWT.NONE);
// as noted, internally we use GridLayout:
_composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
_section.setClient(_composite);
}
/**
* Get the "section" -- needed for working with the font of the text
* @return ExpandableComposite
*/
public ExpandableComposite section() {
return _section;
}
/**
* Get the client Composite -- to use as parent of contained widgets;
* client code is responsible for setting its Layout.
* @return Composite
*/
public Composite composite() {
return _composite;
}
/**
* Layout, i.e., redraw, the whole section.
*/
public void layout() {
_parent.getParent().layout();
}
/* (non-Javadoc)
* @see
org.eclipse.ui.forms.events.IExpansionListener#expansionStat eChanged(org.eclipse.ui.forms.events.ExpansionEvent)
*/
public void expansionStateChanged(final ExpansionEvent e) {
layout();
}
protected final Composite _parent;
protected final ExpandableComposite _section;
protected final Composite _composite;
}
|
|
| |
Re: Problem understanding Forms and Sections [message #467495 is a reply to message #467423] |
Fri, 04 May 2007 16:05 |
Eclipse User |
|
|
|
Originally posted by: vgap4.gmx.de
Hi Paul,
your class works well so long. It is actually quite easy.
But I have another problem.
I have added to the toolkit (btw. I actually use no Form at all - the
parent Composite for the Sections is simply the underlying Composite I
have all in) three of these ExpandableComposites.
When I expand or collapse one of the ExpandableComposites I need somehow
to call for the underlying Composite layout() to recalc the expanded
Composite. Or am I wrong here? I tried to add this to:
public void expansionStateChanged(final ExpansionEvent e) {
layout();
_composite.layout();
}
But that does not work.
In fact I want to have all ExpandableComposites lying one under each
other being collapsed initially. But then it is not possible to expand.
And when I start in a expanded state, I can collapse them but they still
use the amount of space like expanded.
For the underlying Composite I use a GridLayout with
GridData(GridData.FILL_HORIZONTAL) for the ExpandableComposites.
best regards
Ilja
|
|
|
Re: Problem understanding Forms and Sections [message #467545 is a reply to message #467495] |
Sun, 06 May 2007 13:19 |
Paul E. Keyser Messages: 878 Registered: July 2009 |
Senior Member |
|
|
Not quite sure I understand the problem you are seeing -- in my case, when I collapse the section,
unless I do something special, indeed the Composite containing that ExpSection does not resize (so
there is a big blank space). I use the ExpSxn in two places: an editor and a wizard. In the editor,
the ExpSxn is item N-1, in a GridLayout, and on collapse/expand, I have not been able to get the
parent Composite to re-layout correctly, so item N remains where it was, with a big blank space
between the collapsed ExpSxn and item N (ugh). In the wizard, the ExpSxn is the last item in a
GridLayout, and on collapse/expand I cause the whole wizard to resize, so the big blank space that
would left at the *bottom* is hidden by the resize. I have tentatively concluded the failure to
re-layout is a bug of GridLayout (I tried the same thing you did).
Is that what you were asking about?
HTH,
Paul
|
|
|
Re: Problem understanding Forms and Sections [message #467599 is a reply to message #467545] |
Tue, 08 May 2007 15:54 |
Eclipse User |
|
|
|
Originally posted by: vgap4.gmx.de
Paul Keyser schrieb:
> Not quite sure I understand the problem you are seeing -- in my case,
> when I collapse the section, unless I do something special, indeed the
> Composite containing that ExpSection does not resize (so there is a big
> blank space). I use the ExpSxn in two places: an editor and a wizard. In
> the editor, the ExpSxn is item N-1, in a GridLayout, and on
> collapse/expand, I have not been able to get the parent Composite to
> re-layout correctly, so item N remains where it was, with a big blank
> space between the collapsed ExpSxn and item N (ugh). In the wizard, the
> ExpSxn is the last item in a GridLayout, and on collapse/expand I cause
> the whole wizard to resize, so the big blank space that would left at
> the *bottom* is hidden by the resize. I have tentatively concluded the
> failure to re-layout is a bug of GridLayout (I tried the same thing you
> did).
>
> Is that what you were asking about?
>
> HTH,
> Paul
Hi Paul,
yes that's what I was wondering about. I'm looking for a way to relayout
the parent Composite. I tried it with RowLayout as well with the same
result. Only thing I can think of that calculating the size of the
ExpandableSection does not work somehow. I'll try something here and
have a look at the sourcecode. Thanks Paul.
best regards
Ilja
|
|
| |
Re: Problem understanding Forms and Sections [message #467656 is a reply to message #467603] |
Wed, 09 May 2007 17:54 |
Eclipse User |
|
|
|
Originally posted by: vgap4.gmx.de
Paul Keyser schrieb:
> If you do find a problem, please create a bug in Eclipse's bugzilla, and
> I will be sure to confirm it for you and vote for it. On the other hand,
> if you find a workaround ... :)
>
> thanks,
> Paul
It's just tooooo easy:
public void expansionStateChanged(final ExpansionEvent e) {
_section.pack();
_parent.layout();
}
try this for your ExpandableCompositeSection.
Now I have only the problem that pack() overwrites the SWT.FILL or
GridData.FILL_HORIZONTAL style ...
regards
Ilja
|
|
|
Goto Forum:
Current Time: Sat Apr 20 04:07:06 GMT 2024
Powered by FUDForum. Page generated in 0.05447 seconds
|