Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [Databinding] TableViewer not updated when using EditorPart(Tree + TableViewer + EditorPart)
[Databinding] TableViewer not updated when using EditorPart [message #538099] Sat, 05 June 2010 01:10 Go to next message
Hugo Herrera is currently offline Hugo HerreraFriend
Messages: 20
Registered: July 2009
Junior Member

I'm working on an application with a table that displays a list of rows based on a node selection from the tree. I'm using EditorPart to modify the table rows, but once changes are saved, the table is not being updated (refreshed), however if I re-open the row, changes are there.

I tried using Wizard and it worked, the table is being updated, as expected, because the binding..but not when using EditorPart Sad ... can anyone pls help me to figure out what am i missing?

here is TableView code.

public class ItemsTableView extends ViewPart implements ISelectionListener {

private Table table;
private static TableViewer tableViewer;
private final WritableValue selectedYear = new WritableValue(null,Year.class);
private IObservableList itemsOfSelectedYear;
private LocalResourceManager resourceManager = new LocalResourceManager(

public static final String ID = "org.volcansoft.pos.views.itemstableview";

* Create contents of the view part
* @param parent
public void createPartControl(Composite parent) {
final Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new FillLayout());

tableViewer = new TableViewer(container, SWT.FULL_SELECTION
table = tableViewer.getTable();

TableViewerColumn columnCode = new TableViewerColumn(tableViewer, SWT.NONE);

TableViewerColumn columnDescription = new TableViewerColumn(tableViewer, SWT.NONE);

TableViewerColumn columnStock = new TableViewerColumn(tableViewer, SWT.NONE);

TableViewerColumn columnPrice = new TableViewerColumn(tableViewer, SWT.NONE);

itemsOfSelectedYear = MasterDetailObservables
.detailList(selectedYear, BeanProperties.list("items")
.listFactory(), Item.class);

ObservableListContentProvider contentProvider = new ObservableListContentProvider();

initLabelProvider(columnCode, "code", contentProvider);
initLabelProvider(columnDescription, "description", contentProvider);
initLabelProvider(columnStock, "stock", contentProvider);
initLabelProvider(columnPrice, "price", contentProvider);


tableViewer.addDoubleClickListener(new IDoubleClickListener() {

public void doubleClick(DoubleClickEvent event) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Item item = (Item) selection.getFirstElement();
// Wizard wizard = new NewItemWizard(item);
// WizardDialog dialog = new WizardDialog(container.getShell(), wizard);
ItemEditorInput itemInput = new ItemEditorInput(item);
try {
page.openEditor(itemInput, ItemEditor.ID);

} catch (PartInitException e) {

ISelectionService selectionService = (ISelectionService) getSite()


private void initLabelProvider(TableViewerColumn column,
String propertyName, ObservableListContentProvider contentProvider) {
column.setLabelProvider(new ObservableMapCellLabelProvider(Properties
.observeEach(contentProvider.getKnownElements(), BeanProperties
.values(new String[] { propertyName}))){

// public void update(ViewerCell cell) {
// super.update(cell);
// cell.setFont(tableViewer.getTable().getFont());
// cell.setForeground(tableViewer.getTable().getForeground());
// }

// it is important to implement setFocus()!
public void setFocus() {

public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object element = structuredSelection.getFirstElement();
if (element instanceof Year) {
Year year = (Year) element;

public void dispose() {
Re: [Databinding] TableViewer not updated when using EditorPart [message #541312 is a reply to message #538099] Sat, 19 June 2010 20:29 Go to previous message
Hugo Herrera is currently offline Hugo HerreraFriend
Messages: 20
Registered: July 2009
Junior Member
Ok, I found where my problem is. In the editor part I was resolving another object and working with it instead of the one coming from the selection.

public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
itemInput = ((ItemEditorInput) input).getItem();
itemModel = new ItemEditorModel(itemInput);
item = itemModel.getItem();

I'm using JPA and Databinding and learning how to use them, apparently looks clear and simple, but in the practice it has been a nightmare to me Smile

I noticed that if I work over the itemInput (the one coming from selection) whatever change I made is being reflected on the table, however, it is not persisted.

And if I use the itemModel, (the one is being read from my model), when I work on it, changes are not reflected on the GUI, but, they are persisted.

How could I sync this two things? pls, help.
Previous Topic:[Databinding] Table cells to bean properties
Next Topic:SWT Date Time in 24 hours format
Goto Forum:

Current Time: Mon Apr 23 02:17:56 GMT 2018

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

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