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 104705 - Adding custom palette items to existing filetypes do not work on NB6.0 M9 or latest source
Summary: Adding custom palette items to existing filetypes do not work on NB6.0 M9 or ...
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Palette (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: Stanislav Aubrecht
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-24 09:02 UTC by Ayub Khan
Modified: 2008-12-22 13:41 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Sample Palette Module (10.44 KB, application/octet-stream)
2007-05-28 09:09 UTC, Ayub Khan
Details
Exception while opening the palette for a java mimetype (247.85 KB, application/octet-stream)
2007-06-01 07:37 UTC, Ayub Khan
Details
Palette warning on command window (257.57 KB, application/octet-stream)
2007-06-05 08:07 UTC, Ayub Khan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ayub Khan 2007-05-24 09:02:15 UTC
One of the most sought out feature of Nb6.0 is to be able to add any arbitrary
palette items to a exiting file types For Eg:- A user would like to add code
snippets to a palette for Java file. See Geetjan blog on this feature
http://blogs.sun.com/geertjan/entry/palette_api_and_6_0.

But the issue is that following the above tutorial by Geetjan, I am not able to
see palette items for java file types (on NB6.0 M9, I even tried fresh checkout
from cvs trunk and build yesterday, did not work).

Steps to reproduce.

1. Download and install Nb6.0 M9 
2. Download the nbm that Geertjan developed showing howt to add palette items
for Java file type.
http://blogs.sun.com/geertjan/resource/org-netbeans-modules-addjavapaletteitems.nbm
3. Install above nbm in IDE using Tools->Plugin
4. Create a new java project. Open Main.java from Source Packages. Open the
palette from Windows->Palette. According Geetjan, I should see the snapshot as
in the beginning of this blog
http://blogs.sun.com/geertjan/entry/palette_api_and_6_01

I think this feature should be working as expected for NB6.0. So filing as a P1.
Our module websvc/rest will need Palette pretty badly for NB6.0 M10.
Comment 1 Stanislav Aubrecht 2007-05-24 16:35:49 UTC
i tried installing the nbm and i got the exception mentioned below. the
exception is thrown every time i open a new java editor.
after restart the new palette module works fine and no exceptions are thrown
anymore.
reassigning to editor team for evaluation.


java.lang.ClassNotFoundException: Will not load classes from default package
(PaletteFactory)
	at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:171)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at org.openide.loaders.InstanceSupport.findClass(InstanceSupport.java:476)
	at org.openide.loaders.InstanceSupport.instanceClass(InstanceSupport.java:123)
	at
org.openide.loaders.InstanceDataObject$Ser.instanceClass(InstanceDataObject.java:1137)
	at
org.openide.loaders.InstanceDataObject.instanceClass(InstanceDataObject.java:673)
	at
org.netbeans.modules.editor.mimelookup.impl.FolderPathLookup$InstanceConvertor.type(FolderPathLookup.java:118)
	at
org.netbeans.modules.editor.mimelookup.impl.FolderPathLookup$InstanceConvertor.type(FolderPathLookup.java:109)
	at
org.openide.util.lookup.InstanceContent$ConvertingItem.getType(InstanceContent.java:322)
	at
org.openide.util.lookup.InstanceContent$ConvertingItem.instanceOf(InstanceContent.java:243)
	at org.openide.util.lookup.ArrayStorage$1CheckEn.process(ArrayStorage.java:207)
	at org.openide.util.lookup.ArrayStorage$1CheckEn.process(ArrayStorage.java:201)
	at org.openide.util.Enumerations$FilEn.hasMoreElements(Enumerations.java:533)
	at org.openide.util.lookup.AbstractLookup$R.initItems(AbstractLookup.java:998)
	at
org.openide.util.lookup.AbstractLookup$R.allItemsWithoutBeforeLookup(AbstractLookup.java:959)
	at org.openide.util.lookup.AbstractLookup$R.allItems(AbstractLookup.java:943)
	at org.openide.util.lookup.ProxyLookup$R.computeResult(ProxyLookup.java:463)
	at org.openide.util.lookup.ProxyLookup$R.allItems(ProxyLookup.java:418)
	at org.openide.util.lookup.ProxyLookup$R.computeResult(ProxyLookup.java:463)
	at org.openide.util.lookup.ProxyLookup$R.allItems(ProxyLookup.java:418)
	at org.openide.util.lookup.ProxyLookup$R.computeResult(ProxyLookup.java:463)
	at org.openide.util.lookup.ProxyLookup$R.allItems(ProxyLookup.java:418)
	at
org.netbeans.modules.editor.lib2.highlighting.HighlightingManager$Highlighting.rebuildAll(HighlightingManager.java:221)
	at
org.netbeans.modules.editor.lib2.highlighting.HighlightingManager$Highlighting.<init>(HighlightingManager.java:136)
	at
org.netbeans.modules.editor.lib2.highlighting.HighlightingManager.getHighlighting(HighlightingManager.java:91)
	at
org.netbeans.modules.editor.lib2.highlighting.HighlightingManager.getHighlights(HighlightingManager.java:69)
	at
org.netbeans.modules.editor.lib.HighlightingDrawLayer.init(HighlightingDrawLayer.java:229)
	at org.netbeans.editor.DrawEngine.initInfo(DrawEngine.java:160)
	at org.netbeans.editor.DrawEngine.draw(DrawEngine.java:1070)
	at
org.netbeans.editor.DrawEngineLineView.getModel2ViewRect(DrawEngineLineView.java:278)
	at org.netbeans.editor.DrawEngineLineView.modelToView(DrawEngineLineView.java:314)
	at
org.netbeans.editor.DrawEngineLineView.getPreferredSpan(DrawEngineLineView.java:254)
	at
org.netbeans.editor.DrawEngineLineView.minorAxisUpdateLayout(DrawEngineLineView.java:560)
	at org.netbeans.editor.DrawEngineLineView.updateLayout(DrawEngineLineView.java:515)
	at
org.netbeans.lib.editor.view.GapBoxViewChildren.childrenUpdateLayout(GapBoxViewChildren.java:878)
	at
org.netbeans.lib.editor.view.GapBoxViewChildren.childrenUpdateLayout(GapBoxViewChildren.java:883)
	at org.netbeans.lib.editor.view.GapBoxView.updateLayout(GapBoxView.java:737)
	at org.netbeans.lib.editor.view.GapBoxView.directUpdateLayout(GapBoxView.java:886)
	at
org.netbeans.lib.editor.view.GapDocumentView.directUpdateLayout(GapDocumentView.java:150)
	at org.netbeans.lib.editor.view.GapBoxView.markLayoutInvalid(GapBoxView.java:873)
	at
org.netbeans.lib.editor.view.GapBoxViewChildren.markLayoutInvalid(GapBoxViewChildren.java:837)
	at org.netbeans.lib.editor.view.GapBoxView.preferenceChanged(GapBoxView.java:1261)
	at
org.netbeans.editor.DrawEngineLineView.setEstimatedSpan(DrawEngineLineView.java:155)
	at org.netbeans.editor.DrawEngineLineView.modelToView(DrawEngineLineView.java:300)
	at org.netbeans.editor.DrawEngineLineView.modelToView(DrawEngineLineView.java:295)
	at org.netbeans.lib.editor.view.GapBoxView.modelToView(GapBoxView.java:1490)
	at org.netbeans.editor.view.spi.LockView.modelToView(LockView.java:398)
	at javax.swing.plaf.basic.BasicTextUI$RootView.modelToView(BasicTextUI.java:1413)
	at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:947)
	at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:922)
	at org.netbeans.editor.GlyphGutter.paintComponent(GlyphGutter.java:537)
	at javax.swing.JComponent.paint(JComponent.java:1005)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JViewport.paint(JViewport.java:728)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at org.netbeans.core.windows.view.ui.MultiSplitPane.paint(MultiSplitPane.java:294)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JLayeredPane.paint(JLayeredPane.java:559)
	at javax.swing.JComponent.paintChildren(JComponent.java:842)
	at javax.swing.JComponent.paint(JComponent.java:1014)
	at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4963)
	at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4916)
	at javax.swing.JComponent._paintImmediately(JComponent.java:4859)
	at javax.swing.JComponent.paintImmediately(JComponent.java:4666)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:451)
[catch] at
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:114)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
	at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
	at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Comment 2 Vitezslav Stejskal 2007-05-25 02:14:21 UTC
Try adding 'instanceClass' attribute to the 'PaletteFactory.instance' file in
the module's layer.

The problem is in FolderPathLookup, wich uses lookup items that do not properly
wrap around InstanceCookie. In particular, the lookup item must overwrite
instanceOf and delegate to InstanceCookie.Of.instanceOf, if possible.
Comment 3 Stanislav Aubrecht 2007-05-25 08:13:47 UTC
cc'ing the author of the module
Comment 4 Ayub Khan 2007-05-28 09:09:42 UTC
Created attachment 42835 [details]
Sample Palette Module
Comment 5 Ayub Khan 2007-05-28 09:10:02 UTC
Thanks for pointing out the mistake. One issue though, now I see stackoverflow
due to recursive invocation of createPalette(). I am attaching a NB module
"PaletteModule2" (See attached PaletteModule2.zip) that I created using NB that
has the code that tries to attach a palette to Java type.

-Ayub
Comment 6 Ayub Khan 2007-05-28 09:12:50 UTC
On a side note: How do I customize Actions on a Palette. In other words can I
add my own actions (as well hide other actions if any) to palette action popup.
Comment 7 Stanislav Aubrecht 2007-05-28 14:09:47 UTC
> On a side note: How do I customize Actions on a Palette. In other words can I
add my own actions (as well hide other actions if any) to palette action popup.

you can add your own actions (see org.netbeans.spi.palette.PaletteActions), you
cannot hide the default ones.
Comment 8 Ayub Khan 2007-05-30 01:16:02 UTC
This issue is a stopper for our (websvc/rest) deliverable to M10, hence I am
raising the priority  of this bug.

I also found that scripting/ejs module uses the same mechanism as Geertjan did
(ie use instanceOf attr). Using instanceClass is problematic, since it causes
StackOverflow

==========================================================
    <folder name="Editors">
        <folder name="text">
            <folder name="x-ejs">
...             
                <file name="org-netbeans-spi-palette-PaletteFactory.instance">
                    <attr name="instanceOf"
stringvalue="org.netbeans.spi.palette.PaletteController"/>
                    <attr name="instanceCreate"
methodvalue="org.netbeans.modules.languages.ejs.editor.palette.LayerPaletteFactory.createPalette"/>
                </file>
...
==========================================================================
Comment 9 Vitezslav Stejskal 2007-05-30 01:33:05 UTC
Jesse, I'll have to make changes to FolderPathLookup to fix this. Just letting
you know...
Comment 10 Vitezslav Stejskal 2007-05-30 03:13:55 UTC
I think the stackoverflow exception is a problem in PaletteFactory. Basically
what happens is that somebody uses MimeLookup to find PaletteControllers
registered for some mime type. The MimeLookup finds RestPaletteFactory as one of
them and calls its createPalette method. This method calls
PaletteFactory.createPalette, which at the end calls (through the
PaletteSwitch's constructor) MimeLookup *again* to get PaletteControllers for
the same mime type. And we end up in an infinite loop.

The stackoverflow exception seems unrelated to what attribute is used. IMO we
should treat it as a separate issue. Anyway, I'm trying to fix MimeLookup to
correctly work with 'instanceOf' parameters. But it won't fix the stackoverflow
problem.
Comment 11 Vitezslav Stejskal 2007-05-30 06:18:12 UTC
I fixed MimeLookup to read the 'instanceOf' attribute. It looks like it also
helped to prevent that infinite loop in PaletteSwitch. At least the attached
example module is working now - I can see 'Hello' palette when open a java file.
But I don't think that PaletteSwitch and PaletteFactory is correct, the
stackoverflow exception still happens when 'instanceClass' attribute is used.

Checking in
test/unit/src/org/netbeans/modules/editor/mimelookup/impl/test-layer.xml;
/cvs/editor/mimelookup/impl/test/unit/src/org/netbeans/modules/editor/mimelookup/impl/test-layer.xml,v
 <--  test-layer.xml
new revision: 1.3; previous revision: 1.2
done
Checking in
test/unit/src/org/netbeans/modules/editor/mimelookup/impl/FolderPathLookupTest.java;
/cvs/editor/mimelookup/impl/test/unit/src/org/netbeans/modules/editor/mimelookup/impl/FolderPathLookupTest.java,v
 <--  FolderPathLookupTest.java
new revision: 1.3; previous revision: 1.2
done
Checking in src/org/netbeans/modules/editor/mimelookup/impl/FolderPathLookup.java;
/cvs/editor/mimelookup/impl/src/org/netbeans/modules/editor/mimelookup/impl/FolderPathLookup.java,v
 <--  FolderPathLookup.java
new revision: 1.4; previous revision: 1.3
done
Comment 12 Stanislav Aubrecht 2007-05-30 10:11:30 UTC
fixed the stackoverflow part

/cvs/core/palette/src/org/netbeans/spi/palette/PaletteFactory.java,v  <-- 
PaletteFactory.java
new revision: 1.10; previous revision: 1.9
Comment 13 Ayub Khan 2007-06-01 07:36:26 UTC
I have tested the fix. I have to modify the PaletteController.java (see below
for diff) in order to show the "Hello" Palette item. I think you need to fix
this code too, else I get the attached Exception.

=========================================================
Index: src/org/netbeans/spi/palette/PaletteController.java
===================================================================
RCS file: /cvs/core/palette/src/org/netbeans/spi/palette/PaletteController.java,
v
retrieving revision 1.8
diff -r1.8 PaletteController.java
133c133
<     private Model model;
---
>     public Model model;
137c137
<     private Settings settings;
---
>     public Settings settings;
139c139
<     private PropertyChangeSupport support ;
---
>     public PropertyChangeSupport support ;
143c143
<     private PaletteController() {
---
>     public PaletteController() {
147c147
<     PaletteController( Model model, Settings settings ) {
---
>     public PaletteController( Model model, Settings settings ) {
=================================================================
Comment 14 Ayub Khan 2007-06-01 07:37:49 UTC
Created attachment 43079 [details]
Exception while opening the palette for a java mimetype
Comment 15 Vitezslav Stejskal 2007-06-05 05:02:27 UTC
Most likely not. Can you please attach the exception as text, so that we can see
everything. Thanks.
Comment 16 Ayub Khan 2007-06-05 08:06:12 UTC
I cannot reproduce the warning anymore even after reverting those changes
(mentioned above) in PaletteController. Unfortunately I didn't save the log
file, but I do have the screen snapshot of the command window with the
exception. See Palette_warn2.PNG

IMO this bug is fixed for now.
Comment 17 Ayub Khan 2007-06-05 08:07:44 UTC
Created attachment 43227 [details]
Palette warning on command window
Comment 18 Vitezslav Stejskal 2007-06-08 03:38:58 UTC
You should not be using org-netbeans-spi-palette-PaletteFactory.instance
straightaway. AFAIK PaletteFactory is not meant to be instantialized directly
from the layer, hence the exception. Just use some other name for the .instace
file with correct instanceOf and instanceCreate attributes.