1 package info.mikethomas.fahview.v6project;
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.properties.ClientCustomizerProvider;
25 import java.awt.Image;
26 import java.beans.PropertyChangeListener;
27 import javax.swing.Action;
28 import javax.swing.Icon;
29 import javax.swing.ImageIcon;
30 import org.netbeans.api.annotations.common.StaticResource;
31 import org.netbeans.api.project.Project;
32 import org.netbeans.api.project.ProjectInformation;
33 import org.netbeans.spi.project.ProjectState;
34 import org.netbeans.spi.project.ui.LogicalViewProvider;
35 import org.netbeans.spi.project.ui.support.CommonProjectActions;
36 import org.netbeans.spi.project.ui.support.NodeFactorySupport;
37 import org.openide.filesystems.FileObject;
38 import org.openide.loaders.DataFolder;
39 import org.openide.loaders.DataObjectNotFoundException;
40 import org.openide.nodes.AbstractNode;
41 import org.openide.nodes.Children;
42 import org.openide.nodes.FilterNode;
43 import org.openide.nodes.Node;
44 import org.openide.util.Exceptions;
45 import org.openide.util.ImageUtilities;
46 import org.openide.util.Lookup;
47 import org.openide.util.lookup.Lookups;
48 import org.openide.util.lookup.ProxyLookup;
49
50
51
52
53
54
55
56 public class ClientProject implements Project {
57
58
59 @StaticResource()
60 public static final String PROJECT_ICON =
61 "info/mikethomas/fahview/v6project/client.png";
62
63 public static final String PROJECT_FILE = "client.cfg";
64
65
66 private final FileObject directory;
67
68 private final ProjectState state;
69
70 private Lookup lookup;
71
72
73
74
75
76
77
78 ClientProject(final FileObject projectDirectory,
79 final ProjectState projectState) {
80 this.directory = projectDirectory;
81 this.state = projectState;
82 }
83
84
85 @Override
86 public final FileObject getProjectDirectory() {
87 return directory;
88 }
89
90
91 @Override
92 public final Lookup getLookup() {
93 if (lookup == null) {
94 lookup = Lookups.fixed(new Object[] {
95 this,
96 new ClientProjectInformation(),
97 new ClientProjectLogicalView(this),
98 new ClientCustomizerProvider(this),
99 new ClientSubprojectProvider(this)
100 });
101 }
102 return lookup;
103 }
104
105
106
107
108 private final class ClientProjectInformation implements ProjectInformation {
109
110 @Override
111 public String getName() {
112 return getProjectDirectory().getName();
113 }
114
115 @Override
116 public String getDisplayName() {
117 return getName();
118 }
119
120 @Override
121 public Icon getIcon() {
122 return new ImageIcon(ImageUtilities.loadImage(PROJECT_ICON));
123 }
124
125 @Override
126 public Project getProject() {
127 return ClientProject.this;
128 }
129
130 @Override
131 public void addPropertyChangeListener(
132 final PropertyChangeListener listener) { }
133
134 @Override
135 public void removePropertyChangeListener(
136 final PropertyChangeListener listener) { }
137 }
138
139
140
141
142 private static class ClientProjectLogicalView
143 implements LogicalViewProvider {
144
145
146 private final ClientProject project;
147
148
149
150
151
152 public ClientProjectLogicalView(final ClientProject clientProject) {
153 this.project = clientProject;
154 }
155
156
157 @Override
158 public Node createLogicalView() {
159 try {
160
161 FileObject projectDirectory = project.getProjectDirectory();
162 DataFolder projectFolder = DataFolder.findFolder(projectDirectory);
163 Node nodeOfProjectFolder = projectFolder.getNodeDelegate();
164
165
166 return new ProjectNode(nodeOfProjectFolder, project);
167
168 } catch (DataObjectNotFoundException donfe) {
169 Exceptions.printStackTrace(donfe);
170
171
172 return new AbstractNode(Children.LEAF);
173 }
174 }
175
176 @Override
177 public Node findPath(final Node root, final Object target) {
178
179 return null;
180 }
181
182
183
184
185 private static class ProjectNode extends FilterNode {
186
187
188 private final ClientProject project;
189
190
191
192
193
194
195
196 public ProjectNode(final Node node,
197 final ClientProject clientProject)
198 throws DataObjectNotFoundException {
199
200 super(node,
201 NodeFactorySupport.createCompositeChildren(
202 clientProject,
203 "Projects/info-mikethomas-fahview-client/Nodes"),
204 new ProxyLookup(
205 new Lookup[]{
206 Lookups.singleton(clientProject),
207 node.getLookup()
208 }));
209
210 this.project = clientProject;
211 }
212
213 @Override
214 public Action[] getActions(final boolean arg0) {
215 return new Action[]{
216 CommonProjectActions.customizeProjectAction(),
217 CommonProjectActions.deleteProjectAction(),
218 CommonProjectActions.closeProjectAction()
219 };
220 }
221
222 @Override
223 public Image getIcon(final int type) {
224 return ImageUtilities.loadImage(PROJECT_ICON);
225 }
226
227 @Override
228 public Image getOpenedIcon(final int type) {
229 return getIcon(type);
230 }
231
232 @Override
233 public String getDisplayName() {
234 return project.getProjectDirectory().getName();
235 }
236 }
237 }
238 }