Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to continuously update/refresh JFACE tableviewer
How to continuously update/refresh JFACE tableviewer [message #409748] Mon, 14 February 2005 13:57 Go to next message
Eclipse UserFriend
Originally posted by: rathdeep.yahoo.com

Hi all,

I have created a table inside a JFACE tableviewer.
I want to dynamically update the contents of its columns.
Like one column with % of completion of a task. I increase the counter
from 1 to 10000 and i want to refresh its content after each increment.

I have code something like this
TableItem item = table.getItem();

for( int i=0;i<10000;i++)
{
item.setText(4,"%bytes sent" + i); /*
After each insert how to refresh view contents
*/
tableViewer.refresh(table,true); //not working / presently view hangs
until int //i reaches 100000
//
}


Any pointers would of great help.
Re: How to continuously update/refresh JFACE tableviewer [message #409977 is a reply to message #409748] Tue, 15 February 2005 15:28 Go to previous messageGo to next message
Raj Saini is currently offline Raj SainiFriend
Messages: 53
Registered: July 2009
Member
Hi,

To update the contents of your tableViewer dynamically you will need to
write Content Provider and Label Provider for your table viewer. When
Data in yout content model changes, your content provider should update
the table coloums automatically.

For example:
tableViewer = new TableViewer(table);
tableViewer.setLabelProvider(new StockQuoteViewLabelProvider());
tableViewer.setContentProvider(new
StockQuoteContentProvider(tableViewer));

Example ContentProvider:



public class StockQuoteContentProvider implements
IStructuredContentProvider, ContentChangeListener
{
protected TableViewer tableViewer;

public StockQuoteContentProvider(TableViewer tableViewer)
{
this.tableViewer = tableViewer;
}

public Object[] getElements(Object inputElement)
{
return ((StockQuoteService)inputElement).getStockQuotes();
}


public void dispose()
{
//empty
}

public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
{

if (newInput != null)
{
((StockQuoteService) newInput).addChangeListener(this);
}
if (oldInput != null)
{
((StockQuoteService) oldInput).removeChangeListener(this);
}
}


/* (non-Javadoc)
* @see
com.bttlindia.tradestart.quoteservice.ContentChangeListener# add(java.lang.Object)
*/
public void add(final Object obj)
{
tableViewer.getTable().getDisplay().asyncExec(new Runnable ()
{
public void run ()
{
tableViewer.add(obj);
}
});
}

/* (non-Javadoc)
* @see
com.bttlindia.tradestart.quoteservice.ContentChangeListener# update(java.lang.Object)
*/
public void update(final Object obj)
{
tableViewer.getTable().getDisplay().asyncExec(new Runnable()
{
public void run()
{
tableViewer.update(obj, null);
}
});
}

/* (non-Javadoc)
* @see
com.bttlindia.tradestart.quoteservice.ContentChangeListener# remove(java.lang.Object)
*/
public void remove(Object obj)
{
tableViewer.remove(obj);
}

/* (non-Javadoc)
* @see
com.bttlindia.tradestart.quoteservice.ContentChangeListener# refresh()
*/
public void refresh()
{
tableViewer.getTable().getDisplay().asyncExec(new Runnable()
{
public void run()
{
tableViewer.refresh();
}
});
}
}


Example Label Provider:

public class StockQuoteViewLabelProvider extends LabelProvider implements
ITableLabelProvider
{
private Image upImage;
private Image equalImage;
private Image downImage;

public StockQuoteViewLabelProvider()
{
ImageDescriptor upImageDescriptor =
AbstractUIPlugin.imageDescriptorFromPlugin(StockQuotePlugin. PLUGIN_ID,
"icons/full/eview16/up.png");
upImage = upImageDescriptor.createImage();

ImageDescriptor equalImageDescriptor =
AbstractUIPlugin.imageDescriptorFromPlugin(StockQuotePlugin. PLUGIN_ID,
"icons/full/eview16/equal.png");
equalImage = equalImageDescriptor.createImage();

ImageDescriptor downImageDescriptor =
AbstractUIPlugin.imageDescriptorFromPlugin(StockQuotePlugin. PLUGIN_ID,
"icons/full/eview16/down.png");
downImage = downImageDescriptor.createImage();
}
public Image getColumnImage(Object element, int columnIndex)
{
if(columnIndex == 3)
{
if(((StockQuote)element).getLastPriceChange()< 0)
{
return downImage;
}else if(((StockQuote)element).getLastPriceChange() > 0)
{
return upImage;
}
return equalImage;
}
return null;
}

public String getColumnText(Object element, int columnIndex)
{
StockQuote quote = (StockQuote) element;
switch (columnIndex)
{
case 0:
return quote.getSymbol().trim();
case 1:
return quote.getName();
case 2:
return (new BigDecimal
(quote.getLastPrice())).setScale(3, BigDecimal.ROUND_HALF_UP).toString();
case 3:
return (new
BigDecimal(quote.getVarPercentage())).setScale(3,
BigDecimal.ROUND_HALF_UP).toString();
case 4:
return (new Integer(quote.getBidQty())).toString();
case 5:
return (new
BigDecimal(quote.getBidPrice())).setScale(3,
BigDecimal.ROUND_HALF_UP).toString();
case 6:
return (new
BigDecimal(quote.getAskPrice())).setScale(3,
BigDecimal.ROUND_HALF_UP).toString();
case 7:
return (new Integer(quote.getAskQty())).toString();
case 8:
return (new
BigDecimal(quote.getOpenPrice())).setScale(3,
BigDecimal.ROUND_HALF_UP).toString();
case 9:
return (new BigDecimal(quote.getDayHigh())).setScale(3,
BigDecimal.ROUND_HALF_UP).toString();
case 10:
return (new BigDecimal(quote.getDayLow())).setScale(3,
BigDecimal.ROUND_HALF_UP).toString();
case 11:
return (new
BigDecimal(quote.getClosePrice())).setScale(3,
BigDecimal.ROUND_HALF_UP).toString();
case 12:
return new Long(quote.getVolume()).toString();
case 13:
Date transDate = quote.getLastTransactionTime();
SimpleDateFormat format = new SimpleDateFormat("HH:mm");
return format.format(transDate);
}
return "";
}

public void dispose()
{
upImage.dispose();
upImage = null;
equalImage.dispose();
equalImage = null;
downImage.dispose();
downImage = null;
}
}

dc wrote:
> Hi all,
>
> I have created a table inside a JFACE tableviewer. I want to dynamically
> update the contents of its columns.
> Like one column with % of completion of a task. I increase the counter
> from 1 to 10000 and i want to refresh its content after each increment.
> I have code something like this
> TableItem item = table.getItem();
>
> for( int i=0;i<10000;i++)
> {
> item.setText(4,"%bytes sent" + i); /*
> After each insert how to refresh view contents
> */
> tableViewer.refresh(table,true); //not working / presently view hangs
> until int //i reaches 100000
> //
> }
>
>
> Any pointers would of great help.
>
>
Re: How to continuously update/refresh JFACE tableviewer [message #410030 is a reply to message #409977] Wed, 16 February 2005 12:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rathdeep.yahoo.com

Thanks Raj


Raj Saini wrote:

> Hi,

> To update the contents of your tableViewer dynamically you will need to
> write Content Provider and Label Provider for your table viewer. When
> Data in yout content model changes, your content provider should update
> the table coloums automatically.

> For example:
> tableViewer = new TableViewer(table);
> tableViewer.setLabelProvider(new StockQuoteViewLabelProvider());
> tableViewer.setContentProvider(new
> StockQuoteContentProvider(tableViewer));

> Example ContentProvider:



> public class StockQuoteContentProvider implements
> IStructuredContentProvider, ContentChangeListener
> {
> protected TableViewer tableViewer;

> public StockQuoteContentProvider(TableViewer tableViewer)
> {
> this.tableViewer = tableViewer;
> }

> public Object[] getElements(Object inputElement)
> {
> return ((StockQuoteService)inputElement).getStockQuotes();
> }


> public void dispose()
> {
> //empty
> }

> public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
> {

> if (newInput != null)
> {
> ((StockQuoteService) newInput).addChangeListener(this);
> }
> if (oldInput != null)
> {
> ((StockQuoteService) oldInput).removeChangeListener(this);
> }
> }


> /* (non-Javadoc)
> * @see
>
com.bttlindia.tradestart.quoteservice.ContentChangeListener# add(java.lang.Object)
> */
> public void add(final Object obj)
> {
> tableViewer.getTable().getDisplay().asyncExec(new Runnable ()
> {
> public void run ()
> {
> tableViewer.add(obj);
> }
> });
> }

> /* (non-Javadoc)
> * @see
>
com.bttlindia.tradestart.quoteservice.ContentChangeListener# update(java.lang.Object)
> */
> public void update(final Object obj)
> {
> tableViewer.getTable().getDisplay().asyncExec(new Runnable()
> {
> public void run()
> {
> tableViewer.update(obj, null);
> }
> });
> }

> /* (non-Javadoc)
> * @see
>
com.bttlindia.tradestart.quoteservice.ContentChangeListener# remove(java.lang.Object)
> */
> public void remove(Object obj)
> {
> tableViewer.remove(obj);
> }

> /* (non-Javadoc)
> * @see
> com.bttlindia.tradestart.quoteservice.ContentChangeListener# refresh()
> */
> public void refresh()
> {
> tableViewer.getTable().getDisplay().asyncExec(new Runnable()
> {
> public void run()
> {
> tableViewer.refresh();
> }
> });
> }
> }


> Example Label Provider:

> public class StockQuoteViewLabelProvider extends LabelProvider implements
> ITableLabelProvider
> {
> private Image upImage;
> private Image equalImage;
> private Image downImage;

> public StockQuoteViewLabelProvider()
> {
> ImageDescriptor upImageDescriptor =
> AbstractUIPlugin.imageDescriptorFromPlugin(StockQuotePlugin. PLUGIN_ID,
> "icons/full/eview16/up.png");
> upImage = upImageDescriptor.createImage();

> ImageDescriptor equalImageDescriptor =
> AbstractUIPlugin.imageDescriptorFromPlugin(StockQuotePlugin. PLUGIN_ID,
> "icons/full/eview16/equal.png");
> equalImage = equalImageDescriptor.createImage();

> ImageDescriptor downImageDescriptor =
> AbstractUIPlugin.imageDescriptorFromPlugin(StockQuotePlugin. PLUGIN_ID,
> "icons/full/eview16/down.png");
> downImage = downImageDescriptor.createImage();
> }
> public Image getColumnImage(Object element, int columnIndex)
> {
> if(columnIndex == 3)
> {
> if(((StockQuote)element).getLastPriceChange()< 0)
> {
> return downImage;
> }else if(((StockQuote)element).getLastPriceChange() > 0)
> {
> return upImage;
> }
> return equalImage;
> }
> return null;
> }

> public String getColumnText(Object element, int columnIndex)
> {
> StockQuote quote = (StockQuote) element;
> switch (columnIndex)
> {
> case 0:
> return quote.getSymbol().trim();
> case 1:
> return quote.getName();
> case 2:
> return (new BigDecimal
> (quote.getLastPrice())).setScale(3, BigDecimal.ROUND_HALF_UP).toString();
> case 3:
> return (new
> BigDecimal(quote.getVarPercentage())).setScale(3,
> BigDecimal.ROUND_HALF_UP).toString();
> case 4:
> return (new Integer(quote.getBidQty())).toString();
> case 5:
> return (new
> BigDecimal(quote.getBidPrice())).setScale(3,
> BigDecimal.ROUND_HALF_UP).toString();
> case 6:
> return (new
> BigDecimal(quote.getAskPrice())).setScale(3,
> BigDecimal.ROUND_HALF_UP).toString();
> case 7:
> return (new Integer(quote.getAskQty())).toString();
> case 8:
> return (new
> BigDecimal(quote.getOpenPrice())).setScale(3,
> BigDecimal.ROUND_HALF_UP).toString();
> case 9:
> return (new BigDecimal(quote.getDayHigh())).setScale(3,
> BigDecimal.ROUND_HALF_UP).toString();
> case 10:
> return (new BigDecimal(quote.getDayLow())).setScale(3,
> BigDecimal.ROUND_HALF_UP).toString();
> case 11:
> return (new
> BigDecimal(quote.getClosePrice())).setScale(3,
> BigDecimal.ROUND_HALF_UP).toString();
> case 12:
> return new Long(quote.getVolume()).toString();
> case 13:
> Date transDate = quote.getLastTransactionTime();
> SimpleDateFormat format = new SimpleDateFormat("HH:mm");
> return format.format(transDate);
> }
> return "";
> }

> public void dispose()
> {
> upImage.dispose();
> upImage = null;
> equalImage.dispose();
> equalImage = null;
> downImage.dispose();
> downImage = null;
> }
> }

> dc wrote:
>> Hi all,
>>
>> I have created a table inside a JFACE tableviewer. I want to dynamically
>> update the contents of its columns.
>> Like one column with % of completion of a task. I increase the counter
>> from 1 to 10000 and i want to refresh its content after each increment.
>> I have code something like this
>> TableItem item = table.getItem();
>>
>> for( int i=0;i<10000;i++)
>> {
>> item.setText(4,"%bytes sent" + i); /*
>> After each insert how to refresh view contents
>> */
>> tableViewer.refresh(table,true); //not working / presently view hangs
>> until int //i reaches 100000
>> //
>> }
>>
>>
>> Any pointers would of great help.
>>
>>
Re: How to continuously update/refresh JFACE tableviewer [message #1386865 is a reply to message #410030] Sat, 21 June 2014 23:29 Go to previous message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 1
Registered: June 2014
Junior Member
Hello;
I need your help regarding the same topic here. I am recieving data from server and would like to display them syncroniously on a TableViewer. I am using this code snippet :

public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	final ArrayList<ProcessChain> finalInput = (ArrayList<ProcessChain>) newInput;
	final PROCESSCHAINView processchainView = (PROCESSCHAINView) Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(PROCESSCHAINView.ID);
	Display tableviewerDisplay = processchainView.getViewer().getTable().getDisplay();
	if (finalInput != null)
		Activator.getDefault().getWorkbench().getDisplay().syncExec(new Runnable() {
			@Override
			public void run() {
				processchainView.getViewer().update(finalInput, null);
				processchainView.getViewer().refresh();
				}
		});



The viewer is freezing and this is not doing what I want.
Could you please detail the provided solution .
Regards


[Updated on: Mon, 23 June 2014 13:25] by Moderator

Report message to a moderator

Previous Topic:Creating a tool for running testcode
Next Topic:Closeable Views
Goto Forum:
  


Current Time: Sun Dec 21 19:33:57 GMT 2014

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

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