Lines 13-18
Link Here
|
13 |
package org.eclipse.jface.viewers; |
13 |
package org.eclipse.jface.viewers; |
14 |
|
14 |
|
15 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
|
|
16 |
import java.util.Arrays; |
16 |
import java.util.HashSet; |
17 |
import java.util.HashSet; |
17 |
import java.util.List; |
18 |
import java.util.List; |
18 |
|
19 |
|
Lines 143-160
Link Here
|
143 |
*/ |
144 |
*/ |
144 |
public void notVisibleAdded(Object element, int index) { |
145 |
public void notVisibleAdded(Object element, int index) { |
145 |
|
146 |
|
146 |
int requiredCount = index + 1; |
147 |
int requiredCount = getTable().getItemCount() + 1; |
147 |
|
148 |
|
148 |
if (requiredCount > getTable().getItemCount()) { |
149 |
Object[] newCache = new Object[requiredCount]; |
149 |
getTable().setItemCount(requiredCount); |
150 |
System.arraycopy(cachedElements, 0, newCache, 0, index); |
150 |
Object[] newCache = new Object[requiredCount]; |
151 |
if (index < cachedElements.length) { |
151 |
System.arraycopy(cachedElements, 0, newCache, 0, |
152 |
System.arraycopy(cachedElements, index, newCache, index + 1, cachedElements.length - index); |
152 |
cachedElements.length); |
|
|
153 |
cachedElements = newCache; |
154 |
} |
153 |
} |
|
|
154 |
newCache[index] = element; |
155 |
cachedElements = newCache; |
155 |
|
156 |
|
156 |
cachedElements[index] = element; |
157 |
getTable().setItemCount(requiredCount); |
|
|
158 |
} |
159 |
|
160 |
/** |
161 |
* The elements with the given indices need to be removed from the cache. |
162 |
* @param indices |
163 |
*/ |
164 |
public void removeIndices(int[] indices) { |
165 |
if (indices.length==1) { |
166 |
removeIndicesFromTo(indices[0], indices[0]); |
167 |
} |
168 |
int requiredCount = getTable().getItemCount() - indices.length; |
169 |
|
170 |
Arrays.sort(indices); |
171 |
Object[] newCache = new Object[requiredCount]; |
172 |
int indexInNewCache = 0; |
173 |
int nextToSkip = 0; |
174 |
for (int i=0; i<cachedElements.length; i++) { |
175 |
if (nextToSkip < indices.length && i == indices[nextToSkip]) { |
176 |
nextToSkip++; |
177 |
} else { |
178 |
newCache[indexInNewCache++] = cachedElements[i]; |
179 |
} |
180 |
} |
181 |
cachedElements = newCache; |
182 |
} |
183 |
|
184 |
/** |
185 |
* The elements between the given indices (inclusive) need to be removed from the cache. |
186 |
* @param from |
187 |
* @param to |
188 |
*/ |
189 |
public void removeIndicesFromTo(int from, int to) { |
190 |
int indexAfterTo = to + 1; |
191 |
Object[] newCache = new Object[cachedElements.length - (indexAfterTo - from)]; |
192 |
System.arraycopy(cachedElements, 0, newCache, 0, from); |
193 |
if (indexAfterTo < cachedElements.length) { |
194 |
System.arraycopy(cachedElements, indexAfterTo, newCache, from, cachedElements.length - indexAfterTo); |
195 |
} |
196 |
} |
197 |
|
198 |
/** |
199 |
* @param element |
200 |
* @return the index of the element in the cache, or null |
201 |
*/ |
202 |
public int find(Object element) { |
203 |
return Arrays.asList(cachedElements).indexOf(element); |
204 |
} |
157 |
|
205 |
|
|
|
206 |
/** |
207 |
* @param count |
208 |
*/ |
209 |
public void adjustCacheSize(int count) { |
210 |
if (count == cachedElements.length) { |
211 |
return; |
212 |
} else if (count < cachedElements.length) { |
213 |
Object[] newCache = new Object[count]; |
214 |
System.arraycopy(cachedElements, 0, newCache, 0, count); |
215 |
cachedElements = newCache; |
216 |
} else { |
217 |
Object[] newCache = new Object[count]; |
218 |
System.arraycopy(cachedElements, 0, newCache, 0, cachedElements.length); |
219 |
cachedElements = newCache; |
220 |
} |
158 |
} |
221 |
} |
159 |
|
222 |
|
160 |
} |
223 |
} |
Lines 814-819
Link Here
|
814 |
|
877 |
|
815 |
disassociate(items[i]); |
878 |
disassociate(items[i]); |
816 |
} |
879 |
} |
|
|
880 |
if (virtualManager != null) { |
881 |
virtualManager.removeIndicesFromTo(min, items.length - 1); |
882 |
} |
817 |
table.remove(min, items.length - 1); |
883 |
table.remove(min, items.length - 1); |
818 |
} |
884 |
} |
819 |
// Workaround for 1GDGN4Q: ITPUI:WIN2000 - TableViewer icons get |
885 |
// Workaround for 1GDGN4Q: ITPUI:WIN2000 - TableViewer icons get |
Lines 855-861
Link Here
|
855 |
int count = 0; |
921 |
int count = 0; |
856 |
for (int i = 0; i < elements.length; ++i) { |
922 |
for (int i = 0; i < elements.length; ++i) { |
857 |
Widget w = findItem(elements[i]); |
923 |
Widget w = findItem(elements[i]); |
858 |
if (w instanceof TableItem) { |
924 |
if (w == null && virtualManager != null) { |
|
|
925 |
int index = virtualManager.find(elements[i]); |
926 |
if (index != -1) { |
927 |
indices[count++] = index; |
928 |
} |
929 |
} else if (w instanceof TableItem) { |
859 |
TableItem item = (TableItem) w; |
930 |
TableItem item = (TableItem) w; |
860 |
disassociate(item); |
931 |
disassociate(item); |
861 |
indices[count++] = table.indexOf(item); |
932 |
indices[count++] = table.indexOf(item); |
Lines 864-869
Link Here
|
864 |
if (count < indices.length) { |
935 |
if (count < indices.length) { |
865 |
System.arraycopy(indices, 0, indices = new int[count], 0, count); |
936 |
System.arraycopy(indices, 0, indices = new int[count], 0, count); |
866 |
} |
937 |
} |
|
|
938 |
if (virtualManager != null) { |
939 |
virtualManager.removeIndices(indices); |
940 |
} |
867 |
table.remove(indices); |
941 |
table.remove(indices); |
868 |
|
942 |
|
869 |
// Workaround for 1GDGN4Q: ITPUI:WIN2000 - TableViewer icons get |
943 |
// Workaround for 1GDGN4Q: ITPUI:WIN2000 - TableViewer icons get |
Lines 1171-1176
Link Here
|
1171 |
*/ |
1245 |
*/ |
1172 |
public void setItemCount(int count) { |
1246 |
public void setItemCount(int count) { |
1173 |
getTable().setItemCount(count); |
1247 |
getTable().setItemCount(count); |
|
|
1248 |
if (virtualManager != null) { |
1249 |
virtualManager.adjustCacheSize(count); |
1250 |
} |
1174 |
getTable().redraw(); |
1251 |
getTable().redraw(); |
1175 |
} |
1252 |
} |
1176 |
|
1253 |
|