TableViewer displaysTable, but Table is shifted right. [message #276989] |
Thu, 02 December 2004 13:17  |
Eclipse User |
|
|
|
I have created a View that contains a TableViewer, and the TableViewer
contains a Table I explicitly define for it. The View is created
programmatically when the user selects an action from a context menu using
IViewPart newView =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().showView(classID,
classID + "." + altViewID, IWorkbenchPage.VIEW_ACTIVATE);
// I'll explain this stuff below
TabularDataManager tableData = new TabularDataManager(query);
if(newView instanceof com.powertech.audit.views.TabularResultView)
{
((TabularResultView)newView).recreateWithData(tableData, altViewID);
}
Since I need to use the showView() method to get the view to display it
initially has no data and simply contains a blank dataset and an empty
Table. Once the new View is created I call a method on the view that sets
the data I want the view to display and then creates a new Table using the
data ( recreateWithData() ). The method then creates a new TableViewer,
passing it the new Table via the TableViewer constructor. The TableViewer
is then refreshed with the refresh() method. The table appears in the
View with all the columns and data displayed but the entire table is
shifted right about half the width of the View window. In other words if
the text drawing below is the entire View the Table begins as shown:
View
+-----------------------+
| | |
| Blank | Table |
| Space | Displays |
| | |
+-----------------------+
^
|
+ ----- Table begins here
I suspect that the blank space is due to the initial blank Table that
somehow isn't getting removed and the view is trying to display, but I
don't know how to remove the reference to the original blank Table. I
don't even know if this is what is causing the problem. I've posted my
createPartControl(), createTable(), and recreateWithData() methods from my
View below. Please, any help would be appreciated.
public void createPartControl(Composite parent)
{
System.out.println("Enter TabularResultView:createPartControl()");
// Save a copy of the parent of this view
viewParent = parent;
// Determine if data is already set to be loaded into a view
if(tabularDataManager != null)
{
if(tabularDataManager.hasData())
{
// Create the table
createTable();
// Create the viewer
viewer = new TableViewer(table);
}
}
else
{
// Create blank data and an empty table
tabularDataManager = new TabularDataManager();
table = new Table(viewParent,
SWT.H_SCROLL | SWT.V_SCROLL |
SWT.MULTI | SWT.FULL_SELECTION);
// Create the viewer
viewer = new TableViewer(table);
}
viewContentProvider = new ViewContentProvider();
viewLabelProvider = new ViewLabelProvider();
viewer.setContentProvider(viewContentProvider);
viewer.setLabelProvider(viewLabelProvider);
viewer.setInput(tabularDataManager);
System.out.println("Leave TabularResultView:createPartControl()");
}
private void createTable()
{
Vector columnHeadings = tabularDataManager.getColumnHeadings();
System.out.println("columnHeadings.size() = " + columnHeadings.size());
System.out.println("class of first element" +
columnHeadings.firstElement().getClass());
table = new Table(viewParent,
SWT.H_SCROLL | SWT.V_SCROLL |
SWT.MULTI | SWT.FULL_SELECTION);
layout = new TableLayout();
table.setLayout(layout);
table.setLinesVisible(true);
table.setHeaderVisible(true);
for( int i = 0; i < columnHeadings.size(); i++ )
{
String columnHeading = (String)columnHeadings.elementAt(i);
layout.addColumnData(new ColumnWeightData(50,100,true));
TableColumn newColumn = new TableColumn(table, SWT.NONE);
newColumn.setText(columnHeading);
newColumn.setResizable(true);
}
}
public void recreateWithData(TabularDataManager newDataMgr, String tabName)
{
// Update the underlying data model
tabularDataManager = newDataMgr;
// Create a table using the new underlying data model
createTable();
setTabName(tabName);
// Assign the viewer an new TableViewer that uses the new table.
// Keep the old content and label providers but update the view's
// input.
viewer = new TableViewer(table);
viewer.setContentProvider(viewContentProvider);
viewer.setLabelProvider(viewLabelProvider);
viewer.setInput(tabularDataManager);
viewer.refresh();
}
Why would the above code cause the Table to display shifted right? I know
I must be missing something simple. Again, any help would be greatly
appreciated.
Jason
|
|
|
Re: TableViewer displaysTable, but Table is shifted right. [message #277091 is a reply to message #276989] |
Fri, 03 December 2004 18:38  |
Eclipse User |
|
|
|
Okay! I found out what I was doing wrong. My initial hunch that the
orginal, blank table was the culprit for the blank space was correct. To
solve the problem I simply placed a viewer.getTable().dispose(); before
recreating the viewer with the new populated table in my
recreateWithData() method. My new recreateWithData() method is posted
below:
public void recreateWithData(TabularDataManager newDataMgr, String tabName)
{
// Update the underlying data model
tabularDataManager = newDataMgr;
// Create a table using the new underlying data model
createTable();
setTabName(tabName);
// Assign the viewer a new TableViewer that uses the new table.
// Keep the old content and label providers but update the view's
// input.
viewer.getTable().dispose(); // <--- New Addition to Fix Problem!
viewer = new TableViewer(table);
viewer.setContentProvider(viewContentProvider);
viewer.setLabelProvider(viewLabelProvider);
viewer.setInput(tabularDataManager);
viewer.refresh();
}
I hope this helps anyone who runs into a similar issue.
Jason
Jason Palmatier wrote:
> I have created a View that contains a TableViewer, and the TableViewer
> contains a Table I explicitly define for it. The View is created
> programmatically when the user selects an action from a context menu using
> IViewPart newView =
>
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().showView(classID,
> classID + "." + altViewID, IWorkbenchPage.VIEW_ACTIVATE);
> // I'll explain this stuff below
> TabularDataManager tableData = new TabularDataManager(query);
> if(newView instanceof com.powertech.audit.views.TabularResultView)
> {
> ((TabularResultView)newView).recreateWithData(tableData, altViewID);
> }
> Since I need to use the showView() method to get the view to display it
> initially has no data and simply contains a blank dataset and an empty
> Table. Once the new View is created I call a method on the view that sets
> the data I want the view to display and then creates a new Table using the
> data ( recreateWithData() ). The method then creates a new TableViewer,
> passing it the new Table via the TableViewer constructor. The TableViewer
> is then refreshed with the refresh() method. The table appears in the
> View with all the columns and data displayed but the entire table is
> shifted right about half the width of the View window. In other words if
> the text drawing below is the entire View the Table begins as shown:
> View
> +-----------------------+
> | | |
> | Blank | Table |
> | Space | Displays |
> | | |
> +-----------------------+
> ^
> |
> + ----- Table begins here
> I suspect that the blank space is due to the initial blank Table that
> somehow isn't getting removed and the view is trying to display, but I
> don't know how to remove the reference to the original blank Table. I
> don't even know if this is what is causing the problem. I've posted my
> createPartControl(), createTable(), and recreateWithData() methods from my
> View below. Please, any help would be appreciated.
> public void createPartControl(Composite parent)
> {
> System.out.println("Enter TabularResultView:createPartControl()");
> // Save a copy of the parent of this view
> viewParent = parent;
> // Determine if data is already set to be loaded into a view
> if(tabularDataManager != null)
> {
> if(tabularDataManager.hasData())
> {
> // Create the table
> createTable();
> // Create the viewer
> viewer = new TableViewer(table);
> }
> }
> else
> {
> // Create blank data and an empty table
> tabularDataManager = new TabularDataManager();
> table = new Table(viewParent,
> SWT.H_SCROLL | SWT.V_SCROLL |
> SWT.MULTI | SWT.FULL_SELECTION);
> // Create the viewer
> viewer = new TableViewer(table);
> }
> viewContentProvider = new ViewContentProvider();
> viewLabelProvider = new ViewLabelProvider();
> viewer.setContentProvider(viewContentProvider);
> viewer.setLabelProvider(viewLabelProvider);
> viewer.setInput(tabularDataManager);
> System.out.println("Leave TabularResultView:createPartControl()");
> }
> private void createTable()
> {
> Vector columnHeadings = tabularDataManager.getColumnHeadings();
> System.out.println("columnHeadings.size() = " + columnHeadings.size());
> System.out.println("class of first element" +
> columnHeadings.firstElement().getClass());
> table = new Table(viewParent,
> SWT.H_SCROLL | SWT.V_SCROLL |
> SWT.MULTI | SWT.FULL_SELECTION);
> layout = new TableLayout();
> table.setLayout(layout);
> table.setLinesVisible(true);
> table.setHeaderVisible(true);
> for( int i = 0; i < columnHeadings.size(); i++ )
> {
> String columnHeading = (String)columnHeadings.elementAt(i);
> layout.addColumnData(new ColumnWeightData(50,100,true));
> TableColumn newColumn = new TableColumn(table, SWT.NONE);
> newColumn.setText(columnHeading);
> newColumn.setResizable(true);
> }
> }
> public void recreateWithData(TabularDataManager newDataMgr, String tabName)
> {
> // Update the underlying data model
> tabularDataManager = newDataMgr;
> // Create a table using the new underlying data model
> createTable();
> setTabName(tabName);
> // Assign the viewer an new TableViewer that uses the new table.
> // Keep the old content and label providers but update the view's
> // input.
> viewer = new TableViewer(table);
> viewer.setContentProvider(viewContentProvider);
> viewer.setLabelProvider(viewLabelProvider);
> viewer.setInput(tabularDataManager);
> viewer.refresh();
> }
> Why would the above code cause the Table to display shifted right? I know
> I must be missing something simple. Again, any help would be greatly
> appreciated.
> Jason
|
|
|
Powered by
FUDForum. Page generated in 0.62694 seconds