1

I am new to SWT and JFace. I have a Dialog with a TableViewer attached to it. I added a filter to the TableViewer. My requirement is that when the search returns multiple items the Dialog should show them and let the user select the one he wants and afterwards click OK so that the selected value is passed back to the parent function.

I implemented it without any problem. But when the search returns only one value, this value should be passed back to the parent window and the Dialog should close.

I am having problem in closing the dialog through code. I tried to use okPressed() when the condition is met.

This is where I am calling okPressed():

if(!searchStr.isEmpty()){
    dialogSearch();
    if(tableViewer.getTable().getItems().length == 1){
        TableItem[] itemSelected = tableViewer.getTable().getItems();
        pojoRefType = (Object)itemSelected[0].getData();
        this.okPressed();
    } 
}

java.lang.IllegalArgumentException: Argument not valid at org.eclipse.swt.SWT.error(Unknown Source) at org.eclipse.swt.SWT.error(Unknown Source)

Can anyone please suggest how to handle the condition?

4

1 回答 1

0

要关闭对话框,只需调用:

this.setReturnCode(OK);
this.close();

这就是所有要做的...

你也可以试试:

super.okPressed();
于 2012-09-20T18:01:03.133 回答