/* ToolBar to add and select existing saved searches */
final ToolBarManager dialogToolBar = new ToolBarManager(SWT.RIGHT | SWT.FLAT);
/* Toggle Preview */
final String previewActionId = "org.rssowl.ui.internal.dialogs.search.PreviewAction";
IAction previewAction = new Action("&Preview Results", IAction.AS_CHECK_BOX) {
@Override
public void run() {
fIsPreviewVisible = !fIsPreviewVisible;
fSashForm.setWeights(fIsPreviewVisible ? THREE_SASH_WEIGHTS : TWO_SASH_WEIGHTS);
fBottomSash.setVisible(fIsPreviewVisible);
fSashForm.layout();
dialogToolBar.find(previewActionId).update(IAction.TOOL_TIP_TEXT);
/* Select and Show News if required */
if (fIsPreviewVisible && fResultViewer.getTable().getItemCount() > 0) {
/* Select first News if required */
if (fResultViewer.getSelection().isEmpty())
fResultViewer.getTable().select(0);
/* Set input and Focus */
fBrowserViewer.setInput(((IStructuredSelection) fResultViewer.getSelection()).getFirstElement());
hideBrowser(false);
fResultViewer.getTable().setFocus();
/* Make sure to show the selection */
fResultViewer.getTable().showSelection();
}
}
@Override
public ImageDescriptor getImageDescriptor() {
return OwlUI.getImageDescriptor("icons/etool16/highlight.gif");
}
@Override
public String getToolTipText() {
if (fIsPreviewVisible)
return "Hide Preview";
return "Show Preview";
}
};
previewAction.setId(previewActionId);
previewAction.setChecked(fIsPreviewVisible);
dialogToolBar.add(previewAction);
/* Separator */
dialogToolBar.add(new Separator());
/* Existing Saved Searches */
IAction savedSearches = new Action("S&aved Searches", IAction.AS_DROP_DOWN_MENU) {
@Override
public void run() {
getMenuCreator().getMenu(dialogToolBar.getControl()).setVisible(true);
}
@Override
public ImageDescriptor getImageDescriptor() {
return OwlUI.SEARCHMARK;
}
};
savedSearches.setMenuCreator(new IMenuCreator() {
public void dispose() {}
public Menu getMenu(Control parent) {
Set<ISearchMark> searchMarks = Controller.getDefault().getCacheService().getSearchMarks();
Menu menu = new Menu(parent);
/* Create new Saved Search */
MenuItem newSavedSearch = new MenuItem(menu, SWT.NONE);
newSavedSearch.setText("New Saved Search...");
newSavedSearch.setImage(OwlUI.getImage(fResources, "icons/etool16/add.gif"));
newSavedSearch.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
onSave();
}
});
/* Separator */
if (searchMarks.size() > 0)
new MenuItem(menu, SWT.SEPARATOR);
/* Show Existing Saved Searches */
for (final ISearchMark searchMark : searchMarks) {
MenuItem item = new MenuItem(menu, SWT.None);
item.setText(searchMark.getName());
item.setImage(OwlUI.getImage(fResources, OwlUI.SEARCHMARK));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
show(searchMark);
}
});
}
return menu;
}
public Menu getMenu(Menu parent) {
return null;
}
});
dialogToolBar.add(savedSearches);
dialogToolBar.createControl(topControlsContainer);
dialogToolBar.getControl().setLayoutData(new GridData(SWT.END, SWT.BEGINNING, true, false));
dialogToolBar.getControl().getItem(0).setText(previewAction.getText());
dialogToolBar.getControl().getItem(2).setText(savedSearches.getText());
/* Container for Conditions */
final Composite conditionsContainer = new Composite(container, SWT.NONE);
conditionsContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
conditionsContainer.setLayout(LayoutUtils.createGridLayout(2, 5, 10));