001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.sql.project;
021:
022: import java.io.File;
023: import java.io.IOException;
024: import java.util.ArrayList;
025: import java.util.List;
026: import java.util.Properties;
027: import org.apache.tools.ant.module.api.support.ActionUtils;
028: import org.netbeans.api.project.Project;
029: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
030: import org.netbeans.spi.project.ActionProvider;
031: import org.netbeans.spi.project.DeleteOperationImplementation;
032: import org.netbeans.spi.project.CopyOperationImplementation;
033: import org.netbeans.spi.project.MoveOperationImplementation;
034: import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
035: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
036: import org.openide.filesystems.FileObject;
037: import org.openide.util.Lookup;
038: import org.openide.util.lookup.Lookups;
039:
040: /**
041: * Context sensitive menu operations on sql module project
042: *
043: * @author Bing Lu
044: */
045: public class SQLproProjectOperations implements
046: DeleteOperationImplementation, CopyOperationImplementation,
047: MoveOperationImplementation {
048: private SQLproProject project;
049:
050: /** Creates a new instance of JbiProjectOperations */
051: public SQLproProjectOperations(SQLproProject project) {
052: this .project = project;
053: }
054:
055: public List/*<FileObject>*/getDataFiles() {
056: List/*<FileObject>*/files = new ArrayList();
057:
058: files.add(project.getSourceDirectory());
059:
060: PropertyEvaluator evaluator = project.evaluator();
061: String prop = evaluator
062: .getProperty(IcanproProjectProperties.SOURCE_ROOT);
063: if (prop != null) {
064: FileObject projectDirectory = project.getProjectDirectory();
065: FileObject srcDir = project.getAntProjectHelper()
066: .resolveFileObject(prop);
067: if (projectDirectory != srcDir && !files.contains(srcDir))
068: files.add(srcDir);
069: }
070:
071: return files;
072: }
073:
074: private static void addFile(FileObject projectDirectory,
075: String fileName, List/*<FileObject>*/result) {
076: FileObject file = projectDirectory.getFileObject(fileName);
077:
078: if (file != null) {
079: result.add(file);
080: }
081: }
082:
083: public List/*<FileObject>*/getMetadataFiles() {
084: FileObject projectDirectory = project.getProjectDirectory();
085: List/*<FileObject>*/files = new ArrayList();
086:
087: addFile(projectDirectory, "nbproject", files); // NOI18N
088: addFile(projectDirectory, "build.xml", files); // NOI18N
089: addFile(projectDirectory, "catalog.xml", files); //NOI18N
090: addFile(projectDirectory, projectDirectory.getName(), files); //NOI18N
091:
092: return files;
093: }
094:
095: public void notifyDeleting() throws IOException {
096: SQLproActionProvider ap = (SQLproActionProvider) project
097: .getLookup().lookup(SQLproActionProvider.class);
098: assert ap != null;
099:
100: Lookup context = Lookups.fixed(new Object[0]);
101: Properties p = new Properties();
102: String[] targetNames = ap.getTargetNames(
103: ActionProvider.COMMAND_CLEAN, context, p);
104: FileObject buildXML = project.getProjectDirectory()
105: .getFileObject(GeneratedFilesHelper.BUILD_XML_PATH);
106:
107: assert targetNames != null;
108: assert targetNames.length > 0;
109:
110: ActionUtils.runTarget(buildXML, targetNames, p).waitFinished();
111: }
112:
113: public void notifyDeleted() throws IOException {
114:
115: project.getAntProjectHelper().notifyDeleted();
116: }
117:
118: public void notifyCopied(Project original, File originalPath,
119: final String newName) {
120: if (original == null) {
121: // do nothing for the original project.
122: return;
123: }
124:
125: project.getReferenceHelper().fixReferences(originalPath);
126:
127: String oldName = project.getName();
128: project.setName(newName);
129: }
130:
131: public void notifyCopying() {
132: // do nothing.
133: // This does copy the old distribution file over though, which is
134: // probably OK because "ant clean" will clean it up.
135: }
136:
137: public void notifyMoved(Project original, File originalPath,
138: final String newName) {
139: if (original == null) {
140: project.getAntProjectHelper().notifyDeleted();
141: return;
142: }
143: String oldName = project.getName();
144: project.setName(newName);
145: project.getReferenceHelper().fixReferences(originalPath);
146: }
147:
148: public void notifyMoving() throws IOException {
149: notifyDeleting();
150: }
151: }
|