Added
Link Here
|
1 |
/* |
2 |
* Sun Public License Notice |
3 |
* |
4 |
* The contents of this file are subject to the Sun Public License |
5 |
* Version 1.0 (the "License"). You may not use this file except in |
6 |
* compliance with the License. A copy of the License is available at |
7 |
* http://www.sun.com/ |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
|
14 |
package org.netbeans.spi.project.support; |
15 |
|
16 |
import java.io.File; |
17 |
import java.io.IOException; |
18 |
import java.util.ArrayList; |
19 |
import java.util.Collection; |
20 |
import java.util.Iterator; |
21 |
import java.util.List; |
22 |
import org.netbeans.api.project.Project; |
23 |
import org.netbeans.spi.project.CopyOperationImplementation; |
24 |
import org.netbeans.spi.project.DataFilesProviderImplementation; |
25 |
import org.netbeans.spi.project.DeleteOperationImplementation; |
26 |
import org.netbeans.spi.project.MoveOperationImplementation; |
27 |
import org.openide.util.Lookup; |
28 |
|
29 |
/** |
30 |
* Allows gathering information for various project operations. |
31 |
* |
32 |
* @author Jan Lahoda |
33 |
* @since 1.7 |
34 |
*/ |
35 |
public final class ProjectOperations { |
36 |
|
37 |
private ProjectOperations() { |
38 |
} |
39 |
|
40 |
/**Return list of files that are considered metadata files and folders for the given project. |
41 |
* Returns meaningfull values only if some of the <code>is*Supported</code> methods |
42 |
* return <code>true</code>. |
43 |
* |
44 |
* @param prj project to test |
45 |
* @return list of metadata files/folders |
46 |
*/ |
47 |
public static List/*<FileObject>*/ getMetadataFiles(Project prj) { |
48 |
List/*<FileObject>*/ result = new ArrayList(); |
49 |
|
50 |
for (Iterator i = getProjectsOperationsImplementation(prj).iterator(); i.hasNext(); ) { |
51 |
result.addAll(((DataFilesProviderImplementation) i.next()).getMetadataFiles()); |
52 |
} |
53 |
|
54 |
return result; |
55 |
} |
56 |
|
57 |
/**Return list of files that are considered source files and folders for the given project. |
58 |
* Returns meaningfull values only if some of the <code>is*Supported</code> methods |
59 |
* return <code>true</code>. |
60 |
* |
61 |
* @param prj project to test |
62 |
* @return list of data files/folders |
63 |
*/ |
64 |
public static List/*<FileObject>*/ getDataFiles(Project prj) { |
65 |
List/*<FileObject>*/ result = new ArrayList(); |
66 |
|
67 |
for (Iterator i = getProjectsOperationsImplementation(prj).iterator(); i.hasNext(); ) { |
68 |
result.addAll(((DataFilesProviderImplementation) i.next()).getDataFiles()); |
69 |
} |
70 |
|
71 |
return result; |
72 |
} |
73 |
|
74 |
/**Test whether the delete operation is supported on the given project. |
75 |
* |
76 |
* @param prj project to test |
77 |
* @return <code>true</code> if the project supports delete operation, |
78 |
* <code>false</code> otherwise |
79 |
*/ |
80 |
public static boolean isDeleteOperationSupported(Project prj) { |
81 |
return !getDeleteOperationImplementation(prj).isEmpty(); |
82 |
} |
83 |
|
84 |
/**Notification that the project is about to be deleted. |
85 |
* Should be called immediatelly before the project is deleted. |
86 |
* |
87 |
* The project is supposed to do all required cleanup to allow the project to be deleted. |
88 |
* |
89 |
* @param prj project to notify |
90 |
* @throws IOException is some error occurs |
91 |
*/ |
92 |
public static void notifyDeleting(Project prj) throws IOException { |
93 |
for (Iterator i = getDeleteOperationImplementation(prj).iterator(); i.hasNext(); ) { |
94 |
((DeleteOperationImplementation) i.next()).notifyDeleting(); |
95 |
} |
96 |
} |
97 |
|
98 |
/**Notification that the project has been deleted. |
99 |
* Should be called immediatelly after the project is deleted. |
100 |
* |
101 |
* @param prj project to notify |
102 |
* @throws IOException is some error occurs |
103 |
*/ |
104 |
public static void notifyDeleted(Project prj) throws IOException { |
105 |
for (Iterator i = getDeleteOperationImplementation(prj).iterator(); i.hasNext(); ) { |
106 |
((DeleteOperationImplementation) i.next()).notifyDeleted(); |
107 |
} |
108 |
} |
109 |
|
110 |
/**Test whether the copy operation is supported on the given project. |
111 |
* |
112 |
* @param prj project to test |
113 |
* @return <code>true</code> if the project supports the copy operation, |
114 |
* <code>false</code> otherwise |
115 |
*/ |
116 |
public static boolean isCopyOperationSupported(Project prj) { |
117 |
return !getCopyOperationImplementation(prj).isEmpty(); |
118 |
} |
119 |
|
120 |
/**Notification that the project is about to be copyied. |
121 |
* Should be called immediatelly before the project is copied. |
122 |
* |
123 |
* The project is supposed to do all required cleanup to allow the project to be copied. |
124 |
* |
125 |
* @param prj project to notify |
126 |
* @throws IOException is some error occurs |
127 |
*/ |
128 |
public static void notifyCopying(Project prj) throws IOException { |
129 |
for (Iterator i = getCopyOperationImplementation(prj).iterator(); i.hasNext(); ) { |
130 |
((CopyOperationImplementation) i.next()).notifyCopying(); |
131 |
} |
132 |
} |
133 |
|
134 |
/**Notification that the project has been copied. |
135 |
* Should be called immediatelly after the project is copied. |
136 |
* |
137 |
* The project is supposed to do all necessary fixes to the project's structure to |
138 |
* form a valid project. |
139 |
* |
140 |
* Both original and newly created project (copy) are notified, in this order. |
141 |
* |
142 |
* @param original original project |
143 |
* @param nue new project (copy) |
144 |
* @param originalPath the project folder of the original project (for consistency with notifyMoved) |
145 |
* @param name new name of the project |
146 |
* @throws IOException is some error occurs |
147 |
*/ |
148 |
public static void notifyCopied(Project original, Project nue, File originalPath, String name) throws IOException { |
149 |
for (Iterator i = getCopyOperationImplementation(original).iterator(); i.hasNext(); ) { |
150 |
((CopyOperationImplementation) i.next()).notifyCopied(original, originalPath, name); |
151 |
} |
152 |
for (Iterator i = getCopyOperationImplementation(nue).iterator(); i.hasNext(); ) { |
153 |
((CopyOperationImplementation) i.next()).notifyCopied(original, originalPath, name); |
154 |
} |
155 |
} |
156 |
|
157 |
/**Notification that the project is about to be moved. |
158 |
* Should be called immediatelly before the project is moved. |
159 |
* |
160 |
* The project is supposed to do all required cleanup to allow the project to be moved. |
161 |
* |
162 |
* @param prj project to notify |
163 |
* @throws IOException is some error occurs |
164 |
*/ |
165 |
public static void notifyMoving(Project prj) throws IOException { |
166 |
for (Iterator i = getMoveOperationImplementation(prj).iterator(); i.hasNext(); ) { |
167 |
((MoveOperationImplementation) i.next()).notifyMoving(); |
168 |
} |
169 |
} |
170 |
|
171 |
/**Notification that the project has been moved. |
172 |
* Should be called immediatelly after the project is moved. |
173 |
* |
174 |
* The project is supposed to do all necessary fixes to the project's structure to |
175 |
* form a valid project. |
176 |
* |
177 |
* Both original and moved project are notified, in this order. |
178 |
* |
179 |
* @param original original project |
180 |
* @param nue moved project |
181 |
* @param originalPath the project folder of the original project |
182 |
* @param name new name of the project |
183 |
* @throws IOException is some error occurs |
184 |
*/ |
185 |
public static void notifyMoved(Project original, Project nue, File originalPath, String name) throws IOException { |
186 |
for (Iterator i = getMoveOperationImplementation(original).iterator(); i.hasNext(); ) { |
187 |
((MoveOperationImplementation) i.next()).notifyMoved(original, originalPath, name); |
188 |
} |
189 |
for (Iterator i = getMoveOperationImplementation(nue).iterator(); i.hasNext(); ) { |
190 |
((MoveOperationImplementation) i.next()).notifyMoved(original, originalPath, name); |
191 |
} |
192 |
} |
193 |
|
194 |
/**Test whether the move operation is supported on the given project. |
195 |
* |
196 |
* @param prj project to test |
197 |
* @return <code>true</code> if the project supports the move operation, |
198 |
* <code>false</code> otherwise |
199 |
*/ |
200 |
public static boolean isMoveOperationSupported(Project prj) { |
201 |
return true; |
202 |
} |
203 |
|
204 |
private static Collection/*<DeleteOperationImplementation>*/ getDeleteOperationImplementation(Project prj) { |
205 |
return prj.getLookup().lookup(new Lookup.Template(DeleteOperationImplementation.class)).allInstances(); |
206 |
} |
207 |
|
208 |
private static Collection/*<DataFilesProviderImplementation>*/ getProjectsOperationsImplementation(Project prj) { |
209 |
return prj.getLookup().lookup(new Lookup.Template(DataFilesProviderImplementation.class)).allInstances(); |
210 |
} |
211 |
|
212 |
private static Collection/*<CopyOperationImplementation>*/ getCopyOperationImplementation(Project prj) { |
213 |
return prj.getLookup().lookup(new Lookup.Template(CopyOperationImplementation.class)).allInstances(); |
214 |
} |
215 |
|
216 |
private static Collection/*<MoveOperationImplementation>*/ getMoveOperationImplementation(Project prj) { |
217 |
return prj.getLookup().lookup(new Lookup.Template(MoveOperationImplementation.class)).allInstances(); |
218 |
} |
219 |
|
220 |
} |