JFace中的另一個錯誤?我使用標準機制實現了自定義工具提示:實施方法的CellLabelProvider
。JFace查看器自定義工具提示鋼材焦點
一切似乎罰款,但它不是。
我有一個視圖和一個編輯器,都顯示這些自定義工具提示表。如果您將編輯器關注並將鼠標懸停在單元格上,則會看到其工具提示。正確。如果將鼠標懸停在視圖的表格單元格上,則會看到它們的工具提示。正確。
但是:如果你碰巧移動鼠標內的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();
}
}
如果你不喜歡我的問題 - 跟我說話,不要投票。這不公平! – Zordid
您可以創建一個顯示此問題的小片段嗎? –
它不會很小。 :(我包括一個鏈接到自定義工具提示的代碼片段 – Zordid