Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Where does TableViewer select an entry?(I copied the Contacts demo for my app, but cannot see where the list item is selected)
Where does TableViewer select an entry? [message #537248] Tue, 01 June 2010 16:47 Go to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Having fun with e4 at the moment. Getting used to the event handling model is difficult as most of it is hidden from you.

The problem I have is that my equivalent of the ListView class in Contact demo does not re-select the current item in the list whenever one of my EventHandlers fires. I cannot see where in the Contacts demo it does this either. I always end up with no item selected in the list (TableViewer) after any EventHandler fires. Can someone point me where to intecept and restore the current selection in TableViewer?

Thx.

David
Re: Where does TableViewer select an entry? [message #537407 is a reply to message #537248] Wed, 02 June 2010 11:24 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
I have also noticed that with my app based on the Contact demo code when I click in the detail view on the right hand side the highlight is removed from the selected element in the TableViewer on the left hand side.

In contacts demo app the focus moves when you click in the detail view, but the highlight on the selected element in the ListView remains, although it does change. How is this done, not obvious from the Contacts demo code.

Thx.

David
Re: Where does TableViewer select an entry? [message #537434 is a reply to message #537248] Wed, 02 June 2010 12:45 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

David Wynter wrote:
> Hi,
>
> Having fun with e4 at the moment. Getting used to the event handling
> model is difficult as most of it is hidden from you.

In the contacts demo, what event handling? The ListView has code that
posts its selection:

contactsViewer
.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event
.getSelection();
context.modify(IServiceConstants.SELECTION,
selection.getFirstElement());
}
});

the details view listens for a selection change:
@Inject
public void setSelection(@Optional @Named(IServiceConstants.SELECTION)
Contact contact) {...}




What event are you trying to feed back into the ListView? Where is it
coming from? What handling code did you write?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Where does TableViewer select an entry? [message #537446 is a reply to message #537434] Wed, 02 June 2010 13:29 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
I am referring to the doSave handler in DetailsView. I have the equivalent, the 2 methods here:

	public void doSave(@Optional IProgressMonitor monitor) throws IOException, InterruptedException {
		if (monitor == null) {
			monitor = new NullProgressMonitor();
		}
		persistChange(PersistType.UPDATE);
		dirtyable.setDirty(false);
	}

	private void persistChange(final PersistType type) throws IOException, InterruptedException {
		// Uses this format 'testcase name'|'Inbound meta filename'|
		// 'Outbound meta filename'|'Mapping meta filename'|
		// 'Inbound data filename'|'Outbound data filename'
		// maps to Testcase object
		Display display = parent.getDisplay();
		if (!(display==null || display.isDisposed())) {
			display.asyncExec(new Runnable () {
				public void run() {
					FileWriter outputStream = null;
					try {
						outputStream = new FileWriter("../workspace/com.hsbcib.grds.testui/grdstestcase.dat");
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					TestCase original = testCaseComposite.getOriginalTestCase();
					TestCase modified = testCaseComposite.getModifiedTestCase();
					List<TestCase> testcases = TestCaseRepositoryFactory.getTestCaseRepository().getAllTestCases();
					BufferedWriter writer = new BufferedWriter(outputStream);
					try {
						boolean madeChange = false;
						String record = "";
						for(int i=0; i<testcases.size(); i++){
							TestCase aCase = testcases.get(i);
							if(original==null) {
								TestCase aNewCase = new TestCase();
								aNewCase.setName("New Case");
								record = makeTestCaseRecord(aNewCase);
								TestCaseRepositoryFactory.getTestCaseRepository().getAllTestCases().add(aNewCase);									
								writer.write(record);
								break;
							} else if(original != null && original.getName().equals(aCase.getName())) {
								if(type==PersistType.DELETE) {
									TestCaseRepositoryFactory.getTestCaseRepository().getAllTestCases().remove(i);
									continue;
								} else if (type==PersistType.UPDATE) {
									if(!madeChange) {
										record = makeTestCaseRecord(modified);
										TestCaseRepositoryFactory.getTestCaseRepository().getAllTestCases().set(i, modified);
										madeChange=true;
									} else {
										record = makeTestCaseRecord(aCase);
										TestCaseRepositoryFactory.getTestCaseRepository().getAllTestCases().set(i, aCase);
									}
								}
							} else {
								record = makeTestCaseRecord(aCase);
							}
							writer.write(record);
						}
						if (type==PersistType.CLONE) {
							String name = modified.getName();
							// This only works up to 10 clone names, but not unique on name anyway
							if(name.substring(name.length()-1, name.length()).matches("\\d")) {
								int cloneno = Integer.parseInt(name.substring(name.length()-1, name.length()));
								modified.setName(name.substring(0,name.length()-1)+Integer.valueOf(++cloneno));
							} else {
								modified.setName(name+"0");
							}					
							record = makeTestCaseRecord(modified);
							TestCaseRepositoryFactory.getTestCaseRepository().getAllTestCases().add(modified);									
							writer.write(record);
						} else if (type==PersistType.CREATE) {
							TestCase aNewCase = new TestCase();
							aNewCase.setName("New Case");
							record = makeTestCaseRecord(aNewCase);
							TestCaseRepositoryFactory.getTestCaseRepository().getAllTestCases().add(aNewCase);									
							writer.write(record);
						}
						writer.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			});
		}
	}



The difference is that when Contacts finishes its equivalent of the persistance of the data in the doSave the current contact in DetailsView remains the same and the ListView also maintains the same selected contact. In my app, the current element is unselected in my equivalent of ListView and the Detail view has no TestCase selected.

I think it might be the fact that I call this
TestCaseRepositoryFactory.getTestCaseRepository().getAllTestCases().set


and that is the IObservableList. Am I on the right path here?

Thx.

David

[Updated on: Wed, 02 June 2010 13:30]

Report message to a moderator

Re: Where does TableViewer select an entry? [message #537449 is a reply to message #537446] Wed, 02 June 2010 13:47 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Actually I do notice something strange about the Contacts demo. If I select a Contact in the ListView, then click on any entry field in DetailsView, the result is that the Last name in the TableViewer in ListView disappears. It only reappears when you click on that same entry again or onto another entry.

Cannot see where this behaviour is manifest in the code, unless it is part of the framework itself.

I am using e4M5.

Thx.

David
Re: Where does TableViewer select an entry? [message #537519 is a reply to message #537449] Wed, 02 June 2010 17:58 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

David Wynter wrote:
> Actually I do notice something strange about the Contacts demo. If I
> select a Contact in the ListView, then click on any entry field in
> DetailsView, the result is that the Last name in the TableViewer in
> ListView disappears. It only reappears when you click on that same entry
> again or onto another entry.
> Cannot see where this behaviour is manifest in the code, unless it is
> part of the framework itself.

That's done by the databinding part in ListView using
ObservableListContentProvider and ObservableMapLabelProvider

PW



--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Where does TableViewer select an entry? [message #539643 is a reply to message #537519] Fri, 11 June 2010 15:31 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
That is what I use, I just copied the Contacts demo like so.
		// Test case name column
		final TableViewerColumn nameColumn = new TableViewerColumn(testCaseViewer, SWT.NONE);
		nameColumn.getColumn().setText("Test Case Name");
		tableColumnLayout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(100));

		ObservableListContentProvider contentProvider = new ObservableListContentProvider();

		testCaseViewer.setContentProvider(contentProvider);

		IObservableMap[] attributes = BeansObservables.observeMaps(
				contentProvider.getKnownElements(), TestCase.class, new String[] { "name" });
		testCaseViewer.setLabelProvider(new ObservableMapLabelProvider(attributes));

		testCaseViewer.setInput(TestCaseRepositoryFactory.getTestCaseRepository().getAllTestCases());

		GridLayoutFactory.fillDefaults().generateLayout(parent);

But mine does not update. How do you 'touch' the list to cause it to trigger the IObservableList behaviours?

Thx.

David
Re: Where does TableViewer select an entry? [message #540512 is a reply to message #539643] Wed, 16 June 2010 12:42 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

David Wynter wrote:
>
> But mine does not update. How do you 'touch' the list to cause it to
> trigger the IObservableList behaviours?

Is your model object a bean, firing the correct property change events?
Check out org.eclipse.e4.demo.contacts.model.Contact

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Where does TableViewer select an entry? [message #541173 is a reply to message #540512] Fri, 18 June 2010 14:24 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Thx. When I checked I had a PropertyChangeListener on every field except the one in the List. When I added it the re-selection on refresh worked.

David
Re: Where does TableViewer select an entry? [message #577008 is a reply to message #537434] Wed, 02 June 2010 13:29 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
I am referring to the doSave handler in DetailsView. I have the equivalent, the 2 methods here:


public void doSave(@Optional IProgressMonitor monitor) throws IOException, InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
persistChange(PersistType.UPDATE);
dirtyable.setDirty(false);
}

private void persistChange(final PersistType type) throws IOException, InterruptedException {
// Uses this format 'testcase name'|'Inbound meta filename'|
// 'Outbound meta filename'|'Mapping meta filename'|
// 'Inbound data filename'|'Outbound data filename'
// maps to Testcase object
Display display = parent.getDisplay();
if (!(display==null || display.isDisposed())) {
display.asyncExec(new Runnable () {
public void run() {
FileWriter outputStream = null;
try {
outputStream = new FileWriter("../workspace/com.hsbcib.grds.testui/grdstestcase.dat ");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TestCase original = testCaseComposite.getOriginalTestCase();
TestCase modified = testCaseComposite.getModifiedTestCase();
List<TestCase> testcases = TestCaseRepositoryFactory.getTestCaseRepository().getAllTest Cases();
BufferedWriter writer = new BufferedWriter(outputStream);
try {
boolean madeChange = false;
String record = "";
for(int i=0; i<testcases.size(); i++){
TestCase aCase = testcases.get(i);
if(original==null) {
TestCase aNewCase = new TestCase();
aNewCase.setName("New Case");
record = makeTestCaseRecord(aNewCase);
TestCaseRepositoryFactory.getTestCaseRepository().getAllTest Cases().add(aNewCase);
writer.write(record);
break;
} else if(original != null && original.getName().equals(aCase.getName())) {
if(type==PersistType.DELETE) {
TestCaseRepositoryFactory.getTestCaseRepository().getAllTest Cases().remove(i);
continue;
} else if (type==PersistType.UPDATE) {
if(!madeChange) {
record = makeTestCaseRecord(modified);
TestCaseRepositoryFactory.getTestCaseRepository().getAllTest Cases().set(i, modified);
madeChange=true;
} else {
record = makeTestCaseRecord(aCase);
TestCaseRepositoryFactory.getTestCaseRepository().getAllTest Cases().set(i, aCase);
}
}
} else {
record = makeTestCaseRecord(aCase);
}
writer.write(record);
}
if (type==PersistType.CLONE) {
String name = modified.getName();
// This only works up to 10 clone names, but not unique on name anyway
if(name.substring(name.length()-1, name.length()).matches("\\d")) {
int cloneno = Integer.parseInt(name.substring(name.length()-1, name.length()));
modified.setName(name.substring(0,name.length()-1)+Integer.v alueOf(++cloneno));
} else {
modified.setName(name+"0");
}
record = makeTestCaseRecord(modified);
TestCaseRepositoryFactory.getTestCaseRepository().getAllTest Cases().add(modified);
writer.write(record);
} else if (type==PersistType.CREATE) {
TestCase aNewCase = new TestCase();
aNewCase.setName("New Case");
record = makeTestCaseRecord(aNewCase);
TestCaseRepositoryFactory.getTestCaseRepository().getAllTest Cases().add(aNewCase);
writer.write(record);
}
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}



The difference is that when Contacts finishes its equivalent of the persistance of the data in the doSave the current contact in DetailsView reamins the same and the ListView also maintains the same selected contact. In my app, the current element is unselected in my equivalent of ListView and the Detail view has no TestCase selected.

I think it might be the fact that I call this

TestCaseRepositoryFactory.getTestCaseRepository().getAllTest Cases().set


and that is the IObservableList. Am I on the right path here?

Thx.

David
Re: Where does TableViewer select an entry? [message #577021 is a reply to message #577008] Wed, 02 June 2010 13:47 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Actually I do notice something strange about the Contacts demo. If I select a Contact in the ListView, then click on any entry field in DetailsView, the result is that the Last name in the TableViewer in ListView disappears. It only reappears when you click on that same entry again or onto another entry.

Cannot see where this behaviour is manifest in the code, unless it is part of the framework itself.

I am using e4M5.

Thx.

David
Re: Where does TableViewer select an entry? [message #577067 is a reply to message #537449] Wed, 02 June 2010 17:58 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

David Wynter wrote:
> Actually I do notice something strange about the Contacts demo. If I
> select a Contact in the ListView, then click on any entry field in
> DetailsView, the result is that the Last name in the TableViewer in
> ListView disappears. It only reappears when you click on that same entry
> again or onto another entry.
> Cannot see where this behaviour is manifest in the code, unless it is
> part of the framework itself.

That's done by the databinding part in ListView using
ObservableListContentProvider and ObservableMapLabelProvider

PW



--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Where does TableViewer select an entry? [message #577563 is a reply to message #537519] Fri, 11 June 2010 15:31 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
That is what I use, I just copied the Contacts demo like so.

// Test case name column
final TableViewerColumn nameColumn = new TableViewerColumn(testCaseViewer, SWT.NONE);
nameColumn.getColumn().setText("Test Case Name");
tableColumnLayout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(100));

ObservableListContentProvider contentProvider = new ObservableListContentProvider();

testCaseViewer.setContentProvider(contentProvider);

IObservableMap[] attributes = BeansObservables.observeMaps(
contentProvider.getKnownElements(), TestCase.class, new String[] { "name" });
testCaseViewer.setLabelProvider(new ObservableMapLabelProvider(attributes));

testCaseViewer.setInput(TestCaseRepositoryFactory.getTestCas eRepository().getAllTestCases());

GridLayoutFactory.fillDefaults().generateLayout(parent);

But mine does not update. How do you 'touch' the list to cause it to trigger the IObservableList behaviours?

Thx.

David
Re: Where does TableViewer select an entry? [message #577821 is a reply to message #577563] Wed, 16 June 2010 12:43 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

David Wynter wrote:
>
> But mine does not update. How do you 'touch' the list to cause it to
> trigger the IObservableList behaviours?

Is your model object a bean, firing the correct property change events?
Check out org.eclipse.e4.demo.contacts.model.Contact

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Where does TableViewer select an entry? [message #577973 is a reply to message #577821] Fri, 18 June 2010 14:24 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Thx. When I checked I had a PropertyChangeListener on every field except the one in the List. When I added it the re-selection on refresh worked.

David
Previous Topic:Readiness of replacing a RCP app with e4
Next Topic:TestCase failures and incomplete UI and functionality for Eclipse 4.0 M6
Goto Forum:
  


Current Time: Tue Apr 16 08:47:50 GMT 2024

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

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

Back to the top