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.ClientProject;
25 import java.util.ArrayList;
26 import java.util.List;
27 import javax.swing.event.ChangeListener;
28 import org.netbeans.api.project.Project;
29 import org.netbeans.spi.project.ui.support.NodeFactory;
30 import org.netbeans.spi.project.ui.support.NodeList;
31 import org.openide.filesystems.FileObject;
32 import org.openide.loaders.DataObject;
33 import org.openide.loaders.DataObjectNotFoundException;
34 import org.openide.nodes.FilterNode;
35 import org.openide.nodes.Node;
36 import org.openide.util.Exceptions;
37
38
39
40
41
42
43
44 @NodeFactory.Registration(projectType = "info-mikethomas-fahview-client", position = 20)
45 public class ClientNodeFactory implements NodeFactory {
46
47
48 @Override
49 public NodeList<?> createNodes(Project p) {
50 ClientProject project = p.getLookup().lookup(ClientProject.class);
51 assert project != null;
52 return new ClientNodeList(project);
53 }
54
55 private class ClientNodeList implements NodeList<Node> {
56
57 private final Project project;
58
59 public ClientNodeList(Project project) {
60 this.project = project;
61 }
62
63 @Override
64 public List<Node> keys() {
65 FileObject projectDirectory = project.getProjectDirectory();
66 FileObject config = projectDirectory.getFileObject("client.cfg");
67 FileObject info = projectDirectory.getFileObject("unitinfo.txt");
68 FileObject log = projectDirectory.getFileObject("FAHlog.txt");
69 FileObject queue = projectDirectory.getFileObject("queue.dat");
70
71 List<Node> result = new ArrayList<Node>();
72 try {
73 result.add(DataObject.find(config).getNodeDelegate());
74 result.add(DataObject.find(info).getNodeDelegate());
75 result.add(DataObject.find(log).getNodeDelegate());
76 result.add(DataObject.find(queue).getNodeDelegate());
77 } catch (DataObjectNotFoundException ex) {
78 Exceptions.printStackTrace(ex);
79 }
80 return result;
81 }
82
83 @Override
84 public void addChangeListener(ChangeListener l) {}
85
86 @Override
87 public void removeChangeListener(ChangeListener l) {}
88
89 @Override
90 public Node node(Node key) {
91 return new FilterNode(key);
92 }
93
94 @Override
95 public void addNotify() {}
96
97 @Override
98 public void removeNotify() {}
99 }
100 }