2013-01-17 26 views
2

JFace中的另一個錯誤?我使用標準機制實現了自定義工具提示:實施方法​​的CellLabelProviderJFace查看器自定義工具提示鋼材焦點

一切似乎罰款,但它不是。

我有一個視圖和一個編輯器,都顯示這些自定義工具提示表。如果您將編輯器關注並將鼠標懸停在單元格上,則會看到其工具提示。正確。如果將鼠標懸停在視圖的表格單元格上,則會看到它們的工具提示。正確。

但是:如果你碰巧移動鼠標的tooptip並再次搬出去,從編輯到視圖(反之亦然)的焦點轉移!

我不明白這是怎麼回事。這確實很讓人分心。

有沒有人見過?如果沒有,請嘗試一下!

要重現,藉此片斷,這是從JFaceSnippets 3.11採取:

package org.eclipse.jface.snippets.viewers; 

import org.eclipse.jface.viewers.CellLabelProvider; 
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; 
import org.eclipse.jface.viewers.IStructuredContentProvider; 
import org.eclipse.jface.viewers.TableViewer; 
import org.eclipse.jface.viewers.TableViewerColumn; 
import org.eclipse.jface.viewers.Viewer; 
import org.eclipse.jface.viewers.ViewerCell; 
import org.eclipse.jface.window.ToolTip; 
import org.eclipse.swt.SWT; 
import org.eclipse.swt.layout.FillLayout; 
import org.eclipse.swt.widgets.Display; 
import org.eclipse.swt.widgets.Shell; 
import org.eclipse.swt.widgets.Text; 

/** 
* Explore New API: JFace custom tooltips drawing. 
* 
* @author Tom Schindl <[email protected]tion.at> 
* @since 3.3 
*/ 
public class Snippet011CustomTooltips { 
    private static class MyContentProvider implements IStructuredContentProvider { 
     @Override 
     public Object[] getElements(final Object inputElement) { 
      return new String[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" }; 
     } 

     @Override 
     public void dispose() { 
     } 

     @Override 
     public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) { 
     } 
    } 

    /** 
    * @param args 
    */ 
    public static void main(final String[] args) { 
     final Display display = new Display(); 
     final Shell shell = new Shell(display); 
     shell.setLayout(new FillLayout(SWT.VERTICAL)); 

     final Text t = new Text(shell, SWT.MULTI); 
     t.setText("1) Make sure focus is somewhere here. See the blinking caret!\n" 
       + "2) Now get a tooltip displayed in the table by hovering there with the mouse cursor\n" 
       + "3a) If you move the cursor INSIDE the tooltip just shortly and out again, the input focus will be stolen from this text field\n" 
       + "3b) If you DO NOT move the cursor INSIDE the tooltip, input focus will remain with the text edit field\n\n" 
       + "=> to me, this is a bug!"); 

     final TableViewer v = new TableViewer(shell, SWT.FULL_SELECTION); 
     v.getTable().setLinesVisible(true); 
     v.getTable().setHeaderVisible(true); 
     v.setContentProvider(new MyContentProvider()); 
     ColumnViewerToolTipSupport.enableFor(v, ToolTip.NO_RECREATE); 

     final CellLabelProvider labelProvider = new CellLabelProvider() { 
      @Override 
      public String getToolTipText(final Object element) { 
       return "Tooltip (" + element + ") - if you move HERE, the table will grab input focus!"; 
      } 

      @Override 
      public void update(final ViewerCell cell) { 
       cell.setText(cell.getElement().toString()); 
      } 
     }; 

     final TableViewerColumn column = new TableViewerColumn(v, SWT.NONE); 
     column.setLabelProvider(labelProvider); 
     column.getColumn().setText("Table"); 
     column.getColumn().setWidth(100); 

     v.setInput(""); 

     shell.setSize(800, 400); 
     shell.open(); 

     while(!shell.isDisposed()) { 
      if(!display.readAndDispatch()) { 
       display.sleep(); 
      } 
     } 

     display.dispose(); 
    } 

} 
+1

如果你不喜歡我的問題 - 跟我說話,不要投票。這不公平! – Zordid

+0

您可以創建一個顯示此問題的小片段嗎? –

+0

它不會很小。 :(我包括一個鏈接到自定義工具提示的代碼片段 – Zordid

回答

1

我同意你的說法,這種行爲是非常奇怪的,我也希望把它的錯誤。僅僅因爲已經放置了工具提示標籤而將焦點移至底層表格就沒有任何明顯的意義。

protected void afterHideToolTip(Event event) { 
    super.afterHideToolTip(event); 

    // Clear the restored value else this could be a source of a leak 
    setData(VIEWER_CELL_KEY, null); 
    if (event != null && event.widget != viewer.getControl()) { 
     viewer.getControl().setFocus(); 
    } 
} 

如果沒有鼠標放到工具提示,並簡單地擺脫你將鼠標懸停在單元移開,該事件傳遞給afterHideToolTip()是:

的問題是由ColumnViewerToolTipSupport.afterHideToolTip()方法引起空,並且不撥打setFocus()電話。

如果您將鼠標放入工具提示中,然後離開,那麼傳遞到afterHideToolTip()的事件顯然會在工具提示標籤本身死亡時生成。

與我們掌握的一些參數周圍擺弄對行爲沒有任何影響:具有useNativeToolTips()返回true,傳遞RECREATE代替NO_RECREATE ...

你甚至不能子類ColumnViewerToolTipSupport和覆蓋afterHideToolTipEvent(),去除神祕的setFocus()電話,因爲表查看器參考ColumnViewerToolTipSupport.viewer已私人訪問。

我能看到的唯一的行動方式是提交一個bug,看看你能否從JFace開發者那裏得到一些建議。我很想知道這個電話背後的想法是什麼。

+0

非常感謝尋找這個奇怪的設置焦點的源代碼這絕對是一個bug ... – Zordid

+0

我'我會檢查你的答案 - 它不是固定的,但是因爲沒有人知道修正錯誤...... :-) – Zordid