Bug 327515 - Figure class is being used instead of IFigure interface in SWTEventDispatcher
Summary: Figure class is being used instead of IFigure interface in SWTEventDispatcher
Status: NEW
Alias: None
Product: GEF
Classification: Tools
Component: GEF-Legacy Draw2d (show other bugs)
Version: 3.6.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: gef-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 218863 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-10-12 03:04 EDT by Lee Wang-soo CLA
Modified: 2014-07-12 05:50 EDT (History)
5 users (show)

See Also:
nyssen: review? (ahunter.eclipse)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lee Wang-soo CLA 2010-10-12 03:04:59 EDT
Build Identifier: M20100909-0800

Figure class used instead of IFigure interface in SWTEventDispatcher.
Implemnting IFigure ,instead of extending Figure, causes ClassCastingException.

following is snippet from org.eclipse.draw2d.SWTEventDispatcher:

protected void setHoverSource(Figure figure,
			org.eclipse.swt.events.MouseEvent me) {
...}

protected void updateHoverSource(org.eclipse.swt.events.MouseEvent me) {
		/*
		 * Derive source from figure under cursor. ...
		 */
		if (cursorTarget != null) {
			boolean sourceFound = false;
			Figure source = (Figure) cursorTarget;
			while (!sourceFound && source.getParent() != null) {
				if (source.getToolTip() != null)
					sourceFound = true;
				else
					source = (Figure) source.getParent();
			}
			setHoverSource(source, me);
		} else {
			setHoverSource(null, me);
		}
	}

I couldn't find any reason to use Figure class in this code.

Reproducible: Always

Steps to Reproduce:
 nothing to reproduce
Comment 1 Lee Wang-soo CLA 2010-10-13 01:13:22 EDT
Because of this, I am unable to impelment IFigure interface due to class cast exception.  Some of the the implementations in Figure class contains final fucntion designations, which prevents me from overriding some of the functions that I need to rewrite.
Comment 2 Alex Boyko CLA 2010-10-13 01:23:19 EDT
I doubt we'll be able to address Figure vs IFigure issue in the SWTEventdispatcher for 3.6.x release, because it will be an API breaking change. 3.7 at the best... but we're still not supposed to change the API there too.
IFigure interface is not intended to be implemented by clients directly. It states so in the java-doc. What's the problem with Figure in your case? If methods are final there, it means that they are not supposed to be implemented by clients. Can you explain briefly what your ultimate goal is and why subclassing Figure won't do it for you?
Comment 3 Lee Wang-soo CLA 2010-10-13 01:49:20 EDT
I'm developing graphical WYSIWYG HTML editor using GEF and Draw2d. For implementing HTML & CSS rendering, I should override Figure#add(..) to implement somewhat complex figure insertion mechanism, but I can't instantiate 'children' field in my overriding mehtod due to it's private field. And, I want to override translateToAbsolute(.)/translateToRelative(.) for css position calcualtion, but it's final mehtod.
I know IFigure is not intended to implments and there are ways to go around.

But, regardless of above, I think that interface should be used instead of concrete class if possible. IMHO, this case is not API breaking changes, but minor changes which effects others.
Comment 4 Alexander Nyßen CLA 2010-10-26 14:58:55 EDT
Strictly speaking, changing the method to use an IFigure would be an API-breaking change (at least API-tools report it that way). Additionally, the IFigure interface is not intended to be implemented by clients (that was explicitly stated in its Javadoc and additionally emphasized by adding respective annotations in 3.6). 

However, as Figure is the only existing implementation of the IFigure interface, and because of above mentioned restrictions, I think we could change the method signature to use IFigure without actually breaking any existing clients, (we would have to introduce a compatibility problem filter, though). Indeed, I also think using IFigure would make the code cleaner (the reported snippet seems to be the only one using FIgure).
Comment 5 Alexander Nyßen CLA 2010-11-30 16:51:01 EST
*** Bug 218863 has been marked as a duplicate of this bug. ***
Comment 6 Alexander Nyßen CLA 2011-03-24 00:20:39 EDT
Anthony, what do you think?
Comment 7 Anthony Hunter CLA 2011-03-24 08:50:49 EDT
(In reply to comment #6)
> Anthony, what do you think?

We cannot make this fix, it is an API breaking change.
Comment 8 Alexander Nyßen CLA 2011-03-24 10:32:23 EDT
Setting milestone to future then, as this will have to be addressed in the next major version.