| Detect figure selection when CTRL key is pressed [message #897572] |
Tue, 24 July 2012 10:44  |
mark tal Messages: 6 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 10: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 07:09  |
Jan Krakora Messages: 402 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
}
}
};
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.01407 seconds