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.

View | Details | Raw Unified | Return to bug 222138
Collapse All | Expand All

(-)a/openide.loaders/apichanges.xml (+17 lines)
Lines 109-114 Link Here
109
<!-- ACTUAL CHANGES BEGIN HERE: -->
109
<!-- ACTUAL CHANGES BEGIN HERE: -->
110
110
111
  <changes>
111
  <changes>
112
      <change id="lazymenu.properties">
113
          <api name="awt"/>
114
          <summary>Control what client properties pulldown menus have</summary>
115
          <version major="7" minor="42"/>
116
          <date day="22" month="11" year="2012"/>
117
          <author login="jtulach"/>
118
          <compatibility addition="yes"/>
119
          <description>
120
             <p>Layer declaration of a menu can influence what client properties
121
                 the actual <a href="@JDK@/javax/swing/JMenu.html">JMenu</a> 
122
                 instances will have. More 
123
                 <a href="architecture-summary.html#layer-Menu">details</a>.
124
              </p>
125
          </description>
126
          <class package="org.openide.awt" name="MenuBar"/>
127
          <issue number="222138"/>
128
      </change>
112
      <change id="DataObjec.Registration">
129
      <change id="DataObjec.Registration">
113
          <api name="loaders"/>
130
          <api name="loaders"/>
114
          <summary>Introduced <code>DataObject.Registration</code> and <code>DataObject.Registrations</code></summary>
131
          <summary>Introduced <code>DataObject.Registration</code> and <code>DataObject.Registrations</code></summary>
(-)a/openide.loaders/arch.xml (+20 lines)
Lines 916-921 Link Here
916
    A folder Recent stores a set of recently used templates, it's not open to other module. 
916
    A folder Recent stores a set of recently used templates, it's not open to other module. 
917
    </api><p></p>
917
    </api><p></p>
918
</li>
918
</li>
919
<li>
920
    <api name="Menu" group="layer" type="export" category="stable"><p>
921
        The main menu of the application is composed by reading <code>Menu/</code>
922
        folder in the layer. A sub folder is treated as a sub menu. 
923
        Instances of individual files (usually <code>.instance</code> 
924
        or <code>.shadow</code>) may then represent <a href="@JDK@/javax/swing/Action.html">Action</a>
925
        or <a href="@JDK@/javax/swing/JMenuItem.html">JMenuItem</a>
926
        or <a href="@JDK@/javax/swing/JSeparator.html">JSeparator</a>.
927
    </p>
928
    <p>
929
        Since version 7.42 one can attach <code>property-prefix</code> attribute
930
        to every folder. Then all the file attributes are scanned and if some 
931
        of them start with the specified prefix they are placed a 
932
        <a href="@JDK@/javax/swing/JComponent.html#putClientProperty(java.lang.Object,%20java.lang.Object)">
933
        client
934
        properties</a> on the <a href="@JDK@/javax/swing/JMenu.html">JMenu</a>
935
        instance (after stripping the prefix off).
936
    </p>
937
    </api><p></p>
938
</li>
919
</ul>
939
</ul>
920
<p>
940
<p>
921
None of them is forced to found.
941
None of them is forced to found.
(-)a/openide.loaders/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.loaders
2
OpenIDE-Module: org.openide.loaders
3
OpenIDE-Module-Specification-Version: 7.41
3
OpenIDE-Module-Specification-Version: 7.42
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/loaders/Bundle.properties
5
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
5
OpenIDE-Module-Provides: org.netbeans.modules.templates.v1_0
6
OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/openide/loaders/layer.xml
(-)a/openide.loaders/src/org/openide/awt/MenuBar.java (+15 lines)
Lines 54-59 Link Here
54
import java.io.ObjectOutput;
54
import java.io.ObjectOutput;
55
import java.util.ArrayList;
55
import java.util.ArrayList;
56
import java.util.Arrays;
56
import java.util.Arrays;
57
import java.util.Enumeration;
57
import java.util.HashMap;
58
import java.util.HashMap;
58
import java.util.Iterator;
59
import java.util.Iterator;
59
import java.util.LinkedList;
60
import java.util.LinkedList;
Lines 539-544 Link Here
539
            this.slave = new MenuFolder();
540
            this.slave = new MenuFolder();
540
            
541
            
541
            setName(df.getName());
542
            setName(df.getName());
543
            final FileObject pf = df.getPrimaryFile();
544
            Object prefix = pf.getAttribute("property-prefix"); // NOI18N
545
            if (prefix instanceof String) {
546
                Enumeration<String> en = pf.getAttributes();
547
                while (en.hasMoreElements()) {
548
                    String attrName = en.nextElement();
549
                    if (attrName.startsWith((String)prefix)) {
550
                        putClientProperty(
551
                            attrName.substring(((String)prefix).length()), 
552
                            pf.getAttribute(attrName)
553
                        );
554
                    }
555
                }
556
            }
542
557
543
            // Listen for changes in Node's DisplayName/Icon
558
            // Listen for changes in Node's DisplayName/Icon
544
            Node n = master.getNodeDelegate ();
559
            Node n = master.getNodeDelegate ();
(-)a/openide.loaders/test/unit/src/org/openide/awt/MenuBarTest.java (+32 lines)
Lines 56-61 Link Here
56
import java.util.ArrayList;
56
import java.util.ArrayList;
57
import java.util.logging.Level;
57
import java.util.logging.Level;
58
import javax.swing.AbstractAction;
58
import javax.swing.AbstractAction;
59
import javax.swing.JComponent;
59
import javax.swing.JMenu;
60
import javax.swing.JMenu;
60
import javax.swing.JMenuItem;
61
import javax.swing.JMenuItem;
61
import javax.swing.JPanel;
62
import javax.swing.JPanel;
Lines 194-199 Link Here
194
        assertEquals("Still No removals in MenuBar", 0, remove);
195
        assertEquals("Still No removals in MenuBar", 0, remove);
195
        assertEquals("Still Two additions in MenuBar", 2, add);
196
        assertEquals("Still Two additions in MenuBar", 2, add);
196
    }
197
    }
198
    
199
    
200
    public void testClientPropertiesMayBePropagated() throws Exception {
201
        mb.addContainerListener(this);
202
        assertEquals("No children now", 0, mb.getComponentCount());
203
        
204
        class Atom implements FileSystem.AtomicAction {
205
            FileObject m1, m2;
206
            
207
            public void run() throws IOException {
208
                m1 = FileUtil.createFolder(df.getPrimaryFile(), "m1");
209
                m1.setAttribute("property-prefix", "ahoj.");
210
                m1.setAttribute("ahoj.jardo", "Hi!");
211
                m2 = FileUtil.createFolder(df.getPrimaryFile(), "m2");
212
                m2.setAttribute("property-prefix", "buk-");
213
                m2.setAttribute("buk-muk", "Hello!");
214
            }
215
        }
216
        Atom atom = new Atom();
217
        df.getPrimaryFile().getFileSystem().runAtomicAction(atom);
218
        mb.waitFinished();
219
        
220
        assertEquals("Two children there", 2, mb.getComponentCount());
221
        final JMenuItem c0 = (JMenuItem) mb.getComponent(0);
222
        assertEquals("Programatic names deduced from the folder", "m1", c0.getName());
223
        final JMenuItem c1 = (JMenuItem) mb.getComponent(1);
224
        assertEquals("Programatic names deduced from the folder", "m2", c1.getName());
225
        
226
        assertEquals("Hi!", c0.getClientProperty("jardo"));
227
        assertEquals("Hello!", c1.getClientProperty("muk"));
228
    }
197
229
198
    static void simulateExpansionOfMenu(JMenu m1) {
230
    static void simulateExpansionOfMenu(JMenu m1) {
199
        // simulate expansion in the menu
231
        // simulate expansion in the menu

Return to bug 222138