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 07:48 Go to next message
Mokhtar Abdu is currently offline Mokhtar Abdu
Messages: 104
Registered: November 2011
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 08:14 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
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 09:12 Go to previous messageGo to next message
Mokhtar Abdu is currently offline Mokhtar Abdu
Messages: 104
Registered: November 2011
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 09:46 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
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 10:20 Go to previous message
Mokhtar Abdu is currently offline Mokhtar Abdu
Messages: 104
Registered: November 2011
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:[Databinding] Put data to a WritableMap from other Thread
Next Topic:drag and drop change icon
Goto Forum:
  


Current Time: Wed Aug 20 20:40:21 EDT 2014

Powered by FUDForum. Page generated in 0.01556 seconds