private void hookToolBar() {
fToolBarManager = fViewSite.getActionBars().getToolBarManager();
/* BookMark Filter */
final IAction bookmarkFilter = new Action(Messages.BookMarkExplorer_FILTER_ELEMENTS, IAction.AS_DROP_DOWN_MENU) {
@Override
public void run() {
/* Restore Default */
if (fBookMarkFilter.getType() != BookMarkFilter.Type.SHOW_ALL)
doFilter(BookMarkFilter.Type.SHOW_ALL);
/* Toggle to Previous */
else if (fLastFilterType != null)
doFilter(fLastFilterType);
/* Show Menu */
else if (fToolBarManager instanceof ToolBarManager)
OwlUI.positionDropDownMenu(this, (ToolBarManager) fToolBarManager);
}
@Override
public ImageDescriptor getImageDescriptor() {
if (fBookMarkFilter.getType() == BookMarkFilter.Type.SHOW_ALL)
return OwlUI.FILTER;
return OwlUI.getImageDescriptor("icons/etool16/filter_active.gif"); //$NON-NLS-1$
}
};
bookmarkFilter.setId(FILTER_ACTION);
bookmarkFilter.setMenuCreator(new ContextMenuCreator() {
@Override
public Menu createMenu(Control parent) {
Menu menu = new Menu(parent);
/* Filter: None */
final MenuItem showAll = new MenuItem(menu, SWT.RADIO);
showAll.setText(Messages.BookMarkExplorer_SHOW_ALL);
showAll.setSelection(BookMarkFilter.Type.SHOW_ALL == fBookMarkFilter.getType());
menu.setDefaultItem(showAll);
showAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (showAll.getSelection() && fBookMarkFilter.getType() != BookMarkFilter.Type.SHOW_ALL)
doFilter(BookMarkFilter.Type.SHOW_ALL);
}
});
/* Separator */
new MenuItem(menu, SWT.SEPARATOR);
/* Filter: New */
final MenuItem showNew = new MenuItem(menu, SWT.RADIO);
showNew.setText(Messages.BookMarkExplorer_SHOW_NEW);
showNew.setSelection(BookMarkFilter.Type.SHOW_NEW == fBookMarkFilter.getType());
showNew.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (showNew.getSelection() && fBookMarkFilter.getType() != BookMarkFilter.Type.SHOW_NEW)
doFilter(BookMarkFilter.Type.SHOW_NEW);
}
});
/* Filter: Unread */
final MenuItem showUnread = new MenuItem(menu, SWT.RADIO);
showUnread.setText(Messages.BookMarkExplorer_SHOW_UNREAD);
showUnread.setSelection(BookMarkFilter.Type.SHOW_UNREAD == fBookMarkFilter.getType());
showUnread.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (showUnread.getSelection() && fBookMarkFilter.getType() != BookMarkFilter.Type.SHOW_UNREAD)
doFilter(BookMarkFilter.Type.SHOW_UNREAD);
}
});
/* Filter: Sticky */
final MenuItem showSticky = new MenuItem(menu, SWT.RADIO);
showSticky.setText(Messages.BookMarkExplorer_SHOW_STICKY);
showSticky.setSelection(BookMarkFilter.Type.SHOW_STICKY == fBookMarkFilter.getType());
showSticky.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (showSticky.getSelection() && fBookMarkFilter.getType() != BookMarkFilter.Type.SHOW_STICKY)
doFilter(BookMarkFilter.Type.SHOW_STICKY);
}
});
/* Separator */
new MenuItem(menu, SWT.SEPARATOR);
/* Filter: Erroneous */
final MenuItem showErroneous = new MenuItem(menu, SWT.RADIO);
showErroneous.setText(Messages.BookMarkExplorer_SHOW_ERROR);
showErroneous.setSelection(BookMarkFilter.Type.SHOW_ERRONEOUS == fBookMarkFilter.getType());
showErroneous.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (showErroneous.getSelection() && fBookMarkFilter.getType() != BookMarkFilter.Type.SHOW_ERRONEOUS)
doFilter(BookMarkFilter.Type.SHOW_ERRONEOUS);
}
});
/* Filter: Never Visited */
final MenuItem showNeverVisited = new MenuItem(menu, SWT.RADIO);
showNeverVisited.setText(Messages.BookMarkExplorer_SHOW_NEVER_VISITED);
showNeverVisited.setSelection(BookMarkFilter.Type.SHOW_NEVER_VISITED == fBookMarkFilter.getType());
showNeverVisited.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (showNeverVisited.getSelection() && fBookMarkFilter.getType() != BookMarkFilter.Type.SHOW_NEVER_VISITED)
doFilter(BookMarkFilter.Type.SHOW_NEVER_VISITED);
}
});
return menu;
}
});
fToolBarManager.add(bookmarkFilter);
/* Bookmark Group */
fToolBarManager.add(new Separator());
final IAction bookmarkGroup = new Action(Messages.BookMarkExplorer_GROUP_ELEMENTS, IAction.AS_DROP_DOWN_MENU) {
@Override
public void run() {
/* Restore Default */
if (fBookMarkGrouping.getType() != BookMarkGrouping.Type.NO_GROUPING)
doGrouping(BookMarkGrouping.Type.NO_GROUPING);
/* Toggle to previous */
else if (fLastGroupType != null)
doGrouping(fLastGroupType);
/* Show Menu */
else if (fToolBarManager instanceof ToolBarManager)
OwlUI.positionDropDownMenu(this, (ToolBarManager) fToolBarManager);
}
@Override
public ImageDescriptor getImageDescriptor() {
if (fBookMarkGrouping.getType() == BookMarkGrouping.Type.NO_GROUPING)
return OwlUI.getImageDescriptor("icons/etool16/group.gif"); //$NON-NLS-1$
return OwlUI.getImageDescriptor("icons/etool16/group_active.gif"); //$NON-NLS-1$
}
};
bookmarkGroup.setId(GROUP_ACTION);
bookmarkGroup.setMenuCreator(new ContextMenuCreator() {
@Override
public Menu createMenu(Control parent) {
Menu menu = new Menu(parent);
/* Group: None */
final MenuItem noGrouping = new MenuItem(menu, SWT.RADIO);
noGrouping.setText(Messages.BookMarkExplorer_NO_GROUPING);
noGrouping.setSelection(BookMarkGrouping.Type.NO_GROUPING == fBookMarkGrouping.getType());
menu.setDefaultItem(noGrouping);
noGrouping.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (noGrouping.getSelection() && fBookMarkGrouping.getType() != BookMarkGrouping.Type.NO_GROUPING)
doGrouping(BookMarkGrouping.Type.NO_GROUPING);
}
});
/* Separator */
new MenuItem(menu, SWT.SEPARATOR);
/* Group: By Type */
final MenuItem groupByType = new MenuItem(menu, SWT.RADIO);
groupByType.setText(Messages.BookMarkExplorer_GROUP_BY_TYPE);
groupByType.setSelection(BookMarkGrouping.Type.GROUP_BY_TYPE == fBookMarkGrouping.getType());
groupByType.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByType.getSelection() && fBookMarkGrouping.getType() != BookMarkGrouping.Type.GROUP_BY_TYPE)
doGrouping(BookMarkGrouping.Type.GROUP_BY_TYPE);
}
});
/* Group: By State */
final MenuItem groupByState = new MenuItem(menu, SWT.RADIO);
groupByState.setText(Messages.BookMarkExplorer_GROUP_BY_STATE);
groupByState.setSelection(BookMarkGrouping.Type.GROUP_BY_STATE == fBookMarkGrouping.getType());
groupByState.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByState.getSelection() && fBookMarkGrouping.getType() != BookMarkGrouping.Type.GROUP_BY_STATE)
doGrouping(BookMarkGrouping.Type.GROUP_BY_STATE);
}
});
/* Separator */
new MenuItem(menu, SWT.SEPARATOR);
/* Group: By Last Visit */
final MenuItem groupByLastVisit = new MenuItem(menu, SWT.RADIO);
groupByLastVisit.setText(Messages.BookMarkExplorer_GROUP_BY_LAST_VISIT);
groupByLastVisit.setSelection(BookMarkGrouping.Type.GROUP_BY_LAST_VISIT == fBookMarkGrouping.getType());
groupByLastVisit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByLastVisit.getSelection() && fBookMarkGrouping.getType() != BookMarkGrouping.Type.GROUP_BY_LAST_VISIT)
doGrouping(BookMarkGrouping.Type.GROUP_BY_LAST_VISIT);
}
});
/* Group: By Popularity */
final MenuItem groupByPopularity = new MenuItem(menu, SWT.RADIO);
groupByPopularity.setText(Messages.BookMarkExplorer_GROUP_BY_POPULARITY);
groupByPopularity.setSelection(BookMarkGrouping.Type.GROUP_BY_POPULARITY == fBookMarkGrouping.getType());
groupByPopularity.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (groupByPopularity.getSelection() && fBookMarkGrouping.getType() != BookMarkGrouping.Type.GROUP_BY_POPULARITY)
doGrouping(BookMarkGrouping.Type.GROUP_BY_POPULARITY);
}
});
return menu;
}
});
fToolBarManager.add(bookmarkGroup);
/* Collapse All */
fToolBarManager.add(new Separator());
IAction collapseAll = new Action(Messages.BookMarkExplorer_COLLAPSE_ALL) {
@Override
public void run() {
fViewer.collapseAll();
fExpandedNodes.clear();
}
};
collapseAll.setImageDescriptor(OwlUI.getImageDescriptor("icons/etool16/collapseall.gif")); //$NON-NLS-1$
fToolBarManager.add(collapseAll);
/* BookmarkSet Navigation - TODO Consider showing dynamically */
IAction previousSet = new Action(Messages.BookMarkExplorer_PREVIOUS_SET) {
@Override
public void run() {
int index = getIndexOfRootFolder(fSelectedBookMarkSet);
changeSet(getRootFolderAt(index - 1));
}
@Override
public boolean isEnabled() {
int index = getIndexOfRootFolder(fSelectedBookMarkSet);
return index > 0 && fRootFolders.size() > 1;
}
};
previousSet.setId(PREVIOUS_SET_ACTION);
previousSet.setImageDescriptor(OwlUI.getImageDescriptor("icons/etool16/backward.gif")); //$NON-NLS-1$
previousSet.setDisabledImageDescriptor(OwlUI.getImageDescriptor("icons/dtool16/backward.gif")); //$NON-NLS-1$
fToolBarManager.add(previousSet);
IAction nextSet = new Action(Messages.BookMarkExplorer_NEXT_SET) {
@Override
public void run() {
int index = getIndexOfRootFolder(fSelectedBookMarkSet);
changeSet(getRootFolderAt(index + 1));
}
@Override
public boolean isEnabled() {
int index = getIndexOfRootFolder(fSelectedBookMarkSet);
return index < (fRootFolders.size() - 1) && fRootFolders.size() > 1;
}
};
nextSet.setId(NEXT_SET_ACTION);
nextSet.setImageDescriptor(OwlUI.getImageDescriptor("icons/etool16/forward.gif")); //$NON-NLS-1$
nextSet.setDisabledImageDescriptor(OwlUI.getImageDescriptor("icons/dtool16/forward.gif")); //$NON-NLS-1$
fToolBarManager.add(nextSet);
/* Allow Contributions */
fToolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}