protected TimeGraphControl createTimeGraphControl(Composite composite, TimeGraphColorScheme colors) {
return new TimeGraphControl(composite, colors) {
@Override
- public void verticalZoom(boolean zoomIn, boolean adjustItems) {
- boolean changed = TimeGraphCombo.this.verticalZoom(zoomIn);
- if (changed) {
- /*
- * The time graph combo takes care of adjusting item
- * heights, only adjust the font in the time graph
- * control. Only do it if the time graph combo's tree
- * font has actually changed.
- */
- super.verticalZoom(zoomIn, false);
- }
+ public void verticalZoom(boolean zoomIn) {
+ TimeGraphCombo.this.verticalZoom(zoomIn);
}
@Override
- public void resetVerticalZoom(boolean adjustItems) {
+ public void resetVerticalZoom() {
TimeGraphCombo.this.resetVerticalZoom();
- /*
- * The time graph combo takes care of resetting item
- * heights, only reset the font in the time graph control.
- */
- super.resetVerticalZoom(false);
}
};
}
});
}
- private boolean verticalZoom(boolean zoomIn) {
+ private void verticalZoom(boolean zoomIn) {
Tree tree = fTreeViewer.getTree();
FontData fontData = tree.getFont().getFontData()[0];
int height = fontData.getHeight() + (zoomIn ? 1 : -1);
if (height <= 0) {
- return false;
+ return;
}
fontData.setHeight(height);
if (fTreeFont != null) {
fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight());
fTimeGraphViewer.setItemHeight(getItemHeight(tree, true));
alignTreeItems(false);
- redraw();
- return true;
}
private void resetVerticalZoom() {
fTimeGraphViewer.setHeaderHeight(tree.getHeaderHeight());
fTimeGraphViewer.setItemHeight(getItemHeight(tree, true));
alignTreeItems(false);
- redraw();
}
private void sendTimeViewAlignmentChanged() {
TreeItem item = treeItems.get(topIndex);
tree.setTopItem(item);
+ /*
+ * In GTK3, the bounds of the tree items are only sure to be correct
+ * after the tree has been painted.
+ */
+ tree.addPaintListener(new PaintListener() {
+ @Override
+ public void paintControl(PaintEvent e) {
+ tree.removePaintListener(this);
+ doAlignTreeItems();
+ redraw();
+ /*
+ * Bug in GTK. Calling setTopItem() can scroll to the wrong item
+ * when the 'tree view' is dirty. Set it again once it is clean.
+ */
+ if (SWT.getPlatform().equals("gtk")) { //$NON-NLS-1$
+ TreeItem topItem = tree.getTopItem();
+ tree.getDisplay().asyncExec(() -> {
+ if (!tree.isDisposed() && !topItem.isDisposed()) {
+ tree.setTopItem(topItem);
+ }
+ });
+ }
+ }
+ });
+ /* Make sure the paint event is triggered. */
+ tree.redraw();
+ }
+
+ private void doAlignTreeItems() {
+ Tree tree = fTreeViewer.getTree();
+ List<TreeItem> treeItems = getVisibleExpandedItems(tree, false);
+ int topIndex = fTimeGraphViewer.getTopIndex();
+ if (topIndex >= treeItems.size()) {
+ return;
+ }
+ TreeItem item = treeItems.get(topIndex);
+
// get the first filler item so we can calculate the last item's height
TreeItem fillerItem = null;
for (TreeItem treeItem : fTreeViewer.getTree().getItems()) {
* newly visible items at the top of the viewer are also aligned.
*/
fTimeGraphViewer.setTopIndex(topIndex);
- item = treeItems.get(topIndex);
- tree.setTopItem(item);
- while (fTimeGraphViewer.getTopIndex() < topIndex) {
- TreeItem nextItem = item;
- topIndex--;
- item = treeItems.get(topIndex);
- tree.setTopItem(item);
- bounds = item.getBounds();
- alignTreeItem(item, bounds, nextItem);
- fTimeGraphViewer.setTopIndex(topIndex);
+ if (fTimeGraphViewer.getTopIndex() != topIndex) {
+ alignTreeItems(false);
}
}