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-2007 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:
042: /*
043: * DeleteJavaEEModuleAction.java
044: *
045: * Created on October 18, 2006, 9:08 PM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.modules.compapp.projects.jbi.jeese.actions;
052:
053: import java.io.File;
054: import java.util.ArrayList;
055: import java.util.Iterator;
056: import java.util.List;
057: import java.util.ResourceBundle;
058: import org.netbeans.api.project.Project;
059: import org.netbeans.api.project.ant.AntArtifact;
060: import org.netbeans.modules.compapp.javaee.util.ProjectUtil;
061: import org.netbeans.modules.compapp.javaee.sunresources.SunResourcesUtil;
062: import org.netbeans.modules.compapp.projects.jbi.ui.actions.DeleteModuleAction;
063: import org.netbeans.modules.compapp.projects.jbi.ui.customizer.JbiProjectProperties;
064: import org.netbeans.modules.compapp.projects.jbi.ui.customizer.VisualClassPathItem;
065: import org.openide.util.NbBundle;
066:
067: /**
068: * Action to delete JavaEE module/project.
069: *
070: */
071: public class DeleteJavaEEModuleAction extends DeleteModuleAction {
072: private String name = "Delete Java EE Module";
073: private final static String NAME = "nameDeleteAction"; // No I18N
074: private static final String BUILD_DIR = "build"; // No I18N
075:
076: public DeleteJavaEEModuleAction() {
077: init();
078: }
079:
080: private void init() {
081: ResourceBundle rb = NbBundle.getBundle(this .getClass());
082: name = rb.getString(NAME);
083: }
084:
085: protected void deleteModuleProperties(Project jbiProject,
086: VisualClassPathItem vcpi, String artifactName) {
087: String baseDir = ProjectUtil.getProjectBaseDir(jbiProject);
088: String buildDir = baseDir + File.separator + BUILD_DIR
089: + File.separator;
090: String projName = vcpi.getProjectName();
091: deleteFile(buildDir + artifactName);
092:
093: }
094:
095: protected void updateModuleProperties(Project jbiProject,
096: JbiProjectProperties projProp,
097: List<VisualClassPathItem> subprojJars, String subProjName) {
098: if (subprojJars != null) {
099: List<VisualClassPathItem> javaeeList = new ArrayList<VisualClassPathItem>();
100: VisualClassPathItem vcpi = null;
101: Iterator<VisualClassPathItem> itr = subprojJars.iterator();
102: while (itr.hasNext()) {
103: vcpi = itr.next();
104: if ((vcpi.getObject() instanceof AntArtifact)
105: && (VisualClassPathItem
106: .isJavaEEProjectAntArtifact((AntArtifact) vcpi
107: .getObject()))) {
108: javaeeList.add(vcpi);
109: }
110: }
111:
112: projProp.put(JbiProjectProperties.JBI_JAVAEE_JARS,
113: javaeeList);
114: }
115:
116: SunResourcesUtil.removeJavaEEResourceMetaData(jbiProject,
117: subProjName);
118: }
119:
120: private void deleteFile(String filePath) {
121: try {
122: File file = new File(filePath);
123: file.delete();
124: } catch (Exception ex) {
125: // Log
126: }
127: }
128:
129: public String getName() {
130: return name;
131: }
132: }
|