Skip to main content



      Home
Home » Eclipse Projects » GEF » Detect figure selection when CTRL key is pressed
Detect figure selection when CTRL key is pressed [message #897572] Tue, 24 July 2012 10:44 Go to next message
Eclipse UserFriend
Hi,

I want to execute a specific action when figure is selected while CTRL key is pressed down.

public class MyGef extends GraphicalEditorWithFlyoutPalette implements ISelectionListener{
     public void selectionChanged(IWorkbenchPart part, ISelection selection) {
	super.selectionChanged(part, selection);
	
  	IStructuredSelection incoming = (IStructuredSelection) selection;
     }

}



How Can I check if specific key is pressed?

[Updated on: Tue, 24 July 2012 10:45] by Moderator

Re: Detect figure selection when CTRL key is pressed [message #897880 is a reply to message #897572] Wed, 25 July 2012 07:09 Go to previous message
Eclipse UserFriend
Hi,

I think you can do it in GEF code or in draw2d code - before the GEF. The listener you posted is useless for detecting the pressed key.

The draw2d way is about to add a MouseListener to the figure you need to track:
figure.addMouseListener(new MouseListener.Stub() {

    @Override
    public void mousePressed(MouseEvent me) {
	if ((me.getState() & MouseEvent.CONTROL) != 0) {
	    // figure was selected while CTRL key was pressed
        }
    }

});

Beware of setting me.consume(), because you would prevent the GEF from processing the event and the EditPart represented by this figure wouldn't selected.

The GEF way could be realized by extending the DragTracker of the tracked EditPart's getTracker(Request request) method:
public class YourEditPart extends AbstractGraphicalEditPart {
    ...

    @Override
    public DragTracker getDragTracker(Request request) {
	return new DragEditPartsTracker(this) {

	    @Override
	    protected void performConditionalSelection() {
		super.performConditionalSelection();
		    if (getCurrentInput().isControlKeyDown()) {
			// the part was selected while the CTRL key was pressed
		    }
		}

	    };
    }
}


Previous Topic:Replace GEF Designer Editor with Browser
Next Topic:CommandStack
Goto Forum:
  


Current Time: Sun Jul 06 14:45:53 EDT 2025

Powered by FUDForum. Page generated in 0.03113 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top