X

Geertjan's Blog

  • November 6, 2011

On the methodvalue attribute in layer.xml file

Geertjan Wielenga
Product Manager

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/

Join the discussion

Comments ( 1 )
  • Jens Hofschr&ouml;er Monday, November 7, 2011

    Hi

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

    Jens


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.