final DialogMemento memento = new DialogMemento(getShell(),
"org.python.pydev.debug.ui.actions.RunEditorAsCustomUnitTestAction");
SimpleNode ast = pyEdit.getAST();
TreeSelectionDialog dialog = new TreeSelectionDialog(getShell(), new SelectTestLabelProvider(),
new SelectTestTreeContentProvider()) {
Link configTestRunner;
public boolean close() {
memento.writeSettings(getShell());
return super.close();
}
public Control createDialogArea(Composite parent) {
memento.readSettings();
Control ret = super.createDialogArea(parent);
this.text.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.CR || e.keyCode == SWT.LF || e.keyCode == SWT.KEYPAD_CR) {
okPressed();
}
}
});
return ret;
}
/* (non-Javadoc)
* @see org.python.pydev.ui.dialogs.TreeSelectionDialog#createButtonBar(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createButtonBar(Composite parent) {
configTestRunner = new Link(parent, SWT.PUSH);
configTestRunner.setText(" <a>Configure test runner</a>");
configTestRunner.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
PyUnitPrefsPage2.showPage();
}
});
return configTestRunner;
}
protected Point getInitialSize() {
return memento.getInitialSize(super.getInitialSize(), getShell());
}
protected Point getInitialLocation(Point initialSize) {
return memento.getInitialLocation(initialSize, super.getInitialLocation(initialSize), getShell());
}
/*
* @see SelectionStatusDialog#computeResult()
*/
@SuppressWarnings("unchecked")
protected void computeResult() {
doFinalUpdateBeforeComputeResult();
IStructuredSelection selection = (IStructuredSelection) getTreeViewer().getSelection();
List<Object> list = selection.toList();
if (list.size() > 0) {
setResult(list);
} else {
Tree tree = getTreeViewer().getTree();
TreeItem[] items = tree.getItems();
list = new ArrayList<Object>();
//Now, if he didn't select anything, let's create tests with all that is currently filtered
//in the interface
createListWithLeafs(items, list);
setResult(list);
}
}
private void createListWithLeafs(TreeItem[] items, List<Object> leafObjectsList) {
for (TreeItem item : items) {
TreeItem[] children = item.getItems();
if (children.length == 0) {
leafObjectsList.add(item.getData());
} else {
createListWithLeafs(children, leafObjectsList);
}
}
}
};
dialog.setTitle("PyDev: Select tests to run");
dialog.setMessage("Select the tests to run (press enter to run tests shown/selected)");
dialog.setInitialFilter("test");
dialog.setAllowMultiple(true);
dialog.setInput(ast);
int open = dialog.open();
if (open != Window.OK) {
return;
}
Object[] result = dialog.getResult();
final FastStringBuffer buf = new FastStringBuffer();
if (result != null && result.length > 0) {
for (Object o : result) {