KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > project > ui > support > DefaultProjectOperations


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 package org.netbeans.spi.project.ui.support;
20
21 import org.netbeans.api.project.Project;
22 import org.netbeans.spi.project.support.ProjectOperations;
23 import org.netbeans.modules.project.uiapi.DefaultProjectOperationsImplementation;
24
25 /**Support class to allow the project type implementors to perform {@link ProjectOperations}
26  * by simply calling a method in this class. Each method in this class provides a default
27  * confirmation dialog and default behavior.
28  *
29  * If the project type requires a different behavior of an operation, it is required to provide its
30  * own implementation of the operation.
31  *
32  * @since 1.10
33  * @author Jan Lahoda
34  */

35 public final class DefaultProjectOperations {
36     
37     /**
38      * Creates a new instance of DefaultProjectOperations
39      */

40     private DefaultProjectOperations() {
41     }
42     
43     /**Perform default delete operation. Gathers all necessary data, shows a confirmation
44      * dialog and deletes the project (if confirmed by the user).
45      *
46      * @since 1.10
47      *
48      * @param p project to delete
49      * @throws IllegalArgumentException if
50      * <code>p == null</code> or
51      * if {@link org.netbeans.spi.project.support.ProjectOperations#isDeleteOperationSupported}
52      * returns false for this project.
53      */

54     public static void performDefaultDeleteOperation(Project p) throws IllegalArgumentException JavaDoc {
55         if (p == null) {
56             throw new IllegalArgumentException JavaDoc("Project is null");
57         }
58         
59         if (!ProjectOperations.isDeleteOperationSupported(p)) {
60             throw new IllegalStateException JavaDoc("Attempt to delete project that does not support deletion.");
61         }
62         
63         DefaultProjectOperationsImplementation.deleteProject(p);
64     }
65     
66     /**Perform default copy operation. Gathers all necessary data, shows a confirmation
67      * dialog and copies the project (if confirmed by the user).
68      *
69      * @since 1.10
70      *
71      * @param p project to copy
72      * @throws IllegalArgumentException if
73      * <code>p == null</code> or
74      * {@link org.netbeans.spi.project.support.ProjectOperations#isCopyOperationSupported}
75      * returns false for this project.
76      */

77     public static void performDefaultCopyOperation(Project p) throws IllegalArgumentException JavaDoc {
78         if (p == null) {
79             throw new IllegalArgumentException JavaDoc("Project is null");
80         }
81         
82         if (!ProjectOperations.isCopyOperationSupported(p)) {
83             throw new IllegalStateException JavaDoc("Attempt to delete project that does not support copy.");
84         }
85         
86         DefaultProjectOperationsImplementation.copyProject(p);
87     }
88     
89     /**Perform default move operation. Gathers all necessary data, shows a confirmation
90      * dialog and moves the project (if confirmed by the user).
91      *
92      * @since 1.10
93      *
94      * @param p project to move
95      * @throws IllegalArgumentException if
96      * <code>p == null</code> or
97      * {@link ProjectOperations#isMoveOperationSupported}
98      * returns false for this project.
99      */

100     public static void performDefaultMoveOperation(Project p) throws IllegalArgumentException JavaDoc {
101         if (p == null) {
102             throw new IllegalArgumentException JavaDoc("Project is null");
103         }
104         
105         if (!ProjectOperations.isMoveOperationSupported(p)) {
106             throw new IllegalArgumentException JavaDoc("Attempt to delete project that does not support move.");
107         }
108         
109         DefaultProjectOperationsImplementation.moveProject(p);
110     }
111     
112     /**Perform default rename operation. Gathers all necessary data, shows a confirmation
113      * dialog and renames the project (if confirmed by the user).
114      *
115      * @since 1.10
116      *
117      * @param p project to move
118      * @param newName new project's name or null
119      * @throws IllegalArgumentException if
120      * <code>p == null</code> or
121      * {@link ProjectOperations#isMoveOperationSupported}
122      * returns false for this project.
123      */

124     public static void performDefaultRenameOperation(Project p, String JavaDoc newName) throws IllegalArgumentException JavaDoc {
125         if (p == null) {
126             throw new IllegalArgumentException JavaDoc("Project is null");
127         }
128         
129         if (!ProjectOperations.isMoveOperationSupported(p)) {
130             throw new IllegalArgumentException JavaDoc("Attempt to delete project that does not support move.");
131         }
132         
133         DefaultProjectOperationsImplementation.renameProject(p, newName);
134     }
135     
136 }
137
Popular Tags