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.modules.php.project;
042:
043: import java.io.File;
044: import java.io.IOException;
045: import java.util.ArrayList;
046: import java.util.Arrays;
047: import java.util.List;
048: import org.netbeans.api.project.Project;
049: import org.netbeans.spi.project.CopyOperationImplementation;
050: import org.netbeans.spi.project.DeleteOperationImplementation;
051: import org.netbeans.spi.project.MoveOperationImplementation;
052: import org.netbeans.spi.project.support.ant.AntProjectHelper;
053: import org.openide.filesystems.FileObject;
054:
055: /**
056: * @author ads
057: *
058: */
059: public class PhpProjectOperations implements
060: DeleteOperationImplementation, CopyOperationImplementation,
061: MoveOperationImplementation {
062:
063: public PhpProjectOperations(PhpProject project) {
064: this .myProject = project;
065: }
066:
067: /* (non-Javadoc)
068: * @see org.netbeans.spi.myProject.DeleteOperationImplementation#notifyDeleted()
069: */
070: public void notifyDeleted() throws IOException {
071: myProject.getHelper().notifyDeleted();
072: }
073:
074: /* (non-Javadoc)
075: * @see org.netbeans.spi.myProject.DeleteOperationImplementation#notifyDeleting()
076: */
077: public void notifyDeleting() throws IOException {
078: // TODO Auto-generated method stub
079: }
080:
081: /* (non-Javadoc)
082: * @see org.netbeans.spi.myProject.CopyOperationImplementation#notifyCopied(org.netbeans.api.myProject.Project, java.io.File, java.lang.String)
083: */
084: public void notifyCopied(Project originalProject, File file,
085: String newName) throws IOException {
086: if (originalProject == null) {
087: // do nothing for the original myProject.
088: return;
089: }
090:
091: String oldName = myProject.getName();
092: myProject.setName(newName);
093: }
094:
095: /* (non-Javadoc)
096: * @see org.netbeans.spi.myProject.CopyOperationImplementation#notifyCopying()
097: */
098: public void notifyCopying() throws IOException {
099: // TODO Auto-generated method stub
100: }
101:
102: /* (non-Javadoc)
103: * @see org.netbeans.spi.myProject.MoveOperationImplementation#notifyMoved(org.netbeans.api.myProject.Project, java.io.File, java.lang.String)
104: */
105: public void notifyMoved(Project originalProject, File file,
106: String newName) throws IOException {
107: if (originalProject == null) {
108: myProject.getHelper().notifyDeleted();
109: return;
110: }
111: String oldName = myProject.getName();
112: myProject.setName(newName);
113: }
114:
115: /* (non-Javadoc)
116: * @see org.netbeans.spi.myProject.MoveOperationImplementation#notifyMoving()
117: */
118: public void notifyMoving() throws IOException {
119: // TODO Auto-generated method stub
120: }
121:
122: /* (non-Javadoc)
123: * @see org.netbeans.spi.myProject.DataFilesProviderImplementation#getDataFiles()
124: */
125: public List<FileObject> getDataFiles() {
126: List<FileObject> files = new ArrayList<FileObject>();
127:
128: // It seems that we add all sources, including external
129: FileObject[] sources = Utils.getSourceObjects(myProject);
130: files.addAll(Arrays.asList(sources));
131:
132: // TODO check that all files are added...
133: /* SRC directory = myProject directory in our case.
134: Therefore myProject dir wasn't removed
135: - as non empty src dir because of 'nbbroject'
136: - as non empty myProject dir bercause of source files.
137: The folowing should help: */
138: //copied from org.netbeans.modules.cnd.makeproject.MakeProjectOperations
139: FileObject[] projectContent = myProject.getProjectDirectory()
140: .getChildren();
141: List metadataFiles = getMetadataFiles();
142: for (int i = 0; i < projectContent.length; i++) {
143: if (metadataFiles.indexOf(projectContent[i]) < 0) {
144: files.add(projectContent[i]);
145: }
146: }
147: if (files.size() == 0) {
148: // FIXUP: Don't return empty list. If the list is empty, the "Also Delete Sources" checkbox in the dialog is disabled and the myProject dir cannot be deleted.
149: files.add(myProject.getProjectDirectory());
150: }
151: return files;
152: }
153:
154: /* (non-Javadoc)
155: * @see org.netbeans.spi.myProject.DataFilesProviderImplementation#getMetadataFiles()
156: */
157: public List<FileObject> getMetadataFiles() {
158: List<FileObject> files = new ArrayList<FileObject>();
159:
160: // add nbproject dir
161: FileObject projectXml = myProject.getHelper()
162: .resolveFileObject(AntProjectHelper.PROJECT_XML_PATH);
163: if (projectXml != null) {
164: FileObject nbProject = projectXml.getParent();
165: if (nbProject != null) {
166: files.add(nbProject);
167: }
168: }
169:
170: // add myProject dir ?
171: files.add(myProject.getProjectDirectory());
172: return files;
173: }
174:
175: private PhpProject myProject;
176: }
|