Home » Eclipse Projects » JFace » problem creating tableviewer on the wizardpage
| |
Re: problem creating tableviewer on the wizardpage [message #6284 is a reply to message #6123] |
Sun, 17 May 2009 21:45 |
Manohar Messages: 9 Registered: July 2009 |
Junior Member |
|
|
thanks Boris for the information.
I still dont see the table on the wizard page.
If you have some time, can you please see the code, coz I am not sure
what I am doing wrong.
thanks in advance
Manohar
package com.test;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
/**
* This page collects the first and last names
*/
class JSFPreviewPage extends WizardPage {
/**
* NamePage constructor
*/
public JSFPreviewPage() {
super("JSF Preview Page", "JSF Preview Page", null);
setDescription("Layout of JSF Components");
}
/**
* Creates the page contents
*
* @param parent
* the parent composite
*/
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
final TableViewer viewer = new TableViewer(composite);
viewer.setLabelProvider(new MyLabelProvider());
viewer.setContentProvider(new MyContentProvider());
MyModel[] model = createModel();
viewer.setInput(model);
// Set up the table
Table table = viewer.getTable();
new TableColumn(table, SWT.LEFT).setText("Items");
new TableColumn(table, SWT.LEFT).setText("Name");
viewer.getTable().setLinesVisible(true);
viewer.getTable().setHeaderVisible(true);
GridLayoutFactory.swtDefaults().generateLayout(composite) ;
setControl(composite);
}
public class MyLabelProvider extends LabelProvider implements
ITableLabelProvider
{
public String getColumnText(Object element, int columnIndex) {
MyModel person = (MyModel) element;
switch (columnIndex) {
case 0:
return person.getCounter() + "";
case 1:
return person.getName();
default:
throw new RuntimeException("Should not happen");
}
}
public Image getColumnImage(Object arg0, int arg1) {
// TODO Auto-generated method stub
return null;
}
}
private class MyContentProvider implements IStructuredContentProvider {
/* (non-Javadoc)
* @see
org.eclipse.jface.viewers.IStructuredContentProvider#getElem ents(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 String name;
public MyModel(int counter , String name) {
this.counter = counter;
this.name = name;
}
public int getCounter() {
return counter;
}
public void setCounter(int counter) {
this.counter = counter;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String toString() {
return "Item " + this.counter;
}
}
private MyModel[] createModel() {
MyModel[] elements = new MyModel[10];
for (int i = 0; i < 10; i++) {
elements[i] = new MyModel(i, "name");
}
return elements;
}
}
|
|
|
Re: problem creating tableviewer on the wizardpage [message #6299 is a reply to message #6284] |
Mon, 18 May 2009 02:36 |
Boris Bokowski Messages: 272 Registered: July 2009 |
Senior Member |
|
|
Hi Manohar,
I am seeing a table, just no contents, and no table headers. I should have
asked you to attach a screenshot...
Here is what's missing:
TableColumn c1 = new TableColumn(table, SWT.LEFT);
c1.setText("Items");
c1.setWidth(100);
Boris
"Manohar " <manohar.babu@gmail.com> wrote in message
news:16624751fe1a0abe633750818a20a00a$1@www.eclipse.org...
> thanks Boris for the information.
>
> I still dont see the table on the wizard page.
>
> If you have some time, can you please see the code, coz I am not sure
> what I am doing wrong.
>
> thanks in advance
> Manohar
>
> package com.test;
>
> import org.eclipse.jface.layout.GridLayoutFactory;
> import org.eclipse.jface.viewers.IStructuredContentProvider;
> import org.eclipse.jface.viewers.ITableLabelProvider;
> import org.eclipse.jface.viewers.LabelProvider;
> import org.eclipse.jface.viewers.TableViewer;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.jface.wizard.WizardPage;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.Image;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Table;
> import org.eclipse.swt.widgets.TableColumn;
>
> /**
> * This page collects the first and last names
> */
>
> class JSFPreviewPage extends WizardPage {
>
> /**
> * NamePage constructor
> */
> public JSFPreviewPage() {
> super("JSF Preview Page", "JSF Preview Page", null);
> setDescription("Layout of JSF Components");
>
> }
>
> /**
> * Creates the page contents
> * * @param parent
> * the parent composite
> */
> public void createControl(Composite parent) {
> Composite composite = new Composite(parent, SWT.NONE);
> composite.setLayout(new GridLayout(2, false));
>
>
> final TableViewer viewer = new TableViewer(composite);
> viewer.setLabelProvider(new MyLabelProvider());
> viewer.setContentProvider(new MyContentProvider());
>
>
>
>
> MyModel[] model = createModel();
> viewer.setInput(model);
>
> // Set up the table
> Table table = viewer.getTable();
> new TableColumn(table, SWT.LEFT).setText("Items");
> new TableColumn(table, SWT.LEFT).setText("Name");
>
> viewer.getTable().setLinesVisible(true);
> viewer.getTable().setHeaderVisible(true);
> GridLayoutFactory.swtDefaults().generateLayout(composite) ;
> setControl(composite);
>
> }
>
> public class MyLabelProvider extends LabelProvider implements
> ITableLabelProvider {
>
> public String getColumnText(Object element, int columnIndex) {
> MyModel person = (MyModel) element;
> switch (columnIndex) {
> case 0:
> return person.getCounter() + "";
> case 1:
> return person.getName(); default:
> throw new RuntimeException("Should not happen");
> }
>
> }
>
> public Image getColumnImage(Object arg0, int arg1) {
> // TODO Auto-generated method stub
> return null;
> }
>
> }
>
>
> private class MyContentProvider implements IStructuredContentProvider {
>
> /* (non-Javadoc)
> * @see
> org.eclipse.jface.viewers.IStructuredContentProvider#getElem ents(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 String name;
>
>
> public MyModel(int counter , String name) {
> this.counter = counter;
> this.name = name;
> }
>
>
> public int getCounter() {
> return counter;
> }
>
>
> public void setCounter(int counter) {
> this.counter = counter;
> }
>
>
> public String getName() {
> return name;
> }
>
>
> public void setName(String name) {
> this.name = name;
> }
>
>
> public String toString() {
> return "Item " + this.counter;
> }
> }
>
> private MyModel[] createModel() {
> MyModel[] elements = new MyModel[10];
>
> for (int i = 0; i < 10; i++) {
> elements[i] = new MyModel(i, "name");
> }
>
> return elements;
> }
> }
>
|
|
| | |
Goto Forum:
Current Time: Sat Nov 02 16:50:30 GMT 2024
Powered by FUDForum. Page generated in 0.05213 seconds
|