001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.spi.project.ui.support;
042:
043: import org.netbeans.api.project.Project;
044: import org.netbeans.spi.project.support.ProjectOperations;
045: import org.netbeans.modules.project.uiapi.DefaultProjectOperationsImplementation;
046:
047: /**Support class to allow the project type implementors to perform {@link ProjectOperations}
048: * by simply calling a method in this class. Each method in this class provides a default
049: * confirmation dialog and default behavior.
050: *
051: * If the project type requires a different behavior of an operation, it is required to provide its
052: * own implementation of the operation.
053: *
054: * @since 1.10
055: * @author Jan Lahoda
056: */
057: public final class DefaultProjectOperations {
058:
059: /**
060: * Creates a new instance of DefaultProjectOperations
061: */
062: private DefaultProjectOperations() {
063: }
064:
065: /**Perform default delete operation. Gathers all necessary data, shows a confirmation
066: * dialog and deletes the project (if confirmed by the user).
067: *
068: * @since 1.10
069: *
070: * @param p project to delete
071: * @throws IllegalArgumentException if
072: * <code>p == null</code> or
073: * if {@link org.netbeans.spi.project.support.ProjectOperations#isDeleteOperationSupported}
074: * returns false for this project.
075: */
076: public static void performDefaultDeleteOperation(Project p)
077: throws IllegalArgumentException {
078: if (p == null) {
079: throw new IllegalArgumentException("Project is null");
080: }
081:
082: if (!ProjectOperations.isDeleteOperationSupported(p)) {
083: throw new IllegalStateException(
084: "Attempt to delete project that does not support deletion.");
085: }
086:
087: DefaultProjectOperationsImplementation.deleteProject(p);
088: }
089:
090: /**Perform default copy operation. Gathers all necessary data, shows a confirmation
091: * dialog and copies the project (if confirmed by the user).
092: *
093: * @since 1.10
094: *
095: * @param p project to copy
096: * @throws IllegalArgumentException if
097: * <code>p == null</code> or
098: * {@link org.netbeans.spi.project.support.ProjectOperations#isCopyOperationSupported}
099: * returns false for this project.
100: */
101: public static void performDefaultCopyOperation(Project p)
102: throws IllegalArgumentException {
103: if (p == null) {
104: throw new IllegalArgumentException("Project is null");
105: }
106:
107: if (!ProjectOperations.isCopyOperationSupported(p)) {
108: throw new IllegalStateException(
109: "Attempt to delete project that does not support copy.");
110: }
111:
112: DefaultProjectOperationsImplementation.copyProject(p);
113: }
114:
115: /**Perform default move operation. Gathers all necessary data, shows a confirmation
116: * dialog and moves the project (if confirmed by the user).
117: *
118: * @since 1.10
119: *
120: * @param p project to move
121: * @throws IllegalArgumentException if
122: * <code>p == null</code> or
123: * {@link ProjectOperations#isMoveOperationSupported}
124: * returns false for this project.
125: */
126: public static void performDefaultMoveOperation(Project p)
127: throws IllegalArgumentException {
128: if (p == null) {
129: throw new IllegalArgumentException("Project is null");
130: }
131:
132: if (!ProjectOperations.isMoveOperationSupported(p)) {
133: throw new IllegalArgumentException(
134: "Attempt to delete project that does not support move.");
135: }
136:
137: DefaultProjectOperationsImplementation.moveProject(p);
138: }
139:
140: /**Perform default rename operation. Gathers all necessary data, shows a confirmation
141: * dialog and renames the project (if confirmed by the user).
142: *
143: * @since 1.10
144: *
145: * @param p project to move
146: * @param newName new project's name or null
147: * @throws IllegalArgumentException if
148: * <code>p == null</code> or
149: * {@link ProjectOperations#isMoveOperationSupported}
150: * returns false for this project.
151: */
152: public static void performDefaultRenameOperation(Project p,
153: String newName) throws IllegalArgumentException {
154: if (p == null) {
155: throw new IllegalArgumentException("Project is null");
156: }
157:
158: if (!ProjectOperations.isMoveOperationSupported(p)) {
159: throw new IllegalArgumentException(
160: "Attempt to delete project that does not support move.");
161: }
162:
163: DefaultProjectOperationsImplementation
164: .renameProject(p, newName);
165: }
166:
167: }
|