Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Nebula » GridTableViewer - layout problem
GridTableViewer - layout problem [message #591685] Tue, 12 August 2008 08:44
Eclipse UserFriend
Originally posted by: paul.ruthven.synergy.net.au

I am trying to display a GridTableViewer in a View, together with a
Composite that contains other widgets. I am running into some formatting
problems that are driving me crazy.

The following simplified code illustrates my problem.

If I incorporate the code as is, I get a GridTableViewer that displays
scrollbars, and fills the view as I expect.

However, if I uncomment the code labelled "###UNCOMMENT" in an attempt to
display a Composite with a Label above the GridTableViewer, I run into
problems. The scrollbars disappear, and the GridTableViewer no longer
fills the entire width of the view.

Any help with this would be much appreciated.

None of the examples I've found online combine a GridTableViewer with
another Composite in a view.

Thanks
Paul

---------------------------------------------------

package my_package;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableFontProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;

import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
import org.eclipse.nebula.widgets.grid.GridColumn;


public class MyView extends ViewPart {

private GridTableViewer gridViewer;

public void createPartControl(Composite parent) {

//###UNCOMMENT
// parent.setLayout(new GridLayout(1, false));
// parent.setLayoutData(new GridData(GridData.FILL));
//
// Composite topComposite = new Composite(parent, SWT.NONE);
// topComposite.setLayout(new GridLayout(3, false));
// topComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
//
// Label label = new Label(parent, SWT.LEFT);
// label.setText("Test Label");


Composite tableComposite = new Composite(parent, SWT.NONE);
tableComposite.setLayout(new FillLayout());

gridViewer =
new GridTableViewer(
tableComposite, SWT.V_SCROLL | SWT.H_SCROLL);

gridViewer.setLabelProvider(new ColumnLabelProvider());
gridViewer.setContentProvider(new TableContentProvider());
gridViewer.getGrid().setCellSelectionEnabled(true);

gridViewer.getGrid().setLinesVisible(true);
gridViewer.getGrid().setHeaderVisible(true);

GridColumn column1 = new GridColumn(gridViewer.getGrid(), SWT.NONE);
column1.setWidth(100);
column1.setText("Column 1");

GridColumn column2 = new GridColumn(gridViewer.getGrid(), SWT.NONE);
column2.setWidth(100);
column2.setText("Column 2");

gridViewer.setInput(this.getViewSite());

}

/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
gridViewer.getControl().setFocus();
}

class ColumnLabelProvider extends LabelProvider implements
ITableLabelProvider, ITableFontProvider, ITableColorProvider {

@Override
public Image getColumnImage(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}

@Override
public String getColumnText(Object element, int columnIndex) {
if (element instanceof TableRow) {
switch (columnIndex) {
case 0:
return ((TableRow)element).getC1();
case 1:
return ((TableRow)element).getC2();
default:
return "TBD";
}
}
return "TBD";
}

@Override
public Font getFont(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}

@Override
public Color getBackground(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}

@Override
public Color getForeground(Object element, int columnIndex) {
// TODO Auto-generated method stub
return null;
}

}

class TableContentProvider implements IStructuredContentProvider {

private List<TableRow> tableRows;

public TableContentProvider() {
tableRows = new ArrayList<TableRow>();

for (int row=1; row<=100; row++) {
String c1 = "R" + row + " C1";
String c2 = "R" + row + " C2";
TableRow tableRow = new TableRow(c1, c2);
tableRows.add(tableRow);
}
}

@Override
public Object[] getElements(Object inputElement) {
// TODO Auto-generated method stub
System.out.println("getElements called - length = " + tableRows.size());
return tableRows.toArray();
}

@Override
public void dispose() {
// TODO Auto-generated method stub

}

@Override
public void inputChanged(Viewer viewer, Object oldInput, Object
newInput) {
// TODO Auto-generated method stub

}

}

class TableRow {
private String c1;
private String c2;

public TableRow(String c1, String c2) {
this.c1 = c1;
this.c2 = c2;
}

public String getC1() {
return c1;
}

public String getC2() {
return c2;
}


}

}
Previous Topic:GridTableViewer - JFace Databinding - Dates
Next Topic:Grid: GridViewer selection service does not support cell selection
Goto Forum:
  


Current Time: Sun Dec 21 06:26:13 GMT 2014

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

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