Lines 12-24
Link Here
|
12 |
package org.eclipse.jface.viewers; |
12 |
package org.eclipse.jface.viewers; |
13 |
|
13 |
|
14 |
import java.util.ArrayList; |
14 |
import java.util.ArrayList; |
15 |
import java.util.Arrays; |
|
|
16 |
import java.util.HashSet; |
15 |
import java.util.HashSet; |
17 |
import java.util.Iterator; |
16 |
import java.util.Iterator; |
18 |
import java.util.List; |
17 |
import java.util.List; |
19 |
|
18 |
|
20 |
import org.eclipse.core.runtime.Platform; |
19 |
import org.eclipse.core.runtime.Platform; |
21 |
|
20 |
import org.eclipse.jface.util.Assert; |
|
|
21 |
import org.eclipse.jface.util.ListenerList; |
22 |
import org.eclipse.jface.util.SafeRunnable; |
22 |
import org.eclipse.swt.SWT; |
23 |
import org.eclipse.swt.SWT; |
23 |
import org.eclipse.swt.custom.BusyIndicator; |
24 |
import org.eclipse.swt.custom.BusyIndicator; |
24 |
import org.eclipse.swt.events.SelectionListener; |
25 |
import org.eclipse.swt.events.SelectionListener; |
Lines 28-37
Link Here
|
28 |
import org.eclipse.swt.widgets.Item; |
29 |
import org.eclipse.swt.widgets.Item; |
29 |
import org.eclipse.swt.widgets.Widget; |
30 |
import org.eclipse.swt.widgets.Widget; |
30 |
|
31 |
|
31 |
import org.eclipse.jface.util.Assert; |
|
|
32 |
import org.eclipse.jface.util.ListenerList; |
33 |
import org.eclipse.jface.util.SafeRunnable; |
34 |
|
35 |
/** |
32 |
/** |
36 |
* Abstract base implementation for tree-structure-oriented viewers |
33 |
* Abstract base implementation for tree-structure-oriented viewers |
37 |
* (trees and table trees). |
34 |
* (trees and table trees). |
Lines 102-107
Link Here
|
102 |
*/ |
99 |
*/ |
103 |
protected AbstractTreeViewer() { |
100 |
protected AbstractTreeViewer() { |
104 |
} |
101 |
} |
|
|
102 |
|
105 |
/** |
103 |
/** |
106 |
* Adds the given child elements to this viewer as children of the given parent element. |
104 |
* Adds the given child elements to this viewer as children of the given parent element. |
107 |
* If this viewer does not have a sorter, the elements are added at the end of the |
105 |
* If this viewer does not have a sorter, the elements are added at the end of the |
Lines 124-192
Link Here
|
124 |
if (widget == null) |
122 |
if (widget == null) |
125 |
return; |
123 |
return; |
126 |
|
124 |
|
127 |
Control tree = getControl(); |
125 |
Object[] filtered = filter(childElements); |
128 |
|
126 |
for (int i = 0; i < filtered.length; i++) { |
129 |
// optimization! |
127 |
Object element = filtered[i]; |
130 |
// if the widget is not expanded we just invalidate the subtree |
128 |
int index = indexForElement(widget, element); |
131 |
if (widget instanceof Item) { |
129 |
createTreeItem(widget, filtered[i], index); |
132 |
Item ti = (Item) widget; |
|
|
133 |
if (!getExpanded(ti)) { |
134 |
boolean needDummy = isExpandable(parentElement); |
135 |
boolean haveDummy = false; |
136 |
// remove all children |
137 |
Item[] items = getItems(ti); |
138 |
for (int i = 0; i < items.length; i++) { |
139 |
if (items[i].getData() != null) { |
140 |
disassociate(items[i]); |
141 |
items[i].dispose(); |
142 |
} else { |
143 |
if (needDummy && !haveDummy) { |
144 |
haveDummy = true; |
145 |
} else { |
146 |
items[i].dispose(); |
147 |
} |
148 |
} |
149 |
} |
150 |
// append a dummy if necessary |
151 |
if (needDummy && !haveDummy) { |
152 |
newItem(ti, SWT.NULL, -1); |
153 |
} else { |
154 |
// XXX: Workaround (PR missing) |
155 |
tree.redraw(); |
156 |
} |
157 |
|
158 |
return; |
159 |
} |
160 |
} |
130 |
} |
161 |
|
131 |
|
162 |
if (childElements.length > 0) { |
132 |
} /* |
163 |
List children = Arrays.asList(getSortedChildren(parentElement)); |
133 |
* Returns the index where the item should be inserted. |
164 |
for (int cc = 0; cc < childElements.length; cc++) { |
134 |
*/ |
165 |
|
135 |
protected int indexForElement(Widget parent, Object element) { |
166 |
int ix = children.indexOf(childElements[cc]); |
136 |
ViewerSorter sorter = getSorter(); |
167 |
if (ix < 0) // child not found: ignore |
137 |
Item [] items = getChildren(parent); |
168 |
continue; |
138 |
|
169 |
|
139 |
if (sorter == null) |
170 |
Item[] ch = getChildren(widget); |
140 |
return items.length; |
171 |
if (ch.length + 1 == children.size()) { |
141 |
int count = items.length; |
172 |
createTreeItem(widget, childElements[cc], ix); |
142 |
int min = 0, max = count - 1; |
173 |
// insert child at position |
143 |
|
174 |
if (ch.length == 0) { |
144 |
|
175 |
//System.out.println("WORKAROUND setRedraw"); |
145 |
|
176 |
tree.setRedraw(false); // WORKAROUND |
146 |
while (min <= max) { |
177 |
tree.setRedraw(true); // WORKAROUND |
147 |
int mid = (min + max) / 2; |
|
|
148 |
Object data = items[mid].getData(); |
149 |
int compare = sorter.compare(this, data, element); |
150 |
if (compare == 0) { |
151 |
// find first item > element |
152 |
while (compare == 0) { |
153 |
++mid; |
154 |
if (mid >= count) { |
155 |
break; |
178 |
} |
156 |
} |
179 |
continue; |
157 |
data = items[mid].getData(); |
|
|
158 |
compare = sorter.compare(this, data, element); |
180 |
} |
159 |
} |
181 |
|
160 |
return mid; |
182 |
// couldn't handle this child: |
|
|
183 |
// skip other children and do general case |
184 |
// call refresh rather than internalRefresh to preserve selection |
185 |
refresh(parentElement); |
186 |
return; |
187 |
} |
161 |
} |
|
|
162 |
if (compare < 0) |
163 |
min = mid + 1; |
164 |
else |
165 |
max = mid - 1; |
188 |
} |
166 |
} |
|
|
167 |
return min; |
189 |
} |
168 |
} |
|
|
169 |
|
190 |
/** |
170 |
/** |
191 |
* Adds the given child element to this viewer as a child of the given parent element. |
171 |
* Adds the given child element to this viewer as a child of the given parent element. |
192 |
* If this viewer does not have a sorter, the element is added at the end of the |
172 |
* If this viewer does not have a sorter, the element is added at the end of the |