Bug 265664 - EPF Richtext isn't firing ModifyEvents or KeyEvent when it should
Summary: EPF Richtext isn't firing ModifyEvents or KeyEvent when it should
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EPF (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Xiao Dan Xia CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-20 11:08 EST by Richard Bone CLA
Modified: 2023-02-16 16:18 EST (History)
5 users (show)

See Also:


Attachments
test case to try to reproduce (2.48 KB, application/zip)
2009-05-28 18:50 EDT, Jeff Hardy CLA
no flags Details
patch for IES3.4.X and IES3.5 compatibility (4.12 KB, patch)
2009-06-26 01:41 EDT, Xiao Dan Xia CLA
no flags Details | Diff
EPF RichtText Test Plug-in (9.69 KB, application/x-zip-compressed)
2009-12-18 02:45 EST, Flavio Donze CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Bone CLA 2009-02-20 11:08:10 EST
Build ID: M20080911-1700

Steps To Reproduce:
Using EPF: 1.5 build 20080714-1745, on windows XP

We're using the RichTextEditor in some modal dialogs, and have noticed that the events we're hooked into (ModifyEvent and KeyEvent) are not always being fired when we would expect them to.

I can generally be guaranteed that these events will fire if I select the FontStyle combo or if I hit return, but that's about it.

The way we're hooking in has varied.  Right now, on my class extending RichTextEditor, I hook into modify as follows...

richEditor.addModifyListener(new ModifyListener(){
				public void modifyText(ModifyEvent e) {
					//enable some button
				}
			});

I've also tried doing the same, via richEditor.getRichTextControl().addModifyListener
as well as both the preceding with addKeyListener.  

I know that there have been issues with using the RichTextEditor within dialogs in the past.  Perhaps there is still some quirk of event firing in the RichTextEditor when being used in this fashion?


More information:
Comment 1 Bingxue Xu CLA 2009-02-20 16:25:33 EST
Please investigate this one.
Comment 2 Xiao Dan Xia CLA 2009-02-24 05:16:27 EST
Hi,

I wrote a test plugin to simulate the behavior. But I can't reproduce this issue.

My plugins is like this:

1. prepare a editor that extends EditorPart and implements IEditorInput, which will be used to provide editorSite to RTE
2. prepare a dialog that has a MethodRichTextEditor. The code is as below:
	protected Control createDialogArea(Composite parent) {
		Composite baseComposite = (Composite)  super.createDialogArea(parent);
		
		MethodRichTextEditor rte = new MethodRichTextEditor(baseComposite, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL, null, null, new Label(baseComposite, SWT.CENTER),editor.getEditorSite());
		
		rte.addModifyListener(new ModifyListener(){
            public void modifyText(ModifyEvent e) {
                    System.out.println("get modificaiton event: "+(count++));
            }
    });
           //RTE configuration
		return baseComposite;
	}


3. when the test action is activated, the editor is intantiated. The editor's editorSite is then passed for dialog instantiation.

I tried editing actions like changing font style, inputting new characters, removing text, etc.,  I can always receive the modify event.

Can you show me your code?
Comment 3 Richard Bone CLA 2009-05-01 13:01:07 EDT
Hi,

It seems this doesn't happen on every Windows machine.  The only thing we do is add a modify listener to the RichText that we're using.  After debugging on a machine where it doesn't work, it turns out that the status text change events that should be fired from the browser aren't.  The OLE code that should be creating them isn't doing what it should, it seems.
Comment 4 Srimanth CLA 2009-05-01 13:09:00 EDT
We have hit this on multiple WinXP systems. Basically no key events are
trigerred till you hit ENTER key. In the SWT Browser internals, the
org.eclipse.swt.browser.IE class's OLEListener never gets any events
(StatusTextChange). 

We have both systems which work, and those which dont - we will be more than
happy to let you debug on the problem machines if you cant reproduce it. This
problem is a major one for us, as the rich text editor plays an important part
in our tools usecase.
Comment 5 Richard Bone CLA 2009-05-11 14:53:25 EDT
Hi,

Has anyone had a chance yet to take another look at this problem?  As Sri mentioned on May 1st this is a big deal for our tooling and we'd love to know whether there is anything that can be done about it.  Thanks.

Richard
Comment 6 Xiao Dan Xia CLA 2009-05-12 04:38:06 EDT
I can't reproduce it on my two XP box. Both install IE7. Can you try to figure out where's the difference between the working system and non-working system? Such as checking IE versions? Or you can try using firefox by updating the Browser instantiate function in org.eclipse.epf.richtext.RichText.java with this code so as to see if it's browser issue or not?

public RichText(Composite parent, int style, String basePath) {
....
		try {
			editor = new Browser(parent, SWT.MOZILLA);
Comment 7 Richard Bone CLA 2009-05-13 14:33:15 EDT
Hi,

I did try instantiating the browser with SWT.MOZILLA, but it doesn't seem to make any difference.  The behavior is the same as when I used IE.  I was using XULRunner 1.9.x to do the test. The IE version I have is 7 and I'm running on XP Pro SP2.
Comment 8 Jeff Hardy CLA 2009-05-28 18:50:02 EDT
Created attachment 137574 [details]
test case to try to reproduce
Comment 9 Jeff Hardy CLA 2009-05-28 18:53:35 EDT
In comment #8 I attached a project to attempt to help isolate the issue.

This project uses plain SWT (no EPF RichText).  It creates a Dialog with a Browser widget in editing mode.  It attaches a key listener that outputs to the console when a KeyUp occurs.  This is the same method that the EPF RichText uses in the ModifyListener.

You did not specify which version of Eclipse you are using, so I used Eclipse 3.3.2, which is what EPF 1.5 is based on.  If you use a different version of Eclipse you'll have to fix the build path for the project.

Please try this on your affected machines - if the problem is reproducible, this indicates an SWT problem.  If the problem doesn't occur, then EPF RichText must be causing the issue somehow.
Comment 10 Richard Bone CLA 2009-06-12 15:12:33 EDT
So I tried the test that Jeff handed to me.  It didn't deliver the events at all.  I did add in a keyListener, which delivered the events as I would expect.  Jeff, you were saying that you thought this was an SWT problem, right?
Comment 11 Jeff Hardy CLA 2009-06-12 15:55:11 EDT
Yes, please file a new bug against SWT and list the bugzilla number here.  You may want to attach the test case so they can reproduce it.
Comment 12 Richard Bone CLA 2009-06-12 15:56:19 EDT
Is there some reason why this bug can't be moved to SWT?  
Comment 13 Jeff Hardy CLA 2009-06-12 16:13:36 EDT
The SWT guys probably want their own bug for the issue.  This bug tracks the issue as it affects EPF.
Comment 14 Bingxue Xu CLA 2009-06-12 17:46:29 EDT
Hi Ricard,

Which version of Eclispe do you use? As Jeff mentioned, we are still on Eclispe 3.3.2, and have not verified this on neither 3.4 or 3.5.

Thanks.
Comment 15 Richard Bone CLA 2009-06-12 20:00:34 EDT
I'm running 3.4.1
Comment 16 Richard Bone CLA 2009-06-12 20:25:58 EDT
I've also run Jeff's test on 3.4.2 and 3.5, with the same results.  
Comment 17 Bingxue Xu CLA 2009-06-12 20:37:54 EDT
Thanks much for the testing. Please try it on Eclipse 3.3.x and if it works, then it would be very easy for the SWT team to figure out the difference between them.
Comment 18 Richard Bone CLA 2009-06-12 21:20:01 EDT
Just for the record... if you modify Jeff's test to do this...

browserControl.addKeyListener(new KeyAdapter() {
   public void keyPressed(KeyEvent e) {
      System.out.println("KeyPressed: " + e.widget);
   }
});

... it displays KeyPressed just fine. 

Jeff, I also tried running your test on 3.3.2 and it works fine.  Since it's obvious that SWT has changed something about the way they handle key events from 3.3.x to 3.4.x, can we look into getting it to work on these platforms? There are quite a few products out there running on 3.4 and above at this point.
Comment 19 Richard Bone CLA 2009-06-15 12:51:19 EDT
Opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=280146 against SWT
Comment 20 Bingxue Xu CLA 2009-06-15 16:33:35 EDT
Jeff and Dancy,

Will the comments in #18 can be incorporated into the current RTE code to resolve the problem in Eclipse 3.4 or 3.5?
Comment 21 Srimanth CLA 2009-06-17 18:40:20 EDT
RAM is currently required to support Eclipse 3.4 and 3.5, so it would be great if this could be fixed.
Comment 22 Xiao Dan Xia CLA 2009-06-18 10:09:58 EDT
The fix is under testing. We'll deliver the fix once it passes the test.
Comment 23 Xiao Dan Xia CLA 2009-06-26 01:41:02 EDT
Created attachment 140176 [details]
patch for IES3.4.X and IES3.5 compatibility
Comment 24 Xiao Dan Xia CLA 2009-06-26 01:49:40 EDT
The patch passed unit test based on IES 3.5 and IES 3.4.2. Since EPF doesn't support IES3.4.2 and IES 3.5, can you apply this patch and help on integration test on your system?
Comment 25 Richard Bone CLA 2009-07-08 16:48:04 EDT
I tried the patch on my 3.4.2-based target and it works!  We'd be very interested in finding out when a new version with this fix will be available, as we ship EPF in our update site. Thanks!
Comment 26 Richard Bone CLA 2009-07-08 16:48:45 EDT
Let me qualify that last statement... we ship the RTE from EPF, not all of EPF. 
Comment 27 Bingxue Xu CLA 2009-07-08 16:52:56 EDT
The next EPF release 1.5.0.4 is schedlued for Oct. 10, 2009 (both EPF Composer and the RTE feature).

Thanks.
Comment 28 Xiao Dan Xia CLA 2009-07-15 23:21:42 EDT
fixed
Comment 29 Flavio Donze CLA 2009-11-30 10:15:50 EST
I just updated to version 1.5.0.4 and using Eclipse 3.5.1.

I still don't receive the Modify and KeyEvents.

This is my test code:

Shell shell = new Shell(Display.getCurrent().getActiveShell(), SWT.CLOSE);
shell.setLayout(new FillLayout());
IRichText richTextComponent = RichTextFormToolkit.createRichText(new FormToolkit(Display.getCurrent()),
		shell, null, SWT.NONE);
richTextComponent.addModifyListener(new ModifyListener() {
	@Override
	public void modifyText(ModifyEvent e) {
		System.out.println("modifyText " + e);
	}
});
richTextComponent.addKeyListener(new KeyListener() {
	@Override
	public void keyReleased(KeyEvent e) {
		System.out.println("keyReleased " + e);
	}

	@Override
	public void keyPressed(KeyEvent e) {
		System.out.println("keyPressed " + e);
	}
});
shell.open();

I would like to get EVERY key stroke. Right now I only get ModifyEvents when hitting ENTER, F1-F12 Buttons, KeyPad and such, but not the normal keyboard including numbers.
Is this a new issue, am I doing something wrong?
Comment 30 Flavio Donze CLA 2009-12-17 04:43:19 EST
Am I expecting the wrong behavior as described in the comment above?
Comment 31 Xiao Dan Xia CLA 2009-12-17 06:12:37 EST
(In reply to comment #30)
> Am I expecting the wrong behavior as described in the comment above?

This is a SWT problem in eclipse 3.4 and above. This issue can be workarounded by using KeyAdaptor to replace KeyListener, just like the following sample:

browserControl.addKeyListener(new KeyAdapter() {
   public void keyPressed(KeyEvent e) {
      System.out.println("KeyPressed: " + e.widget);
   }
});
Comment 32 Flavio Donze CLA 2009-12-18 02:44:40 EST
I just downloaded the attached test case and yes I only get the keyevents when I change the listener to a KeyAdapter.

Still adding a KeyAdapter or ModifyListener my IRichText does not forward these events.

I made a little Test Plug-in (will attach it), maybe you can try it out and tell me if you get any output in the console when typing.

View.java
IRichText richText = RichTextFormToolkit.createRichText(toolkit, parent, null, SWT.NONE);
richText.addModifyListener(new ModifyListener() {
	@Override
	public void modifyText(ModifyEvent e) {
		System.out.println("modifyText: " + e);
		
	}
});
richText.addKeyListener(new KeyAdapter() {
	@Override
	public void keyPressed(KeyEvent e) {
		System.out.println("keyPressed: " + e);
	}
});

BTW I'm using Eclipse 3.5.1
Comment 33 Flavio Donze CLA 2009-12-18 02:45:38 EST
Created attachment 154748 [details]
EPF RichtText Test Plug-in
Comment 34 Flavio Donze CLA 2009-12-18 08:25:49 EST
I gave the test to two of our other software developers. The modify event works on their machine:

Windows XP Media Center Editon Version 2002 SP3
Internet Explorer 8.0.6001.18702

Windows Vista Business Service Pack 2
Internet Explorer 8.0.6001.18865


On mine the test fails. I don't get any modify events.

Windows XP Professional Version 2002 Service Pack 3
Internet Explorer 8.0.6001.18702

Is this a SWT bug?
Comment 35 Flavio Donze CLA 2009-12-18 09:53:20 EST
Sorry my fault it doesn't work on their machine either. They still had my "hacked" bundles in the TargetPlatform (see http://www.eclipse.org/forums/index.php?t=tree&th=16670&S=28cf035914bb5b2b73482ea57f1ed6c8#page_top).
Comment 36 Xiao Dan Xia CLA 2009-12-20 12:19:25 EST
on Windows, you need to use editorControl to manage the listener. Following code is an sample:

Control browserControl = getControlSite((Composite)richText.getRichTextControl().getControl());

		
		browserControl.addKeyListener(new KeyAdapter() {
		    @Override
		    public void keyPressed(KeyEvent e) {
		        System.out.println("keyPressed: " + e);
		    }
		});

     protected Control getControlSite(Composite composite) {
		Control[] controls = composite.getChildren();
		for (int i = 0; i < controls.length; i++) {
			String controlClass = controls[i].getClass().getName();
			if (controlClass.equals("org.eclipse.swt.browser.WebSite")) { //$NON-NLS-1$
				return controls[i];
			} else if (controls[i] instanceof Composite) {
				return getControlSite((Composite) controls[i]);
			}
		}
		return null;
	}
Comment 37 Flavio Donze CLA 2009-12-22 04:17:13 EST
Hi Xiao Dan Xia,

Thanks for this tip. I do get the KeyEvents now.
But shouldn't this issue be reopened since this is a workaround?
I still don't get the modify events.

I have a different problem with the solution you describe. I want to use databinding so I added a KeyAdapter and want to update my business object on every keystroke.

public void keyReleased(KeyEvent e) {
String newValue = editor.getText();
...
}

Now when I type 'abc' I do get the 'c' event but the 'newValue' is still 'ab'.
Storing my business object the value is cut of 'ab' instead of 'abc'.

Maybe this would work with the modify event but since I don't receive those I'm screwed :-).
Comment 38 Bingxue Xu CLA 2010-01-04 19:41:49 EST
I'd suggest opening a bug or discussion against SWT/broswer widget by preparing some test plug-ins directly to prove or disapprove the events are been sent or received. If those are bugs or inteneded changes with the newer versions of SWT, EPF could not fix them.

Thanks.
Comment 39 Xiao Dan Xia CLA 2010-01-05 10:07:27 EST
I tried my test plugin on eclipse 3.3.2 and eclipse 3.5.0. On eclipse 3.3.2, modify event can be received and text can be correctly retrieved. On eclipse 3.5.0, I can't get modify event as well as keyReleased event(I can get keyPressed event). So, it should be a SWT problem. Can you try your plugin on eclipse3.3.2? BTW, there's already a bug against SWT(https://bugs.eclipse.org/bugs/show_bug.cgi?id=280146) to track keyUp issue. You may add comments and discussion there.
Comment 40 Flavio Donze CLA 2010-01-06 07:39:41 EST
I've tested my test plug-in with eclipse 3.2.2 and I do get the ModifyEvents and keyPressed.

As mentioned above I have done some hacking in the passed (July 2009) on the rte.js file. Afterwards I did get ModifyEvents using eclipse 3.5.1 but still having a strange behavior. see the following link for details:
http://www.eclipse.org/forums/index.php?t=tree&th=16670&S=28cf035914bb5b2b73482ea57f1ed6c8#page_top

I actually "don't care" about the KeyEvents, I would rather get the modify events for my databinding.
Maybe fixing the rte.js file would solve the issue?
Comment 41 Xiao Dan Xia CLA 2010-01-07 05:00:09 EST
For your case, as a workaround, you can try move your change to function keyReleased() and attach keyrelease event to this function. Refer to following code fragment.
   
     function enableRichTextEditing(html) {
              ...

	if ("attachEvent" in doc) {
		doc.attachEvent("onkeyup", keyReleased); 
                      ....
	}	
	if ("addEventListener" in doc) {
		doc.addEventListener("keypress", keyPressed, true);
		doc.addEventListener("keyrelease", keyReleased, true);
          ...
     }


function keyReleased(event) {
	var keyCode = event.keyCode;
	if (keyCode == 0 && !document.all) {
		keyCode = event.charCode;
		switch (keyCode) {
		    case 98:
		     	keyCode = KEY_B;
				break;
			case 99:
				keyCode = KEY_C;
				break;
			case 102:
				keyCode = KEY_F;
				break;
		    case 105:
		        keyCode = KEY_I;
		        break;
			case 115:
				keyCode = KEY_S;
				break;
		    case 117:
		        keyCode = KEY_U;
		        break;
			case 118:
				keyCode = KEY_V;
				break;
			case 120:
				keyCode = KEY_X;
				break;
			case 122:
				keyCode = KEY_Z;
				break;
		}
	}
	var ctrlKey = event.ctrlKey;
	var shiftKey = event.shiftKey;
	var altKey = event.altKey;

	if ( !ctrlKey && !altKey ) {
       var modified = true;
	   for (var i = 0; i < excludeModify.length; i++ ) {
	     if ( keyCode == excludeModify[i] ) {
	       modified = false;
	     }
	   }
	   if ( modified == true ) {
		   setTimeout("setStatus(STATUS_MODIFIED, null);", 10);
	   }
	}
}
Comment 42 Flavio Donze CLA 2010-01-07 11:18:01 EST
Thanks a lot. I do now get my desired ModifyEvents. Also when CTRL or ALT is pressed but that doesn't matter I can handle this in my listener.

But shouldn't this issue be reopened since there are still problems around?

greets and thanks again!
Comment 43 Nikolas Falco CLA 2010-07-28 08:36:00 EDT
I run test posted by Jeff Hardy using an addKeyListener(KeyAdapter) instead addListener on eclipse 3.6, every time i press a key, console log correctly.
So SWT browser widget haven't problem to catch key event.

Running test post by Flavio Donzé that already use addKeyListenet(KeyAdapter), listener is waked up only on backspace, canc or enter was.
Instead key listener never print to console "keyPressed..." message.
Comment 44 Nikolas Falco CLA 2010-07-28 08:37:53 EDT
I run on Windows XP SP3
My browser are:
Internet Explorer 8.0.6001.18702
Firefox 3.6.8