【问题标题】:JFace different instances of dropped POJOJFace 丢弃 POJO 的不同实例
【发布时间】:2013-08-08 07:20:29
【问题描述】:

我有一个 Label 包裹在 POJO 中。所有外部操作都委托给标签。

我(内部)将DragSource 挂钩到所述Label。转帐是LocalSelectionTransfer

DragSourceAdapter的实现:

@Override public void dragSetData(DragSourceEvent e)
{
      transfer.setSelection(new StructuredSelection(this)); // *this* is the POJO wrapper
}

问题

在放置事件(外部)时,如果我这样做

final Object newObj = ((StructuredSelection) transfer.getSelection()).getFirstElement();

newObj 将是 POJO$1POJO$2 等。

这是什么原因?为什么我没有得到 instanceof POJO

【问题讨论】:

    标签: java drag-and-drop swt jface


    【解决方案1】:

    正如你所说,new StructuredSelection(this)DragSourceAdapter 的实现内部,所以this 是实现(你的“POJO”的匿名内部类)而不是 POJO 本身!您需要改为 new StructuredSelection(POJO.this) 来引用外部实例(显然,将 POJO 替换为您的类的实际名称)。

    顺便说一句,但我不会将与 GUI 直接相关的类称为“POJO”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-23
      • 1970-01-01
      • 2021-06-05
      • 1970-01-01
      相关资源
      最近更新 更多