break;
}
/* Type: Enumeration */
case ISearchValueType.ENUM: {
final Text text = new Text(inputField, SWT.BORDER);
text.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event event) {
fInputValue = text.getText();
if (!fInputValue.equals(input))
fModified = true;
}
});
/* Provide Auto-Complete Field */
OwlUI.hookAutoComplete(text, field.getSearchValueType().getEnumValues(), true, true);
/* Pre-Select input if given */
String inputValue = (input != null ? input.toString() : null);
if (inputValue != null)
text.setText(inputValue);
/* Update Input Value */
fInputValue = text.getText();
break;
}
/* Type: Number */
case ISearchValueType.NUMBER:
case ISearchValueType.INTEGER: {
final Spinner spinner = new Spinner(inputField, SWT.BORDER);
spinner.setMinimum(0);
spinner.setMaximum(1000);
spinner.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event event) {
fInputValue = spinner.getSelection();
if (!fInputValue.equals(input))
fModified = true;
}
});
/* Pre-Select input if given */
Object presetInput = (input == null) ? fInputValue : input;
if (presetInput != null && presetInput instanceof Integer)
spinner.setSelection((Integer) presetInput);
/* Update Input Value */
fInputValue = spinner.getSelection();
break;
}
/* Type: String */
case ISearchValueType.STRING:
case ISearchValueType.LINK: {
final Text text = new Text(inputField, SWT.BORDER);
OwlUI.makeAccessible(text, NLS.bind(Messages.SearchConditionItem_SEARCH_VALUE_FIELD, field.getName()));
text.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event event) {
fInputValue = text.getText();
if (!fInputValue.equals(input))
fModified = true;
}
});
/* Show UI Hint for extra information is available */
ControlDecoration controlDeco = new ControlDecoration(text, SWT.LEFT | SWT.TOP);
controlDeco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL).getImage());
controlDeco.setShowOnlyOnFocus(true);
/* Provide auto-complete for Categories, Authors and Feeds */
if (field.getId() == INews.CATEGORIES || field.getId() == INews.AUTHOR || field.getId() == INews.FEED) {
controlDeco.setDescriptionText(Messages.SearchConditionItem_CONTENT_ASSIST_INFO);
final Pair<SimpleContentProposalProvider, ContentProposalAdapter> pair = OwlUI.hookAutoComplete(text, null, false, true);
/* Load proposals in the Background */
JobRunner.runInBackgroundThread(100, new Runnable() {
public void run() {
if (!text.isDisposed()) {
Set<String> values = new TreeSet<String>(new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
});
if (field.getId() == INews.CATEGORIES)
values.addAll(fDaoService.getCategoryDAO().loadAllNames());
else if (field.getId() == INews.AUTHOR)
values.addAll(fDaoService.getPersonDAO().loadAllNames());
else if (field.getId() == INews.FEED)
values.addAll(CoreUtils.getFeedLinks());
/* Apply Proposals */
if (!text.isDisposed())
OwlUI.applyAutoCompleteProposals(values, pair.getFirst(), pair.getSecond());
}
}
});
}
/* Show UI Hint that Wildcards can be used */
else {
controlDeco.setDescriptionText(Messages.SearchConditionItem_SEARCH_HELP);
}
/* Pre-Select input if given */
Object presetInput = (input == null && fInputValue instanceof String) ? fInputValue : input;
if (presetInput != null)
text.setText(presetInput.toString());
/* Update Input Value */
fInputValue = text.getText();
break;
}
}
}