Reputation: 1441
In my Eclipse plugin I have an editor with a tree viewer (specifically saying it is a FilteredTree
). Initially, the size of the viewer fits in the parent composite.
When I extend some node in the viewer and the amount of children is to high to display all of them in the viewer, the viewer becomes scrollable, and this is OK.
My problem is that when I resize the entire editor part, the viewer gets expanded vertically (horizontally as well, so it is big enough to display all the elements and the scroll bars disappear. How to avoid resizing the viewer?
EDIT:
Some requested details about implementation:
I use GridLayout
for the viewer itself and also for all the containers above.
The editor is a simple multipage editor. Here is a snippet of the problematic page class implementation:
public class MyPage extends FormPage {
[...]
@Override
protected void createFormContent(IManagedForm managedForm) {
FormToolkit toolkit = managedForm.getToolkit();
ScrolledForm form = managedForm.getForm();
Composite body = form.getBody();
toolkit.decorateFormHeading(form.getForm());
toolkit.paintBordersFor(body);
fBlock = new MyMasterDetailsBlock();
fBlock.createContent(managedForm);
}
}
The MyMasterDetailsBlock
class inherits from MasterDetailsBlock
:
public class ModelMasterDetailsBlock extends MasterDetailsBlock{
[...]
@Override
protected void createMasterPart(IManagedForm managedForm, Composite parent) {
fToolkit = managedForm.getToolkit();
fMasterSection = fToolkit.createSection(parent, ExpandableComposite.EXPANDED|ExpandableComposite.TITLE_BAR);
fMasterSectionPart = new SectionPart(fMasterSection, fToolkit, 0);
GridData masterSectionGridData = new GridData(SWT.FILL, SWT.FILL, false, true);
fMasterSection.setLayoutData(masterSectionGridData);
createTreeEditorBlock();
}
private void createTreeEditorBlock() {
fMainComposite = new Composite(fMasterSection, SWT.FILL);
fMainComposite.setLayout(new GridLayout(1, false));
fToolkit.adapt(fMainComposite);
fToolkit.paintBordersFor(fMainComposite);
fMasterSection.setClient(fMainComposite);
FilteredTree filteredTree = new FilteredTree(composite, SWT.BORDER, new patternFilter(), true);
fTreeViewer = filteredTree.getViewer();
Tree tree = fTreeViewer.getTree();
tree.setLayout(new GridLayout(1, false));
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
fToolkit.paintBordersFor(tree);
}
}
Upvotes: 1
Views: 355
Reputation: 111142
When you create the tree you are setting the layout data for the tree to:
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
This is telling the layout that you want the tree to fill all the space. If you want the tree to be a fixed size you need to use something like:
GridData data = new GridData(SWT.TOP, SWT.LEFT, false, false);
data.widthHint = 200;
data.heightHint = 300;
tree.setLayoutData(data);
where you choose the width and height hint values.
Upvotes: 1