View Javadoc
1   package info.mikethomas.fahview.v6project.nodes;
2   
3   /*
4    * #%L
5    * This file is part of FAHView-v6project.
6    * %%
7    * Copyright (C) 2011 - 2017 Mike Thomas <mikepthomas@outlook.com>
8    * %%
9    * FAHView is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as published by
11   * the Free Software Foundation, either version 3 of the License, or
12   * (at your option) any later version.
13   * %
14   * FAHView is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * %
19   * You should have received a copy of the GNU General Public License
20   * along with FAHView.  If not, see <http://www.gnu.org/licenses/>.
21   * #L%
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   * <p>WorkNodeFactory class.</p>
40   *
41   * @author <a href="mailto:mikepthomas@outlook.com">Michael Thomas</a>
42   * @version $Id: $Id
43   */
44  @NodeFactory.Registration(projectType = "info-mikethomas-fahview-work", position = 10)
45  public class WorkNodeFactory implements NodeFactory {
46  
47      /** {@inheritDoc} */
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 }