How to add a double-click listener to my GEF edito

2019-02-16 21:56发布

I'm using GEF. I have a graphical editor with some "boxes" implemented. Now, I want to add a double-click listener to each box (Rectangle). I tried to add a listener to the GraphicalViewer but it did not work.

3条回答
迷人小祖宗
3楼-- · 2019-02-16 22:23
viewer.getControl().addListener(SWT.MouseDoubleClick, new Listener() {

        @Override
        public void handleEvent(Event event) {
        //write the double click action
    });
查看更多
爷、活的狠高调
4楼-- · 2019-02-16 22:26

In the GraphicalEditPart of the "box" for which you want to add the listener, you have to override the performRequest(Request req) method. When the framework identifies a double-click on the part's figure, it calls this method with a request that has req.getType()==RequestConstants.REQ_OPEN. You can take over from here. Complete code to test that his works:

@Override
public void performRequest(Request req) {
    if(req.getType() == RequestConstants.REQ_OPEN) {
        System.out.println("requested double-click."); 
    }
}

Hope this does the trick.

查看更多
登录 后发表回答