Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Tree column resize problem on OS X
Tree column resize problem on OS X [message #15122] Wed, 17 June 2009 00:50
Bjorn Gustafsson is currently offline Bjorn GustafssonFriend
Messages: 9
Registered: July 2009
Junior Member
Hi,
I'm using a tree table with several columns, using a TreeColumnLayout. The
tree table is contained in a SashForm.

I have a problem on OS X: when expanding nodes in the tree the column with
the tree becomes wider and following columns get partially hidden under
the Sash. A horizontal scroll appears which allows viewing of those
columns, but there is no way for the user to adjust the tree width so
that the full tree comes back in view - resizing using the Sash, or by
resizing individual columns using their column divider, does not reveal
the hidden columns.
(On Win XP it behaves differently (and more appropriately for my
application): the tree column's width remains intact when the tree is
expanded/compressed)

My question is: Is there a way to preserve the tree column width under OS
X so it remains intact when the tree is expanded/contracted?

Any input is much appreciated!
With Best Regards,
Bjorn Gustafsson


Here is a snippet that demonstrates my problem:
(I'm using Eclipse 3.4.2 on both OS X and Win XP)

import org.eclipse.jface.layout.TreeColumnLayout;
import org.eclipse.jface.viewers.ColumnPixelData;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;

/**
*
* Snippet that demonstrates a problem with managing tree columns in OS X:
* When expanding nodes in the tree, the column where the tree resides
expands as well, pushing
* following columns out to the right. This change goes undetected and
after a tree expansion, the
* right-hand side of tree becomes partially obscured under the sash.
*
*/
public class TreeColumnProblemSnippet {

public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
new TreeColumnProblemSnippet(shell);
shell.setSize( 800, 600 );
shell.open();
while ( !shell.isDisposed() ) {
if ( !display.readAndDispatch() ) {
display.sleep();
}
}

display.dispose();
}

public TreeColumnProblemSnippet(Shell shell) {

SashForm sashForm = new SashForm( shell, SWT.HORIZONTAL );

Composite comp = new Composite(sashForm, SWT.None);

final TreeViewer treeViewer = new TreeViewer( comp, SWT.None );

treeViewer.setContentProvider( new MyContentProvider() );

treeViewer.setInput( treeRoot);

final Tree tree = treeViewer.getTree();
tree.setHeaderVisible(true);

buildTreeColumns(tree);

// Add empty component to the right-hand side of the sash form
new Composite(sashForm,SWT.DEFAULT);

sashForm.setWeights( new int[] { 50, 50 } );
}

private TreeColumn treeColumn;

private void buildTreeColumns(Tree tree) {

treeColumn = new TreeColumn(tree, SWT.LEFT);
treeColumn.setText("tree column");

TreeColumn secondColumn = new TreeColumn(tree, SWT.NONE);
secondColumn.setAlignment(SWT.RIGHT);
secondColumn.setText("c2");

TreeColumn thirdColumn = new TreeColumn(tree, SWT.NONE);
thirdColumn.setAlignment(SWT.RIGHT);
thirdColumn.setText("c3");


/*
* TreeColumnLayout:
* TreeColumnLayout is the Layout used to maintain TreeColumn sizes in a
Tree.
* "You can only add the Layout to a container whose only child is the
Tree control you want
* the Layout applied to. Don't assign the layout directly to the Tree."
*/
Composite treeParent = tree.getParent();
TreeColumnLayout treeLayout = new TreeColumnLayout();
treeParent.setLayout(treeLayout);

treeColumn.setResizable(true);
secondColumn.setResizable(false);

treeLayout.setColumnData(treeColumn, new ColumnWeightData(100));
treeLayout.setColumnData(secondColumn, new ColumnWeightData(100));
treeLayout.setColumnData(thirdColumn, new ColumnPixelData(30));

tree.setLinesVisible(true);

}

/*
* Contents of the demo tree: just numbers
*/

private Integer treeRoot = new Integer(0);

static class MyContentProvider implements ITreeContentProvider
{
public Object[] getChildren( Object parentElement ) {
Integer rootInt = (Integer) parentElement;
return new Integer[] {(rootInt*10)+1, (rootInt*10)+2, (rootInt*10)+3};
}

public Object getParent( Object element ) {
return null;
}

public boolean hasChildren( Object element ) {
return true;
}

public Object[] getElements( Object inputElement ) {
return getChildren(inputElement);
}

public void dispose()
{
}

public void inputChanged( Viewer viewer, Object oldInput,
Object newInput ) {
}
}


}
Previous Topic:hide the parent node in treeviewer
Next Topic:Re: create TreeItem in TreeViewer
Goto Forum:
  


Current Time: Thu Mar 28 21:43:15 GMT 2024

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

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

Back to the top