[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Large tables with TitleAreaDialog & TableViewer

I am using the JFace TitleAreaDialog to present a JFace TableViewer in
the main dialog area. I'm using the new 3.3 Table API to provide an
tab-editing etc and it works fine. However when I have a table with many
rows, rather than getting scroll bars and being able to scroll down the
table, the dialog windows is displayed as tall as the display allows and it
appears that the table extends below the visible part of the window as
when one navigates down the table the cursor disappears out of sight to
rows that are not visible...

I have tried limiting the size of the Composite and the size of the
table using setSize but it doesn't achieve the desired result. I don't have
a clear enough understanding of how the dialog window determines its
size. Somehow I need to make the dialog window size to be reasonably
constrained such that the table within its dialog area is similarly
constrained and uses scroll bars to allow table navigation down the table.
Any suggestions much appreciated.

Below is a snippet of code that illustrates the problem:


import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell;


public class SnippetLargeTableInDialog extends TitleAreaDialog { private class MyContentProvider implements IStructuredContentProvider {

/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object inputElement) {
return (MyModel[])inputElement;
}


/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
}

/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}
public class MyModel {
public int counter;
public MyModel(int counter) {
this.counter = counter;
}
public String toString() {
return "Item " + this.counter;
}
}
public SnippetLargeTableInDialog(Shell shell) {
super(shell);
setShellStyle(SWT.SHELL_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL
| getDefaultOrientation());
}
@Override
protected Control createDialogArea(Composite parent) {
Composite contents = (Composite)super.createDialogArea(parent);
Composite ourComposite = new Composite (contents, SWT.BORDER);
ourComposite.setLayout(new FillLayout());
int style = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION;


final TableViewer v = new TableViewer(ourComposite,style);
v.setLabelProvider(new LabelProvider());
v.setContentProvider(new MyContentProvider());
MyModel[] model = createModel();
v.setInput(model);
v.getTable().setLinesVisible(true);
v.reveal(model[99]);
return ourComposite;
}
private MyModel[] createModel() {
MyModel[] elements = new MyModel[100];
for( int i = 0; i < 100; i++ ) {
elements[i] = new MyModel(i);
}
return elements;
}
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display ();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Button b = new Button(shell, SWT.BORDER | SWT.BOLD);
b.setText("Press me");
b.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent arg0) {
System.out.println("widgetSelected");
TitleAreaDialog dialog = new SnippetLargeTableInDialog(shell);
dialog.open();
// TODO Auto-generated method stub
}

public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
});
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}

Thanks in advance for any suggestions

Paul Bandler