1 package info.mikethomas.fahview.v6project;
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 java.io.IOException;
25 import java.util.Collections;
26 import java.util.HashSet;
27 import java.util.Set;
28 import javax.swing.event.ChangeListener;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.api.project.ProjectManager;
31 import org.netbeans.spi.project.SubprojectProvider;
32 import org.openide.filesystems.FileObject;
33 import org.openide.util.Exceptions;
34
35 /**
36 * <p>ClientSubprojectProvider class.</p>
37 *
38 * @author <a href="mailto:mikepthomas@outlook.com">Michael Thomas</a>
39 * @version $Id: $Id
40 */
41 public class ClientSubprojectProvider implements SubprojectProvider {
42
43 /** Project <code>project</code>. */
44 private final Project project;
45
46 /**
47 * <p>Constructor for ClientSubprojectProvider.</p>
48 *
49 * @param parentProject a {@link org.netbeans.api.project.Project} object.
50 */
51 public ClientSubprojectProvider(final Project parentProject) {
52 this.project = parentProject;
53 }
54
55 /** {@inheritDoc} */
56 @Override
57 public final Set<?extends Project> getSubprojects() {
58 Set<Project> newProjects = new HashSet<Project>();
59 FileObject dir = project.getProjectDirectory();
60 if (dir != null) {
61 for (FileObject childFolder : dir.getChildren()) {
62 try {
63 Project subp = ProjectManager.getDefault().
64 findProject(childFolder);
65 if (subp != null) {
66 newProjects.add(subp);
67 }
68 } catch (IOException ex) {
69 Exceptions.printStackTrace(ex);
70 } catch (IllegalArgumentException ex) {
71 // Do nothing
72 }
73 }
74 }
75 return Collections.unmodifiableSet(newProjects);
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 public void addChangeListener(final ChangeListener listener) { }
81
82 /** {@inheritDoc} */
83 @Override
84 public void removeChangeListener(final ChangeListener listener) { }
85 }