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

(-)a/mobility.project/src/org/netbeans/modules/mobility/project/ui/ProjectRootNodeChildren.java (-7 / +66 lines)
Lines 39-45 Link Here
39
package org.netbeans.modules.mobility.project.ui;
39
package org.netbeans.modules.mobility.project.ui;
40
40
41
import java.util.Arrays;
41
import java.util.Arrays;
42
import java.util.HashSet;
43
import java.util.LinkedList;
42
import java.util.List;
44
import java.util.List;
45
import java.util.Set;
46
import javax.swing.event.ChangeEvent;
47
import javax.swing.event.ChangeListener;
43
import org.netbeans.api.java.project.JavaProjectConstants;
48
import org.netbeans.api.java.project.JavaProjectConstants;
44
import org.netbeans.api.project.ProjectUtils;
49
import org.netbeans.api.project.ProjectUtils;
45
import org.netbeans.api.project.SourceGroup;
50
import org.netbeans.api.project.SourceGroup;
Lines 47-77 Link Here
47
import org.netbeans.modules.mobility.project.J2MEProject;
52
import org.netbeans.modules.mobility.project.J2MEProject;
48
import org.netbeans.modules.mobility.project.ui.ProjectRootNodeChildren.ChildKind;
53
import org.netbeans.modules.mobility.project.ui.ProjectRootNodeChildren.ChildKind;
49
import org.netbeans.spi.java.project.support.ui.PackageView;
54
import org.netbeans.spi.java.project.support.ui.PackageView;
50
import org.netbeans.spi.project.support.ant.AntProjectHelper;
55
import org.netbeans.spi.project.ui.support.NodeFactory;
51
import org.openide.nodes.AbstractNode;
56
import org.netbeans.spi.project.ui.support.NodeList;
52
import org.openide.nodes.ChildFactory;
57
import org.openide.nodes.ChildFactory;
53
import org.openide.nodes.Children;
54
import org.openide.nodes.FilterNode;
55
import org.openide.nodes.Node;
58
import org.openide.nodes.Node;
56
import org.openide.util.NbBundle;
59
import org.openide.util.Lookup;
60
import org.openide.util.LookupEvent;
61
import org.openide.util.LookupListener;
57
import org.openide.util.lookup.Lookups;
62
import org.openide.util.lookup.Lookups;
58
63
59
/**
64
/**
60
 *
65
 *
61
 * @author Tim Boudreau
66
 * @author Tim Boudreau
62
 */
67
 */
63
public class ProjectRootNodeChildren extends ChildFactory<ChildKind> {
68
final class ProjectRootNodeChildren extends ChildFactory.Detachable<ChildKind> implements LookupListener, ChangeListener {
64
69
65
    private final J2MEProject project;
70
    private final J2MEProject project;
71
    private Lookup.Result<NodeFactory> res;
72
    private static final String FOREIGN_NODES_PATH = 
73
            "Projects/org-netbeans-modules-java-j2seproject/Nodes"; //XXX
66
74
67
    public static enum ChildKind {
75
    public static enum ChildKind {
68
        Sources, 
76
        Sources, 
69
        Resources,
77
        Resources,
70
        Configurations
78
        Configurations,
79
        Foreign,
71
    }
80
    }
72
81
73
    ProjectRootNodeChildren(J2MEProject project) {
82
    ProjectRootNodeChildren(J2MEProject project) {
74
        this.project = project;
83
        this.project = project;
84
    }
85
86
    private Set <NodeList> lists = new HashSet<NodeList>();
87
    private final Object lock = new Object();
88
    @Override
89
    protected void addNotify() {
90
        res = Lookups.forPath (FOREIGN_NODES_PATH).lookupResult(NodeFactory.class);
91
        res.addLookupListener(this);
92
    }
93
94
    @Override
95
    protected void removeNotify() {
96
        res = null;
97
        Set<NodeList> s;
98
        synchronized (lock) {
99
            s = new HashSet<NodeList>(lists);
100
            lists.clear();
101
        }
102
        for (NodeList l : s) {
103
            l.removeChangeListener(this);
104
            l.removeNotify();
105
        }
75
    }
106
    }
76
107
77
    protected boolean createKeys(List<ChildKind> toPopulate) {
108
    protected boolean createKeys(List<ChildKind> toPopulate) {
Lines 88-96 Link Here
88
                return new Node[]{createResourcesNode()};
119
                return new Node[]{createResourcesNode()};
89
            case Sources:
120
            case Sources:
90
                return createSourcesNodes();
121
                return createSourcesNodes();
122
            case Foreign :
123
                return createForeignNodes();
91
            default:
124
            default:
92
                throw new AssertionError();
125
                throw new AssertionError();
93
        }
126
        }
127
    }
128
129
    private Node[] createForeignNodes() {
130
        List<Node> nodes = new LinkedList<Node>();
131
        Set<NodeList> found = new HashSet<NodeList>();
132
        for (NodeFactory f : res.allInstances()) {
133
            NodeList list = f.createNodes(project);
134
            list.addNotify();
135
            list.addChangeListener(this);
136
            for (Object key : list.keys()) {
137
                nodes.add(list.node(key));
138
            }
139
        }
140
        synchronized (lock) {
141
            lists.addAll (found);
142
        }
143
        Node[] result = nodes.toArray(new Node[nodes.size()]);
144
        return result;
94
    }
145
    }
95
146
96
    private Node createConfigurationsNode() {
147
    private Node createConfigurationsNode() {
Lines 115-118 Link Here
115
        }
166
        }
116
        return result.length == 0 ? new Node[] { Node.EMPTY } : result;
167
        return result.length == 0 ? new Node[] { Node.EMPTY } : result;
117
    }
168
    }
169
170
    public void resultChanged(LookupEvent ev) {
171
        refresh(false);
172
    }
173
174
    public void stateChanged(ChangeEvent e) {
175
        refresh (true);
176
    }
118
}
177
}

Return to bug 151716