/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
+ * Copyright (c) 2010, 2011, 2012 Ericsson\r
*\r
* All rights reserved. This program and the accompanying materials are\r
* made available under the terms of the Eclipse Public License v1.0 which\r
import org.eclipse.jface.resource.FontDescriptor;\r
import org.eclipse.jface.resource.JFaceResources;\r
import org.eclipse.jface.resource.LocalResourceManager;\r
-import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
import org.eclipse.linuxtools.internal.tmf.ui.Activator;\r
+import org.eclipse.linuxtools.internal.tmf.ui.Messages;\r
import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider;\r
import org.eclipse.linuxtools.tmf.core.component.TmfComponent;\r
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;\r
fTable.addMouseListener(new MouseAdapter() {\r
@Override\r
public void mouseDoubleClick(final MouseEvent event) {\r
- if (event.button != 1)\r
+ if (event.button != 1) {\r
return;\r
+ }\r
// Identify the selected row\r
final Point point = new Point(event.x, event.y);\r
final TableItem item = fTable.getItem(point);\r
imageBounds.width = BOOKMARK_IMAGE.getBounds().width;\r
if (imageBounds.contains(point)) {\r
final Long rank = (Long) item.getData(Key.RANK);\r
- if (rank != null)\r
+ if (rank != null) {\r
toggleBookmark(rank);\r
+ }\r
}\r
}\r
}\r
});\r
\r
- final Listener bookmarkListener = new Listener () {\r
+ final Listener tooltipListener = new Listener () {\r
Shell tooltipShell = null;\r
@Override\r
public void handleEvent(final Event event) {\r
switch (event.type) {\r
case SWT.MouseHover:\r
final TableItem item = fTable.getItem(new Point(event.x, event.y));\r
- if (item == null)\r
+ if (item == null) {\r
return;\r
+ }\r
+ final Long rank = (Long) item.getData(Key.RANK);\r
+ if (rank == null) {\r
+ return;\r
+ }\r
final String tooltipText = (String) item.getData(Key.BOOKMARK);\r
- if (tooltipText == null)\r
- return;;\r
- final Rectangle bounds = item.getImageBounds(0);\r
- if (!bounds.contains(event.x,event.y))\r
- return;\r
- if ((tooltipShell != null) && !tooltipShell.isDisposed())\r
- tooltipShell.dispose();\r
- tooltipShell = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);\r
- tooltipShell.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));\r
- final FillLayout layout = new FillLayout();\r
- layout.marginWidth = 2;\r
- tooltipShell.setLayout(layout);\r
- final Label label = new Label(tooltipShell, SWT.WRAP);\r
- label.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));\r
- label.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));\r
- label.setText(tooltipText);\r
- label.addListener(SWT.MouseExit, this);\r
- label.addListener(SWT.MouseDown, this);\r
- label.addListener(SWT.MouseWheel, this);\r
- final Point size = tooltipShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
- final Point pt = fTable.toDisplay(event.x, event.y);\r
- tooltipShell.setBounds(pt.x, pt.y, size.x, size.y);\r
- tooltipShell.setVisible(true);\r
- break;\r
+ final Rectangle bounds = item.getImageBounds(0);\r
+ bounds.width = BOOKMARK_IMAGE.getBounds().width;\r
+ if (!bounds.contains(event.x,event.y)) {\r
+ return;\r
+ }\r
+ if ((tooltipShell != null) && !tooltipShell.isDisposed()) {\r
+ tooltipShell.dispose();\r
+ }\r
+ tooltipShell = new Shell(fTable.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);\r
+ tooltipShell.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));\r
+ final FillLayout layout = new FillLayout();\r
+ layout.marginWidth = 2;\r
+ tooltipShell.setLayout(layout);\r
+ final Label label = new Label(tooltipShell, SWT.WRAP);\r
+ String text = rank.toString() + (tooltipText != null ? ": " + tooltipText : ""); //$NON-NLS-1$ //$NON-NLS-2$\r
+ label.setForeground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));\r
+ label.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));\r
+ label.setText(text);\r
+ label.addListener(SWT.MouseExit, this);\r
+ label.addListener(SWT.MouseDown, this);\r
+ label.addListener(SWT.MouseWheel, this);\r
+ final Point size = tooltipShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
+ Point pt = fTable.toDisplay(event.x, event.y);\r
+ pt.x += BOOKMARK_IMAGE.getBounds().width;\r
+ pt.y += size.y;\r
+ tooltipShell.setBounds(pt.x, pt.y, size.x, size.y);\r
+ tooltipShell.setVisible(true);\r
+ break;\r
case SWT.Dispose:\r
case SWT.KeyDown:\r
case SWT.MouseMove:\r
}\r
};\r
\r
- fTable.addListener(SWT.MouseHover, bookmarkListener);\r
- fTable.addListener(SWT.Dispose, bookmarkListener);\r
- fTable.addListener(SWT.KeyDown, bookmarkListener);\r
- fTable.addListener(SWT.MouseMove, bookmarkListener);\r
- fTable.addListener(SWT.MouseExit, bookmarkListener);\r
- fTable.addListener(SWT.MouseDown, bookmarkListener);\r
- fTable.addListener(SWT.MouseWheel, bookmarkListener);\r
+ fTable.addListener(SWT.MouseHover, tooltipListener);\r
+ fTable.addListener(SWT.Dispose, tooltipListener);\r
+ fTable.addListener(SWT.KeyDown, tooltipListener);\r
+ fTable.addListener(SWT.MouseMove, tooltipListener);\r
+ fTable.addListener(SWT.MouseExit, tooltipListener);\r
+ fTable.addListener(SWT.MouseDown, tooltipListener);\r
+ fTable.addListener(SWT.MouseWheel, tooltipListener);\r
\r
// Create resources\r
createResources();\r
if (e.data instanceof Long) {\r
final long rank = (Long) e.data;\r
int index = (int) rank;\r
- if (fTable.getData(Key.FILTER_OBJ) != null)\r
+ if (fTable.getData(Key.FILTER_OBJ) != null) {\r
index = fCache.getFilteredEventIndex(rank) + 1; // +1 for top filter status row\r
+ }\r
fTable.setSelection(index + 1); // +1 for header row\r
fSelectedRank = rank;\r
- } else if (e.data instanceof ITmfLocation<?>)\r
+ } else if (e.data instanceof ITmfLocation<?>) {\r
// DOES NOT WORK: rank undefined in context from seekLocation()\r
- // ITmfLocation<?> location = (ITmfLocation<?>) e.data;\r
- // TmfContext context = fTrace.seekLocation(location);\r
- // fTable.setSelection((int) context.getRank());\r
+ // ITmfLocation<?> location = (ITmfLocation<?>) e.data;\r
+ // TmfContext context = fTrace.seekLocation(location);\r
+ // fTable.setSelection((int) context.getRank());\r
return;\r
- else\r
+ } else {\r
return;\r
+ }\r
final TableItem[] selection = fTable.getSelection();\r
if ((selection != null) && (selection.length > 0)) {\r
final TmfTimestamp ts = (TmfTimestamp) fTable.getSelection()[0].getData(Key.TIMESTAMP);\r
- if (ts != null)\r
+ if (ts != null) {\r
broadcast(new TmfTimeSynchSignal(TmfEventsTable.this, ts));\r
+ }\r
}\r
}\r
});\r
fRawViewer.setVisible(true);\r
fSashForm.layout();\r
final int index = fTable.getSelectionIndex();\r
- if (index >= +1)\r
+ if (index >= +1) {\r
fRawViewer.selectAndReveal(index - 1);\r
+ }\r
}\r
};\r
\r
public void menuAboutToShow(final IMenuManager manager) {\r
if (fTable.getSelectionIndex() == 0) {\r
// Right-click on header row\r
- if (fHeaderState == HeaderState.FILTER)\r
+ if (fHeaderState == HeaderState.FILTER) {\r
tablePopupMenu.add(showSearchBarAction);\r
- else\r
+ } else {\r
tablePopupMenu.add(showFilterBarAction);\r
+ }\r
return;\r
}\r
final Point point = fTable.toControl(Display.getDefault().getCursorLocation());\r
if (point.x <= (imageBounds.x + imageBounds.width)) {\r
// Right-click on left margin\r
final Long rank = (Long) item.getData(Key.RANK);\r
- if ((rank != null) && (fBookmarksFile != null))\r
- if (fBookmarksMap.containsKey(rank))\r
+ if ((rank != null) && (fBookmarksFile != null)) {\r
+ if (fBookmarksMap.containsKey(rank)) {\r
tablePopupMenu.add(new ToggleBookmarkAction(\r
Messages.TmfEventsTable_RemoveBookmarkActionText, rank));\r
- else\r
+ } else {\r
tablePopupMenu.add(new ToggleBookmarkAction(\r
Messages.TmfEventsTable_AddBookmarkActionText, rank));\r
+ }\r
+ }\r
return;\r
}\r
}\r
if (fTable.isVisible() && fRawViewer.isVisible()) {\r
tablePopupMenu.add(hideTableAction);\r
tablePopupMenu.add(hideRawAction);\r
- } else if (!fTable.isVisible())\r
+ } else if (!fTable.isVisible()) {\r
tablePopupMenu.add(showTableAction);\r
- else if (!fRawViewer.isVisible())\r
+ } else if (!fRawViewer.isVisible()) {\r
tablePopupMenu.add(showRawAction);\r
+ }\r
tablePopupMenu.add(new Separator());\r
tablePopupMenu.add(clearFiltersAction);\r
final ITmfFilterTreeNode[] savedFilters = FilterManager.getSavedFilters();\r
if (savedFilters.length > 0) {\r
final MenuManager subMenu = new MenuManager(Messages.TmfEventsTable_ApplyPresetFilterMenuName);\r
- for (final ITmfFilterTreeNode node : savedFilters)\r
+ for (final ITmfFilterTreeNode node : savedFilters) {\r
if (node instanceof TmfFilterNode) {\r
final TmfFilterNode filter = (TmfFilterNode) node;\r
subMenu.add(new Action(filter.getFilterName()) {\r
fCache.applyFilter(filter);\r
fTable.clearAll();\r
fTable.setData(Key.FILTER_OBJ, filter);\r
- fTable.setItemCount(3); // +1 for header row, +2 for top and bottom filter status\r
- // rows\r
+ fTable.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows\r
startFilterThread();\r
fireFilterApplied(filter);\r
}\r
});\r
}\r
+ }\r
tablePopupMenu.add(subMenu);\r
}\r
appendToTablePopupMenu(tablePopupMenu, item);\r
if (fTable.isVisible() && fRawViewer.isVisible()) {\r
rawViewerPopupMenu.add(hideTableAction);\r
rawViewerPopupMenu.add(hideRawAction);\r
- } else if (!fTable.isVisible())\r
+ } else if (!fTable.isVisible()) {\r
rawViewerPopupMenu.add(showTableAction);\r
- else if (!fRawViewer.isVisible())\r
+ } else if (!fRawViewer.isVisible()) {\r
rawViewerPopupMenu.add(showRawAction);\r
+ }\r
appendToRawPopupMenu(tablePopupMenu);\r
}\r
});\r
stopFilterThread();\r
ColorSettingsManager.removeColorSettingsListener(this);\r
fComposite.dispose();\r
- if ((fTrace != null) && fDisposeOnClose)\r
+ if ((fTrace != null) && fDisposeOnClose) {\r
fTrace.dispose();\r
+ }\r
fResourceManager.dispose();\r
super.dispose();\r
}\r
protected void setItemData(final TableItem item, final ITmfEvent event, final long rank) {\r
final ITmfEventField[] fields = extractItemFields(event);\r
final String[] content = new String[fields.length];\r
- for (int i = 0; i < fields.length; i++)\r
+ for (int i = 0; i < fields.length; i++) {\r
content[i] = fields[i].getValue() != null ? fields[i].getValue().toString() : ""; //$NON-NLS-1$\r
- item.setText(content);\r
- item.setData(Key.TIMESTAMP, new TmfTimestamp(event.getTimestamp()));\r
- item.setData(Key.RANK, rank);\r
-\r
- boolean bookmark = false;\r
- final Long markerId = fBookmarksMap.get(rank);\r
- if (markerId != null) {\r
- bookmark = true;\r
- try {\r
- final IMarker marker = fBookmarksFile.findMarker(markerId);\r
- item.setData(Key.BOOKMARK, marker.getAttribute(IMarker.MESSAGE));\r
- } catch (final CoreException e) {\r
- displayException(e);\r
- }\r
- } else\r
- item.setData(Key.BOOKMARK, null);\r
-\r
- boolean searchMatch = false;\r
- boolean searchNoMatch = false;\r
- final ITmfFilter searchFilter = (ITmfFilter) fTable.getData(Key.SEARCH_OBJ);\r
- if (searchFilter != null)\r
- if (searchFilter.matches(event))\r
- searchMatch = true;\r
- else\r
- searchNoMatch = true;\r
-\r
- final ColorSetting colorSetting = ColorSettingsManager.getColorSetting(event);\r
- if (searchNoMatch) {\r
- item.setForeground(colorSetting.getDimmedForegroundColor());\r
- item.setBackground(colorSetting.getDimmedBackgroundColor());\r
+ }\r
+ item.setText(content);\r
+ item.setData(Key.TIMESTAMP, new TmfTimestamp(event.getTimestamp()));\r
+ item.setData(Key.RANK, rank);\r
+\r
+ boolean bookmark = false;\r
+ final Long markerId = fBookmarksMap.get(rank);\r
+ if (markerId != null) {\r
+ bookmark = true;\r
+ try {\r
+ final IMarker marker = fBookmarksFile.findMarker(markerId);\r
+ item.setData(Key.BOOKMARK, marker.getAttribute(IMarker.MESSAGE));\r
+ } catch (final CoreException e) {\r
+ displayException(e);\r
+ }\r
+ } else {\r
+ item.setData(Key.BOOKMARK, null);\r
+ }\r
+\r
+ boolean searchMatch = false;\r
+ boolean searchNoMatch = false;\r
+ final ITmfFilter searchFilter = (ITmfFilter) fTable.getData(Key.SEARCH_OBJ);\r
+ if (searchFilter != null) {\r
+ if (searchFilter.matches(event)) {\r
+ searchMatch = true;\r
} else {\r
- item.setForeground(colorSetting.getForegroundColor());\r
- item.setBackground(colorSetting.getBackgroundColor());\r
+ searchNoMatch = true;\r
}\r
+ }\r
+\r
+ final ColorSetting colorSetting = ColorSettingsManager.getColorSetting(event);\r
+ if (searchNoMatch) {\r
+ item.setForeground(colorSetting.getDimmedForegroundColor());\r
+ item.setBackground(colorSetting.getDimmedBackgroundColor());\r
+ } else {\r
+ item.setForeground(colorSetting.getForegroundColor());\r
+ item.setBackground(colorSetting.getBackgroundColor());\r
+ }\r
\r
- if (searchMatch) {\r
- if (bookmark)\r
- item.setImage(SEARCH_MATCH_BOOKMARK_IMAGE);\r
- else\r
- item.setImage(SEARCH_MATCH_IMAGE);\r
- } else if (bookmark)\r
- item.setImage(BOOKMARK_IMAGE);\r
- else\r
- item.setImage((Image) null);\r
+ if (searchMatch) {\r
+ if (bookmark) {\r
+ item.setImage(SEARCH_MATCH_BOOKMARK_IMAGE);\r
+ } else {\r
+ item.setImage(SEARCH_MATCH_IMAGE);\r
+ }\r
+ } else if (bookmark) {\r
+ item.setImage(BOOKMARK_IMAGE);\r
+ } else {\r
+ item.setImage((Image) null);\r
+ }\r
}\r
\r
protected void setHeaderRowItemData(final TableItem item) {\r
final TableColumn column = fTable.getColumns()[i];\r
final String filter = (String) column.getData(txtKey);\r
if (filter == null) {\r
- if (fHeaderState == HeaderState.SEARCH)\r
+ if (fHeaderState == HeaderState.SEARCH) {\r
item.setText(i, SEARCH_HINT);\r
- else if (fHeaderState == HeaderState.FILTER)\r
+ } else if (fHeaderState == HeaderState.FILTER) {\r
item.setText(i, FILTER_HINT);\r
+ }\r
item.setForeground(i, fGrayColor);\r
item.setFont(i, fTable.getFont());\r
} else {\r
}\r
\r
protected void setFilterStatusRowItemData(final TableItem item) {\r
- for (int i = 0; i < fTable.getColumns().length; i++)\r
+ for (int i = 0; i < fTable.getColumns().length; i++) {\r
if (i == 0) {\r
- if ((fTrace == null) || (fFilterCheckCount == fTrace.getNbEvents()))\r
+ if ((fTrace == null) || (fFilterCheckCount == fTrace.getNbEvents())) {\r
item.setImage(FILTER_IMAGE);\r
- else\r
+ } else {\r
item.setImage(STOP_IMAGE);\r
+ }\r
item.setText(0, fFilterMatchCount + "/" + fFilterCheckCount); //$NON-NLS-1$\r
- } else\r
+ } else {\r
item.setText(i, ""); //$NON-NLS-1$\r
+ }\r
+ }\r
item.setData(Key.TIMESTAMP, null);\r
item.setData(Key.RANK, null);\r
item.setForeground(null);\r
\r
@Override\r
public void mouseDown(final MouseEvent event) {\r
- if (event.button != 1)\r
+ if (event.button != 1) {\r
return;\r
+ }\r
// Identify the selected row\r
final Point point = new Point(event.x, event.y);\r
item = fTable.getItem(point);\r
\r
// Icon selected\r
if (item.getImageBounds(0).contains(point)) {\r
- if (fHeaderState == HeaderState.SEARCH)\r
+ if (fHeaderState == HeaderState.SEARCH) {\r
fHeaderState = HeaderState.FILTER;\r
- else if (fHeaderState == HeaderState.FILTER)\r
+ } else if (fHeaderState == HeaderState.FILTER) {\r
fHeaderState = HeaderState.SEARCH;\r
+ }\r
fTable.refresh();\r
return;\r
}\r
}\r
}\r
\r
- if (columnIndex == -1)\r
+ if (columnIndex == -1) {\r
return;\r
+ }\r
\r
column = fTable.getColumns()[columnIndex];\r
\r
String txtKey = null;\r
- if (fHeaderState == HeaderState.SEARCH)\r
+ if (fHeaderState == HeaderState.SEARCH) {\r
txtKey = Key.SEARCH_TXT;\r
- else if (fHeaderState == HeaderState.FILTER)\r
+ } else if (fHeaderState == HeaderState.FILTER) {\r
txtKey = Key.FILTER_TXT;\r
+ }\r
\r
// The control that will be the editor must be a child of the Table\r
final Text newEditor = (Text) fTable.createTableEditorControl(Text.class);\r
final String headerString = (String) column.getData(txtKey);\r
- if (headerString != null)\r
+ if (headerString != null) {\r
newEditor.setText(headerString);\r
+ }\r
newEditor.addFocusListener(new FocusAdapter() {\r
@Override\r
public void focusLost(final FocusEvent e) {\r
final boolean changed = updateHeader(newEditor.getText());\r
- if (changed)\r
+ if (changed) {\r
applyHeader();\r
+ }\r
}\r
});\r
newEditor.addKeyListener(new KeyAdapter() {\r
if (e.character == SWT.CR) {\r
updateHeader(newEditor.getText());\r
applyHeader();\r
- } else if (e.character == SWT.ESC)\r
+ } else if (e.character == SWT.ESC) {\r
tableEditor.getEditor().dispose();\r
+ }\r
}\r
});\r
newEditor.selectAll();\r
objKey = Key.FILTER_OBJ;\r
txtKey = Key.FILTER_TXT;\r
}\r
- if (text.trim().length() > 0)\r
+ if (text.trim().length() > 0) {\r
try {\r
final String regex = TmfFilterMatchesNode.regexFix(text);\r
Pattern.compile(regex);\r
}\r
final TmfFilterMatchesNode filter = new TmfFilterMatchesNode(null);\r
String fieldId = (String) column.getData(Key.FIELD_ID);\r
- if (fieldId == null)\r
+ if (fieldId == null) {\r
fieldId = column.getText();\r
+ }\r
filter.setField(fieldId);\r
filter.setRegex(regex);\r
column.setData(objKey, filter);\r
ex.getDescription(), ex.getMessage());\r
return false;\r
}\r
- else {\r
+ } else {\r
if (column.getData(txtKey) == null) {\r
tableEditor.getEditor().dispose();\r
return false;\r
final TmfFilterAndNode filter = new TmfFilterAndNode(null);\r
for (final TableColumn column : fTable.getColumns()) {\r
final Object filterObj = column.getData(Key.SEARCH_OBJ);\r
- if (filterObj instanceof ITmfFilterTreeNode)\r
+ if (filterObj instanceof ITmfFilterTreeNode) {\r
filter.addChild((ITmfFilterTreeNode) filterObj);\r
+ }\r
}\r
if (filter.getChildrenCount() > 0) {\r
fTable.setData(Key.SEARCH_OBJ, filter);\r
final TmfFilterAndNode filter = new TmfFilterAndNode(null);\r
for (final TableColumn column : fTable.getColumns()) {\r
final Object filterObj = column.getData(Key.FILTER_OBJ);\r
- if (filterObj instanceof ITmfFilterTreeNode)\r
+ if (filterObj instanceof ITmfFilterTreeNode) {\r
filter.addChild((ITmfFilterTreeNode) filterObj);\r
+ }\r
}\r
if (filter.getChildrenCount() > 0) {\r
fCache.applyFilter(filter);\r
stopFilterThread();\r
fTable.clearAll();\r
fTable.setData(Key.FILTER_OBJ, null);\r
- if (fTrace != null)\r
+ if (fTrace != null) {\r
fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row\r
- else\r
+ } else {\r
fTable.setItemCount(1); // +1 for header row\r
+ }\r
fireFilterApplied(null);\r
}\r
}\r
fTable.setData(Key.SEARCH_OBJ, null);\r
fTable.refresh();\r
fireSearchApplied(null);\r
- } else if (fHeaderState == HeaderState.FILTER)\r
+ } else if (fHeaderState == HeaderState.FILTER) {\r
clearFilters();\r
- } else if (e.character == SWT.CR)\r
- if ((e.stateMask & SWT.SHIFT) == 0)\r
+ }\r
+ } else if (e.character == SWT.CR) {\r
+ if ((e.stateMask & SWT.SHIFT) == 0) {\r
searchNext();\r
- else\r
+ } else {\r
searchPrevious();\r
+ }\r
+ }\r
}\r
});\r
}\r
\r
protected void fireFilterApplied(final ITmfFilter filter) {\r
- for (final ITmfEventsFilterListener listener : fEventsFilterListeners)\r
+ for (final ITmfEventsFilterListener listener : fEventsFilterListeners) {\r
listener.filterApplied(filter, fTrace);\r
+ }\r
}\r
\r
protected void fireSearchApplied(final ITmfFilter filter) {\r
- for (final ITmfEventsFilterListener listener : fEventsFilterListeners)\r
+ for (final ITmfEventsFilterListener listener : fEventsFilterListeners) {\r
listener.searchApplied(filter, fTrace);\r
+ }\r
}\r
\r
protected void startFilterThread() {\r
synchronized (fFilterSyncObj) {\r
- if (fFilterThread != null)\r
+ if (fFilterThread != null) {\r
fFilterThread.cancel();\r
+ }\r
final ITmfFilterTreeNode filter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ);\r
fFilterThread = new FilterThread(filter);\r
fFilterThread.start();\r
\r
protected void stopFilterThread() {\r
synchronized (fFilterSyncObj) {\r
- if (fFilterThread != null)\r
+ if (fFilterThread != null) {\r
fFilterThread.cancel();\r
+ }\r
}\r
}\r
\r
protected void clearFilters() {\r
- if (fTable.getData(Key.FILTER_OBJ) == null)\r
+ if (fTable.getData(Key.FILTER_OBJ) == null) {\r
return;\r
+ }\r
fCache.clearFilter();\r
fTable.clearAll();\r
for (final TableColumn column : fTable.getColumns()) {\r
column.setData(Key.FILTER_TXT, null);\r
}\r
fTable.setData(Key.FILTER_OBJ, null);\r
- if (fTrace != null)\r
+ if (fTrace != null) {\r
fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row\r
- else\r
+ } else {\r
fTable.setItemCount(1); // +1 for header row\r
+ }\r
fFilterMatchCount = 0;\r
fFilterCheckCount = 0;\r
- if (fSelectedRank >= 0)\r
+ if (fSelectedRank >= 0) {\r
fTable.setSelection((int) fSelectedRank + 1); // +1 for header row\r
- else\r
+ } else {\r
fTable.setSelection(0);\r
+ }\r
fireFilterApplied(null);\r
}\r
\r
@SuppressWarnings("unchecked")\r
@Override\r
public void run() {\r
- if (fTrace == null)\r
+ if (fTrace == null) {\r
return;\r
+ }\r
final int nbRequested = (int) (fTrace.getNbEvents() - fFilterCheckCount);\r
- if (nbRequested <= 0)\r
+ if (nbRequested <= 0) {\r
return;\r
+ }\r
request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, TmfTimeRange.ETERNITY, (int) fFilterCheckCount,\r
nbRequested, fTrace.getCacheSize(), ExecutionType.BACKGROUND) {\r
@Override\r
public void handleData(final ITmfEvent event) {\r
super.handleData(event);\r
- if (request.isCancelled())\r
+ if (request.isCancelled()) {\r
return;\r
+ }\r
if (filter.matches(event)) {\r
final long rank = fFilterCheckCount;\r
final int index = (int) fFilterMatchCount;\r
fFilterMatchCount++;\r
fCache.storeEvent(event.clone(), rank, index);\r
refreshTable();\r
- } else if ((fFilterCheckCount % 100) == 0)\r
+ } else if ((fFilterCheckCount % 100) == 0) {\r
refreshTable();\r
+ }\r
fFilterCheckCount++;\r
}\r
};\r
if (refreshBusy) {\r
refreshPending = true;\r
return;\r
- } else\r
+ } else {\r
refreshBusy = true;\r
+ }\r
}\r
Display.getDefault().asyncExec(new Runnable() {\r
@Override\r
public void run() {\r
- if (request.isCancelled())\r
+ if (request.isCancelled()) {\r
return;\r
- if (fTable.isDisposed())\r
+ }\r
+ if (fTable.isDisposed()) {\r
return;\r
- fTable.setItemCount((int) fFilterMatchCount + 3); // +1 for header row, +2 for top and bottom filter\r
- // status rows\r
+ }\r
+ fTable.setItemCount((int) fFilterMatchCount + 3); // +1 for header row, +2 for top and bottom filter status rows\r
fTable.refresh();\r
synchronized (syncObj) {\r
refreshBusy = false;\r
}\r
\r
public void cancel() {\r
- if (request != null)\r
+ if (request != null) {\r
request.cancel();\r
+ }\r
}\r
}\r
\r
protected void searchNext() {\r
synchronized (fSearchSyncObj) {\r
- if (fSearchThread != null)\r
+ if (fSearchThread != null) {\r
return;\r
+ }\r
final ITmfFilterTreeNode searchFilter = (ITmfFilterTreeNode) fTable.getData(Key.SEARCH_OBJ);\r
- if (searchFilter == null)\r
+ if (searchFilter == null) {\r
return;\r
+ }\r
final int selectionIndex = fTable.getSelectionIndex();\r
int startIndex;\r
- if (selectionIndex > 0)\r
+ if (selectionIndex > 0) {\r
startIndex = selectionIndex; // -1 for header row, +1 for next event\r
- else\r
+ } else {\r
// header row is selected, start at top event\r
startIndex = Math.max(0, fTable.getTopIndex() - 1); // -1 for header row\r
+ }\r
final ITmfFilterTreeNode eventFilter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ);\r
if (eventFilter != null)\r
+ {\r
startIndex = Math.max(0, startIndex - 1); // -1 for top filter status row\r
+ }\r
fSearchThread = new SearchThread(searchFilter, eventFilter, startIndex, fSelectedRank, Direction.FORWARD);\r
fSearchThread.schedule();\r
}\r
\r
protected void searchPrevious() {\r
synchronized (fSearchSyncObj) {\r
- if (fSearchThread != null)\r
+ if (fSearchThread != null) {\r
return;\r
+ }\r
final ITmfFilterTreeNode searchFilter = (ITmfFilterTreeNode) fTable.getData(Key.SEARCH_OBJ);\r
- if (searchFilter == null)\r
+ if (searchFilter == null) {\r
return;\r
+ }\r
final int selectionIndex = fTable.getSelectionIndex();\r
int startIndex;\r
- if (selectionIndex > 0)\r
+ if (selectionIndex > 0) {\r
startIndex = selectionIndex - 2; // -1 for header row, -1 for previous event\r
- else\r
+ } else {\r
// header row is selected, start at precedent of top event\r
startIndex = fTable.getTopIndex() - 2; // -1 for header row, -1 for previous event\r
+ }\r
final ITmfFilterTreeNode eventFilter = (ITmfFilterTreeNode) fTable.getData(Key.FILTER_OBJ);\r
if (eventFilter != null)\r
+ {\r
startIndex = startIndex - 1; // -1 for top filter status row\r
+ }\r
fSearchThread = new SearchThread(searchFilter, eventFilter, startIndex, fSelectedRank, Direction.BACKWARD);\r
fSearchThread.schedule();\r
}\r
@SuppressWarnings("unchecked")\r
@Override\r
protected IStatus run(final IProgressMonitor monitor) {\r
- if (fTrace == null)\r
+ if (fTrace == null) {\r
return Status.OK_STATUS;\r
+ }\r
final Display display = Display.getDefault();\r
- if (startIndex < 0)\r
+ if (startIndex < 0) {\r
rank = (int) fTrace.getNbEvents() - 1;\r
- else if (startIndex >= (fTable.getItemCount() - (eventFilter == null ? 1 : 3)))\r
+ } else if (startIndex >= (fTable.getItemCount() - (eventFilter == null ? 1 : 3))) {\r
// for top and bottom\r
// filter status rows\r
rank = 0;\r
- else {\r
+ } else {\r
int idx = startIndex;\r
while (foundRank == -1) {\r
final CachedEvent event = fCache.peekEvent(idx);\r
- if (event == null)\r
+ if (event == null) {\r
break;\r
+ }\r
rank = event.rank;\r
if (searchFilter.matches(event.event) && ((eventFilter == null) || eventFilter.matches(event.event))) {\r
foundRank = event.rank;\r
break;\r
}\r
- if (direction == Direction.FORWARD)\r
+ if (direction == Direction.FORWARD) {\r
idx++;\r
- else\r
+ } else {\r
idx--;\r
+ }\r
}\r
- if (foundRank == -1)\r
+ if (foundRank == -1) {\r
if (direction == Direction.FORWARD) {\r
rank++;\r
- if (rank > (fTrace.getNbEvents() - 1))\r
+ if (rank > (fTrace.getNbEvents() - 1)) {\r
rank = 0;\r
+ }\r
} else {\r
rank--;\r
- if (rank < 0)\r
+ if (rank < 0) {\r
rank = (int) fTrace.getNbEvents() - 1;\r
+ }\r
}\r
+ }\r
}\r
final int startRank = (int) rank;\r
boolean wrapped = false;\r
((ITmfDataProvider<ITmfEvent>) fTrace).sendRequest(request);\r
try {\r
request.waitForCompletion();\r
- if (request.isCancelled())\r
+ if (request.isCancelled()) {\r
return Status.OK_STATUS;\r
+ }\r
} catch (final InterruptedException e) {\r
synchronized (fSearchSyncObj) {\r
fSearchThread = null;\r
}\r
return Status.OK_STATUS;\r
}\r
- if (foundRank == -1)\r
+ if (foundRank == -1) {\r
if (direction == Direction.FORWARD) {\r
if (rank == 0) {\r
synchronized (fSearchSyncObj) {\r
return Status.OK_STATUS;\r
}\r
}\r
+ }\r
}\r
int index = (int) foundRank;\r
- if (eventFilter != null)\r
+ if (eventFilter != null) {\r
index = fCache.getFilteredEventIndex(foundRank);\r
- final int selection = index + 1 + (eventFilter != null ? +1 : 0); // +1 for header row, +1 for top filter\r
- // status row\r
+ }\r
+ final int selection = index + 1 + (eventFilter != null ? +1 : 0); // +1 for header row, +1 for top filter status row\r
\r
display.asyncExec(new Runnable() {\r
@Override\r
public void run() {\r
- if (monitor.isCanceled())\r
+ if (monitor.isCanceled()) {\r
return;\r
- if (fTable.isDisposed())\r
+ }\r
+ if (fTable.isDisposed()) {\r
return;\r
+ }\r
fTable.setSelection(selection);\r
fSelectedRank = foundRank;\r
synchronized (fSearchSyncObj) {\r
}\r
\r
protected void packColumns() {\r
- if (fPackDone)\r
+ if (fPackDone) {\r
return;\r
+ }\r
for (final TableColumn column : fTable.getColumns()) {\r
final int headerWidth = column.getWidth();\r
column.pack();\r
- if (column.getWidth() < headerWidth)\r
+ if (column.getWidth() < headerWidth) {\r
column.setWidth(headerWidth);\r
+ }\r
}\r
fPackDone = true;\r
}\r
* true if the trace should be disposed when the table is disposed\r
*/\r
public void setTrace(final ITmfTrace<?> trace, final boolean disposeOnClose) {\r
- if ((fTrace != null) && fDisposeOnClose)\r
+ if ((fTrace != null) && fDisposeOnClose) {\r
fTrace.dispose();\r
+ }\r
fTrace = trace;\r
fPackDone = false;\r
fSelectedRank = 0;\r
fTable.removeAll();\r
fCache.setTrace(fTrace); // Clear the cache\r
if (fTrace != null) {\r
- if (!fTable.isDisposed() && (fTrace != null))\r
- if (fTable.getData(Key.FILTER_OBJ) == null)\r
+ if (!fTable.isDisposed() && (fTrace != null)) {\r
+ if (fTable.getData(Key.FILTER_OBJ) == null) {\r
fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row\r
- else {\r
+ } else {\r
stopFilterThread();\r
fFilterMatchCount = 0;\r
fFilterCheckCount = 0;\r
fTable.setItemCount(3); // +1 for header row, +2 for top and bottom filter status rows\r
startFilterThread();\r
}\r
+ }\r
fRawViewer.setTrace(fTrace);\r
}\r
}\r
fCacheUpdatePending = true;\r
fCacheUpdateCompleted = completed;\r
return;\r
- } else\r
+ } else {\r
fCacheUpdateBusy = true;\r
+ }\r
}\r
// Event cache is now updated. Perform update on the UI thread\r
- if (!fTable.isDisposed())\r
+ if (!fTable.isDisposed()) {\r
fTable.getDisplay().asyncExec(new Runnable() {\r
@Override\r
public void run() {\r
fTable.refresh();\r
packColumns();\r
}\r
- if (completed)\r
+ if (completed) {\r
populateCompleted();\r
+ }\r
synchronized (fCacheUpdateSyncObj) {\r
fCacheUpdateBusy = false;\r
if (fCacheUpdatePending) {\r
}\r
}\r
});\r
+ }\r
}\r
\r
protected void populateCompleted() {\r
final StringBuffer defaultMessage = new StringBuffer();\r
for (int i = 0; i < fTable.getColumns().length; i++) {\r
if (i > 0)\r
+ {\r
defaultMessage.append(", "); //$NON-NLS-1$\r
+ }\r
defaultMessage.append(tableItem.getText(i));\r
}\r
final InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),\r
}\r
\r
public void removeBookmark(final IMarker bookmark) {\r
- for (final Entry<Long, Long> entry : fBookmarksMap.entrySet())\r
+ for (final Entry<Long, Long> entry : fBookmarksMap.entrySet()) {\r
if (entry.getValue().equals(bookmark.getId())) {\r
fBookmarksMap.remove(entry.getKey());\r
fTable.refresh();\r
return;\r
}\r
+ }\r
}\r
\r
private void toggleBookmark(final long rank) {\r
- if (fBookmarksFile == null)\r
+ if (fBookmarksFile == null) {\r
return;\r
+ }\r
if (fBookmarksMap.containsKey(rank)) {\r
final Long markerId = fBookmarksMap.remove(rank);\r
fTable.refresh();\r
try {\r
final IMarker bookmark = fBookmarksFile.findMarker(markerId);\r
- if (bookmark != null)\r
+ if (bookmark != null) {\r
bookmark.delete();\r
+ }\r
} catch (final CoreException e) {\r
displayException(e);\r
}\r
- } else\r
+ } else {\r
addBookmark(fBookmarksFile);\r
+ }\r
}\r
\r
public void refreshBookmarks(final IFile bookmarksFile) {\r
final int rank = marker.getAttribute(IMarker.LOCATION, -1);\r
if (rank != -1) {\r
int index = rank;\r
- if (fTable.getData(Key.FILTER_OBJ) != null)\r
+ if (fTable.getData(Key.FILTER_OBJ) != null) {\r
index = fCache.getFilteredEventIndex(rank) + 1; // +1 for top filter status row\r
- else if (rank >= fTable.getItemCount())\r
+ } else if (rank >= fTable.getItemCount()) {\r
fPendingGotoRank = rank;\r
+ }\r
fTable.setSelection(index + 1); // +1 for header row\r
}\r
}\r
/*\r
* (non-Javadoc)\r
*\r
- * @see\r
- * org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener#colorSettingsChanged(org.eclipse.linuxtools\r
- * .tmf.ui.views.colors.ColorSetting[])\r
+ * @see org.eclipse.linuxtools.tmf.ui.views.colors.IColorSettingsListener#colorSettingsChanged(org.eclipse.linuxtools.tmf.ui.views.colors.ColorSetting[])\r
*/\r
@Override\r
public void colorSettingsChanged(final ColorSetting[] colorSettings) {\r
\r
@Override\r
public void addEventsFilterListener(final ITmfEventsFilterListener listener) {\r
- if (!fEventsFilterListeners.contains(listener))\r
+ if (!fEventsFilterListeners.contains(listener)) {\r
fEventsFilterListeners.add(listener);\r
+ }\r
}\r
\r
@Override\r
\r
@TmfSignalHandler\r
public void experimentUpdated(final TmfExperimentUpdatedSignal signal) {\r
- if ((signal.getExperiment() != fTrace) || fTable.isDisposed())\r
+ if ((signal.getExperiment() != fTrace) || fTable.isDisposed()) {\r
return;\r
+ }\r
// Perform the refresh on the UI thread\r
Display.getDefault().asyncExec(new Runnable() {\r
@Override\r
public void run() {\r
- if (!fTable.isDisposed() && (fTrace != null))\r
+ if (!fTable.isDisposed() && (fTrace != null)) {\r
if (fTable.getData(Key.FILTER_OBJ) == null) {\r
fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row\r
if ((fPendingGotoRank != -1) && ((fPendingGotoRank + 1) < fTable.getItemCount())) { // +1 for header row\r
fTable.setSelection((int) fPendingGotoRank + 1); // +1 for header row\r
fPendingGotoRank = -1;\r
}\r
- } else\r
+ } else {\r
startFilterThread();\r
- if (!fRawViewer.isDisposed() && (fTrace != null))\r
+ }\r
+ }\r
+ if (!fRawViewer.isDisposed() && (fTrace != null)) {\r
fRawViewer.refreshEventCount();\r
+ }\r
}\r
});\r
}\r
\r
@TmfSignalHandler\r
public void traceUpdated(final TmfTraceUpdatedSignal signal) {\r
- if ((signal.getTrace() != fTrace) || fTable.isDisposed())\r
+ if ((signal.getTrace() != fTrace) || fTable.isDisposed()) {\r
return;\r
+ }\r
// Perform the refresh on the UI thread\r
Display.getDefault().asyncExec(new Runnable() {\r
@Override\r
public void run() {\r
- if (!fTable.isDisposed() && (fTrace != null))\r
+ if (!fTable.isDisposed() && (fTrace != null)) {\r
if (fTable.getData(Key.FILTER_OBJ) == null) {\r
fTable.setItemCount((int) fTrace.getNbEvents() + 1); // +1 for header row\r
if ((fPendingGotoRank != -1) && ((fPendingGotoRank + 1) < fTable.getItemCount())) { // +1 for header row\r
fTable.setSelection((int) fPendingGotoRank + 1); // +1 for header row\r
fPendingGotoRank = -1;\r
}\r
- } else\r
+ } else {\r
startFilterThread();\r
- if (!fRawViewer.isDisposed() && (fTrace != null))\r
+ }\r
+ }\r
+ if (!fRawViewer.isDisposed() && (fTrace != null)) {\r
fRawViewer.refreshEventCount();\r
+ }\r
}\r
});\r
}\r
public void currentTimeUpdated(final TmfTimeSynchSignal signal) {\r
if ((signal.getSource() != this) && (fTrace != null) && (!fTable.isDisposed())) {\r
\r
- // Create a request for one event that will be queued after other ongoing requests. When this request is\r
- // completed\r
- // do the work to select the actual event with the timestamp specified in the signal. This procedure\r
- // prevents\r
+ // Create a request for one event that will be queued after other ongoing requests. When this request is completed\r
+ // do the work to select the actual event with the timestamp specified in the signal. This procedure prevents\r
// the method fTrace.getRank() from interfering and delaying ongoing requests.\r
- final TmfDataRequest<ITmfEvent> subRequest = new TmfDataRequest<ITmfEvent>(ITmfEvent.class, 0, 1,\r
- ExecutionType.FOREGROUND) {\r
+ final TmfDataRequest<ITmfEvent> subRequest = new TmfDataRequest<ITmfEvent>(ITmfEvent.class, 0, 1, ExecutionType.FOREGROUND) {\r
\r
TmfTimestamp ts = new TmfTimestamp(signal.getCurrentTime());\r
\r
@Override\r
public void handleCompleted() {\r
super.handleCompleted();\r
- if (fTrace == null)\r
+ if (fTrace == null) {\r
return;\r
+ }\r
\r
// Verify if the event is within the trace range and adjust if necessary\r
ITmfTimestamp timestamp = ts;\r
- if (timestamp.compareTo(fTrace.getStartTime(), true) == -1)\r
+ if (timestamp.compareTo(fTrace.getStartTime(), true) == -1) {\r
timestamp = fTrace.getStartTime();\r
- if (timestamp.compareTo(fTrace.getEndTime(), true) == 1)\r
+ }\r
+ if (timestamp.compareTo(fTrace.getEndTime(), true) == 1) {\r
timestamp = fTrace.getEndTime();\r
+ }\r
\r
// Get the rank of the selected event in the table\r
final ITmfContext context = fTrace.seekEvent(timestamp);\r
@Override\r
public void run() {\r
// Return if table is disposed\r
- if (fTable.isDisposed())\r
+ if (fTable.isDisposed()) {\r
return;\r
+ }\r
\r
int index = (int) rank;\r
- if (fTable.isDisposed())\r
+ if (fTable.isDisposed()) {\r
return;\r
+ }\r
if (fTable.getData(Key.FILTER_OBJ) != null)\r
+ {\r
index = fCache.getFilteredEventIndex(rank) + 1; // +1 for top filter status row\r
+ }\r
fTable.setSelection(index + 1); // +1 for header row\r
fRawViewer.selectAndReveal(rank);\r
}\r
*/
public class TmfVirtualTable extends Composite {
- // The table
- private Table fTable;
- private int fTableRows = 0; // Number of table rows
- private int fFullyVisibleRows = 0; // Number of fully visible table rows
- private int fFrozenRowCount = 0; // Number of frozen table rows at top of table
-
- private int fTableTopEventRank = 0; // Global rank of the first entry displayed
- private int fSelectedEventRank = 0; // Global rank of the selected event
- private boolean fPendingSelection = false; // Pending selection update
-
- private int fTableItemCount = 0;
-
- // The slider
- private Slider fSlider;
-
- private int fLinuxItemHeight = 0; // Calculated item height for Linux workaround
- private TooltipProvider tooltipProvider = null;
- private IDoubleClickListener doubleClickListener = null;
-
- // ------------------------------------------------------------------------
- // Constructor
- // ------------------------------------------------------------------------
-
- /**
- * @param parent
- * @param style
- */
- public TmfVirtualTable(Composite parent, int style) {
- super(parent, style & (~SWT.H_SCROLL) & (~SWT.V_SCROLL) & (~SWT.SINGLE) & (~SWT.FULL_SELECTION) & (~SWT.HIDE_SELECTION) & (~SWT.CHECK));
-
- // Create the controls
- createTable(style & (SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.CHECK));
- createSlider(style & SWT.V_SCROLL);
-
- // Prevent the slider from being traversed
- setTabList(new Control[] { fTable });
-
- // Set the layout
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 2;
- gridLayout.horizontalSpacing = 0;
- gridLayout.verticalSpacing = 0;
- gridLayout.marginWidth = 0;
- gridLayout.marginHeight = 0;
- setLayout(gridLayout);
-
- GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- fTable.setLayoutData(tableGridData);
-
- GridData sliderGridData = new GridData(SWT.FILL, SWT.FILL, false, true);
- fSlider.setLayoutData(sliderGridData);
-
- // Add the listeners
- fTable.addMouseWheelListener(new MouseWheelListener() {
- @Override
- public void mouseScrolled(MouseEvent event) {
- if (fTableItemCount <= fFullyVisibleRows) {
- return;
- }
- fTableTopEventRank -= event.count;
- if (fTableTopEventRank < 0) {
- fTableTopEventRank = 0;
- }
- int latestFirstRowOffset = fTableItemCount - fFullyVisibleRows;
- if (fTableTopEventRank > latestFirstRowOffset) {
- fTableTopEventRank = latestFirstRowOffset;
- }
-
- fSlider.setSelection(fTableTopEventRank);
- refreshTable();
- }
- });
-
- fTable.addListener(SWT.MouseWheel, new Listener() {
- // disable mouse scroll of horizontal scroll bar
- @Override
+ // The table
+ private Table fTable;
+ private int fTableRows = 0; // Number of table rows
+ private int fFullyVisibleRows = 0; // Number of fully visible table rows
+ private int fFrozenRowCount = 0; // Number of frozen table rows at top of table
+
+ private int fTableTopEventRank = 0; // Global rank of the first entry displayed
+ private int fSelectedEventRank = 0; // Global rank of the selected event
+ private boolean fPendingSelection = false; // Pending selection update
+
+ private int fTableItemCount = 0;
+
+ // The slider
+ private Slider fSlider;
+
+ private int fLinuxItemHeight = 0; // Calculated item height for Linux workaround
+ private TooltipProvider tooltipProvider = null;
+ private IDoubleClickListener doubleClickListener = null;
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * @param parent
+ * @param style
+ */
+ public TmfVirtualTable(Composite parent, int style) {
+ super(parent, style & (~SWT.H_SCROLL) & (~SWT.V_SCROLL) & (~SWT.SINGLE) & (~SWT.FULL_SELECTION) & (~SWT.HIDE_SELECTION) & (~SWT.CHECK));
+
+ // Create the controls
+ createTable(style & (SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.CHECK));
+ createSlider(style & SWT.V_SCROLL);
+
+ // Prevent the slider from being traversed
+ setTabList(new Control[] { fTable });
+
+ // Set the layout
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ gridLayout.horizontalSpacing = 0;
+ gridLayout.verticalSpacing = 0;
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ setLayout(gridLayout);
+
+ GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ fTable.setLayoutData(tableGridData);
+
+ GridData sliderGridData = new GridData(SWT.FILL, SWT.FILL, false, true);
+ fSlider.setLayoutData(sliderGridData);
+
+ // Add the listeners
+ fTable.addMouseWheelListener(new MouseWheelListener() {
+ @Override
+ public void mouseScrolled(MouseEvent event) {
+ if (fTableItemCount <= fFullyVisibleRows) {
+ return;
+ }
+ fTableTopEventRank -= event.count;
+ if (fTableTopEventRank < 0) {
+ fTableTopEventRank = 0;
+ }
+ int latestFirstRowOffset = fTableItemCount - fFullyVisibleRows;
+ if (fTableTopEventRank > latestFirstRowOffset) {
+ fTableTopEventRank = latestFirstRowOffset;
+ }
+
+ fSlider.setSelection(fTableTopEventRank);
+ refreshTable();
+ }
+ });
+
+ fTable.addListener(SWT.MouseWheel, new Listener() {
+ // disable mouse scroll of horizontal scroll bar
+ @Override
public void handleEvent(Event event) {
- event.doit = false;
- }
- });
-
- fTable.addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent event) {
- int tableHeight = Math.max(0, fTable.getClientArea().height - fTable.getHeaderHeight());
- fFullyVisibleRows = tableHeight / getItemHeight();
- if (fTableItemCount > 0) {
- fSlider.setThumb(Math.max(1, Math.min(fTableRows, fFullyVisibleRows)));
- }
- }
- });
- // Implement a "fake" tooltip
- final String TOOLTIP_DATA_KEY = "_TABLEITEM"; //$NON-NLS-1$
- final Listener labelListener = new Listener () {
- @Override
+ event.doit = false;
+ }
+ });
+
+ fTable.addControlListener(new ControlAdapter() {
+ @Override
+ public void controlResized(ControlEvent event) {
+ int tableHeight = Math.max(0, fTable.getClientArea().height - fTable.getHeaderHeight());
+ fFullyVisibleRows = tableHeight / getItemHeight();
+ if (fTableItemCount > 0) {
+ fSlider.setThumb(Math.max(1, Math.min(fTableRows, fFullyVisibleRows)));
+ }
+ }
+ });
+ // Implement a "fake" tooltip
+ final String TOOLTIP_DATA_KEY = "_TABLEITEM"; //$NON-NLS-1$
+ final Listener labelListener = new Listener () {
+ @Override
public void handleEvent (Event event) {
- Label label = (Label)event.widget;
- Shell shell = label.getShell ();
- switch (event.type) {
- case SWT.MouseDown:
- Event e = new Event ();
- e.item = (TableItem) label.getData (TOOLTIP_DATA_KEY);
- // Assuming table is single select, set the selection as if
- // the mouse down event went through to the table
- fTable.setSelection (new TableItem [] {(TableItem) e.item});
- fTable.notifyListeners (SWT.Selection, e);
- shell.dispose ();
- fTable.setFocus();
- break;
- case SWT.MouseExit:
- case SWT.MouseWheel:
- shell.dispose ();
- break;
- }
- }
- };
-
- Listener tableListener = new Listener () {
- Shell tip = null;
- Label label = null;
- @Override
+ Label label = (Label)event.widget;
+ Shell shell = label.getShell ();
+ switch (event.type) {
+ case SWT.MouseDown:
+ Event e = new Event ();
+ e.item = (TableItem) label.getData (TOOLTIP_DATA_KEY);
+ // Assuming table is single select, set the selection as if
+ // the mouse down event went through to the table
+ fTable.setSelection (new TableItem [] {(TableItem) e.item});
+ fTable.notifyListeners (SWT.Selection, e);
+ shell.dispose ();
+ fTable.setFocus();
+ break;
+ case SWT.MouseExit:
+ case SWT.MouseWheel:
+ shell.dispose ();
+ break;
+ }
+ }
+ };
+
+ Listener tableListener = new Listener () {
+ Shell tip = null;
+ Label label = null;
+ @Override
public void handleEvent (Event event) {
- switch (event.type) {
- case SWT.Dispose:
- case SWT.KeyDown:
- case SWT.MouseMove: {
- if (tip == null) break;
- tip.dispose ();
- tip = null;
- label = null;
- break;
- }
- case SWT.MouseHover: {
- TableItem item = fTable.getItem (new Point(event.x, event.y));
- if (item != null) {
- for(int i=0;i<fTable.getColumnCount();i++){
- Rectangle bounds = item.getBounds(i);
- if (bounds.contains(event.x,event.y)){
- if (tip != null && !tip.isDisposed()) tip.dispose();
- 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;
- }
- }
- }
- }
- }
- }
- };
- fTable.addListener(SWT.Dispose, tableListener);
- fTable.addListener(SWT.KeyDown, tableListener);
- fTable.addListener(SWT.MouseMove, tableListener);
- fTable.addListener(SWT.MouseHover, tableListener);
- addControlListener(new ControlAdapter() {
- @Override
- public void controlResized(ControlEvent event) {
- resize();
- }
- });
-
- // And display
- refresh();
- }
-
- // ------------------------------------------------------------------------
- // Table handling
- // ------------------------------------------------------------------------
-
- /**
- * Create the table and add listeners
- */
- private void createTable(int style) {
- fTable = new Table(this, style | SWT.NO_SCROLL);
-
- fTable.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent event) {
- if (fTable.getSelectionIndices().length > 0) {
- handleTableSelection();
- }
- }
- });
+ switch (event.type) {
+ case SWT.Dispose:
+ case SWT.KeyDown:
+ case SWT.MouseMove: {
+ if (tip == null) break;
+ tip.dispose ();
+ tip = null;
+ label = null;
+ break;
+ }
+ case SWT.MouseHover: {
+ TableItem item = fTable.getItem (new Point(event.x, event.y));
+ if (item != null) {
+ for(int i=0;i<fTable.getColumnCount();i++){
+ Rectangle bounds = item.getBounds(i);
+ if (bounds.contains(event.x,event.y)){
+ if (tip != null && !tip.isDisposed()) tip.dispose();
+ 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;
+ }
+ }
+ }
+ }
+ }
+ }
+ };
+ fTable.addListener(SWT.Dispose, tableListener);
+ fTable.addListener(SWT.KeyDown, tableListener);
+ fTable.addListener(SWT.MouseMove, tableListener);
+ fTable.addListener(SWT.MouseHover, tableListener);
+ addControlListener(new ControlAdapter() {
+ @Override
+ public void controlResized(ControlEvent event) {
+ resize();
+ }
+ });
+
+ // And display
+ refresh();
+ }
+
+ // ------------------------------------------------------------------------
+ // Table handling
+ // ------------------------------------------------------------------------
+
+ /**
+ * Create the table and add listeners
+ */
+ private void createTable(int style) {
+ fTable = new Table(this, style | SWT.NO_SCROLL);
+
+ fTable.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ if (fTable.getSelectionIndices().length > 0) {
+ handleTableSelection();
+ }
+ }
+ });
fTable.addKeyListener(new KeyListener() {
- @Override
- public void keyPressed(KeyEvent event) {
- handleTableKeyEvent(event);
- }
- @Override
- public void keyReleased(KeyEvent event) {
- }
- });
+ @Override
+ public void keyPressed(KeyEvent event) {
+ handleTableKeyEvent(event);
+ }
+ @Override
+ public void keyReleased(KeyEvent event) {
+ }
+ });
fTable.addListener(
- SWT.MouseDoubleClick, new Listener() {
- @Override
- public void handleEvent(Event event) {
- if (doubleClickListener != null) {
- TableItem item = fTable.getItem (new Point (event.x, event.y));
- if (item != null) {
- for(int i=0;i<fTable.getColumnCount();i++){
- Rectangle bounds = item.getBounds(i);
- if (bounds.contains(event.x,event.y)){
- doubleClickListener.handleDoubleClick(TmfVirtualTable.this, item, i);
- break;
- }
- }
- }
- }
- }
- }
- );
- }
-
- /**
- * Update the rows and selected item
- */
- private void handleTableSelection() {
- int selectedRow = fTable.getSelectionIndices()[0];
- if (selectedRow < fFrozenRowCount) {
- fSelectedEventRank = selectedRow;
- } else {
- fSelectedEventRank = fTableTopEventRank + selectedRow;
- }
-
- /*
- * Feature in Windows. When a partially visible table item is selected,
- * after ~500 ms the top index is changed to ensure the selected item is
- * fully visible. This leaves a blank space at the bottom of the virtual
- * table. The workaround is to update the top event rank, refresh the
- * table and reset the top index to 0 after a sufficient delay.
- */
- if (selectedRow >= fFullyVisibleRows) {
- final Display display = fTable.getDisplay();
- Thread thread = new Thread("Top index check") { //$NON-NLS-1$
- @Override
- public void run() {
- try {
- Thread.sleep(600);
- } catch (InterruptedException e) {
- }
- display.asyncExec(new Runnable() {
- @Override
+ SWT.MouseDoubleClick, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ if (doubleClickListener != null) {
+ TableItem item = fTable.getItem (new Point (event.x, event.y));
+ if (item != null) {
+ for(int i=0;i<fTable.getColumnCount();i++){
+ Rectangle bounds = item.getBounds(i);
+ if (bounds.contains(event.x,event.y)){
+ doubleClickListener.handleDoubleClick(TmfVirtualTable.this, item, i);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ );
+ }
+
+ /**
+ * Update the rows and selected item
+ */
+ private void handleTableSelection() {
+ int selectedRow = fTable.getSelectionIndices()[0];
+ if (selectedRow < fFrozenRowCount) {
+ fSelectedEventRank = selectedRow;
+ } else {
+ fSelectedEventRank = fTableTopEventRank + selectedRow;
+ }
+
+ /*
+ * Feature in Windows. When a partially visible table item is selected,
+ * after ~500 ms the top index is changed to ensure the selected item is
+ * fully visible. This leaves a blank space at the bottom of the virtual
+ * table. The workaround is to update the top event rank, refresh the
+ * table and reset the top index to 0 after a sufficient delay.
+ */
+ if (selectedRow >= fFullyVisibleRows) {
+ final Display display = fTable.getDisplay();
+ Thread thread = new Thread("Top index check") { //$NON-NLS-1$
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(600);
+ } catch (InterruptedException e) {
+ }
+ display.asyncExec(new Runnable() {
+ @Override
public void run() {
- if (fTable.isDisposed()) return;
- int topIndex = fTable.getTopIndex();
- if (topIndex != 0) {
- fTableTopEventRank += topIndex;
- refreshTable();
- fSlider.setSelection(fTableTopEventRank);
- fTable.setTopIndex(0);
- }
- }
- });
- }
- };
- thread.start();
- }
- }
-
- /**
- * Handle key-based navigation in table.
- *
- * @param event
- */
- private void handleTableKeyEvent(KeyEvent event) {
-
- int lastEventRank = fTableItemCount - 1;
- int lastPageTopEntryRank = Math.max(0, fTableItemCount - fFullyVisibleRows);
-
- int previousSelectedEventRank = fSelectedEventRank;
- int selectedRow = fSelectedEventRank - fTableTopEventRank;
- boolean needsRefresh = false;
-
- // In all case, perform the following steps:
- // - Update the selected entry rank (within valid range)
- // - Update the selected row
- // - Update the page's top entry if necessary (which also adjusts the selected row)
- // - If the top displayed entry was changed, table refresh is needed
- switch (event.keyCode) {
-
- case SWT.ARROW_DOWN: {
- event.doit = false;
- if (fSelectedEventRank < lastEventRank) {
- fSelectedEventRank++;
- selectedRow = fSelectedEventRank - fTableTopEventRank;
- if (selectedRow >= fFullyVisibleRows) {
- fTableTopEventRank++;
- needsRefresh = true;
- }
- }
- break;
- }
-
- case SWT.ARROW_UP: {
- event.doit = false;
- if (fSelectedEventRank > 0) {
- fSelectedEventRank--;
- selectedRow = fSelectedEventRank - fTableTopEventRank;
- if (selectedRow < fFrozenRowCount && fTableTopEventRank > 0) {
- fTableTopEventRank--;
- needsRefresh = true;
- }
- }
- break;
- }
-
- case SWT.END: {
- event.doit = false;
- fTableTopEventRank = lastPageTopEntryRank;
- fSelectedEventRank = lastEventRank;
- needsRefresh = true;
- break;
- }
-
- case SWT.HOME: {
- event.doit = false;
- fSelectedEventRank = fFrozenRowCount;
- fTableTopEventRank = 0;
- needsRefresh = true;
- break;
- }
-
- case SWT.PAGE_DOWN: {
- event.doit = false;
- if (fSelectedEventRank < lastEventRank) {
- fSelectedEventRank += fFullyVisibleRows;
- if (fSelectedEventRank > lastEventRank) {
- fSelectedEventRank = lastEventRank;
- }
- selectedRow = fSelectedEventRank - fTableTopEventRank;
- if (selectedRow > fFullyVisibleRows - 1) {
- fTableTopEventRank += fFullyVisibleRows;
- if (fTableTopEventRank > lastPageTopEntryRank) {
- fTableTopEventRank = lastPageTopEntryRank;
- }
- needsRefresh = true;
- }
- }
- break;
- }
-
- case SWT.PAGE_UP: {
- event.doit = false;
- if (fSelectedEventRank > 0) {
- fSelectedEventRank -= fFullyVisibleRows;
- if (fSelectedEventRank < fFrozenRowCount) {
- fSelectedEventRank = fFrozenRowCount;
- }
- selectedRow = fSelectedEventRank - fTableTopEventRank;
- if (selectedRow < 0) {
- fTableTopEventRank -= fFullyVisibleRows;
- if (fTableTopEventRank < 0) {
- fTableTopEventRank = 0;
- }
- needsRefresh = true;
- }
- }
- break;
- }
- default: {
- return;
- }
- }
-
- boolean done = true;
- if (needsRefresh) {
- done = refreshTable(); // false if table items not updated yet in this thread
- } else {
- fTable.select(selectedRow);
- }
-
- if (fFullyVisibleRows < fTableItemCount) {
- fSlider.setSelection(fTableTopEventRank);
- }
-
- if (fSelectedEventRank != previousSelectedEventRank && fTable.getSelection().length > 0) {
- if (done) {
- Event e = new Event();
- e.item = fTable.getSelection()[0];
- fTable.notifyListeners(SWT.Selection, e);
- } else {
- fPendingSelection = true;
- }
- }
- }
-
- private boolean setDataItem(int index, TableItem item) {
- if (index != -1) {
- Event event = new Event();
- event.item = item;
- if (index < fFrozenRowCount) {
- event.index = index;
- } else {
- event.index = index + fTableTopEventRank;
- }
- event.doit = true;
- fTable.notifyListeners(SWT.SetData, event);
- return event.doit; // false if table item not updated yet in this thread
- }
- return true;
- }
-
- // ------------------------------------------------------------------------
- // Slider handling
- // ------------------------------------------------------------------------
-
- private void createSlider(int style) {
- fSlider = new Slider(this, SWT.VERTICAL | SWT.NO_FOCUS);
- fSlider.setMinimum(0);
- fSlider.setMaximum(0);
- if ((style & SWT.V_SCROLL) == 0) {
- fSlider.setVisible(false);
- }
-
- fSlider.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- switch (event.detail) {
- case SWT.ARROW_DOWN:
- case SWT.ARROW_UP:
- case SWT.NONE:
- case SWT.END:
- case SWT.HOME:
- case SWT.PAGE_DOWN:
- case SWT.PAGE_UP: {
- fTableTopEventRank = fSlider.getSelection();
- refreshTable();
- break;
- }
- }
- }
- });
- }
-
- // ------------------------------------------------------------------------
- // Simulated Table API
- // ------------------------------------------------------------------------
-
- public void setHeaderVisible(boolean b) {
- fTable.setHeaderVisible(b);
- }
-
- public void setLinesVisible(boolean b) {
- fTable.setLinesVisible(b);
- }
-
- public TableItem[] getSelection() {
- return fTable.getSelection();
- }
-
- @Override
+ if (fTable.isDisposed()) return;
+ int topIndex = fTable.getTopIndex();
+ if (topIndex != 0) {
+ fTableTopEventRank += topIndex;
+ refreshTable();
+ fSlider.setSelection(fTableTopEventRank);
+ fTable.setTopIndex(0);
+ }
+ }
+ });
+ }
+ };
+ thread.start();
+ }
+ }
+
+ /**
+ * Handle key-based navigation in table.
+ *
+ * @param event
+ */
+ private void handleTableKeyEvent(KeyEvent event) {
+
+ int lastEventRank = fTableItemCount - 1;
+ int lastPageTopEntryRank = Math.max(0, fTableItemCount - fFullyVisibleRows);
+
+ int previousSelectedEventRank = fSelectedEventRank;
+ int selectedRow = fSelectedEventRank - fTableTopEventRank;
+ boolean needsRefresh = false;
+
+ // In all case, perform the following steps:
+ // - Update the selected entry rank (within valid range)
+ // - Update the selected row
+ // - Update the page's top entry if necessary (which also adjusts the selected row)
+ // - If the top displayed entry was changed, table refresh is needed
+ switch (event.keyCode) {
+
+ case SWT.ARROW_DOWN: {
+ event.doit = false;
+ if (fSelectedEventRank < lastEventRank) {
+ fSelectedEventRank++;
+ selectedRow = fSelectedEventRank - fTableTopEventRank;
+ if (selectedRow >= fFullyVisibleRows) {
+ fTableTopEventRank++;
+ needsRefresh = true;
+ }
+ }
+ break;
+ }
+
+ case SWT.ARROW_UP: {
+ event.doit = false;
+ if (fSelectedEventRank > 0) {
+ fSelectedEventRank--;
+ selectedRow = fSelectedEventRank - fTableTopEventRank;
+ if (selectedRow < fFrozenRowCount && fTableTopEventRank > 0) {
+ fTableTopEventRank--;
+ needsRefresh = true;
+ }
+ }
+ break;
+ }
+
+ case SWT.END: {
+ event.doit = false;
+ fTableTopEventRank = lastPageTopEntryRank;
+ fSelectedEventRank = lastEventRank;
+ needsRefresh = true;
+ break;
+ }
+
+ case SWT.HOME: {
+ event.doit = false;
+ fSelectedEventRank = fFrozenRowCount;
+ fTableTopEventRank = 0;
+ needsRefresh = true;
+ break;
+ }
+
+ case SWT.PAGE_DOWN: {
+ event.doit = false;
+ if (fSelectedEventRank < lastEventRank) {
+ fSelectedEventRank += fFullyVisibleRows;
+ if (fSelectedEventRank > lastEventRank) {
+ fSelectedEventRank = lastEventRank;
+ }
+ selectedRow = fSelectedEventRank - fTableTopEventRank;
+ if (selectedRow > fFullyVisibleRows - 1) {
+ fTableTopEventRank += fFullyVisibleRows;
+ if (fTableTopEventRank > lastPageTopEntryRank) {
+ fTableTopEventRank = lastPageTopEntryRank;
+ }
+ needsRefresh = true;
+ }
+ }
+ break;
+ }
+
+ case SWT.PAGE_UP: {
+ event.doit = false;
+ if (fSelectedEventRank > 0) {
+ fSelectedEventRank -= fFullyVisibleRows;
+ if (fSelectedEventRank < fFrozenRowCount) {
+ fSelectedEventRank = fFrozenRowCount;
+ }
+ selectedRow = fSelectedEventRank - fTableTopEventRank;
+ if (selectedRow < 0) {
+ fTableTopEventRank -= fFullyVisibleRows;
+ if (fTableTopEventRank < 0) {
+ fTableTopEventRank = 0;
+ }
+ needsRefresh = true;
+ }
+ }
+ break;
+ }
+ default: {
+ return;
+ }
+ }
+
+ boolean done = true;
+ if (needsRefresh) {
+ done = refreshTable(); // false if table items not updated yet in this thread
+ } else {
+ fTable.select(selectedRow);
+ }
+
+ if (fFullyVisibleRows < fTableItemCount) {
+ fSlider.setSelection(fTableTopEventRank);
+ }
+
+ if (fSelectedEventRank != previousSelectedEventRank && fTable.getSelection().length > 0) {
+ if (done) {
+ Event e = new Event();
+ e.item = fTable.getSelection()[0];
+ fTable.notifyListeners(SWT.Selection, e);
+ } else {
+ fPendingSelection = true;
+ }
+ }
+ }
+
+ private boolean setDataItem(int index, TableItem item) {
+ if (index != -1) {
+ Event event = new Event();
+ event.item = item;
+ if (index < fFrozenRowCount) {
+ event.index = index;
+ } else {
+ event.index = index + fTableTopEventRank;
+ }
+ event.doit = true;
+ fTable.notifyListeners(SWT.SetData, event);
+ return event.doit; // false if table item not updated yet in this thread
+ }
+ return true;
+ }
+
+ // ------------------------------------------------------------------------
+ // Slider handling
+ // ------------------------------------------------------------------------
+
+ private void createSlider(int style) {
+ fSlider = new Slider(this, SWT.VERTICAL | SWT.NO_FOCUS);
+ fSlider.setMinimum(0);
+ fSlider.setMaximum(0);
+ if ((style & SWT.V_SCROLL) == 0) {
+ fSlider.setVisible(false);
+ }
+
+ fSlider.addListener(SWT.Selection, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ switch (event.detail) {
+ case SWT.ARROW_DOWN:
+ case SWT.ARROW_UP:
+ case SWT.NONE:
+ case SWT.END:
+ case SWT.HOME:
+ case SWT.PAGE_DOWN:
+ case SWT.PAGE_UP: {
+ fTableTopEventRank = fSlider.getSelection();
+ refreshTable();
+ break;
+ }
+ }
+ }
+ });
+ }
+
+ // ------------------------------------------------------------------------
+ // Simulated Table API
+ // ------------------------------------------------------------------------
+
+ public void setHeaderVisible(boolean b) {
+ fTable.setHeaderVisible(b);
+ }
+
+ public void setLinesVisible(boolean b) {
+ fTable.setLinesVisible(b);
+ }
+
+ public TableItem[] getSelection() {
+ return fTable.getSelection();
+ }
+
+ @Override
public void addListener(int eventType, Listener listener) {
fTable.addListener(eventType, listener);
}
-
- @Override
- public void addKeyListener(KeyListener listener) {
- fTable.addKeyListener(listener);
- }
+
+ @Override
+ public void addKeyListener(KeyListener listener) {
+ fTable.addKeyListener(listener);
+ }
@Override
- public void addMouseListener(MouseListener listener) {
- fTable.addMouseListener(listener);
- }
-
- public void addSelectionListener(SelectionListener listener) {
- fTable.addSelectionListener(listener);
- }
-
- @Override
- public void setMenu(Menu menu) {
- fTable.setMenu(menu);
- }
-
- public void clearAll() {
- setItemCount(0);
- }
-
- public void setItemCount(int nbItems) {
- nbItems = Math.max(0, nbItems);
-
- if (nbItems != fTableItemCount) {
- fTableItemCount = nbItems;
- fTable.remove(fTableItemCount, fTable.getItemCount() - 1);
- fSlider.setMaximum(nbItems);
- resize();
- int tableHeight = Math.max(0, fTable.getClientArea().height - fTable.getHeaderHeight());
- fFullyVisibleRows = tableHeight / getItemHeight();
- if (fTableItemCount > 0) {
- fSlider.setThumb(Math.max(1, Math.min(fTableRows, fFullyVisibleRows)));
- }
- }
- }
-
- public int getItemCount() {
- return fTableItemCount;
- }
-
- public int getItemHeight() {
- /*
- * Bug in Linux. The method getItemHeight doesn't always return the correct value.
- */
- if (fLinuxItemHeight >= 0 && System.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
- if (fLinuxItemHeight != 0) {
- return fLinuxItemHeight;
- }
- if (fTable.getItemCount() > 1) {
- int itemHeight = fTable.getItem(1).getBounds().y - fTable.getItem(0).getBounds().y;
- if (itemHeight > 0) {
- fLinuxItemHeight = itemHeight;
- return fLinuxItemHeight;
- }
- }
- } else {
- fLinuxItemHeight = -1; // Not Linux, don't perform os.name check anymore
- }
- return fTable.getItemHeight();
- }
-
- public int getTopIndex() {
- return fTableTopEventRank + fFrozenRowCount;
- }
-
- public void setTopIndex(int i) {
- if (fTableItemCount > 0) {
- i = Math.min(i, fTableItemCount - 1);
- i = Math.max(i, fFrozenRowCount);
-
- fTableTopEventRank = i - fFrozenRowCount;
- if (fFullyVisibleRows < fTableItemCount) {
- fSlider.setSelection(fTableTopEventRank);
- }
-
- refreshTable();
- }
- }
-
- public int indexOf(TableItem ti) {
- int index = fTable.indexOf(ti);
- if (index < fFrozenRowCount) {
- return index;
- } else {
- return (index - fFrozenRowCount) + getTopIndex();
- }
- }
-
- public TableColumn[] getColumns() {
- return fTable.getColumns();
- }
-
- public TableItem getItem(Point point) {
- return fTable.getItem(point);
- }
-
- private void resize() {
- // Compute the numbers of rows that fit the new area
- int tableHeight = Math.max(0, getSize().y - fTable.getHeaderHeight());
- int itemHeight = getItemHeight();
- fTableRows = Math.min((tableHeight + itemHeight - 1) / itemHeight, fTableItemCount);
-
- if (fTableTopEventRank + fFullyVisibleRows > fTableItemCount) {
- // If we are at the end, get elements before to populate
- fTableTopEventRank = Math.max(0, fTableItemCount - fFullyVisibleRows);
- refreshTable();
- } else if (fTableRows > fTable.getItemCount() || fTableItemCount < fTable.getItemCount()) {
- // Only refresh if new table items are needed or if table items need to be deleted
- refreshTable();
- }
-
- }
-
- // ------------------------------------------------------------------------
- // Controls interactions
- // ------------------------------------------------------------------------
-
- @Override
- public boolean setFocus() {
- boolean isVisible = isVisible();
- if (isVisible) {
- fTable.setFocus();
- }
- return isVisible;
- }
-
- public void refresh() {
- boolean done = refreshTable();
- if (fPendingSelection && done) {
- fPendingSelection = false;
- if (fTable.getSelection().length > 0) {
- Event e = new Event();
- e.item = fTable.getSelection()[0];
- fTable.notifyListeners(SWT.Selection, e);
- }
- }
- }
-
- public void setColumnHeaders(ColumnData columnData[]) {
- for (int i = 0; i < columnData.length; i++) {
- TableColumn column = new TableColumn(fTable, columnData[i].alignment, i);
- column.setText(columnData[i].header);
- if (columnData[i].width > 0) {
- column.setWidth(columnData[i].width);
- } else {
- column.pack();
- }
- }
- }
-
- public int removeAll() {
- setItemCount(0);
- fSlider.setMaximum(0);
- fTable.removeAll();
- fSelectedEventRank = fFrozenRowCount;
- return 0;
- }
-
- private boolean refreshTable() {
- boolean done = true;
- for (int i = 0; i < fTableRows; i++) {
- if (i + fTableTopEventRank < fTableItemCount) {
- TableItem tableItem;
- if (i < fTable.getItemCount()) {
- tableItem = fTable.getItem(i);
- } else {
- tableItem = new TableItem(fTable, SWT.NONE);
- }
- done &= setDataItem(i, tableItem); // false if table item not updated yet in this thread
- } else {
- if (fTable.getItemCount() > fTableItemCount - fTableTopEventRank) {
- fTable.remove(fTableItemCount - fTableTopEventRank);
- }
- }
- }
-
- int lastRowOffset = fTableTopEventRank + fTableRows - 1;
- if ((fSelectedEventRank >= fTableTopEventRank + fFrozenRowCount) && (fSelectedEventRank <= lastRowOffset)) {
- int selectedRow = fSelectedEventRank - fTableTopEventRank;
- fTable.select(selectedRow);
- } else if (fSelectedEventRank < fFrozenRowCount) {
- fTable.select(fSelectedEventRank);
- } else {
- fTable.deselectAll();
- }
- return done;
- }
-
- public void setSelection(int i) {
- if (fTableItemCount > 0) {
- i = Math.min(i, 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);
- }
- if (fFullyVisibleRows < fTableItemCount) {
- fSlider.setSelection(fTableTopEventRank);
- }
-
- refreshTable();
-
- }
- }
-
- public int getSelectionIndex() {
- int index = fTable.getSelectionIndex();
- if (index == -1) {
- return fSelectedEventRank;
- }
- if (index < fFrozenRowCount) {
- return index;
- } else {
- return (index - fFrozenRowCount) + getTopIndex();
- }
- }
-
- public void setFrozenRowCount(int count) {
- fFrozenRowCount = count;
- refreshTable();
- }
-
- public TableEditor createTableEditor() {
- return new TableEditor(fTable);
- }
-
- public Control createTableEditorControl(Class<? extends Control> control) {
- try {
- return (Control) control.getConstructor(Composite.class, int.class).newInstance(new Object[] {fTable, SWT.NONE});
- } catch (Exception e) {
- Activator.getDefault().logError("Error creating table editor control", e); //$NON-NLS-1$
- }
- return null;
- }
-
- /**
- * @return the tooltipProvider
- */
- public TooltipProvider getTooltipProvider() {
- return tooltipProvider;
- }
-
- /**
- * @param tooltipProvider the tooltipProvider to set
- */
- public void setTooltipProvider(TooltipProvider tooltipProvider) {
- this.tooltipProvider = tooltipProvider;
- }
-
- /**
- * @return the doubleClickListener
- */
- public IDoubleClickListener getDoubleClickListener() {
- return doubleClickListener;
- }
-
- /**
- * @param doubleClickListener the doubleClickListener to set
- */
- public void setDoubleClickListener(IDoubleClickListener doubleClickListener) {
- this.doubleClickListener = doubleClickListener;
- }
-
+ public void addMouseListener(MouseListener listener) {
+ fTable.addMouseListener(listener);
+ }
+
+ public void addSelectionListener(SelectionListener listener) {
+ fTable.addSelectionListener(listener);
+ }
+
+ @Override
+ public void setMenu(Menu menu) {
+ fTable.setMenu(menu);
+ }
+
+ public void clearAll() {
+ setItemCount(0);
+ }
+
+ public void setItemCount(int nbItems) {
+ nbItems = Math.max(0, nbItems);
+
+ if (nbItems != fTableItemCount) {
+ fTableItemCount = nbItems;
+ fTable.remove(fTableItemCount, fTable.getItemCount() - 1);
+ fSlider.setMaximum(nbItems);
+ resize();
+ int tableHeight = Math.max(0, fTable.getClientArea().height - fTable.getHeaderHeight());
+ fFullyVisibleRows = tableHeight / getItemHeight();
+ if (fTableItemCount > 0) {
+ fSlider.setThumb(Math.max(1, Math.min(fTableRows, fFullyVisibleRows)));
+ }
+ }
+ }
+
+ public int getItemCount() {
+ return fTableItemCount;
+ }
+
+ public int getItemHeight() {
+ /*
+ * Bug in Linux. The method getItemHeight doesn't always return the correct value.
+ */
+ if (fLinuxItemHeight >= 0 && System.getProperty("os.name").contains("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
+ if (fLinuxItemHeight != 0) {
+ return fLinuxItemHeight;
+ }
+ if (fTable.getItemCount() > 1) {
+ int itemHeight = fTable.getItem(1).getBounds().y - fTable.getItem(0).getBounds().y;
+ if (itemHeight > 0) {
+ fLinuxItemHeight = itemHeight;
+ return fLinuxItemHeight;
+ }
+ }
+ } else {
+ fLinuxItemHeight = -1; // Not Linux, don't perform os.name check anymore
+ }
+ return fTable.getItemHeight();
+ }
+
+ public int getTopIndex() {
+ return fTableTopEventRank + fFrozenRowCount;
+ }
+
+ public void setTopIndex(int i) {
+ if (fTableItemCount > 0) {
+ i = Math.min(i, fTableItemCount - 1);
+ i = Math.max(i, fFrozenRowCount);
+
+ fTableTopEventRank = i - fFrozenRowCount;
+ if (fFullyVisibleRows < fTableItemCount) {
+ fSlider.setSelection(fTableTopEventRank);
+ }
+
+ refreshTable();
+ }
+ }
+
+ public int indexOf(TableItem ti) {
+ int index = fTable.indexOf(ti);
+ if (index < fFrozenRowCount) {
+ return index;
+ } else {
+ return (index - fFrozenRowCount) + getTopIndex();
+ }
+ }
+
+ public TableColumn[] getColumns() {
+ return fTable.getColumns();
+ }
+
+ public TableItem getItem(Point point) {
+ return fTable.getItem(point);
+ }
+
+ private void resize() {
+ // Compute the numbers of rows that fit the new area
+ int tableHeight = Math.max(0, getSize().y - fTable.getHeaderHeight());
+ int itemHeight = getItemHeight();
+ fTableRows = Math.min((tableHeight + itemHeight - 1) / itemHeight, fTableItemCount);
+
+ if (fTableTopEventRank + fFullyVisibleRows > fTableItemCount) {
+ // If we are at the end, get elements before to populate
+ fTableTopEventRank = Math.max(0, fTableItemCount - fFullyVisibleRows);
+ refreshTable();
+ } else if (fTableRows > fTable.getItemCount() || fTableItemCount < fTable.getItemCount()) {
+ // Only refresh if new table items are needed or if table items need to be deleted
+ refreshTable();
+ }
+
+ }
+
+ // ------------------------------------------------------------------------
+ // Controls interactions
+ // ------------------------------------------------------------------------
+
+ @Override
+ public boolean setFocus() {
+ boolean isVisible = isVisible();
+ if (isVisible) {
+ fTable.setFocus();
+ }
+ return isVisible;
+ }
+
+ public void refresh() {
+ boolean done = refreshTable();
+ if (fPendingSelection && done) {
+ fPendingSelection = false;
+ if (fTable.getSelection().length > 0) {
+ Event e = new Event();
+ e.item = fTable.getSelection()[0];
+ fTable.notifyListeners(SWT.Selection, e);
+ }
+ }
+ }
+
+ public void setColumnHeaders(ColumnData columnData[]) {
+ for (int i = 0; i < columnData.length; i++) {
+ TableColumn column = new TableColumn(fTable, columnData[i].alignment, i);
+ column.setText(columnData[i].header);
+ if (columnData[i].width > 0) {
+ column.setWidth(columnData[i].width);
+ } else {
+ column.pack();
+ }
+ }
+ }
+
+ public int removeAll() {
+ setItemCount(0);
+ fSlider.setMaximum(0);
+ fTable.removeAll();
+ fSelectedEventRank = fFrozenRowCount;
+ return 0;
+ }
+
+ private boolean refreshTable() {
+ boolean done = true;
+ for (int i = 0; i < fTableRows; i++) {
+ if (i + fTableTopEventRank < fTableItemCount) {
+ TableItem tableItem;
+ if (i < fTable.getItemCount()) {
+ tableItem = fTable.getItem(i);
+ } else {
+ tableItem = new TableItem(fTable, SWT.NONE);
+ }
+ done &= setDataItem(i, tableItem); // false if table item not updated yet in this thread
+ } else {
+ if (fTable.getItemCount() > fTableItemCount - fTableTopEventRank) {
+ fTable.remove(fTableItemCount - fTableTopEventRank);
+ }
+ }
+ }
+
+ int lastRowOffset = fTableTopEventRank + fTableRows - 1;
+ if (fSelectedEventRank < fFrozenRowCount) {
+ fTable.select(fSelectedEventRank);
+ } else if (!done) {
+ fTable.deselectAll();
+ } else if ((fSelectedEventRank >= fTableTopEventRank + fFrozenRowCount) && (fSelectedEventRank <= lastRowOffset)) {
+ int selectedRow = fSelectedEventRank - fTableTopEventRank;
+ fTable.select(selectedRow);
+ } else {
+ fTable.deselectAll();
+ }
+ return done;
+ }
+
+ public void setSelection(int i) {
+ if (fTableItemCount > 0) {
+ i = Math.min(i, 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);
+ }
+ if (fFullyVisibleRows < fTableItemCount) {
+ fSlider.setSelection(fTableTopEventRank);
+ }
+
+ refreshTable();
+
+ }
+ }
+
+ public int getSelectionIndex() {
+ int index = fTable.getSelectionIndex();
+ if (index == -1) {
+ return fSelectedEventRank;
+ }
+ if (index < fFrozenRowCount) {
+ return index;
+ } else {
+ return (index - fFrozenRowCount) + getTopIndex();
+ }
+ }
+
+ public void setFrozenRowCount(int count) {
+ fFrozenRowCount = count;
+ refreshTable();
+ }
+
+ public TableEditor createTableEditor() {
+ return new TableEditor(fTable);
+ }
+
+ public Control createTableEditorControl(Class<? extends Control> control) {
+ try {
+ return (Control) control.getConstructor(Composite.class, int.class).newInstance(new Object[] {fTable, SWT.NONE});
+ } catch (Exception e) {
+ Activator.getDefault().logError("Error creating table editor control", e); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ /**
+ * @return the tooltipProvider
+ */
+ public TooltipProvider getTooltipProvider() {
+ return tooltipProvider;
+ }
+
+ /**
+ * @param tooltipProvider the tooltipProvider to set
+ */
+ public void setTooltipProvider(TooltipProvider tooltipProvider) {
+ this.tooltipProvider = tooltipProvider;
+ }
+
+ /**
+ * @return the doubleClickListener
+ */
+ public IDoubleClickListener getDoubleClickListener() {
+ return doubleClickListener;
+ }
+
+ /**
+ * @param doubleClickListener the doubleClickListener to set
+ */
+ public void setDoubleClickListener(IDoubleClickListener doubleClickListener) {
+ this.doubleClickListener = doubleClickListener;
+ }
+
}