1 package info.mikethomas.fahview.v6project.nodes;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import info.mikethomas.fahview.v6project.ClientSubprojectProvider;
25 import info.mikethomas.fahview.v6project.WorkProject;
26 import java.awt.Image;
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.Set;
30 import javax.swing.event.ChangeListener;
31 import org.netbeans.api.project.Project;
32 import org.netbeans.spi.project.ui.support.NodeFactory;
33 import org.netbeans.spi.project.ui.support.NodeFactorySupport;
34 import org.netbeans.spi.project.ui.support.NodeList;
35 import org.openide.loaders.DataObject;
36 import org.openide.loaders.DataObjectNotFoundException;
37 import org.openide.nodes.FilterNode;
38 import org.openide.nodes.Node;
39 import org.openide.util.Exceptions;
40 import org.openide.util.ImageUtilities;
41
42
43
44
45
46
47
48 @NodeFactory.Registration(projectType = "info-mikethomas-fahview-client", position = 10)
49 public class ClientSubProjectNodeFactory implements NodeFactory {
50
51
52 @Override
53 public NodeList<?> createNodes(Project p) {
54 ClientSubprojectProvider csp = p.getLookup().
55 lookup(ClientSubprojectProvider.class);
56 assert csp != null;
57 return new ReportsNodeList(csp.getSubprojects());
58 }
59
60 private class ReportsNodeList implements NodeList<Project> {
61
62 Set<? extends Project> subprojects;
63
64 public ReportsNodeList(Set<? extends Project> subprojects) {
65 this.subprojects = subprojects;
66 }
67
68 @Override
69 public List<Project> keys() {
70 List<Project> result = new ArrayList<Project>();
71 for (Project oneReportSubProject : subprojects) {
72 result.add(oneReportSubProject);
73 }
74 return result;
75 }
76
77 @Override
78 public void addChangeListener(ChangeListener l) {}
79
80 @Override
81 public void removeChangeListener(ChangeListener l) {}
82
83 @Override
84 public Node node(Project key) {
85 FilterNode fn = null;
86 try {
87 fn = new FilterNode(DataObject.find(key.
88 getProjectDirectory()).getNodeDelegate(),
89 NodeFactorySupport.createCompositeChildren(
90 key, "Projects/info-mikethomas-fahview-work/Nodes")){
91 @Override
92 public Image getIcon(int type) {
93 return ImageUtilities.loadImage(WorkProject.PROJECT_ICON);
94 }
95 @Override
96 public Image getOpenedIcon(int type) {
97 return getIcon(type);
98 }
99 };
100 } catch (DataObjectNotFoundException ex) {
101 Exceptions.printStackTrace(ex);
102 }
103 return fn;
104 }
105
106 @Override
107 public void addNotify() {}
108
109 @Override
110 public void removeNotify() {}
111 }
112 }