Where does TableViewer select an entry? [message #537248] |
Tue, 01 June 2010 12:47  |
Eclipse User |
|
|
|
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 #537446 is a reply to message #537434] |
Wed, 02 June 2010 09:29   |
Eclipse User |
|
|
|
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 09:30] by Moderator
|
|
|
|
|
|
|
|
Re: Where does TableViewer select an entry? [message #577008 is a reply to message #537434] |
Wed, 02 June 2010 09:29  |
Eclipse User |
|
|
|
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 09:47  |
Eclipse User |
|
|
|
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 #577563 is a reply to message #537519] |
Fri, 11 June 2010 11:31  |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.09726 seconds