Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 14:44 Go to next message
mark tal is currently offline mark talFriend
Messages: 11
Registered: July 2012
Junior Member
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 14:45]

Report message to a moderator

Re: Detect figure selection when CTRL key is pressed [message #897880 is a reply to message #897572] Wed, 25 July 2012 11:09 Go to previous message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
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: Tue Mar 19 05:52:38 GMT 2024

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

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

Back to the top