1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package net.sf.webphotos.netbeans.project; |
17 | |
|
18 | |
import java.beans.PropertyChangeListener; |
19 | |
import java.io.File; |
20 | |
import java.io.IOException; |
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Arrays; |
23 | |
import java.util.Collections; |
24 | |
import java.util.HashMap; |
25 | |
import java.util.List; |
26 | |
import java.util.Map; |
27 | |
import javax.swing.Icon; |
28 | |
import javax.swing.ImageIcon; |
29 | |
import org.netbeans.api.project.Project; |
30 | |
import org.netbeans.api.project.ProjectInformation; |
31 | |
import org.netbeans.spi.project.ActionProvider; |
32 | |
import org.netbeans.spi.project.CopyOperationImplementation; |
33 | |
import org.netbeans.spi.project.DeleteOperationImplementation; |
34 | |
import org.netbeans.spi.project.ProjectState; |
35 | |
import org.netbeans.spi.project.ui.support.DefaultProjectOperations; |
36 | |
import org.openide.filesystems.FileObject; |
37 | |
import org.openide.util.Exceptions; |
38 | |
import org.openide.util.ImageUtilities; |
39 | |
import org.openide.util.Lookup; |
40 | |
import org.openide.util.lookup.Lookups; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public class WebPhotosProject implements Project { |
47 | |
|
48 | |
private final FileObject projectDirectory; |
49 | |
private final ProjectState state; |
50 | |
private Lookup lkp; |
51 | |
|
52 | 3 | public WebPhotosProject(FileObject projectDir, ProjectState state) { |
53 | 3 | this.projectDirectory = projectDir; |
54 | 3 | this.state = state; |
55 | 3 | } |
56 | |
|
57 | |
FileObject getFolder(int folder, boolean create) { |
58 | 0 | FileObject result = |
59 | |
projectDirectory.getFileObject(WebPhotosProjectFactory.PROJECT_ARCHIVES[folder]).getParent(); |
60 | 0 | if (result == null && create) { |
61 | |
try { |
62 | 0 | result = projectDirectory.createData(WebPhotosProjectFactory.PROJECT_ARCHIVES[folder]).getParent(); |
63 | 0 | } catch (IOException ioe) { |
64 | 0 | Exceptions.printStackTrace(ioe); |
65 | 0 | } |
66 | |
} |
67 | 0 | return result; |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
public FileObject getProjectDirectory() { |
72 | 0 | return projectDirectory; |
73 | |
} |
74 | |
|
75 | |
@Override |
76 | |
public Lookup getLookup() { |
77 | 0 | if (lkp == null) { |
78 | 0 | lkp = Lookups.fixed(new Object[]{ |
79 | |
state, |
80 | |
new ActionProviderImpl(), |
81 | |
new WebPhotosDeleteOperation(), |
82 | |
new WebPhotosCopyOperation(this), |
83 | |
new WebPhotosProjectInformation(), |
84 | |
new WebPhotosProjectLogicalView(this), |
85 | |
}); |
86 | |
} |
87 | 0 | return lkp; |
88 | |
} |
89 | |
|
90 | |
private final class ActionProviderImpl implements ActionProvider { |
91 | |
|
92 | 0 | private Map<String, Runnable> supportedOps = new HashMap<String, Runnable>(); |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | 0 | public ActionProviderImpl() { |
98 | 0 | supportedOps.put(ActionProvider.COMMAND_COPY, new Runnable() { |
99 | |
|
100 | |
@Override |
101 | |
public void run() { |
102 | 0 | DefaultProjectOperations.performDefaultCopyOperation(WebPhotosProject.this); |
103 | 0 | } |
104 | |
}); |
105 | 0 | supportedOps.put(ActionProvider.COMMAND_DELETE, new Runnable() { |
106 | |
|
107 | |
@Override |
108 | |
public void run() { |
109 | 0 | DefaultProjectOperations.performDefaultDeleteOperation(WebPhotosProject.this); |
110 | 0 | } |
111 | |
}); |
112 | 0 | } |
113 | |
|
114 | |
|
115 | |
|
116 | |
@Override |
117 | |
public String[] getSupportedActions() { |
118 | 0 | return supportedOps.keySet().toArray(new String[supportedOps.keySet().size()]); |
119 | |
} |
120 | |
|
121 | |
@Override |
122 | |
public void invokeAction(String action, Lookup lookup) throws IllegalArgumentException { |
123 | 0 | supportedOps.get(action).run(); |
124 | 0 | } |
125 | |
|
126 | |
@Override |
127 | |
public boolean isActionEnabled(String command, Lookup lookup) throws IllegalArgumentException { |
128 | 0 | if (Arrays.binarySearch(getSupportedActions(), command) >= 0) { |
129 | 0 | return true; |
130 | |
} else { |
131 | 0 | throw new IllegalArgumentException(command); |
132 | |
} |
133 | |
} |
134 | |
} |
135 | |
|
136 | 0 | private final class WebPhotosDeleteOperation implements DeleteOperationImplementation { |
137 | |
|
138 | |
@Override |
139 | |
public void notifyDeleting() throws IOException { |
140 | 0 | } |
141 | |
|
142 | |
@Override |
143 | |
public void notifyDeleted() throws IOException { |
144 | 0 | } |
145 | |
|
146 | |
@Override |
147 | |
public List<FileObject> getMetadataFiles() { |
148 | 0 | List<FileObject> dataFiles = new ArrayList<FileObject>(); |
149 | 0 | return dataFiles; |
150 | |
} |
151 | |
|
152 | |
@Override |
153 | |
public List<FileObject> getDataFiles() { |
154 | 0 | List<FileObject> dataFiles = new ArrayList<FileObject>(); |
155 | 0 | return dataFiles; |
156 | |
} |
157 | |
} |
158 | |
|
159 | |
private class WebPhotosCopyOperation implements CopyOperationImplementation { |
160 | |
|
161 | |
private final WebPhotosProject project; |
162 | |
private final FileObject projectDir; |
163 | |
|
164 | 0 | public WebPhotosCopyOperation(WebPhotosProject project) { |
165 | 0 | this.project = project; |
166 | 0 | this.projectDir = project.getProjectDirectory(); |
167 | 0 | } |
168 | |
|
169 | |
@Override |
170 | |
public void notifyCopying() throws IOException { |
171 | 0 | } |
172 | |
|
173 | |
@Override |
174 | |
public void notifyCopied(Project arg0, File arg1, String arg2) throws IOException { |
175 | 0 | } |
176 | |
|
177 | |
@Override |
178 | |
public List<FileObject> getMetadataFiles() { |
179 | 0 | return Collections.EMPTY_LIST; |
180 | |
} |
181 | |
|
182 | |
@Override |
183 | |
public List<FileObject> getDataFiles() { |
184 | 0 | return Collections.EMPTY_LIST; |
185 | |
} |
186 | |
} |
187 | |
|
188 | 0 | private final class WebPhotosProjectInformation implements ProjectInformation { |
189 | |
|
190 | |
@Override |
191 | |
public String getName() { |
192 | 0 | return getProjectDirectory().getName(); |
193 | |
} |
194 | |
|
195 | |
@Override |
196 | |
public String getDisplayName() { |
197 | 0 | return getName(); |
198 | |
} |
199 | |
|
200 | |
@Override |
201 | |
public Icon getIcon() { |
202 | 0 | return new ImageIcon(ImageUtilities.loadImage( |
203 | |
Constants.PROJECT_ICON)); |
204 | |
} |
205 | |
|
206 | |
@Override |
207 | |
public Project getProject() { |
208 | 0 | return WebPhotosProject.this; |
209 | |
} |
210 | |
|
211 | |
@Override |
212 | |
public void addPropertyChangeListener(PropertyChangeListener arg0) { |
213 | |
|
214 | 0 | assert arg0 != null : arg0; |
215 | 0 | } |
216 | |
|
217 | |
@Override |
218 | |
public void removePropertyChangeListener(PropertyChangeListener arg0) { |
219 | |
|
220 | 0 | assert arg0 != null : arg0; |
221 | 0 | } |
222 | |
} |
223 | |
} |