}
}
// Dispose of any items in the list to be removed.
for (int i = coolItemsToRemove.size() - 1; i >= 0; i--) {
CoolItem coolItem = (CoolItem) coolItemsToRemove.get(i);
if (!coolItem.isDisposed()) {
Control control = coolItem.getControl();
if (control != null) {
coolItem.setControl(null);
control.dispose();
}
coolItem.dispose();
}
}
// Add any new items by telling them to fill.
coolItems = coolBar.getItems();
IContributionItem sourceItem;
IContributionItem destinationItem;
int sourceIndex = 0;
int destinationIndex = 0;
final Iterator visibleItemItr = visibleItems.iterator();
while (visibleItemItr.hasNext()) {
sourceItem = (IContributionItem) visibleItemItr.next();
// Retrieve the corresponding contribution item from SWT's
// data.
if (sourceIndex < coolItems.length) {
destinationItem = (IContributionItem) coolItems[sourceIndex]
.getData();
} else {
destinationItem = null;
}
// The items match is they are equal or both separators.
if (destinationItem != null) {
if (sourceItem.equals(destinationItem)) {
sourceIndex++;
destinationIndex++;
sourceItem.update();
continue;
} else if ((destinationItem.isSeparator())
&& (sourceItem.isSeparator())) {
coolItems[sourceIndex].setData(sourceItem);
sourceIndex++;
destinationIndex++;
sourceItem.update();
continue;
}
}
// Otherwise, a new item has to be added.
final int start = coolBar.getItemCount();
if (sourceItem instanceof ToolBarContributionItem) {
IToolBarManager manager = ((ToolBarContributionItem)sourceItem).getToolBarManager();
if(manager instanceof IToolBarManager2) {
((IToolBarManager2)manager).setOverrides(getOverrides());
}
}
sourceItem.fill(coolBar, destinationIndex);
final int newItems = coolBar.getItemCount() - start;
for (int i = 0; i < newItems; i++) {
coolBar.getItem(destinationIndex++).setData(sourceItem);
}
changed = true;
}
// Remove any old widgets not accounted for.
for (int i = coolItems.length - 1; i >= sourceIndex; i--) {
final CoolItem item = coolItems[i];
if (!item.isDisposed()) {
Control control = item.getControl();
if (control != null) {
item.setControl(null);
control.dispose();
}
item.dispose();
changed = true;
}
}
// Update wrap indices.
updateWrapIndices();
// Update the sizes.
for (int i = 0; i < items.length; i++) {
IContributionItem item = items[i];
item.update(SIZE);
}
// if the coolBar was previously locked then lock it
if (relock) {
coolBar.setLocked(true);