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.WorkProject;
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-work", position = 10)
45 public class WorkNodeFactory implements NodeFactory {
46
47
48 @Override
49 public NodeList<?> createNodes(Project p) {
50 WorkProject project = p.getLookup().lookup(WorkProject.class);
51 assert project != null;
52 return new WorkNodeList(project);
53 }
54
55 private class WorkNodeList implements NodeList<Node> {
56
57 private final Project project;
58
59 public WorkNodeList(Project project) {
60 this.project = project;
61 }
62
63 @Override
64 public List<Node> keys() {
65 FileObject projectDirectory = project.getProjectDirectory();
66
67 List<Node> result = new ArrayList<Node>();
68 try {
69 FileObject work = projectDirectory.getFileObject("current.xyz");
70 result.add(DataObject.find(work).getNodeDelegate());
71
72 for(int i = 0; i <= 9; i++)
73 {
74 FileObject log = projectDirectory.getFileObject("logfile_0" + i + ".txt");
75 FileObject data = projectDirectory.getFileObject("wudata_0" + i + ".log");
76 if(log != null)
77 result.add(DataObject.find(log).getNodeDelegate());
78 if(data != null)
79 result.add(DataObject.find(data).getNodeDelegate());
80 }
81
82 } catch (DataObjectNotFoundException ex) {
83 Exceptions.printStackTrace(ex);
84 }
85 return result;
86 }
87
88 @Override
89 public void addChangeListener(ChangeListener l) {}
90
91 @Override
92 public void removeChangeListener(ChangeListener l) {}
93
94 @Override
95 public Node node(Node key) {
96 return new FilterNode(key);
97 }
98
99 @Override
100 public void addNotify() {}
101
102 @Override
103 public void removeNotify() {}
104 }
105 }