1 /*******************************************************************************
2 * Copyright (c) 2010 Red Hat, Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Chris Aniszczyk <caniszczyk@gmail.com> - initial implementation
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.internal
;
13 import org
.eclipse
.core
.runtime
.jobs
.IJobChangeEvent
;
14 import org
.eclipse
.core
.runtime
.jobs
.JobChangeAdapter
;
15 import org
.eclipse
.jface
.viewers
.TreeViewer
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Text
;
19 import org
.eclipse
.swt
.widgets
.Tree
;
20 import org
.eclipse
.ui
.dialogs
.FilteredTree
;
21 import org
.eclipse
.ui
.dialogs
.PatternFilter
;
22 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
23 import org
.eclipse
.ui
.progress
.WorkbenchJob
;
26 * A FilteredCheckboxTree implementation to be used internally in EGit code. This tree stores
27 * all the tree elements internally, and keeps the check state in sync. This way, even if an
28 * element is filtered, the caller can get and set the checked state.
30 public class FilteredCheckboxTree
extends FilteredTree
{
32 private static final long FILTER_DELAY
= 400;
35 CachedCheckboxTreeViewer checkboxViewer
;
38 * Constructor that creates a tree with preset style bits and a CachedContainerCheckedTreeViewer for the tree.
40 * @param parent parent composite
41 * @param toolkit optional toolkit to create UI elements with, required if the tree is being created in a form editor
43 public FilteredCheckboxTree(Composite parent
, FormToolkit toolkit
) {
44 this(parent
, toolkit
, SWT
.NONE
);
48 * Constructor that creates a tree with preset style bits and a CachedContainerCheckedTreeViewer for the tree.
50 * @param parent parent composite
51 * @param toolkit optional toolkit to create UI elements with, required if the tree is being created in a form editor
54 public FilteredCheckboxTree(Composite parent
, FormToolkit toolkit
, int treeStyle
) {
55 this(parent
, toolkit
, treeStyle
, new PatternFilter());
59 * Constructor that creates a tree with preset style bits and a CachedContainerCheckedTreeViewer for the tree.
61 * @param parent parent composite
62 * @param toolkit optional toolkit to create UI elements with, required if the tree is being created in a form editor
64 * @param filter pattern filter to use in the filter control
66 public FilteredCheckboxTree(Composite parent
, FormToolkit toolkit
, int treeStyle
, PatternFilter filter
) {
67 super(parent
, treeStyle
, filter
);
69 init(treeStyle
, filter
);
73 * @see org.eclipse.ui.dialogs.FilteredTree#doCreateTreeViewer(org.eclipse.swt.widgets.Composite, int)
75 protected TreeViewer
doCreateTreeViewer(Composite parent
, int style
) {
76 int treeStyle
= style
| SWT
.CHECK
| SWT
.MULTI
| SWT
.V_SCROLL
| SWT
.H_SCROLL
| SWT
.BORDER
;
78 if (fToolkit
!= null) {
79 tree
= fToolkit
.createTree(parent
, treeStyle
);
81 tree
= new Tree(parent
, treeStyle
);
84 checkboxViewer
= new CachedCheckboxTreeViewer(tree
);
85 return checkboxViewer
;
89 * Overridden to hook a listener on the job and set the deferred content provider
90 * to synchronous mode before a filter is done.
91 * @see org.eclipse.ui.dialogs.FilteredTree#doCreateRefreshJob()
93 protected WorkbenchJob
doCreateRefreshJob() {
94 WorkbenchJob filterJob
= super.doCreateRefreshJob();
95 filterJob
.addJobChangeListener(new JobChangeAdapter() {
96 public void done(IJobChangeEvent event
) {
97 if (event
.getResult().isOK()) {
98 getDisplay().asyncExec(new Runnable() {
100 if (checkboxViewer
.getTree().isDisposed())
102 checkboxViewer
.restoreLeafCheckState();
112 * @see org.eclipse.ui.dialogs.FilteredTree#doCreateFilterText(org.eclipse.swt.widgets.Composite)
114 protected Text
doCreateFilterText(Composite parent
) {
115 // Overridden so the text gets create using the toolkit if we have one
116 Text parentText
= super.doCreateFilterText(parent
);
117 if (fToolkit
!= null) {
118 int style
= parentText
.getStyle();
119 parentText
.dispose();
120 return fToolkit
.createText(parent
, null, style
);
126 * @return The checkbox treeviewer
128 public CachedCheckboxTreeViewer
getCheckboxTreeViewer() {
129 return checkboxViewer
;
133 * Overrides org.eclipse.ui.dialogs.FilteredTree#getRefreshJobDelay() in
134 * Eclipse 3.5 and newer. No effect in eclipse 3.4
136 * @return refresh delay
138 // TODO: remove this javadoc when support for 3.4 is dropped
139 protected long getRefreshJobDelay() {