Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » problem creating tableviewer on the wizardpage
problem creating tableviewer on the wizardpage [message #5119] Thu, 14 May 2009 17:51 Go to next message
Manohar is currently offline ManoharFriend
Messages: 9
Registered: July 2009
Junior Member
Hi,

I was trying to create a TableViewer on the WizardPage , I am setting the
input, content provider and label provider correctly, but It doesnt
render tableviewer on the wizardpage, do I need to do anything else.

thanks in advance
Manohar
Re: problem creating tableviewer on the wizardpage [message #6123 is a reply to message #5119] Fri, 15 May 2009 17:43 Go to previous messageGo to next message
Boris Bokowski is currently offline Boris BokowskiFriend
Messages: 272
Registered: July 2009
Senior Member
Hi Manohar,

Did you forget the SWT layout? Try adding
GridLayoutFactory.swtDefaults().generateLayout(composite) after you have
created your widgets inside a composite.

Another common problem is forgetting to call setControl() from
WizardPage.createPartControl, have a look at existing subclasses of
WizardPage to see what the pattern is.

Boris

"Manohar " <manohar.babu@gmail.com> wrote in message
news:fecf7ce13957046f3b5ddb812a7c9f30$1@www.eclipse.org...
> Hi,
>
> I was trying to create a TableViewer on the WizardPage , I am setting the
> input, content provider and label provider correctly, but It doesnt
> render tableviewer on the wizardpage, do I need to do anything else.
>
> thanks in advance
> Manohar
>
Re: problem creating tableviewer on the wizardpage [message #6284 is a reply to message #6123] Sun, 17 May 2009 21:45 Go to previous messageGo to next message
Manohar is currently offline ManoharFriend
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 Go to previous messageGo to next message
Boris Bokowski is currently offline Boris BokowskiFriend
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;
> }
> }
>
Re: problem creating tableviewer on the wizardpage [message #7730 is a reply to message #6299] Mon, 18 May 2009 19:38 Go to previous messageGo to next message
Manohar is currently offline ManoharFriend
Messages: 9
Registered: July 2009
Junior Member
if you check this line, I am setting the column names...

// Set up the table
Table table = viewer.getTable();
new TableColumn(table, SWT.LEFT).setText("Items");
new TableColumn(table, SWT.LEFT).setText("Name");

thanks
Manohar
Re: problem creating tableviewer on the wizardpage [message #7934 is a reply to message #7730] Tue, 19 May 2009 15:40 Go to previous message
Boris Bokowski is currently offline Boris BokowskiFriend
Messages: 272
Registered: July 2009
Senior Member
Hi Manohar,

"Manohar " <manohar.babu@gmail.com> wrote in message
news:6b740b26e1d6d9a6634bc3ed36d0fad5$1@www.eclipse.org...
> if you check this line, I am setting the column names...
>
> // Set up the table
> Table table = viewer.getTable();
> new TableColumn(table, SWT.LEFT).setText("Items");
> new TableColumn(table, SWT.LEFT).setText("Name");

Yes, but you are not setting the column widths so they get a width of zero
and are not visible.

Boris
Previous Topic:Observe elements to update labels in TreeViewer
Next Topic:Binding to a TitleAreaDialog (3.4.2)
Goto Forum:
  


Current Time: Sat Nov 02 16:50:30 GMT 2024

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

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

Back to the top