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
Hi,

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(
JFaceResources.getResources());

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
| SWT.MULTI | SWT.BORDER);
table = tableViewer.getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);

TableViewerColumn columnCode = new TableViewerColumn(tableViewer, SWT.NONE);
columnCode.getColumn().setWidth(80);
columnCode.getColumn().setText("Code");

TableViewerColumn columnDescription = new TableViewerColumn(tableViewer, SWT.NONE);
columnDescription.getColumn().setWidth(350);
columnDescription.getColumn().setText("Description");

TableViewerColumn columnStock = new TableViewerColumn(tableViewer, SWT.NONE);
columnStock.getColumn().setWidth(50);
columnStock.getColumn().setText("Stock");

TableViewerColumn columnPrice = new TableViewerColumn(tableViewer, SWT.NONE);
columnPrice.getColumn().setWidth(50);
columnPrice.getColumn().setText("Price");

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

ObservableListContentProvider contentProvider = new ObservableListContentProvider();
tableViewer.setContentProvider(contentProvider);

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

tableViewer.setInput(itemsOfSelectedYear);

tableViewer.addDoubleClickListener(new IDoubleClickListener() {

@Override
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);
// dialog.open();
ItemEditorInput itemInput = new ItemEditorInput(item);
try {
page.openEditor(itemInput, ItemEditor.ID);

} catch (PartInitException e) {
System.out.println(e.getStackTrace());
}
}
});

ISelectionService selectionService = (ISelectionService) getSite()
.getService(ISelectionService.class);
selectionService.addSelectionListener(this);

getSite().setSelectionProvider(tableViewer);
}

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() {
tableViewer.getTable().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;
selectedYear.setValue(year);
}
}
}

public void dispose() {
super.dispose();
resourceManager.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 {
setSite(site);
setInput(input);
itemInput = ((ItemEditorInput) input).getItem();
itemModel = new ItemEditorModel(itemInput);
item = itemModel.getItem();
setPartName(item.getCode());
}


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: How to add validator for cell editor?
Next Topic:Incorrect showItem behaviour (got problem with TreeViewerEditor)
Goto Forum:
  


Current Time: Thu Dec 18 21:02:15 GMT 2014

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

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