如何在树中拖动项目时更改反馈效果?

时间:2016-02-25 11:25:48

标签: eclipse-rap

当我拖动包含html-text的项目时,用户会看到html字符串。 enter image description here

我使用RAP 2.3

我使用基于公共Eclipse RAP示例的代码。当用户开始拖动操作时,我找不到改变反馈效果的方法。

Tree tree = new Tree( parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION );
TreeViewer result = new TreeViewer( tree );
result.setContentProvider( new TreeContentProvider() );
TreeLabelProvider labelProvider = new TreeLabelProvider( parent.getDisplay(), MODERN_STYLE );
result.setLabelProvider( labelProvider );
result.setInput( createModel() );
result.expandAll();

Transfer[] types = new Transfer[] { TreeObjectTransfer.getInstance() };
TreeDragListener dragListener = new TreeDragListener( viewer );
viewer.addDragSupport( DND.DROP_MOVE, types, dragListener );
TreeDropListener dropListener = new TreeDropListener( viewer );
viewer.addDropSupport( DND.DROP_MOVE, types, dropListener );

和DragSourceAdapter:

private static class TreeDragListener extends DragSourceAdapter {
private final TreeViewer viewer;
private Object dragData;

TreeDragListener( TreeViewer viewer ) {
    this.viewer = viewer;
}

@Override
public void dragStart( DragSourceEvent event ) {
    dragData = getTreeObject( event.x, event.y );
}

@Override
public void dragSetData( DragSourceEvent event ) {
    event.data = dragData;
}

@Override
public void dragFinished( DragSourceEvent event ) {
    viewer.refresh();
}

private TreeObject getTreeObject( int x, int y ) {
    TreeObject result = null;
    ViewerCell cell = viewer.getCell( new Point( x, y ) );
    if( cell != null ) {
        result = ( TreeObject )cell.getElement();
    }
    return result;
}
}

结果: 最后,我找不到一个好的解决方案,所以我用下一个方法 cell.setFont() cell.setForeground()替换了html-tags的属性。在这种情况下,没有发生反馈效果的错误。

0 个答案:

没有答案