/* BookMarks got Added */
public void entitiesAdded(Set<BookMarkEvent> events) {
/* Reveal and Select if single Entity added */
if (events.size() == 1) {
final BookMarkEvent event = events.iterator().next();
JobRunner.runInUIThread(fViewer.getControl(), new Runnable() {
public void run() {
expand(event.getEntity().getParent());
}
});
}
}
};
{
/* SearchMark Listener */
fSearchMarkListener = new SearchMarkListener() {
/* SearchMarks got Updated */
public void entitiesUpdated(final Set<SearchMarkEvent> events) {
JobRunner.runInUIThread(fViewer.getControl(), new Runnable() {
public void run() {
Set<ISearchMark> updatedSearchMarks = null;
Map<ISearchMark, IFolder> reparentedSearchMarks = null;
/* Retrieve Updated SearchMarks */
for (SearchMarkEvent event : events) {
if (event.isRoot()) {
/* SearchMark got reparented */
if (event.getOldParent() != null) {
if (reparentedSearchMarks == null)
reparentedSearchMarks = new HashMap<ISearchMark, IFolder>();
reparentedSearchMarks.put(event.getEntity(), event.getOldParent());
}
/* Normal Update */
else {
if (updatedSearchMarks == null)
updatedSearchMarks = new HashSet<ISearchMark>();
updatedSearchMarks.add(event.getEntity());
}
}
}
/* Event not interesting for us or we are disposed */
if (updatedSearchMarks == null && reparentedSearchMarks == null)
return;
/* Ask Filter */
if (fBookmarkFilter.needsRefresh(ISearchMark.class, events))
fViewer.refresh(false);
/* Ask Group */
else if (fBookmarkGrouping.needsRefresh(ISearchMark.class))
fViewer.refresh(false);
/* Handle reparented SearchMarks */
else if (reparentedSearchMarks != null) {
Set<Entry<ISearchMark, IFolder>> entries = reparentedSearchMarks.entrySet();
Set<IFolder> parentsToUpdate = new HashSet<IFolder>();
try {
fViewer.getControl().getParent().setRedraw(false);
for (Entry<ISearchMark, IFolder> entry : entries) {
ISearchMark reparentedSearchMark = entry.getKey();
IFolder oldParent = entry.getValue();
/* Reparent while keeping the Selection */
ISelection selection = fViewer.getSelection();
fViewer.remove(oldParent, new Object[] { reparentedSearchMark });
fViewer.refresh(reparentedSearchMark.getParent(), false);
fViewer.setSelection(selection);
/* Remember to update parents */
parentsToUpdate.add(oldParent);
parentsToUpdate.add(reparentedSearchMark.getParent());
}
} finally {
fViewer.getControl().getParent().setRedraw(true);
}
/* Update old Parents of Reparented Bookmarks */
for (IFolder folder : parentsToUpdate)
updateFolderAndParents(folder);
}
/* Handle Updated Searchmarks */
if (updatedSearchMarks != null)
fViewer.update(updatedSearchMarks.toArray(), null);
}
});
}
/* SearchMarks got Deleted */
public void entitiesDeleted(final Set<SearchMarkEvent> events) {
JobRunner.runInUIThread(fViewer.getControl(), new Runnable() {
public void run() {
Set<ISearchMark> removedSearchMarks = null;
/* Retrieve Removed SearchMarks */
for (SearchMarkEvent event : events) {
if (event.isRoot()) {
if (removedSearchMarks == null)
removedSearchMarks = new HashSet<ISearchMark>();
removedSearchMarks.add(event.getEntity());
}
}
/* Event not interesting for us or we are disposed */
if (removedSearchMarks == null || removedSearchMarks.size() == 0)
return;
/* Ask Filter */
if (fBookmarkFilter.needsRefresh(ISearchMark.class, events))
fViewer.refresh(false);
/* Ask Group */
else if (fBookmarkGrouping.needsRefresh(ISearchMark.class))
fViewer.refresh(false);
/* React normally then */
else
fViewer.remove(removedSearchMarks.toArray());
}
});
}
/* SearchMarks got Added */
public void entitiesAdded(Set<SearchMarkEvent> events) {
/* Reveal and Select if single Entity added */
if (events.size() == 1) {
final SearchMarkEvent event = events.iterator().next();
JobRunner.runInUIThread(fViewer.getControl(), new Runnable() {
public void run() {
expand(event.getEntity().getParent());
}
});
}
}
/* SearchMark result changed */
public void resultsChanged(final Set<SearchMarkEvent> events) {
JobRunner.runInUIThread(fViewer.getControl(), new Runnable() {
public void run() {
/* Ask Filter for a refresh */
if (fBookmarkFilter.needsRefresh(ISearchMark.class, events))
fViewer.refresh(false);
/* Update SearchMarks */
Set<ISearchMark> updatedSearchMarks = new HashSet<ISearchMark>(events.size());
for (SearchMarkEvent event : events) {
updatedSearchMarks.add(event.getEntity());
}
fViewer.update(updatedSearchMarks.toArray(), null);
/* Update Parents */