((GridData) searchContainer.getLayoutData()).widthHint = 180;
final ToolBarManager manager = new ToolBarManager(SWT.FLAT);
final NewsFilter filter = fFeedView.getFilter();
IAction quickSearch = new Action(Messages.FilterBar_QUICK_SEARCH, IAction.AS_DROP_DOWN_MENU) {
@Override
public void run() {
OwlUI.positionDropDownMenu(this, manager);
}
@Override
public String getId() {
return QUICKSEARCH_ACTION;
}
};
quickSearch.setImageDescriptor(OwlUI.getImageDescriptor("icons/etool16/find.gif")); //$NON-NLS-1$
quickSearch.setMenuCreator(new ContextMenuCreator() {
@Override
public Menu createMenu(Control parent) {
Menu menu = new Menu(parent);
/* Search on: Subject */
final MenuItem searchHeadline = new MenuItem(menu, SWT.RADIO);
searchHeadline.setText(NewsFilter.SearchTarget.HEADLINE.getName());
searchHeadline.setSelection(NewsFilter.SearchTarget.HEADLINE == filter.getSearchTarget());
searchHeadline.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (searchHeadline.getSelection() && filter.getSearchTarget() != NewsFilter.SearchTarget.HEADLINE)
doSearch(NewsFilter.SearchTarget.HEADLINE);
}
});
/* Search on: Entire News */
final MenuItem searchEntireNews = new MenuItem(menu, SWT.RADIO);
searchEntireNews.setText(NewsFilter.SearchTarget.ALL.getName());
searchEntireNews.setSelection(NewsFilter.SearchTarget.ALL == filter.getSearchTarget());
searchEntireNews.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (searchEntireNews.getSelection() && filter.getSearchTarget() != NewsFilter.SearchTarget.ALL)
doSearch(NewsFilter.SearchTarget.ALL);
}
});
new MenuItem(menu, SWT.SEPARATOR);
/* Search on: Author */
final MenuItem searchAuthor = new MenuItem(menu, SWT.RADIO);
searchAuthor.setText(NewsFilter.SearchTarget.AUTHOR.getName());
searchAuthor.setSelection(NewsFilter.SearchTarget.AUTHOR == filter.getSearchTarget());
searchAuthor.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (searchAuthor.getSelection() && filter.getSearchTarget() != NewsFilter.SearchTarget.AUTHOR)
doSearch(NewsFilter.SearchTarget.AUTHOR);
}
});
/* Search on: Category */
final MenuItem searchCategory = new MenuItem(menu, SWT.RADIO);
searchCategory.setText(NewsFilter.SearchTarget.CATEGORY.getName());
searchCategory.setSelection(NewsFilter.SearchTarget.CATEGORY == filter.getSearchTarget());
searchCategory.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (searchCategory.getSelection() && filter.getSearchTarget() != NewsFilter.SearchTarget.CATEGORY)
doSearch(NewsFilter.SearchTarget.CATEGORY);
}
});
/* Search on: Source */
final MenuItem searchSource = new MenuItem(menu, SWT.RADIO);
searchSource.setText(NewsFilter.SearchTarget.SOURCE.getName());
searchSource.setSelection(NewsFilter.SearchTarget.SOURCE == filter.getSearchTarget());
searchSource.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (searchSource.getSelection() && filter.getSearchTarget() != NewsFilter.SearchTarget.SOURCE)
doSearch(NewsFilter.SearchTarget.SOURCE);
}
});
/* Search on: Attachments */
final MenuItem searchAttachments = new MenuItem(menu, SWT.RADIO);
searchAttachments.setText(NewsFilter.SearchTarget.ATTACHMENTS.getName());
searchAttachments.setSelection(NewsFilter.SearchTarget.ATTACHMENTS == filter.getSearchTarget());
searchAttachments.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (searchAttachments.getSelection() && filter.getSearchTarget() != NewsFilter.SearchTarget.ATTACHMENTS)
doSearch(NewsFilter.SearchTarget.ATTACHMENTS);
}
});
/* Search on: Labels */
final MenuItem searchLabels = new MenuItem(menu, SWT.RADIO);
searchLabels.setText(NewsFilter.SearchTarget.LABELS.getName());
searchLabels.setSelection(NewsFilter.SearchTarget.LABELS == filter.getSearchTarget());
searchLabels.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (searchLabels.getSelection() && filter.getSearchTarget() != NewsFilter.SearchTarget.LABELS)
doSearch(NewsFilter.SearchTarget.LABELS);
}
});
/* Offer to Save as Search */
INewsMark inputMark = ((FeedViewInput) fFeedView.getEditorInput()).getMark();
if (inputMark instanceof IBookMark || inputMark instanceof INewsBin || inputMark instanceof FolderNewsMark) {
/* Separator */
new MenuItem(menu, SWT.SEPARATOR);
/* Convert Filter to Saved Search */
final MenuItem createSavedSearch = new MenuItem(menu, SWT.RADIO);
createSavedSearch.setText(Messages.FilterBar_SAVE_SEARCH);
createSavedSearch.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onCreateSavedSearch(true);
}
});
}
return menu;
}
});
manager.add(quickSearch);
manager.createControl(searchContainer);
/* Input for the Search */
fSearchInput = new Text(searchContainer, SWT.BORDER | SWT.SINGLE | SWT.SEARCH | SWT.CANCEL);
fSearchInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
fSearchInput.setMessage(fFeedView.getFilter().getSearchTarget().getName());
/* Register this Input Field to Context Service */
Controller.getDefault().getContextService().registerInputField(fSearchInput);
/* Reset any Filter if set on ESC */
fSearchInput.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.ESC)
clearQuickSearch(true);
}
});
/* Handle the CR Key Pressed */
fSearchInput.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN || e.detail == SWT.TRAVERSE_PAGE_NEXT || e.detail == SWT.TRAVERSE_PAGE_PREVIOUS) {
e.doit = false;
fFeedView.handleQuicksearchTraversalEvent(e.detail);
}
}
});
/* Run search when text is entered */
fSearchInput.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
/* Clear Search immediately */
if (fSearchInput.getText().length() == 0 && fFeedView.getFilter().isPatternSet()) {
fFeedView.getFilter().setPattern(fSearchInput.getText());
if (!fBlockRefresh) {
BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
public void run() {
fFeedView.refresh(true, false);
}
});
}
setClearBarVisible(false);
}
/* Run Search in JobTracker */
else if (fSearchInput.getText().length() > 0) {
fQuickSearchTracker.run(new TaskAdapter() {
public IStatus run(IProgressMonitor monitor) {
BusyIndicator.showWhile(Display.getDefault(), new Runnable() {
public void run() {
fFeedView.getFilter().setPattern(fSearchInput.getText());
fFeedView.refresh(true, false);
}
});
setClearBarVisible(true);
return Status.OK_STATUS;
}
});
}
}
});
fSearchInput.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
fFeedView.getEditorSite().getActionBars().getGlobalActionHandler(ActionFactory.CUT.getId()).setEnabled(true);
fFeedView.getEditorSite().getActionBars().getGlobalActionHandler(ActionFactory.COPY.getId()).setEnabled(true);
fFeedView.getEditorSite().getActionBars().getGlobalActionHandler(ActionFactory.PASTE.getId()).setEnabled(true);
}
public void focusLost(FocusEvent e) {
fFeedView.getEditorSite().getActionBars().getGlobalActionHandler(ActionFactory.CUT.getId()).setEnabled(false);
fFeedView.getEditorSite().getActionBars().getGlobalActionHandler(ActionFactory.COPY.getId()).setEnabled(false);
fFeedView.getEditorSite().getActionBars().getGlobalActionHandler(ActionFactory.PASTE.getId()).setEnabled(false);
}
});
/* Clear Button */
if (!Application.IS_MAC) {
ToolBar toolBar = new ToolBar(searchContainer, SWT.FLAT | SWT.HORIZONTAL);
fFilterToolBar = new ToolBarManager(toolBar);
fFilterToolBar.getControl().setBackground(parent.getBackground());
fFilterToolBar.getControl().setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, true));
/* Initially Hide */
((GridData) toolBar.getLayoutData()).exclude = true;
toolBar.setVisible(false);
IAction clearTextAction = new Action("", IAction.AS_PUSH_BUTTON) {//$NON-NLS-1$
@Override
public void run() {
clearQuickSearch(true);
}
};
clearTextAction.setToolTipText(Messages.FilterBar_CLEAR);
clearTextAction.setImageDescriptor(OwlUI.getImageDescriptor("icons/etool16/clear.gif")); //$NON-NLS-1$
fFilterToolBar.add(clearTextAction);
fFilterToolBar.update(false);
fFilterToolBar.getControl().setVisible(false);