Bug 245949 - [Viewers] ViewerCell.getElement() - problem with caching the element reference
Summary: [Viewers] ViewerCell.getElement() - problem with caching the element reference
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-02 05:47 EDT by Jacek Kolodziejczyk CLA
Modified: 2019-09-06 16:17 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jacek Kolodziejczyk CLA 2008-09-02 05:47:17 EDT
Build ID: I20080617-2000

Steps To Reproduce:
I have a an empty row at the end of a ColumnViewer to insert new elements, like there are in many data oriented applications. Editors are activated on ColumnViewerEditorActivationEvent.TRAVERSAL. What I do when a cell was edited in the insert item, is to replace the insert item's data (dummy element) with the newly created domain element (having the entered cell value) using StructuredViewer.associate, update the labels and create a new insert item.
The pseudo code:
	if (currentElement == DUMMY) {
		DomainObject element = createDomainObject();
		element.setValue(editor.getValue();
		viewer.associate(element, currentItem);
		viewer.update(element, null);
		viewer.add(DUMMY);
	}

The problem is when I traverse to the next cell by TAB, it goes to the new insert item below instead to the one just created in the current row. 

More information:
This is because the element reference changes between the current editor is closed and the new one is opened. I think this would not happen if ViewerCell would not cache the element reference, but always take it from the row.getElement() (which takes it from the Item.getData())

So I suggest changing ViewerCell.getElement() from this:

   public Object getElement() {
		if (element != null) {
			return element;
		}

		if (row != null) {
			return row.getElement();
		}

		return null;
	}

to this at least: 

   public Object getElement() {
		if (row != null) {
			return row.getElement();
		}
		
		if (element != null) {
			return element;
		}

		return null;
	}

if the element member is needed at all when the row is empty (I'm not aware of such a case possibility and the sense of a cell with an empty row).
Comment 1 Mike Wilson CLA 2009-05-05 10:40:27 EDT
Changing Version tag to something more believable.
Comment 2 Thomas Schindl CLA 2010-01-28 17:13:04 EST
multi change because of intenion of stepping back as platform-ui committer
Comment 3 Eclipse Webmaster CLA 2019-09-06 16:17:53 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.