Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » dynamic dispose and create of treeviewer + columns(but the treeviewer doesn't show unless i manually resize its parent sashform)
dynamic dispose and create of treeviewer + columns [message #1022165] Thu, 21 March 2013 11:48 Go to next message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
Hi,

I dispose my treeviewer and recreate it dynamically (with its columns) everytime i pass a new input (as column number is dynamic too). My problem is that the tree doesn't show unless I manually resize the sashForm containing the composite that holds this treeviewer.
Any help??
I used tree.pack() but it packs the tree to much especially the height.

Regards,
Mok

Re: dynamic dispose and create of treeviewer + columns [message #1022175 is a reply to message #1022165] Thu, 21 March 2013 12:14 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 2013-03-21 12:48, Xtexter Mising name wrote:
> Hi,
>
> I dispose my treeviewer and recreate it dynamically (with its columns)
> everytime i pass a new input (as column number is dynamic too). My
> problem is that the tree doesn't show unless I manually resize the
> sashForm containing the composite that holds this treeviewer.
> Any help??

You shouldn't dispose the tree all the time. Instead, only dispose the
columns and recreate the new ones.

HTH & Greetings from Bremen,

Daniel Krügler
Re: dynamic dispose and create of treeviewer + columns [message #1022195 is a reply to message #1022175] Thu, 21 March 2013 13:12 Go to previous messageGo to next message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
Thank you Daniel Krügler but I did this and unfortunately I got the exception
"Column 0 has no label.." Perhaps even I dispose the columns (say 3 columns) , they are still there somewhere as my CellLabelProvider object is still aware of them. I suppose my labelprovider encounters 6 columns when i run twice...

this is how i dispose my columns and recreate them as you suggested (which stll didn't work)
//treeviewer and tree creation fragment

trViewer= new TreeViewer(composite, SWT.BORDER);
		tree = trViewer.getTree();
		tree.setHeaderVisible(true);
		tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,      
                true, 1, 1));
		sashForm.setWeights(new int[] {34, 117, 226, 83});

//dispose and create columns
private void createColumns(ArrayList<Car> input) {
		
                //dispose all columns
		TreeColumn[] clmns =  trViewer.getTree().getColumns();
		for (TreeColumn clm : clmns) {
			clm.dispose();
		}
		for (Car car : input) {
			TreeViewerColumn treeViewerColumn = new      
                        TreeViewerColumn(trViewer, SWT.NONE);
			TreeColumn trclmnNewColumn = treeViewerColumn.getColumn();
			trclmnNewColumn.setWidth(120);
			trclmnNewColumn.setText(car.getModel());
		}
		
	}

//finally this is where i set the providers and input
trViewer.setContentProvider(new CarsContentProvider());
trViewer.setLabelProvider(new CarsLabelProvider());
trViewer.setInput(loadCarsData());


Can you help me???

Regards,
Mok from Bonn
Re: dynamic dispose and create of treeviewer + columns [message #1022216 is a reply to message #1022195] Thu, 21 March 2013 13:46 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 2013-03-21 14:12, Mokhtar Abdu wrote:
> Thank you Daniel Krügler but I did this and unfortunately I got the
> exception
> "Column 0 has no label.." Perhaps even I dispose the columns (say 3
> columns) , they are still there somewhere as my CellLabelProvider object
> is still aware of them. I suppose my labelprovider encounters 6 columns
> when i run twice...

What are you running twice? You better don't try to dispose the columns
twice. It sounds as if you are are refreshing the tree, while disposing.

Also, to should wrap the disposal code within

tree.setRedraw(false);
try {
// Dispose columns
// Create new columns, EditingSupport, CellLabelProviders, etc.
} finally {
tree.setRedraw(true);
}

HTH & Greetings from Bremen,

Daniel Krügler
Re: dynamic dispose and create of treeviewer + columns [message #1022237 is a reply to message #1022216] Thu, 21 March 2013 14:20 Go to previous message
Mokhtar Alshubei is currently offline Mokhtar AlshubeiFriend
Messages: 121
Registered: November 2011
Location: Germany
Senior Member
The problem still exists. Sad WIth twice i meant when I call the method twice with two different inputs or the same. This means, there could be more or less column numbers as well as data. Here is my method after integrating what you suggested:
public  void updateCandidatesTable() {
				
		ArrayList<ResultsVersion> selectedVersions = getSelectedVersions(); //model if none selected
		
		
		trVrCandidates.getTree().setRedraw(false);
		try {
		// Dispose columns
			TreeColumn[] clmns =  trVrCandidates.getTree().getColumns();
			for (TreeColumn clm : clmns) {
				clm.dispose();
			}
		// Create new columns, EditingSupport, CellLabelProviders, etc.
			for (ResultsVersion rv : model) {
				TreeViewerColumn treeViewerColumn = new TreeViewerColumn(trVrCandidates, SWT.NONE);
				TreeColumn trclmnNewColumn = treeViewerColumn.getColumn();
				trclmnNewColumn.setWidth(120);
				trclmnNewColumn.setText(rv.getTimeTag());
			}
		
			trVrCandidates.setContentProvider(new AnalysisResultContentProvider());
			trVrCandidates.setLabelProvider(new AnalysisResultLabelProvider());
			//set input
			ArrayList<ResultsVersion> modelWithFirstVersion = new ArrayList<ResultsVersion>();
			modelWithFirstVersion.add(selectedVersions.get(0));
			trVrCandidates.setInput(modelWithFirstVersion);
		} finally {
			trVrCandidates.getTree().setRedraw(true);
		}
		
	}

And this is the error:
An error has occurred. See error log for more details.
assertion failed: Column 0 has no label provider.

Thanks for helping
Previous Topic:ScrolledForm Layout Problem
Next Topic:treeviewer columns disposal
Goto Forum:
  


Current Time: Thu Mar 28 08:11:12 GMT 2024

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

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

Back to the top