Bug 326146 - Consuming draw2d-events has no effect on the original swt-events
Summary: Consuming draw2d-events has no effect on the original swt-events
Status: NEW
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy Draw2d (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: gef-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-24 09:39 EDT by Heiko Böttger CLA
Modified: 2010-09-24 09:39 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Heiko Böttger CLA 2010-09-24 09:39:18 EDT
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();
    }
  }
}