diff -r 16bd4d64f3f1 openide.loaders/apichanges.xml --- a/openide.loaders/apichanges.xml Wed Nov 14 14:56:58 2012 +0100 +++ b/openide.loaders/apichanges.xml Thu Nov 15 16:02:19 2012 +0100 @@ -109,6 +109,23 @@ + + + Control what client properties pulldown menus have + + + + + +

Layer declaration of a menu can influence what client properties + the actual JMenu + instances will have. More + details. +

+
+ + +
Introduced DataObject.Registration and DataObject.Registrations diff -r 16bd4d64f3f1 openide.loaders/arch.xml --- a/openide.loaders/arch.xml Wed Nov 14 14:56:58 2012 +0100 +++ b/openide.loaders/arch.xml Thu Nov 15 16:02:19 2012 +0100 @@ -916,6 +916,26 @@ A folder Recent stores a set of recently used templates, it's not open to other module.

+
  • +

    + The main menu of the application is composed by reading Menu/ + folder in the layer. A sub folder is treated as a sub menu. + Instances of individual files (usually .instance + or .shadow) may then represent Action + or JMenuItem + or JSeparator. +

    +

    + Since version 7.42 one can attach property-prefix attribute + to every folder. Then all the file attributes are scanned and if some + of them start with the specified prefix they are placed a + + client + properties on the JMenu + instance (after stripping the prefix off). +

    +

    +
  • None of them is forced to found. diff -r 16bd4d64f3f1 openide.loaders/manifest.mf --- a/openide.loaders/manifest.mf Wed Nov 14 14:56:58 2012 +0100 +++ b/openide.loaders/manifest.mf Thu Nov 15 16:02:19 2012 +0100 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.loaders -OpenIDE-Module-Specification-Version: 7.41 +OpenIDE-Module-Specification-Version: 7.42 OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0 OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml diff -r 16bd4d64f3f1 openide.loaders/src/org/openide/awt/MenuBar.java --- a/openide.loaders/src/org/openide/awt/MenuBar.java Wed Nov 14 14:56:58 2012 +0100 +++ b/openide.loaders/src/org/openide/awt/MenuBar.java Thu Nov 15 16:02:19 2012 +0100 @@ -54,6 +54,7 @@ import java.io.ObjectOutput; import java.util.ArrayList; import java.util.Arrays; +import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -539,6 +540,20 @@ this.slave = new MenuFolder(); setName(df.getName()); + final FileObject pf = df.getPrimaryFile(); + Object prefix = pf.getAttribute("property-prefix"); // NOI18N + if (prefix instanceof String) { + Enumeration en = pf.getAttributes(); + while (en.hasMoreElements()) { + String attrName = en.nextElement(); + if (attrName.startsWith((String)prefix)) { + putClientProperty( + attrName.substring(((String)prefix).length()), + pf.getAttribute(attrName) + ); + } + } + } // Listen for changes in Node's DisplayName/Icon Node n = master.getNodeDelegate (); diff -r 16bd4d64f3f1 openide.loaders/test/unit/src/org/openide/awt/MenuBarTest.java --- a/openide.loaders/test/unit/src/org/openide/awt/MenuBarTest.java Wed Nov 14 14:56:58 2012 +0100 +++ b/openide.loaders/test/unit/src/org/openide/awt/MenuBarTest.java Thu Nov 15 16:02:19 2012 +0100 @@ -56,6 +56,7 @@ import java.util.ArrayList; import java.util.logging.Level; import javax.swing.AbstractAction; +import javax.swing.JComponent; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JPanel; @@ -194,6 +195,37 @@ assertEquals("Still No removals in MenuBar", 0, remove); assertEquals("Still Two additions in MenuBar", 2, add); } + + + public void testClientPropertiesMayBePropagated() throws Exception { + mb.addContainerListener(this); + assertEquals("No children now", 0, mb.getComponentCount()); + + class Atom implements FileSystem.AtomicAction { + FileObject m1, m2; + + public void run() throws IOException { + m1 = FileUtil.createFolder(df.getPrimaryFile(), "m1"); + m1.setAttribute("property-prefix", "ahoj."); + m1.setAttribute("ahoj.jardo", "Hi!"); + m2 = FileUtil.createFolder(df.getPrimaryFile(), "m2"); + m2.setAttribute("property-prefix", "buk-"); + m2.setAttribute("buk-muk", "Hello!"); + } + } + Atom atom = new Atom(); + df.getPrimaryFile().getFileSystem().runAtomicAction(atom); + mb.waitFinished(); + + assertEquals("Two children there", 2, mb.getComponentCount()); + final JMenuItem c0 = (JMenuItem) mb.getComponent(0); + assertEquals("Programatic names deduced from the folder", "m1", c0.getName()); + final JMenuItem c1 = (JMenuItem) mb.getComponent(1); + assertEquals("Programatic names deduced from the folder", "m2", c1.getName()); + + assertEquals("Hi!", c0.getClientProperty("jardo")); + assertEquals("Hello!", c1.getClientProperty("muk")); + } static void simulateExpansionOfMenu(JMenu m1) { // simulate expansion in the menu