Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Dynamic tables in a view
Dynamic tables in a view [message #896284] Tue, 17 July 2012 21:03 Go to next message
Timothy Vogel is currently offline Timothy VogelFriend
Messages: 82
Registered: July 2009
Member
I can't get a view to behave and I'm hoping you have some suggestions.

Based on a menu choice, I need to display a different table of data in a single view. My approach is to subclass Composite with the correct columns, attributes and data for each table. Based on the value passed from the menu handler to the view, I create an instance of the correct subclass. The issue is the table does not fill the view and when creating the second one, the first still appears.

I have tried various combinations of layouts and computeSize but without success. If I copy the table code into the createPartControl, the appearance is correct but I don't think this will work for dynamically setting the table.

pseudo code
class ReferenceTable extends ViewPart {
  createPartControl(Composite parent) {
    parent.setLayoutData(new GridLayout();
  }

  setTable(String tableName) {
    if previous table
      dispose previous table

    compositeTable = new RequestedTable(parent, SWT.NONE);

    parent.layout();
  }
}

class RequestedTable extends Composite {
  public RequestedTable(Composite parent, int style) {
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayoutData(new FillLayout());

	TableColumnLayout tcl_composite = new TableColumnLayout();
	composite.setLayout(tcl_composite);

	tableViewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
	table = tableViewer.getTable();

	// create columns in table here

	// load data into table

	// enable viewer to show data
	tableViewer.setContentProvider(new ArrayContentProvider());
	tableViewer.setInput(data);

    
  }
}
Re: Dynamic tables in a view [message #896369 is a reply to message #896284] Wed, 18 July 2012 08:17 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi,

how exactly looks the code where you dispose the old table?
Re: Dynamic tables in a view [message #896413 is a reply to message #896369] Wed, 18 July 2012 10:37 Go to previous messageGo to next message
Timothy Vogel is currently offline Timothy VogelFriend
Messages: 82
Registered: July 2009
Member
Thanks for your reply!

	public void setTable(String tblName) {
		if (compositeTable != null) {
			compositeTable.dispose();
			compositeTable = null;
		}

		// nested if, then, else loop to select the correct table composite subclss
		compositeTable = new RequestedTable(parent, SWT.NONE);

		parent.layout();
Re: Dynamic tables in a view [message #896456 is a reply to message #896413] Wed, 18 July 2012 12:32 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
To fill the table the entire ViewPart I would try to set the layout data as follows
public void setTable(String tblName) {
    if (compositeTable != null) {
        compositeTable.dispose();
	compositeTable = null;
    }

    // nested if, then, else loop to select the correct table composite subclss
    compositeTable = new RequestedTable(parent, SWT.NONE);
    compositetable.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create())
	
    parent.layout();
}

I would't create the "root" composite in the RequestedTable since it's the Composite itself
class RequestedTable extends Composite {
  
    public RequestedTable(Composite parent, int style) {
	TableColumnLayout tcl_composite = new TableColumnLayout();
	setLayout(tcl_composite);

	tableViewer = new TableViewer(RequestedTable.this, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
	table = tableViewer.getTable();

	// create columns in table here

	// load data into table

	// enable viewer to show data
	tableViewer.setContentProvider(new ArrayContentProvider());
	tableViewer.setInput(data);
  }
}
Re: Dynamic tables in a view [message #896674 is a reply to message #896456] Thu, 19 July 2012 11:01 Go to previous message
Timothy Vogel is currently offline Timothy VogelFriend
Messages: 82
Registered: July 2009
Member
Jan,
Thanks for your suggestions!

Your suggestion did not quite work but it put me onto the path that did work.

Instead of inheriting from Composite, I used the composite in the object. I implement a simple interface that has a dispose method that calls the composite's dispose so that I don't leak resources.

Thanks again!
Previous Topic:How to open console and problems view while running a job
Next Topic:Save reference of input of a Part
Goto Forum:
  


Current Time: Tue Mar 19 09:41:54 GMT 2024

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

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

Back to the top