On the methodvalue attribute in layer.xml file

The methodvalue attribute can be in form of pgk1.pkg2.ClassName.methodName which should point to existing class with static method usually having no, one or two arguments. This method does not need to be public or in public class, if the filesystem has permissions to call the method. The method can take one of the following 5 signatures:

static Value methodName();
static Value methodName(FileObject fo);
static Value methodName(FileObject fo, String attrName);
static Value methodName(Map attrs); // since 7.0
static Value methodName(Map attrs, String attrName); // since 7.0

where Value can be any java type.

For example, note the line in bold below:

<folder name="Actions">
    <folder name="Build">
        <file name="org-module1-SomeAction.instance">
            <attr bundlevalue="org.module1.Bundle#CTL_SomeAction" name="displayName"/>
            <attr
name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled" />
            <attr name="delegate" newvalue="org.module1.SomeAction"/>
            <attr boolvalue="false" name="noIconInMenu"/>
        </file>
    </folder>
</folder>

You can see a method "alwaysEnabled" is being referred to in a class called "Actions". Here's that method:

    static Action alwaysEnabled(Map map) {
        return AlwaysEnabledAction.create(map);
    }

So, in the above code, you see the 4th of the 5 signatures shown at the start of this blog entry. The "map" consists of all the attributes defined in the layer entry and now you can use them elsewhere.

Great blog entry (in German) by Jens Hofschröer in Aachen:

http://blog.nigjo.de/netbeans/2010/05/moeglichkeiten-einer-methodvalue-implementierung/

Comments:

Hi

Even though the comments says "since 7.0", these methods are available since NetBeans 6.7

Jens

Posted by Jens Hofschröer on November 06, 2011 at 05:42 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today