Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » insight required on changing values in TableViewer with asyncExec
insight required on changing values in TableViewer with asyncExec [message #117948] Fri, 09 January 2009 05:45 Go to next message
Tom H is currently offline Tom HFriend
Messages: 139
Registered: July 2009
Senior Member
Hi,

Sorry for the long mangled code post...

So I'm having a bit of trouble bulding a stocks table that updates in real
time, and uses "tableItem.setBackground( 2, Graphics.getColor(255,0,0) );"
so update the colour of the cell when the value changes

At the moment, I don't seem to be able to make any changes to the current
TableItems at all in the Runnable... It just ignores me ;-(

Any ideas what I am doing wrong in Runnable, or elsewhere?

Thanks,

Tom



package catshelter;

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

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.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.rwt.graphics.Graphics;
import org.eclipse.rwt.lifecycle.UICallBack;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

public class WatchlistSecurityView extends ViewPart {

private String[] securities = { "FTSE 100 Cash", "Wall Street Cash",
"FTSE to finish Up", "Germany 30", "Spot FX USD/JPY",
"Spot FX EUR/USD", "Spot Gold ", "US Light Crude", "Barclays Plc",
"Royal Dutch Shell Plc -A", "BNP Paribas", "UBS AG" };

private String[] columns = { "Market", "Period", "Sell", "Buy", "Change",
"% Chg", "Update", "High", "Low" };
TableViewer viewer;

@Override
public void createPartControl(final Composite parent) {

Composite contents = new Composite(parent, SWT.NONE);
contents.setLayout(new GridLayout(1, false));

viewer = new TableViewer(contents, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.FULL_SELECTION);
viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
viewer.setContentProvider(new SecurityListContentProvider());

SecurityListLabelProvider lp = new SecurityListLabelProvider();
lp.createColumns(viewer);
viewer.setLabelProvider(lp);
viewer.getTable().setLinesVisible(false);
viewer.setInput(getViewSite());
Button b = new Button(contents, SWT.BORDER);
b.setText("Activate!");

final Runnable runnable = new Runnable() {
public void run() {

// while(true){
// if(Event.waitFor()){
System.out.println("executing Runnable");
/*
* MessageDialog.openInformation( parent.getShell(),
* "Treeviewer", "You selected " );
*/
List buffer = new ArrayList();

Random generator = new Random();
for (int i = 0; i < securities.length; i++) {
// TableItem item = new TableItem( viewer.getTable(),
// SWT.NONE);
TableItem item = (TableItem) viewer.getElementAt(i);

item.setText(0, securities[i]);
for (int j = 1; j < columns.length; j++) {
item.setText(j, String.valueOf(generator.nextInt(100)));
}
item.setBackground( Graphics.getColor(0,0,128) );

// TableItem item = new TableItem(viewer.getTable(),
// SWT.NONE);
// item.setText(0,"test");
// viewer.add( new String[] {"item","item","item"} );

// TableItem item = (TableItem)viewer.getElementAt(0);
// item.setBackground( 2, Graphics.getColor(255,0,0) );

// viewer.refresh();
// }
// }
}
}
};

b.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}

public void widgetSelected(SelectionEvent e) {
System.out.println("Starting UICallback");
// list.put(inputText.getText(),Status.INCOMPLETE);
UICallBack.activate("notifierId");
/*
* notifierThread = new Thread(createRunnable());
* notifierThread.setDaemon(true); notifierThread.start();
*/
// shell.getDisplay().asyncExec(runnable);
PlatformUI.createDisplay().asyncExec(runnable);
UICallBack.deactivate("notifierId");
}
});

}

public class SecurityListContentProvider implements
IStructuredContentProvider {

@Override
public Object[] getElements(Object inputElement) {
Random generator = new Random();
List rowList = new ArrayList();

for (int i = 0; i < securities.length; i++) {
String[] row = new String[securities.length];
row[0] = securities[i];
for (int j = 1; j < columns.length; j++) {
row[j] = "" + String.valueOf(generator.nextInt(100));
}
rowList.add(row);
}

return rowList.toArray();
}

@Override
public void dispose() {
}

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

}

public class SecurityListLabelProvider extends LabelProvider implements
ITableLabelProvider {

public void createColumns(TableViewer viewer) {
Table table = viewer.getTable();

int[] bounds = { 100, 100, 100 };

for (int i = 0; i < columns.length; i++) {
TableViewerColumn column = new TableViewerColumn(viewer,
SWT.NONE);
column.getColumn().setText(columns[i]);
column.getColumn().setWidth(100);
column.getColumn().setResizable(true);
}
table.setHeaderVisible(true);
table.setLinesVisible(true);
}

@Override
public Image getColumnImage(Object element, int columnIndex) {
Random generator = new Random();
ClassLoader loader = getClass().getClassLoader();

if (columnIndex == 0) {
int myInt = generator.nextInt(100);
if (myInt < 34) {
return Graphics.getImage("icons/state_edit.png", loader);
} else if (myInt > 66) {
return Graphics.getImage("icons/state_closed.png", loader);
} else {
return Graphics.getImage("icons/state_deal.png", loader);
}
}
return null;
}

@Override
public String getColumnText(Object element, int columnIndex) {
String[] str = (String[]) element;
return str[columnIndex];

}

}

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

}

}
Re: insight required on changing values in TableViewer with asyncExec [message #117962 is a reply to message #117948] Fri, 09 January 2009 09:00 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2396
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
This is a multi-part message in MIME format.
--------------050604090806000709080605
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Hi Tom,

I've modified a little bit your example to make it work (see attached
file). Hope that this will help.

Best,
Ivan

Tom H wrote:
>
>
> Hi,
>
> Sorry for the long mangled code post...
>
> So I'm having a bit of trouble bulding a stocks table that updates in
> real time, and uses "tableItem.setBackground( 2,
> Graphics.getColor(255,0,0) );" so update the colour of the cell when
> the value changes
>
> At the moment, I don't seem to be able to make any changes to the
> current TableItems at all in the Runnable... It just ignores me ;-(
>
> Any ideas what I am doing wrong in Runnable, or elsewhere?
>
> Thanks,
>
> Tom
>
>
>
> package catshelter;
>
> import java.util.List;
> import java.util.ArrayList;
> import java.util.Random;
>
> 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.TableViewerColumn;
> import org.eclipse.jface.viewers.Viewer;
> import org.eclipse.rwt.graphics.Graphics;
> import org.eclipse.rwt.lifecycle.UICallBack;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.SelectionEvent;
> import org.eclipse.swt.events.SelectionListener;
> import org.eclipse.swt.graphics.Image;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Table;
> import org.eclipse.swt.widgets.TableItem;
> import org.eclipse.ui.PlatformUI;
> import org.eclipse.ui.part.ViewPart;
>
> public class WatchlistSecurityView extends ViewPart {
>
> private String[] securities = { "FTSE 100 Cash", "Wall Street Cash",
> "FTSE to finish Up", "Germany 30", "Spot FX USD/JPY",
> "Spot FX EUR/USD", "Spot Gold ", "US Light Crude",
> "Barclays Plc",
> "Royal Dutch Shell Plc -A", "BNP Paribas", "UBS AG" };
>
> private String[] columns = { "Market", "Period", "Sell", "Buy",
> "Change",
> "% Chg", "Update", "High", "Low" };
> TableViewer viewer;
>
> @Override
> public void createPartControl(final Composite parent) {
>
> Composite contents = new Composite(parent, SWT.NONE);
> contents.setLayout(new GridLayout(1, false));
>
> viewer = new TableViewer(contents, SWT.MULTI | SWT.H_SCROLL
> | SWT.V_SCROLL | SWT.FULL_SELECTION);
> viewer.getTable().setLayoutData(new
> GridData(GridData.FILL_BOTH));
> viewer.setContentProvider(new SecurityListContentProvider());
>
> SecurityListLabelProvider lp = new SecurityListLabelProvider();
> lp.createColumns(viewer);
> viewer.setLabelProvider(lp);
> viewer.getTable().setLinesVisible(false);
> viewer.setInput(getViewSite());
> Button b = new Button(contents, SWT.BORDER);
> b.setText("Activate!");
>
> final Runnable runnable = new Runnable() {
> public void run() {
>
> // while(true){
> // if(Event.waitFor()){
> System.out.println("executing Runnable");
> /*
> * MessageDialog.openInformation( parent.getShell(),
> * "Treeviewer", "You selected " );
> */
> List buffer = new ArrayList();
>
> Random generator = new Random();
> for (int i = 0; i < securities.length; i++) {
> // TableItem item = new TableItem( viewer.getTable(),
> // SWT.NONE);
> TableItem item = (TableItem) viewer.getElementAt(i);
>
> item.setText(0, securities[i]);
> for (int j = 1; j < columns.length; j++) {
> item.setText(j,
> String.valueOf(generator.nextInt(100)));
> }
> item.setBackground( Graphics.getColor(0,0,128) );
>
> // TableItem item = new TableItem(viewer.getTable(),
> // SWT.NONE);
> // item.setText(0,"test");
> // viewer.add( new String[] {"item","item","item"} );
>
> // TableItem item =
> (TableItem)viewer.getElementAt(0);
> // item.setBackground( 2,
> Graphics.getColor(255,0,0) );
>
> // viewer.refresh();
> // }
> // }
> }
> }
> };
>
> b.addSelectionListener(new SelectionListener() {
> public void widgetDefaultSelected(SelectionEvent e) {
> }
>
> public void widgetSelected(SelectionEvent e) {
> System.out.println("Starting UICallback");
> // list.put(inputText.getText(),Status.INCOMPLETE);
> UICallBack.activate("notifierId");
> /*
> * notifierThread = new Thread(createRunnable());
> * notifierThread.setDaemon(true);
> notifierThread.start();
> */
> // shell.getDisplay().asyncExec(runnable);
> PlatformUI.createDisplay().asyncExec(runnable);
> UICallBack.deactivate("notifierId");
> }
> });
>
> }
>
> public class SecurityListContentProvider implements
> IStructuredContentProvider {
>
> @Override
> public Object[] getElements(Object inputElement) {
> Random generator = new Random();
> List rowList = new ArrayList();
>
> for (int i = 0; i < securities.length; i++) {
> String[] row = new String[securities.length];
> row[0] = securities[i];
> for (int j = 1; j < columns.length; j++) {
> row[j] = "" + String.valueOf(generator.nextInt(100));
> }
> rowList.add(row);
> }
>
> return rowList.toArray();
> }
>
> @Override
> public void dispose() {
> }
>
> @Override
> public void inputChanged(Viewer viewer, Object oldInput,
> Object newInput) {
> }
>
> }
>
> public class SecurityListLabelProvider extends LabelProvider
> implements
> ITableLabelProvider {
>
> public void createColumns(TableViewer viewer) {
> Table table = viewer.getTable();
>
> int[] bounds = { 100, 100, 100 };
>
> for (int i = 0; i < columns.length; i++) {
> TableViewerColumn column = new TableViewerColumn(viewer,
> SWT.NONE);
> column.getColumn().setText(columns[i]);
> column.getColumn().setWidth(100);
> column.getColumn().setResizable(true);
> }
> table.setHeaderVisible(true);
> table.setLinesVisible(true);
> }
>
> @Override
> public Image getColumnImage(Object element, int columnIndex) {
> Random generator = new Random();
> ClassLoader loader = getClass().getClassLoader();
>
> if (columnIndex == 0) {
> int myInt = generator.nextInt(100);
> if (myInt < 34) {
> return Graphics.getImage("icons/state_edit.png",
> loader);
> } else if (myInt > 66) {
> return Graphics.getImage("icons/state_closed.png",
> loader);
> } else {
> return Graphics.getImage("icons/state_deal.png",
> loader);
> }
> }
> return null;
> }
>
> @Override
> public String getColumnText(Object element, int columnIndex) {
> String[] str = (String[]) element;
> return str[columnIndex];
>
> }
>
> }
>
> @Override
> public void setFocus() {
> // TODO Auto-generated method stub
>
> }
>
> }
>
>

--------------050604090806000709080605
Content-Type: text/plain;
name="WatchlistSecurityView.java"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="WatchlistSecurityView.java"

aW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7DQppbXBvcnQgamF2YS51dGls Lkxpc3Q7DQpp
bXBvcnQgamF2YS51dGlsLlJhbmRvbTsNCg0KaW1wb3J0IG9yZy5lY2xpcHNl LmpmYWNlLnZp
ZXdlcnMuSVN0cnVjdHVyZWRDb250ZW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hYmxlIHNob3VsZE5v dEhhcHBlbiAp
IHsNCiAgICAgICAgICAgIHNob3VsZE5vdEhhcHBlbi5wcmludFN0YWNrVHJh Y2UoKTsNCiAg
ICAgICAgICB9DQogICAgICAgICAgLy8gcGVyZm9ybSB1cGRhdGUNCiAgICAg ICAgICBkaXNw
bGF5LnN5bmNFeGVjKCBuZXcgUnVubmFibGUoKSB7DQoNCiAgICAgICAgICAg IHB1YmxpYyB2
b2lkIHJ1bigpIHsNCiAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxu KCAiRXhlY3V0
aW5nIFJ1bm5hYmxlIiApOw0KICAgICAgICAgICAgICBSYW5kb20gZ2VuZXJh dG9yID0gbmV3
IFJhbmRvbSgpOw0KICAgICAgICAgICAgICBmb3IoIGludCBpID0gMDsgaSA8 IHNlY3VyaXRp
ZXMubGVuZ3RoOyBpKysgKSB7DQogICAgICAgICAgICAgICAgVGFibGVJdGVt IGl0ZW0gPSB0
YWJsZS5nZXRJdGVtKCBpICk7DQogICAgICAgICAgICAgICAgZm9yKCBpbnQg aiA9IDE7IGog
PCBjb2x1bW5zLmxlbmd0aDsgaisrICkgew0KICAgICAgICAgICAgICAgICAg aXRlbS5zZXRU
ZXh0KCBqLCBTdHJpbmcudmFsdWVPZiggZ2VuZXJhdG9yLm5leHRJbnQoIDEw MCApICkgKTsN
CiAgICAgICAgICAgICAgICB9DQogICAgICAgICAgICAgIH0NCiAgICAgICAg ICAgICAgaWYo
IGRlYWN0aXZhdGUgKSB7DQogICAgICAgICAgICAgICAgLy8gZGVhY3RpdmF0 ZSBVSS1jYWxs
YmFjayBtZWNoYW5pc20NCiAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnBy aW50bG4oICJT
dG9wcGluZyBVSUNhbGxiYWNrIiApOw0KICAgICAgICAgICAgICAgIFN0cmlu ZyBpZCA9IFdh
dGNobGlzdFNlY3VyaXR5Vmlldy5jbGFzcy5nZXROYW1lKCk7DQogICAgICAg ICAgICAgICAg
VU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B7DQogICAgICBSYW5kb20gZ2VuZXJhdG9yID0gbmV3IFJhbmRvbSgpOw0K ICAgICAgQ2xh
c3NMb2FkZXIgbG9hZGVyID0gZ2V0Q2xhc3MoKS5nZXRDbGFzc0xvYWRlcigp Ow0KICAgICAg
aWYoIGNvbHVtbkluZGV4ID09IDAgKSB7DQogICAgICAgIGludCBteUludCA9 IGdlbmVyYXRv
ci5uZXh0SW50KCAxMDAgKTsNCiAgICAgICAgLy8gaWYoIG15SW50IDwgMzQg KSB7DQogICAg
ICAgIC8vIHJldHVybiBHcmFwaGljcy5nZXRJbWFnZSggImljb25zL3N0YXRl X2VkaXQucG5n
IiwgbG9hZGVyICk7DQogICAgICAgIC8vIH0gZWxzZSBpZiggbXlJbnQgPiA2 NiApIHsNCiAg
ICAgICAgLy8gcmV0dXJuIEdyYXBoaWNzLmdldEltYWdlKCAiaWNvbnMvc3Rh dGVfY2xvc2Vk
LnBuZyIsIGxvYWRlciApOw0KICAgICAgICAvLyB9IGVsc2Ugew0KICAgICAg ICAvLyByZXR1
cm4gR3JhcGhpY3MuZ2V0SW1hZ2UoICJpY29ucy9zdGF0ZV9kZWFsLnBuZyIs IGxvYWRlciAp
Ow0KICAgICAgICAvLyB9DQogICAgICB9DQogICAgICByZXR1cm4gbnVsbDsN CiAgICB9DQoN
CiAgICBAT3ZlcnJpZGUNCiAgICBwdWJsaWMgU3RyaW5nIGdldENvbHVtblRl eHQoIE9iamVj
dCBlbGVtZW50LCBpbnQgY29sdW1uSW5kZXggKSB7DQogICAgICBTdHJpbmdb XSBzdHIgPSAo
IFN0cmluZ1tdICllbGVtZW50Ow0KICAgICAgcmV0dXJuIHN0clsgY29sdW1u SW5kZXggXTsN
CiAgICB9DQogIH0NCg0KICBAT3ZlcnJpZGUNCiAgcHVibGljIHZvaWQgc2V0 Rm9jdXMoKSB7
DQogICAgLy8gVE9ETyBBdXRvLWdlbmVyYXRlZCBtZXRob2Qgc3R1Yg0KICB9 DQp9
--------------050604090806000709080605--
Re: insight required on changing values in TableViewer with asyncExec [message #118167 is a reply to message #117962] Sat, 10 January 2009 02:59 Go to previous messageGo to next message
Tom H is currently offline Tom HFriend
Messages: 139
Registered: July 2009
Senior Member
Hey Ivan,

Thanks for your brilliant effort, I've got it updating just how I need
from your example.

However I am now trying to set a column colour to the initial table, ie I
want to set the buy and sell column to blue and red, but using a
getElements that returns an Array of Arrays of Strings;
String[] row = new String[securities.length];
etc, means that I can't set TableItem properties to it.
Do you have further insight on how to initialise a table, and
setForeground on it?
I've pasted the current code below. So far I can't see how to create a
TableItem, without providing a parent, which the TableItem immediately
gets appended to....?

Many Thanks,

Tom

public Object[] getElements(Object inputElement) {
Random generator = new Random();
List rowList = new ArrayList();
for (int i = 0; i < securities.length; i++) {
String[] row = new String[securities.length];
row[0] = securities[i];
for (int j = 1; j < columns.length; j++) {
row[j] = "" + String.valueOf(generator.nextInt(100));
}
rowList.add(row);
}
return rowList.toArray();
}
Re: insight required on changing values in TableViewer with asyncExec [message #118251 is a reply to message #118167] Mon, 12 January 2009 09:32 Go to previous messageGo to next message
Benjamin Muskalla is currently offline Benjamin MuskallaFriend
Messages: 237
Registered: July 2009
Senior Member
Hi Tom,

have you ever tried to implement a decorating label provider? Like
IColorLabelProvider or ITableColorProvider. I think this is the
recommended way as JFace tries to separate your model from the concrete
widget. Modifying the widgets directly can lead to unexpected results as
JFace replaces the widgets under certain circumstances (like refresh())
and does not preserve the changes you've made.

Greets
Benny

Tom H wrote:
> Hey Ivan,
>
> Thanks for your brilliant effort, I've got it updating just how I need
> from your example.
> However I am now trying to set a column colour to the initial table, ie
> I want to set the buy and sell column to blue and red, but using a
> getElements that returns an Array of Arrays of Strings;
> String[] row = new String[securities.length];
> etc, means that I can't set TableItem properties to it.
> Do you have further insight on how to initialise a table, and
> setForeground on it?
> I've pasted the current code below. So far I can't see how to create a
> TableItem, without providing a parent, which the TableItem immediately
> gets appended to....?
>
> Many Thanks,
>
> Tom
>
> public Object[] getElements(Object inputElement) {
> Random generator = new Random();
> List rowList = new ArrayList();
> for (int i = 0; i < securities.length; i++) {
> String[] row = new String[securities.length];
> row[0] = securities[i];
> for (int j = 1; j < columns.length; j++) {
> row[j] = "" + String.valueOf(generator.nextInt(100));
> }
> rowList.add(row);
> }
> return rowList.toArray();
> }
>
Re: insight required on changing values in TableViewer with asyncExec [message #118369 is a reply to message #118251] Tue, 13 January 2009 11:29 Go to previous message
Tom H is currently offline Tom HFriend
Messages: 139
Registered: July 2009
Senior Member
Ah, right that works splendidly!
Previous Topic:How to change List font?
Next Topic:Running an application using workspace RWT plugins
Goto Forum:
  


Current Time: Wed Feb 01 23:35:01 GMT 2023

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

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

Back to the top