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 37543
Collapse All | Expand All

(-)openide/src/org/openide/explorer/ExplorerUtils.java (+25 lines)
Lines 186-189 Link Here
186
        return new DefaultEMLookup (em, map);
186
        return new DefaultEMLookup (em, map);
187
    }
187
    }
188
    
188
    
189
    /** Utility method to get context help from a node selection.
190
     *  Tries to find context helps for selected nodes.
191
     *  If there are some, and they all agree, uses that.
192
     *  In all other cases, uses the supplied generic help.
193
     *
194
     *  @param sel a list of nodes to search for help in
195
     *  @param def the default help to use if they have none or do not agree
196
     *  @return a help context
197
     */
198
    public static HelpCtx getHelpCtx (Node[] sel, HelpCtx def) {
199
        HelpCtx result = null;
200
        for (int i = 0; i < sel.length; i++) {
201
            HelpCtx attempt = sel[i].getHelpCtx ();
202
            if (attempt != null && ! attempt.equals (HelpCtx.DEFAULT_HELP)) {
203
                if (result == null || result.equals (attempt)) {
204
                    result = attempt;
205
                } else {
206
                    // More than one found, and they conflict. Get general help on the Explorer instead.
207
                    result = null;
208
                    break;
209
                }
210
            }
211
        }
212
        return result != null ? result : def;
213
    }
189
}
214
}
(-)projects/projectui/src/org/netbeans/modules/project/ui/ProjectTab.java (-2 / +4 lines)
Lines 83-89 Link Here
83
    
83
    
84
    public ProjectTab() {
84
    public ProjectTab() {
85
85
86
        // This should not be here byt for some reason it does not work
86
        // This should not be here but for some reason it does not work
87
        // In the module installer
87
        // In the module installer
88
        Hacks.hackFolderActions();
88
        Hacks.hackFolderActions();
89
        
89
        
Lines 194-200 Link Here
194
    }
194
    }
195
    
195
    
196
    public HelpCtx getHelpCtx() {
196
    public HelpCtx getHelpCtx() {
197
        return new HelpCtx(ProjectTab.class);
197
        return ExplorerUtils.getHelpCtx(
198
                manager.getSelectedNodes(),
199
                new HelpCtx( ProjectTab.class ) );
198
    }
200
    }
199
     
201
     
200
    public int getPersistenceType() {
202
    public int getPersistenceType() {
(-)openide/test/unit/src/org/openide/explorer/ExplorerUtilsTest.java (+87 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openide.explorer;
15
16
import junit.textui.TestRunner;
17
18
import org.netbeans.junit.*;
19
import org.openide.nodes.*;
20
import org.openide.util.HelpCtx;
21
22
/**
23
 * Check the behaviour of the ExplorerUtils
24
 *
25
 * @author Petr Nejedly
26
 */
27
public class ExplorerUtilsTest extends NbTestCase {
28
    public ExplorerUtilsTest(String testName) {
29
        super(testName);
30
    }
31
    
32
    public static void main(String[] args) {
33
        TestRunner.run(new NbTestSuite(ExplorerUtilsTest.class));
34
        System.exit(0);
35
    }
36
    
37
    public void testGetHelpCtx () throws Exception {
38
        HelpCtx DEF = new HelpCtx("default");
39
        
40
        assertEquals("Use default help for no nodes",
41
            DEF,
42
            ExplorerUtils.getHelpCtx(new Node[0], DEF));
43
        
44
        assertEquals("Use default help for single node w/o help",
45
            DEF,
46
            ExplorerUtils.getHelpCtx(new Node[] {new NoHelpNode()}, DEF));
47
            
48
        assertEquals("Use provided help for single node with help",
49
            new HelpCtx("foo"),
50
            ExplorerUtils.getHelpCtx(new Node[] {new WithHelpNode("foo")}, DEF));
51
52
        assertEquals("Use default help for more nodes w/o help",
53
            DEF,
54
            ExplorerUtils.getHelpCtx(new Node[] {new NoHelpNode(), new NoHelpNode()}, DEF));
55
            
56
        assertEquals("Use provided help if only one node has help",
57
            new HelpCtx("foo"),
58
            ExplorerUtils.getHelpCtx(new Node[] {new NoHelpNode(), new WithHelpNode("foo")}, DEF));
59
            
60
        assertEquals("Use provided help if more nodes have the same help",
61
            new HelpCtx("foo"),
62
            ExplorerUtils.getHelpCtx(new Node[] {new WithHelpNode("foo"), new WithHelpNode("foo")}, DEF));
63
            
64
        assertEquals("Use default help if nodes have different helps",
65
            DEF,
66
            ExplorerUtils.getHelpCtx(new Node[] {new WithHelpNode("foo"), new WithHelpNode("bar")}, DEF));
67
    }
68
69
    
70
    private static final class NoHelpNode extends AbstractNode {
71
        public NoHelpNode() {
72
            super(Children.LEAF);
73
        }
74
    }
75
    
76
    private static final class WithHelpNode extends AbstractNode {
77
        private final String id;
78
        public WithHelpNode(String id) {
79
            super(Children.LEAF);
80
            this.id = id;
81
        }
82
        public HelpCtx getHelpCtx() {
83
            return new HelpCtx(id);
84
        }
85
    }
86
    
87
}

Return to bug 37543