/* Sort by Name if set so */
if (Owl.getPreferenceService().getGlobalScope().getBoolean(DefaultPreferences.BE_SORT_BY_NAME))
fFolderViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
IFolder f1 = (IFolder) e1;
IFolder f2 = (IFolder) e2;
return f1.getName().compareTo(f2.getName());
}
});
/* Filter excluded Folders */
fFolderViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (fExcludes == null)
return true;
return !fExcludes.contains(element) && !fExcludes.contains(parentElement);
}
});
fFolderViewer.setContentProvider(new ITreeContentProvider() {
public Object[] getElements(Object inputElement) {
Set<IFolder> rootFolders = Controller.getDefault().getCacheService().getRootFolders();
return rootFolders.toArray();
}
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof IFolder) {
IFolder folder = (IFolder) parentElement;
return folder.getFolders().toArray();
}
return new Object[0];
}
public Object getParent(Object element) {
if (element instanceof IFolder) {
IFolder folder = (IFolder) element;
return folder.getParent();
}
return null;
}
public boolean hasChildren(Object element) {
if (element instanceof IFolder) {
IFolder folder = (IFolder) element;
return !folder.getFolders().isEmpty();
}
return false;
}
public void dispose() {}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
});
fFolderViewer.setLabelProvider(new BookMarkLabelProvider());
fFolderViewer.setInput(new Object());
fFolderViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (!selection.isEmpty())
onFolderSelected((IFolder) selection.getFirstElement());
}
});
fFolderViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
IFolder folder = (IFolder) selection.getFirstElement();
/* Expand / Collapse Folder */
if (!folder.getFolders().isEmpty()) {
boolean expandedState = !fFolderViewer.getExpandedState(folder);
fFolderViewer.setExpandedState(folder, expandedState);
}
/* Select Folder and toggle */