TableViewer viewer = ...
import
org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
import org.eclipse.jface.viewers.IStructuredSelection;
public final class DoubleClickColumnViewerEditorActivationStrategy extends
ColumnViewerEditorActivationStrategy {
public DoubleClickColumnViewerEditorActivationStrategy(
ColumnViewer viewer) {
super(viewer);
}
/**
* Create at Jan 18, 2008 5:38:15 PM<br>
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy#isEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent)
*/
@Override
protected boolean isEditorActivationEvent(
ColumnViewerEditorActivationEvent event) {
boolean singleSelect = ((IStructuredSelection) getViewer()
.getSelection()).size() == 1;
return singleSelect
&& (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC || event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL);
}
}
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
import org.eclipse.jface.viewers.IStructuredSelection;
public final class DoubleClickColumnViewerEditorActivationStrategy extends
ColumnViewerEditorActivationStrategy {
public DoubleClickColumnViewerEditorActivationStrategy(
ColumnViewer viewer) {
super(viewer);
}
/**
* Create at Jan 18, 2008 5:38:15 PM<br>
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy#isEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent)
*/
@Override
protected boolean isEditorActivationEvent(
ColumnViewerEditorActivationEvent event) {
boolean singleSelect = ((IStructuredSelection) getViewer()
.getSelection()).size() == 1;
return singleSelect
&& (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
|| event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC || event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL);
}
}
注意红色地方, 这是和原来不一样的. 原来是单击.
然后调用
TableViewerEditor.create(viewer,
new
DoubleClickColumnViewerEditorActivationStrategy(viewer), ColumnViewerEditor.DEFAULT);
就OK了.
正好今天在网上看到有其他兄弟写的添加MouseListener的做法, 私下以为虽然可能达到了功能目的, 但是代码增加不少, 而且和SWT的设计理念也有些差异. 可能多看看SWT的源码, 会有比较好的解决方案.
TreeViewer和TableViewer一样, 看看源码就明了了.
另: 正在研究怎么编辑Treeviewer, 头大不已. 关键是要不同的编辑器~~~, 不知道有没有达人指点一二?