KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > jbuilder > ui > Utils


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
20 package org.netbeans.modules.projectimport.jbuilder.ui;
21
22 import java.io.File JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.LinkedList JavaDoc;
27 import org.netbeans.modules.projectimport.j2seimport.AbstractProject;
28 import org.netbeans.modules.projectimport.j2seimport.WarningContainer;
29 import org.netbeans.modules.projectimport.j2seimport.ui.WarningMessage;
30 import org.openide.util.NbBundle;
31
32 /**
33  *
34  * @author Radek Matous
35  */

36 final class Utils {
37     
38     /** Creates a new instance of Utils */
39     private Utils() {}
40     
41     static boolean checkNotFoundUserLibraries(Collection JavaDoc prjDefs) {
42         boolean notfound = notFoundUserLibraries(prjDefs).size() > 0;
43         if (!notfound && prjDefs != null) {
44             for (Iterator JavaDoc it = prjDefs.iterator(); it.hasNext();) {
45                 AbstractProject prj = (AbstractProject) it.next();
46                 if (prj.getJdkId() != null && prj.getJDKDirectory() == null) return true;
47             }
48         }
49         return notfound;
50     }
51     
52     private static Collection JavaDoc notFoundUserLibraries(Collection JavaDoc allPrjDefs) {
53         Collection JavaDoc notFoundUserLibraries = new HashSet JavaDoc();
54         if (allPrjDefs != null) {
55             Iterator JavaDoc prjsIt = allPrjDefs.iterator();
56             while (prjsIt.hasNext()) {
57                 AbstractProject ap = (AbstractProject)prjsIt.next();
58                 Iterator JavaDoc it = ap.getUserLibraries().iterator();
59                 while (it.hasNext()) {
60                     AbstractProject.UserLibrary uLib = (AbstractProject.UserLibrary)it.next();
61                     if (uLib.fileNotFound()) {
62                         notFoundUserLibraries.add(uLib);
63                     }
64                 }
65             }
66         }
67         
68         return notFoundUserLibraries;
69     }
70     
71     static Collection JavaDoc getInvalidUserLibraries(Collection JavaDoc allPrjDefs) {
72         Collection JavaDoc invalidUserLibraries = new HashSet JavaDoc();
73         if (allPrjDefs != null) {
74             Iterator JavaDoc prjsIt = allPrjDefs.iterator();
75             while (prjsIt.hasNext()) {
76                 AbstractProject ap = (AbstractProject)prjsIt.next();
77                 if (ap.getJDKDirectory() == null && ap.getJdkId() != null) {
78                     invalidUserLibraries.add(new AbstractProject.UserLibrary(ap.getJdkId(), false));
79                 }
80                 Iterator JavaDoc it = ap.getUserLibraries().iterator();
81                 while (it.hasNext()) {
82                     AbstractProject.UserLibrary uLib = (AbstractProject.UserLibrary)it.next();
83                     if (!uLib.isValid()) {
84                         invalidUserLibraries.add(uLib);
85                     }
86                 }
87             }
88         }
89         
90         return invalidUserLibraries;
91     }
92     
93     static StringBuffer JavaDoc getDependencyErrors(Collection JavaDoc prjDefs, File JavaDoc destinationDir) {
94         return getProjectsErrors(collectAllDependencies(prjDefs), destinationDir);
95     }
96     
97     static StringBuffer JavaDoc getProjectsErrors(Collection JavaDoc prjDefs, File JavaDoc destinationDir) {
98         StringBuffer JavaDoc errBuf = null;
99         if (prjDefs != null) {
100             for (Iterator JavaDoc it = prjDefs.iterator(); it.hasNext();) {
101                 AbstractProject ap = (AbstractProject)it.next();
102                 File JavaDoc importLocation = new File JavaDoc(destinationDir, ap.getName());
103                 
104                 if (ap.getErrors().size() > 0 || importLocation.exists()) {
105                     errBuf = (errBuf == null) ? new StringBuffer JavaDoc() : errBuf;
106                     for (Iterator JavaDoc errIt = ap.getErrors().iterator(); errIt.hasNext();) {
107                         errBuf.append((String JavaDoc)errIt.next()).append(" ");//NOI18N
108
}
109                     if (importLocation.exists()) {
110                         String JavaDoc errMsg = NbBundle.getMessage(JBWizardPanel.class,
111                                 "MSG_ProjectAlreadyExists",importLocation.getAbsolutePath()); // NOI18N
112
errBuf.append(errMsg).append(" ");//NOI18N
113
}
114                 }
115             }
116         }
117         return errBuf;
118     }
119
120     static String JavaDoc getHtmlWarnings(Collection JavaDoc prjDefs) {
121         Collection JavaDoc all = new LinkedList JavaDoc();
122         if (prjDefs != null) {
123             for (Iterator JavaDoc it = prjDefs.iterator(); it.hasNext();) {
124                 AbstractProject ap = (AbstractProject)it.next();
125                 all.addAll(ap.getWarnings().getAllWarnings());
126             }
127         }
128                         
129         return (all.isEmpty()) ? null :
130             WarningMessage.createHtmlString("",all.iterator(), true, 4);//NOI18N
131
}
132     
133     private static Collection JavaDoc collectAllDependencies(Collection JavaDoc prjDefs) {
134         Collection JavaDoc result = new HashSet JavaDoc();
135         if (prjDefs != null && prjDefs.size() > 0) {
136             for (Iterator JavaDoc it = prjDefs.iterator(); it.hasNext();) {
137                 AbstractProject ap = (AbstractProject)it.next();
138                 for (Iterator JavaDoc depsIt = ap.getDependencies().iterator(); depsIt.hasNext();) {
139                     AbstractProject dep = (AbstractProject)depsIt.next();
140                     result.add(dep);
141                 }
142                 
143             }
144             if (result.size() > 0) {
145                 result.addAll(collectAllDependencies(result));
146             }
147         }
148         
149         return result;
150     }
151 }
152
Popular Tags