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.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   * <p>ClientSubProjectNodeFactory class.</p>
44   *
45   * @author <a href="mailto:mikepthomas@outlook.com">Michael Thomas</a>
46   * @version $Id: $Id
47   */
48  @NodeFactory.Registration(projectType = "info-mikethomas-fahview-client", position = 10)
49  public class ClientSubProjectNodeFactory implements NodeFactory {
50  
51      /** {@inheritDoc} */
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 }