/*******************************************************************************
- * Copyright (c) 2010 Ericsson
+ * Copyright (c) 2010, 2013 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
case SWT.MouseWheel:
shell.dispose ();
break;
+ default:
+ break;
}
}
};
}
if (tooltipProvider == null) {
return;
- } else {
- String tooltipText = tooltipProvider.getTooltip(i, item.getData());
- if (tooltipText == null) {
- return;
- }
- tip = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
- tip.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- FillLayout layout = new FillLayout();
- layout.marginWidth = 2;
- tip.setLayout(layout);
- label = new Label(tip, SWT.WRAP);
- label.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
- label.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- label.setData(TOOLTIP_DATA_KEY, item);
- label.setText(tooltipText);
-
- label.addListener(SWT.MouseExit, labelListener);
- label.addListener(SWT.MouseDown, labelListener);
- label.addListener(SWT.MouseWheel, labelListener);
- Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- Point pt = fTable.toDisplay(bounds.x, bounds.y);
- tip.setBounds(pt.x, pt.y, size.x, size.y);
- tip.setVisible(true);
}
- break;
+ String tooltipText = tooltipProvider.getTooltip(i, item.getData());
+ if (tooltipText == null) {
+ return;
+ }
+ tip = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
+ tip.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
+ FillLayout layout = new FillLayout();
+ layout.marginWidth = 2;
+ tip.setLayout(layout);
+ label = new Label(tip, SWT.WRAP);
+ label.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
+ label.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
+ label.setData(TOOLTIP_DATA_KEY, item);
+ label.setText(tooltipText);
+
+ label.addListener(SWT.MouseExit, labelListener);
+ label.addListener(SWT.MouseDown, labelListener);
+ label.addListener(SWT.MouseWheel, labelListener);
+ Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ Point pt = fTable.toDisplay(bounds.x, bounds.y);
+ tip.setBounds(pt.x, pt.y, size.x, size.y);
+ tip.setVisible(true);
}
}
}
+ break;
}
+ default:
+ break;
}
}
};
if (fSelectedEventRank < lastEventRank) {
fSelectedEventRank++;
selectedRow = fSelectedEventRank - fTableTopEventRank;
- if (selectedRow >= fFullyVisibleRows) {
+ if (selectedRow == fFullyVisibleRows) {
fTableTopEventRank++;
needsRefresh = true;
+ } else if (selectedRow < fFrozenRowCount || selectedRow > fFullyVisibleRows) {
+ fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank));
+ needsRefresh = true;
}
}
break;
if (fSelectedEventRank > 0) {
fSelectedEventRank--;
selectedRow = fSelectedEventRank - fTableTopEventRank;
- if (selectedRow < fFrozenRowCount && fTableTopEventRank > 0) {
+ if (selectedRow == fFrozenRowCount - 1 && fTableTopEventRank > 0) {
fTableTopEventRank--;
needsRefresh = true;
+ } else if (selectedRow < fFrozenRowCount || selectedRow > fFullyVisibleRows) {
+ fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank));
+ needsRefresh = true;
}
}
break;
fSelectedEventRank = lastEventRank;
}
selectedRow = fSelectedEventRank - fTableTopEventRank;
- if (selectedRow > fFullyVisibleRows - 1) {
+ if (selectedRow > fFullyVisibleRows + fFrozenRowCount - 1 && selectedRow < 2 * fFullyVisibleRows) {
fTableTopEventRank += fFullyVisibleRows;
if (fTableTopEventRank > lastPageTopEntryRank) {
fTableTopEventRank = lastPageTopEntryRank;
}
needsRefresh = true;
+ } else if (selectedRow < fFrozenRowCount || selectedRow >= 2 * fFullyVisibleRows) {
+ fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank));
+ needsRefresh = true;
}
}
break;
fSelectedEventRank = fFrozenRowCount;
}
selectedRow = fSelectedEventRank - fTableTopEventRank;
- if (selectedRow < 0) {
+ if (selectedRow < fFrozenRowCount && selectedRow > -fFullyVisibleRows) {
fTableTopEventRank -= fFullyVisibleRows;
if (fTableTopEventRank < 0) {
fTableTopEventRank = 0;
}
needsRefresh = true;
+ } else if (selectedRow <= -fFullyVisibleRows || selectedRow >= fFullyVisibleRows) {
+ fTableTopEventRank = Math.max(0, Math.min(fSelectedEventRank - fFrozenRowCount, lastPageTopEntryRank));
+ needsRefresh = true;
}
}
break;
refreshTable();
break;
}
+ default:
+ break;
}
}
});
fTable.setMenu(menu);
}
+ /**
+ * Gets the menu of this table
+ * @return a Menu
+ */
+ @Override
+ public Menu getMenu() {
+ return fTable.getMenu();
+ }
+
/**
* Method clearAll empties a table.
*/
*
*/
public void setItemCount(int nbItems) {
- nbItems = Math.max(0, nbItems);
+ final int nb = Math.max(0, nbItems);
- if (nbItems != fTableItemCount) {
- fTableItemCount = nbItems;
+ if (nb != fTableItemCount) {
+ fTableItemCount = nb;
fTable.remove(fTableItemCount, fTable.getItemCount() - 1);
- fSlider.setMaximum(nbItems);
+ fSlider.setMaximum(nb);
resize();
int tableHeight = Math.max(0, fTable.getClientArea().height - fTable.getHeaderHeight());
fFullyVisibleRows = tableHeight / getItemHeight();
/**
* Method setTopIndex.
- * @param i int suggested top index for the table.
+ * @param index int suggested top index for the table.
*/
- public void setTopIndex(int i) {
+ public void setTopIndex(int index) {
if (fTableItemCount > 0) {
- i = Math.min(i, fTableItemCount - 1);
+ int i = Math.min(index, fTableItemCount - 1);
i = Math.max(i, fFrozenRowCount);
fTableTopEventRank = i - fFrozenRowCount;
int index = fTable.indexOf(ti);
if (index < fFrozenRowCount) {
return index;
- } else {
- return (index - fFrozenRowCount) + getTopIndex();
}
+ return (index - fFrozenRowCount) + getTopIndex();
}
/**
/**
* Method setSelection.
- * @param i int the item number to select in the table.
+ * @param index int the item number to select in the table.
*/
- public void setSelection(int i) {
+ public void setSelection(int index) {
if (fTableItemCount > 0) {
- i = Math.min(i, fTableItemCount - 1);
+ int i = Math.min(index, fTableItemCount - 1);
i = Math.max(i, 0);
fSelectedEventRank = i;
if ((i < fTableTopEventRank + fFrozenRowCount && i >= fFrozenRowCount) ||
(i >= fTableTopEventRank + fFullyVisibleRows)) {
- fTableTopEventRank = Math.max(0, i - fFrozenRowCount - fFullyVisibleRows / 2);
+ int lastPageTopEntryRank = Math.max(0, fTableItemCount - fFullyVisibleRows);
+ fTableTopEventRank = Math.max(0, Math.min(lastPageTopEntryRank, i - fFrozenRowCount - fFullyVisibleRows / 2));
}
if (fFullyVisibleRows < fTableItemCount) {
fSlider.setSelection(fTableTopEventRank);
}
if (index < fFrozenRowCount) {
return index;
- } else {
- return (index - fFrozenRowCount) + getTopIndex();
}
+ return (index - fFrozenRowCount) + getTopIndex();
}
/**