summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2014-02-19 05:46:23 (EST)
committerLars Vogel2014-02-19 05:46:23 (EST)
commit495351bd026b05ca81c10dba18f98befecdef931 (patch)
treedb5c77cb97fd8e2f040bbe2535d481714e53c844
parent43237680b7ae0b87c0119e31e2f80cdbe8ced375 (diff)
downloadrt.equinox.p2-495351bd026b05ca81c10dba18f98befecdef931.zip
rt.equinox.p2-495351bd026b05ca81c10dba18f98befecdef931.tar.gz
rt.equinox.p2-495351bd026b05ca81c10dba18f98befecdef931.tar.bz2
Bug 428523 - [Minor] Code cleanup in org.eclipse.equinox.p2.uirefs/changes/25/22225/1
For DelayedFilterCheckboxTree Change-Id: I8105a2e39a723bb1093173e00e68ad4e5a279fb6 Signed-off-by: Lars Vogel <Lars.Vogel@gmail.com>
-rw-r--r--bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/DelayedFilterCheckboxTree.java65
1 files changed, 47 insertions, 18 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/DelayedFilterCheckboxTree.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/DelayedFilterCheckboxTree.java
index 2ebc6b5..25e86f2 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/DelayedFilterCheckboxTree.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/DelayedFilterCheckboxTree.java
@@ -59,16 +59,18 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
init(treeStyle, filter);
}
+ @Override
protected TreeViewer doCreateTreeViewer(Composite composite, int style) {
checkboxViewer = new ContainerCheckedTreeViewer(composite, style);
checkboxViewer.addCheckStateListener(new ICheckStateListener() {
+ @Override
public void checkStateChanged(CheckStateChangedEvent event) {
// We use an additive check state cache so we need to remove
// previously checked items if the user unchecked them.
if (!event.getChecked() && checkState != null) {
- if (event.getElement() == ALL_ITEMS_HACK)
+ if (event.getElement() == ALL_ITEMS_HACK) {
clearCheckStateCache();
- else {
+ } else {
ArrayList<Object> toRemove = new ArrayList<Object>(1);
// See bug 258117. Ideally we would get check state changes
// for children when the parent state changed, but we aren't, so
@@ -77,8 +79,8 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
if (contentProvider.hasChildren(event.getElement())) {
Set<Object> unchecked = new HashSet<Object>();
Object[] children = contentProvider.getChildren(event.getElement());
- for (int i = 0; i < children.length; i++) {
- unchecked.add(children[i]);
+ for (Object element : children) {
+ unchecked.add(element);
}
Iterator<Object> iter = checkState.iterator();
while (iter.hasNext()) {
@@ -107,9 +109,11 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
return checkboxViewer;
}
+ @Override
protected Composite createFilterControls(Composite filterParent) {
super.createFilterControls(filterParent);
filterParent.addDisposeListener(new DisposeListener() {
+ @Override
public void widgetDisposed(DisposeEvent e) {
cancelPreFilterJob();
}
@@ -120,6 +124,7 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
public void contentProviderSet(final DeferredQueryContentProvider deferredProvider) {
this.contentProvider = deferredProvider;
deferredProvider.addListener(new IInputChangeListener() {
+ @Override
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
if (newInput == null) {
return;
@@ -140,9 +145,11 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
// selection preserving viewer refresh.
checkboxViewer.getTree().setRedraw(false);
display.asyncExec(new Runnable() {
+ @Override
public void run() {
- if (checkboxViewer.getTree().isDisposed())
+ if (checkboxViewer.getTree().isDisposed()) {
return;
+ }
rememberExpansions();
restoreLeafCheckState();
rememberExpansions();
@@ -163,17 +170,21 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
* to synchronous mode before a filter is done.
* @see org.eclipse.ui.dialogs.FilteredTree#doCreateRefreshJob()
*/
+ @Override
protected WorkbenchJob doCreateRefreshJob() {
filterJob = super.doCreateRefreshJob();
filterJob.addJobChangeListener(new JobChangeAdapter() {
+ @Override
public void aboutToRun(final IJobChangeEvent event) {
// If we know we've already filtered and loaded repos, nothing more to do
- if (!ignoreFiltering)
+ if (!ignoreFiltering) {
return;
+ }
final boolean[] shouldPreFilter = new boolean[1];
shouldPreFilter[0] = false;
display.syncExec(new Runnable() {
+ @Override
public void run() {
if (filterText != null && !filterText.isDisposed()) {
String text = getFilterString();
@@ -181,8 +192,9 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
// actually filtering to do, check for a prefilter
// job and the content provider to synchronous mode.
// We want the prefilter job to complete before continuing with filtering.
- if (text == null || (initialText != null && initialText.equals(text)))
+ if (text == null || (initialText != null && initialText.equals(text))) {
return;
+ }
if (!contentProvider.getSynchronous() && preFilterJob == null) {
if (filterText != null && !filterText.isDisposed()) {
shouldPreFilter[0] = true;
@@ -203,20 +215,25 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
}
}
+ @Override
public void running(IJobChangeEvent event) {
display.syncExec(new Runnable() {
+ @Override
public void run() {
rememberLeafCheckState();
}
});
}
+ @Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
display.asyncExec(new Runnable() {
+ @Override
public void run() {
- if (checkboxViewer.getTree().isDisposed())
+ if (checkboxViewer.getTree().isDisposed()) {
return;
+ }
checkboxViewer.getTree().setRedraw(false);
// remember things expanded by the filter
@@ -240,17 +257,20 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
ignoreFiltering = false;
preFilterJob = jobProvider == null ? null : jobProvider.getPreFilterJob();
if (preFilterJob == null) {
- if (filterJob != null)
+ if (filterJob != null) {
filterJob.wakeUp();
+ }
return;
}
ignoreFiltering = true;
preFilterJob.addJobChangeListener(new JobChangeAdapter() {
+ @Override
public void done(IJobChangeEvent event) {
ignoreFiltering = false;
contentProvider.setSynchronous(true);
- if (filterJob != null)
+ if (filterJob != null) {
filterJob.wakeUp();
+ }
preFilterJob = null;
}
});
@@ -275,19 +295,25 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
void rememberLeafCheckState() {
ContainerCheckedTreeViewer v = (ContainerCheckedTreeViewer) getViewer();
Object[] checked = v.getCheckedElements();
- if (checkState == null)
+ if (checkState == null) {
checkState = new HashSet<Object>(checked.length);
- for (int i = 0; i < checked.length; i++)
- if (!v.getGrayed(checked[i]) && contentProvider.getChildren(checked[i]).length == 0)
- if (!checkState.contains(checked[i]))
+ }
+ for (int i = 0; i < checked.length; i++) {
+ if (!v.getGrayed(checked[i]) && contentProvider.getChildren(checked[i]).length == 0) {
+ if (!checkState.contains(checked[i])) {
checkState.add(checked[i]);
+ }
+ }
+ }
}
void restoreLeafCheckState() {
- if (checkboxViewer == null || checkboxViewer.getTree().isDisposed())
+ if (checkboxViewer == null || checkboxViewer.getTree().isDisposed()) {
return;
- if (checkState == null)
+ }
+ if (checkState == null) {
return;
+ }
checkboxViewer.setCheckedElements(new Object[0]);
checkboxViewer.setGrayedElements(new Object[0]);
@@ -295,15 +321,17 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
// and rely on our container checked code to update the parents properly.
Iterator<Object> iter = checkState.iterator();
Object element = null;
- if (iter.hasNext())
+ if (iter.hasNext()) {
checkboxViewer.expandAll();
+ }
while (iter.hasNext()) {
element = iter.next();
checkboxViewer.setChecked(element, true);
}
// We are only firing one event, knowing that this is enough for our listeners.
- if (element != null)
+ if (element != null) {
checkboxViewer.fireCheckStateChanged(element, true);
+ }
}
void rememberExpansions() {
@@ -326,6 +354,7 @@ public class DelayedFilterCheckboxTree extends FilteredTree {
* (non-Javadoc)
* @see org.eclipse.ui.dialogs.FilteredTree#getRefreshJobDelay()
*/
+ @Override
protected long getRefreshJobDelay() {
return FILTER_DELAY;
}