- /** *//**
- * 设置左边(右边)表格的滚动条根据右边(左边)滚动条滚动而滚动
- */
- // Make selection the same in both tables
- tParameterAlarm1.addListener(SWT.Selection, new Listener() ...{
- public void handleEvent(Event event) ...{
- tParameterAlarm2.setSelection(tParameterAlarm1.getSelectionIndices());
- }
- });
- // On Windows, the selection is gray if the table does not have focus.
- // To make both tables appear in focus, draw teh selection background
- // here.
- // This part only works on version 3.2 or later.
- Listener eraseListener = new Listener() ...{
- public void handleEvent(Event event) ...{
- if ((event.detail & SWT.SELECTED) != 0) ...{
- GC gc = event.gc;
- Rectangle rect = event.getBounds();
- gc.setForeground(container.getDisplay().getSystemColor(
- SWT.COLOR_LIST_SELECTION_TEXT));
- gc.setBackground(container.getDisplay().getSystemColor(
- SWT.COLOR_LIST_SELECTION));
- gc.fillRectangle(rect);
- event.detail &= ~SWT.SELECTED;
- }
- }
- };
- tParameterAlarm1.addListener(SWT.EraseItem, eraseListener);
- // Make vertical scrollbars scroll together
- ScrollBar vBarLeft = tParameterAlarm1.getVerticalBar();
- vBarLeft.addListener(SWT.Selection, new Listener() ...{
- public void handleEvent(Event event) ...{
- tParameterAlarm2.setTopIndex(tParameterAlarm1.getTopIndex());
- }
- });
- tParameterAlarm2.addListener(SWT.Selection, new Listener() ...{
- public void handleEvent(Event event) ...{
- tParameterAlarm1.setSelection(tParameterAlarm2.getSelectionIndices());
- }
- });
- tParameterAlarm2.addListener(SWT.EraseItem, eraseListener);
- ScrollBar vBarRight = tParameterAlarm2.getVerticalBar();
- vBarRight.addListener(SWT.Selection, new Listener() ...{
- public void handleEvent(Event event) ...{
- tParameterAlarm1.setTopIndex(tParameterAlarm2.getTopIndex());
- }
- });
其中tParameterAlarm1为左边表格的TableViewer,tParameterAlarm2为右边表格的TableViewer