This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 144541 - ExtUtilities.getExtEditorUI throws ClassCastException
Summary: ExtUtilities.getExtEditorUI throws ClassCastException
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 6.x
Hardware: PC Linux
: P1 blocker with 1 vote (vote)
Assignee: Vitezslav Stejskal
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-20 09:41 UTC by mgoe
Modified: 2008-08-22 06:07 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Image showing the truncated line numbers (3.22 KB, image/png)
2008-08-20 10:59 UTC, mgoe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mgoe 2008-08-20 09:41:41 UTC
In an application based on the netbeans platform I use:

JEditorPane editorPane = new JEditorPane();
ExtEditorUI extEditorUI = ExtUtilities.getExtEditorUI(editorPane);
JComponent editorComponent = extEditorUI.getExtComponent();

With the platform delivered with Netbeans 6.1 this code worked without problems.
With the platform delivered with Netbeans 6.5 (m1 and beta) the call ExtUtilities.getExtEditorUI(editorPane) throws 
the following ClassCastException:

java.lang.ClassCastException: org.netbeans.modules.languages.dataobject.LanguagesEditorKit$2 cannot be cast to 
org.netbeans.editor.ext.ExtEditorUI
	at org.netbeans.editor.ext.ExtUtilities.getExtEditorUI(ExtUtilities.java:63)

Since I have not found a workaround I have set P1 priority.

Best regards,
Martin
Comment 1 Vitezslav Stejskal 2008-08-20 09:57:36 UTC
I'm looking into this. Generally, ExtUtilities as well as ExtEditorUI has been deprecated and moved to
editor.deprecated.pre61completion module. You should not be using them anymore. Instead use
Utilities.getEditorUI(editorPane).getExtComponent().
Comment 2 Vitezslav Stejskal 2008-08-20 10:22:10 UTC
I fixed ExtUtilities to prevent CCE, but as I said before, you should use EditorUI instead.
http://hg.netbeans.org/main/rev/bd32860b2cc6
Comment 3 mgoe 2008-08-20 10:58:45 UTC
Thanks for your fast reply,

I just switched to Utilities.getEditorUI(editorPane).getExtComponent() and it worked as before. Thank you.
Btw. how do I find out how to replace deprecated code?

There is another small problem with the editor returned by the call above. Line numbers (when switched on) are 
truncated as shown in the image I attach in a minute.

I use a TopComponent as follows:

public class MyEditor extends TopComponent {
    public MyEditor () {
        setLayout(new BorderLayout());
        Lookup lookup = MimeLookup.getLookup(MimePath.get("text/x-mylanguage"));
        EditorKit editorKit = lookup.lookup(EditorKit.class);
        JEditorPane editorPane = new JEditorPane();
        editorPane.setEditorKit(editorKit);
        
        EditorUI editorUI = Utilities.getEditorUI(editorPane);
        JComponent editorComponent = editorUI.getExtComponent();
        JToolBar toolBar = editorUI.getToolBarComponent();
        add(toolBar, BorderLayout.NORTH);
        add(editorComponent, BorderLayout.CENTER);
    }
}

Thanks again for looking into this.
Comment 4 mgoe 2008-08-20 10:59:55 UTC
Created attachment 67940 [details]
Image showing the truncated line numbers
Comment 5 Vitezslav Stejskal 2008-08-20 13:21:56 UTC
> how do I find out how to replace deprecated code?

Well, I don't think there is a single common place to go and check, but in general changes are always announced on
apireviews@netbeans.org and nbdev@netbeans.org. It's also good idea to look in the IDE's log file and search for any
warnings. They usually mention an issue number, which you can then look up in the IssueZilla and learn more about the
problem. The issue report may include links to transition guides, how-tos, etc.

In this particular case the description is in a wiki page at http://wiki.netbeans.org/EditorSettingsUpgrade. Please read
through it and see if and how much of your application is affected by these changes. I suspect that you get quite a lot
of warnings when starting up your application and that they complain about injecting module dependencies and using
deprecated modules, etc. We try to do changes as much backward compatible as possible, but as a rule of thumb you should
always try to fix all the warnings that the platform gives you. If you have questions about some warning please ask on
nbdev.


> Line numbers (when switched on) are truncated

I suspect that the line numbers component for some reason does not update its width. When exactly are you loading text
to the JEditorPane's document? And how do you do it? Maybe we could just discuss this offline. Do you want to send me an
email to vstejskal@netbeans.org? Thanks
Comment 6 Quality Engineering 2008-08-20 17:26:30 UTC
Integrated into 'main-golden', available in build *200808201401* on http://bits.netbeans.org/dev/nightly/
Changeset: http://hg.netbeans.org/main/rev/bd32860b2cc6
User: Vita Stejskal <vstejskal@netbeans.org>
Log: #144541: preventing class cast exception
Comment 7 Quality Engineering 2008-08-22 06:07:52 UTC
Integrated into 'main-golden', available in build *200808220201* on http://bits.netbeans.org/dev/nightly/
Changeset: http://hg.netbeans.org/main/rev/24ef74f72b95
User: Vita Stejskal <vstejskal@netbeans.org>
Log: #144541: GlyphGutter should survive document change in the associated component