Community
Participate
Working Groups
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
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.
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?
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.
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).
*** Bug 218863 has been marked as a duplicate of this bug. ***
Anthony, what do you think?
(In reply to comment #6) > Anthony, what do you think? We cannot make this fix, it is an API breaking change.
Setting milestone to future then, as this will have to be addressed in the next major version.