Community
Participate
Working Groups
Build Identifier: 20100617-1415 This is related to all events. I recently wrote a DeleteAction handling the DeleteCommand for a draw2d-based editor. After this the delete-event occured twice in our widget. The org.eclipse.draw2d.SWTEventDispatcher-Listeners don't check the draw2d-event's isConsumed()-state. The all should copy it back to the origional swt-event.doit field before returning. This bug report should better benamed as "Consuming events in draw2d have no effect on the origial swt-event" Reproducible: Always Steps to Reproduce: import org.eclipse.draw2d.*; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.*; public class FigureCanvaseTestApp { public static void main(String[] args) { Shell shell = new Shell(); shell.setLayout(new FillLayout()); FigureCanvas canvas = new FigureCanvas(shell); canvas.getLightweightSystem().setEventDispatcher(new SWTEventDispatcher() { // uncomment to fix for keyEvent // /** // * @see EventDispatcher#dispatchKeyPressed(org.eclipse.swt.events.KeyEvent) // */ // @Override // public void dispatchKeyPressed(org.eclipse.swt.events.KeyEvent e) { // IFigure focusOwner = getFocusOwner(); // if (focusOwner != null) { // org.eclipse.draw2d.KeyEvent event = new org.eclipse.draw2d.KeyEvent(this, focusOwner, e); // focusOwner.handleKeyPressed(event); // e.doit = !event.isConsumed(); // } // } // // @Override // public void dispatchKeyReleased(KeyEvent e) { // IFigure focusOwner = getFocusOwner(); // if (focusOwner != null) { // org.eclipse.draw2d.KeyEvent event = new org.eclipse.draw2d.KeyEvent(this, focusOwner, e); // focusOwner.handleKeyReleased(event); // e.doit = !event.isConsumed(); // } // } }); Figure rootFigure = new Figure(); rootFigure.setRequestFocusEnabled(true); rootFigure.setOpaque(true); rootFigure.setBackgroundColor(ColorConstants.blue); rootFigure.addKeyListener(new org.eclipse.draw2d.KeyListener() { @Override public void keyPressed(org.eclipse.draw2d.KeyEvent ke) { System.out.println("figure - keyPressed - isConsumed: " + ke.isConsumed()); ke.consume(); } @Override public void keyReleased(org.eclipse.draw2d.KeyEvent ke) { } }); canvas.setContents(rootFigure); canvas.addKeyListener(new KeyListener() { @Override public void keyReleased(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { System.out.println("canvas - keyPressed - doit: " + e.doit); } }); shell.setBounds(10, 10, 600, 400); shell.layout(); shell.setVisible(true); canvas.setFocus(); rootFigure.requestFocus(); Display display = shell.getDisplay(); while (!shell.isDisposed()) { if (!shell.getDisplay().readAndDispatch()) display.sleep(); } } }