KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > project > support > ProjectOperations


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.project.support;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26 import org.netbeans.api.project.Project;
27 import org.netbeans.spi.project.CopyOperationImplementation;
28 import org.netbeans.spi.project.DataFilesProviderImplementation;
29 import org.netbeans.spi.project.DeleteOperationImplementation;
30 import org.netbeans.spi.project.MoveOperationImplementation;
31 import org.openide.filesystems.FileObject;
32
33 /**
34  * Allows gathering information for various project operations.
35  *
36  * @author Jan Lahoda
37  * @since 1.7
38  */

39 public final class ProjectOperations {
40     
41     private ProjectOperations() {
42     }
43     
44     /**Return list of files that are considered metadata files and folders for the given project.
45      * Returns meaningful values only if some of the <code>is*Supported</code> methods
46      * return <code>true</code>.
47      *
48      * @param prj project to test
49      * @return list of metadata files/folders
50      */

51     public static List JavaDoc<FileObject> getMetadataFiles(Project prj) {
52         List JavaDoc<FileObject> result = new ArrayList JavaDoc<FileObject>();
53         
54         for (DataFilesProviderImplementation i : prj.getLookup().lookupAll(DataFilesProviderImplementation.class)) {
55             result.addAll(i.getMetadataFiles());
56             assert !result.contains(null) : "Nulls in " + result + " from " + i;
57         }
58         
59         return result;
60     }
61             
62     /**Return list of files that are considered source files and folders for the given project.
63      * Returns meaningful values only if some of the <code>is*Supported</code> methods
64      * return <code>true</code>.
65      *
66      * @param prj project to test
67      * @return list of data files/folders
68      */

69     public static List JavaDoc<FileObject> getDataFiles(Project prj) {
70         List JavaDoc<FileObject> result = new ArrayList JavaDoc<FileObject>();
71         
72         for (DataFilesProviderImplementation i : prj.getLookup().lookupAll(DataFilesProviderImplementation.class)) {
73             result.addAll(i.getDataFiles());
74             assert !result.contains(null) : "Nulls in " + result + " from " + i;
75         }
76         
77         return result;
78     }
79     
80     /**Test whether the delete operation is supported on the given project.
81      *
82      * @param prj project to test
83      * @return <code>true</code> if the project supports delete operation,
84      * <code>false</code> otherwise
85      */

86     public static boolean isDeleteOperationSupported(Project prj) {
87         return prj.getLookup().lookup(DeleteOperationImplementation.class) != null;
88     }
89     
90     /**Notification that the project is about to be deleted.
91      * Should be called immediately before the project is deleted.
92      *
93      * The project is supposed to do all required cleanup to allow the project to be deleted.
94      *
95      * @param prj project to notify
96      * @throws IOException is some error occurs
97      */

98     public static void notifyDeleting(Project prj) throws IOException JavaDoc {
99         for (DeleteOperationImplementation i : prj.getLookup().lookupAll(DeleteOperationImplementation.class)) {
100             i.notifyDeleting();
101         }
102     }
103     
104     /**Notification that the project has been deleted.
105      * Should be called immediately after the project is deleted.
106      *
107      * @param prj project to notify
108      * @throws IOException is some error occurs
109      */

110     public static void notifyDeleted(Project prj) throws IOException JavaDoc {
111         for (DeleteOperationImplementation i : prj.getLookup().lookupAll(DeleteOperationImplementation.class)) {
112             i.notifyDeleted();
113         }
114     }
115     
116     /**Test whether the copy operation is supported on the given project.
117      *
118      * @param prj project to test
119      * @return <code>true</code> if the project supports the copy operation,
120      * <code>false</code> otherwise
121      */

122     public static boolean isCopyOperationSupported(Project prj) {
123         return prj.getLookup().lookup(CopyOperationImplementation.class) != null;
124     }
125     
126     /**Notification that the project is about to be copyied.
127      * Should be called immediatelly before the project is copied.
128      *
129      * The project is supposed to do all required cleanup to allow the project to be copied.
130      *
131      * @param prj project to notify
132      * @throws IOException is some error occurs
133      */

134     public static void notifyCopying(Project prj) throws IOException JavaDoc {
135         for (CopyOperationImplementation i : prj.getLookup().lookupAll(CopyOperationImplementation.class)) {
136             i.notifyCopying();
137         }
138     }
139     
140     /**Notification that the project has been copied.
141      * Should be called immediatelly after the project is copied.
142      *
143      * The project is supposed to do all necessary fixes to the project's structure to
144      * form a valid project.
145      *
146      * Both original and newly created project (copy) are notified, in this order.
147      *
148      * @param original original project
149      * @param nue new project (copy)
150      * @param originalPath the project folder of the original project (for consistency with notifyMoved)
151      * @param name new name of the project
152      * @throws IOException is some error occurs
153      */

154     public static void notifyCopied(Project original, Project nue, File JavaDoc originalPath, String JavaDoc name) throws IOException JavaDoc {
155         for (CopyOperationImplementation i : original.getLookup().lookupAll(CopyOperationImplementation.class)) {
156             i.notifyCopied(null, originalPath, name);
157         }
158         for (CopyOperationImplementation i : nue.getLookup().lookupAll(CopyOperationImplementation.class)) {
159             i.notifyCopied(original, originalPath, name);
160         }
161     }
162     
163     /**Notification that the project is about to be moved.
164      * Should be called immediately before the project is moved.
165      *
166      * The project is supposed to do all required cleanup to allow the project to be moved.
167      *
168      * @param prj project to notify
169      * @throws IOException is some error occurs
170      */

171     public static void notifyMoving(Project prj) throws IOException JavaDoc {
172         for (MoveOperationImplementation i : prj.getLookup().lookupAll(MoveOperationImplementation.class)) {
173             i.notifyMoving();
174         }
175     }
176     
177     /**Notification that the project has been moved.
178      * Should be called immediatelly after the project is moved.
179      *
180      * The project is supposed to do all necessary fixes to the project's structure to
181      * form a valid project.
182      *
183      * Both original and moved project are notified, in this order.
184      *
185      * @param original original project
186      * @param nue moved project
187      * @param originalPath the project folder of the original project
188      * @param name new name of the project
189      * @throws IOException is some error occurs
190      */

191     public static void notifyMoved(Project original, Project nue, File JavaDoc originalPath, String JavaDoc name) throws IOException JavaDoc {
192         for (MoveOperationImplementation i : original.getLookup().lookupAll(MoveOperationImplementation.class)) {
193             i.notifyMoved(null, originalPath, name);
194         }
195         for (MoveOperationImplementation i : nue.getLookup().lookupAll(MoveOperationImplementation.class)) {
196             i.notifyMoved(original, originalPath, name);
197         }
198     }
199     
200     /**
201      * Tests whether the move or rename operations are supported on the given project.
202      *
203      * @param prj project to test
204      * @return <code>true</code> if the project supports the move operation,
205      * <code>false</code> otherwise
206      */

207     public static boolean isMoveOperationSupported(Project prj) {
208         return true; // XXX ???
209
}
210     
211 }
212
Popular Tags