final boolean wasDeleted = _deleted;
_lastSearch = partialName;
_progressMonitor.setCanceled(true);
WorkspaceJob job = new WorkspaceJob("Searching for components ...") {
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
synchronized (_completionLock) {
_progressMonitor.setCanceled(false);
Comparator<WodCompletionProposal> nameOrder = new Comparator<WodCompletionProposal>() {
public int compare(WodCompletionProposal p1, WodCompletionProposal p2) {
return p1.getDisplayString().compareTo(p2.getDisplayString());
}
};
try {
final Set<WodCompletionProposal> proposals = new TreeSet<WodCompletionProposal>(nameOrder);
WodCompletionUtils.fillInElementTypeCompletionProposals(_project, partialName, 0, partialName.length(), proposals, false, _progressMonitor);
if (!_progressMonitor.isCanceled()) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (!componentNameCombo.isDisposed()) {
componentNameCombo.remove(0, componentNameCombo.getItemCount() - 1);
boolean exactMatch = false;
for (WodCompletionProposal elementName : proposals) {
String displayString = elementName.getDisplayString();
if (displayString != null && displayString.equals(_lastSearch)) {
exactMatch = true;
}
componentNameCombo.add(displayString);
}
try {
Method setListVisible = componentNameCombo.getClass().getDeclaredMethod("setListVisible", boolean.class);
setListVisible.setAccessible(true);
if (!isWindows) {
setListVisible.invoke(componentNameCombo, false);
}
Point _selection = componentNameCombo.getSelection();
if (!(componentNameCombo.getItemCount() <= 1)) {
String text = componentNameCombo.getItem(0);
_selection.y = text.length();
synchronized (_ignoreModify) {
String partialText = componentNameCombo.getText();
if (!text.toLowerCase().startsWith(partialText.toLowerCase())) {
return;
}
_ignoreModify = true;
setListVisible.invoke(componentNameCombo, true);
componentNameCombo.setText(text);
componentNameCombo.setSelection(_selection);
_ignoreModify = false;
}
} else {
if (componentNameCombo.getItemCount() == 1) {
setListVisible.invoke(componentNameCombo, false);
String text = componentNameCombo.getItem(0);
if (_selection.x == _selection.y && !wasDeleted) {
_selection.y = text.length();
synchronized (_ignoreModify) {
_ignoreModify = true;
componentNameCombo.setText(text);
componentNameCombo.setSelection(_selection);
_ignoreModify = false;
}
_lastSelection = _selection;
}
}
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
}
});
}
} catch (OperationCanceledException t) {
// ignore
} catch (Throwable t) {
t.printStackTrace();
}
return Status.OK_STATUS;
}
}
};
job.schedule();
}
}