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