从eclipse插件编辑器的drop listener调用firePropertyChange

时间:2015-11-15 10:01:41

标签: eclipse-plugin eclipse-rcp

我已经在我的eclipse插件编辑器中实现了拖放支持。现在我想通过从drop listener调用firePropertyChange来通知编辑器。

firePropertyChange(IEditorPart.PROP_DIRTY);

这是正确的方法吗?还是有其他选择。

DropListener代码:

    public class DropListener extends ViewerDropAdapter {

    private final TableViewer viewer;

    private AbstractCSVFile model;

     private CSVRow target ;

     private final PropertyChangeSupport propertySupport = new PropertyChangeSupport(this);

    public  DropListener(TableViewer viewer) {
        super(viewer);
        this.viewer = viewer;
        // TODO Auto-generated constructor stub
    }

    @Override
      public void drop(DropTargetEvent event) {
        int location = this.determineLocation(event);
        target = (CSVRow) determineTarget(event);
        String translatedLocation ="";

        switch (location){
        case 1 :
          translatedLocation = "Dropped before the target ";
          break;
        case 2 :
          translatedLocation = "Dropped after the target ";
          break;
        case 3 :
          translatedLocation = "Dropped on the target ";
          break;
        case 4 :
          translatedLocation = "Dropped into nothing ";
          break;
        }
        System.out.println(translatedLocation);
        System.out.println("The drop was done on the element: " + target);
        super.drop(event);
      }

    @Override
    public boolean performDrop(Object data) {

        System.out.println("Drop to be performed with the event data > " + data.toString());

        if (target != null) {

            model = (AbstractCSVFile)getViewer().getInput();

            System.out.println("viewer input >>>>" +getViewer().getInput());


            model.addObjectRowAfterElement(target, data.toString());

            //notify editor here ....

            viewer.refresh();
        }




        return false;
    }

    @Override
    public boolean validateDrop(Object target, int operation, TransferData transferType) {
        // TODO Auto-generated method stub
        return true;
    }

}

1 个答案:

答案 0 :(得分:0)

我已将DropListener添加为Editor的内部类,并在其中调用了该属性:

firePropertyChange(IEditorPart.PROP_DIRTY);

使用此链接作为参考。 https://github.com/jonalv/bioclipse.brunn/blob/c5e9ba0caa593e16485fdd313a0d06131207ea11/plugins/net.bioclipse.brunn.ui/src/net/bioclipse/brunn/ui/editors/masterPlateEditor/MasterPlateEditor.java