2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.j2ee.clientproject;
45
import javax.swing.JComponent;
46
import org.openide.WizardDescriptor;
49
* Utility methods for the module.
53
private static final String WIZARD_PANEL_CONTENT_DATA = "WizardPanel_contentData"; // NOI18N
54
private static final String WIZARD_PANEL_CONTENT_SELECTED_INDEX = "WizardPanel_contentSelectedIndex"; //NOI18N;
59
public static String toClasspathString(File[] classpathEntries) {
60
if (classpathEntries == null) {
63
StringBuffer classpath = new StringBuffer();
64
for (int i = 0; i < classpathEntries.length; i++) {
65
classpath.append(classpathEntries[i].getAbsolutePath());
66
if (i + 1 < classpathEntries.length) {
67
classpath.append(':');
70
return classpath.toString();
73
// public static void notifyError(Exception ex) {
74
// NotifyDescriptor ndd = new NotifyDescriptor.Message(ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
75
// DialogDisplayer.getDefault().notify(ndd);
78
// public static void mergeSteps(WizardDescriptor wizard, WizardDescriptor.Panel[] panels, String[] steps) {
79
// Object prop = wizard.getProperty (WIZARD_PANEL_CONTENT_DATA);
80
// String[] beforeSteps;
82
// if (prop instanceof String[]) {
83
// beforeSteps = (String[]) prop;
84
// offset = beforeSteps.length;
85
// if (offset > 0 && ("...".equals(beforeSteps[offset - 1]))) {// NOI18N
89
// beforeSteps = null;
92
// String[] resultSteps = new String[ (offset) + panels.length];
93
// for (int i = 0; i < offset; i++) {
94
// resultSteps[i] = beforeSteps[i];
96
// setSteps(panels, steps, resultSteps, offset);
99
private static void setSteps(WizardDescriptor.Panel[] panels, String[] steps, String[] resultSteps, int offset) {
100
int n = steps == null ? 0 : steps.length;
101
for (int i = 0; i < panels.length; i++) {
102
final JComponent component = (JComponent) panels[i].getComponent();
103
String step = i < n ? steps[i] : null;
105
step = component.getName();
107
component.putClientProperty(WIZARD_PANEL_CONTENT_DATA, resultSteps);
108
component.putClientProperty(WIZARD_PANEL_CONTENT_SELECTED_INDEX, i);
109
component.getAccessibleContext().setAccessibleDescription(step);
110
resultSteps[i + offset] = step;
114
public static void setSteps(WizardDescriptor.Panel[] panels, String[] steps) {
115
setSteps(panels, steps, steps, 0);
119
// * JMI transaction must be started and JMI classpath must be set to use this method
121
// public static void save(JavaClass jc) {
125
// DataObject dataObject = null;
127
// DataObject.find(JavaModel.getFileObject(jc.getResource()));
128
// } catch (DataObjectNotFoundException dnfe) {
130
// SaveCookie saveCookie = dataObject == null ? null : (SaveCookie) dataObject.getCookie(SaveCookie.class);
131
// // TODO: SaveCookie - is returned if file is not modified?
132
//// assert saveCookie != null: ("SaveCookie not found for " + jc.getName());
133
// if (saveCookie != null) {
135
// saveCookie.save();
136
// } catch (IOException ioe) {
137
// ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ioe);
143
// * JMI transaction must be started and JMI classpath must be set to use this method
145
// public static boolean isModified(JavaClass ce) {
146
// DataObject dataObject = JavaMetamodel.getManager().getDataObject(ce.getResource());
147
// assert dataObject != null: ("DataObject not found for " + ce.getName());
148
// return dataObject.isModified();
151
// public static boolean areInSameJ2EEApp(Project p1, Project p2) {
152
// Set globalPath = GlobalPathRegistry.getDefault().getSourceRoots();
153
// Iterator iter = globalPath.iterator();
154
// while (iter.hasNext()) {
155
// FileObject sourceRoot = (FileObject)iter.next();
156
// Project project = FileOwnerQuery.getOwner(sourceRoot);
157
// if (project != null) {
158
// Object j2eeAppProvider = project.getLookup().lookup(J2eeAppProvider.class);
159
// if (j2eeAppProvider != null) { // == it is j2ee app
160
// J2eeAppProvider j2eeApp = (J2eeAppProvider)j2eeAppProvider;
161
// J2eeModuleProvider[] j2eeModules = j2eeApp.getChildModuleProviders();
162
// if ((j2eeModules != null) && (j2eeModules.length > 0)) { // == there are some modules in the j2ee app
163
// J2eeModuleProvider affectedPrjProvider1 =
164
// (J2eeModuleProvider)p1.getLookup().lookup(J2eeModuleProvider.class);
165
// J2eeModuleProvider affectedPrjProvider2 =
166
// (J2eeModuleProvider)p2.getLookup().lookup(J2eeModuleProvider.class);
167
// if (affectedPrjProvider1 != null && affectedPrjProvider2 != null) {
168
// List childModules = Arrays.asList(j2eeModules);
169
// if (childModules.contains(affectedPrjProvider1) &&
170
// childModules.contains(affectedPrjProvider2)) {
181
// // =========================================================================
183
// // utils for ejb code synchronization
187
// /** Returns list of all EJB projects that can be called from the caller project.
189
// * @param enterpriseProject the caller enterprise project
191
// public static Project [] getCallableEjbProjects (Project enterpriseProject) {
192
// Project[] allProjects = OpenProjects.getDefault().getOpenProjects();
194
// boolean isCallerEJBModule = false;
195
// J2eeModuleProvider callerJ2eeModuleProvider = (J2eeModuleProvider) enterpriseProject.getLookup().lookup(J2eeModuleProvider.class);
196
// if (callerJ2eeModuleProvider != null && callerJ2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.CAR)) {
197
// // TODO: HACK - this should be set by calling AntArtifactQuery.findArtifactsByType(p, EjbProjectConstants.ARTIFACT_TYPE_EJBJAR)
198
// // but now freeform doesn't implement this correctly
199
// isCallerEJBModule = true;
201
// // TODO: HACK - this must be solved by freeform's own implementation of EnterpriseReferenceContainer, see issue 57003
202
// // call ejb should not make this check, all should be handled in EnterpriseReferenceContainer
203
// boolean isCallerFreeform = enterpriseProject.getClass().getName().equals("org.netbeans.modules.ant.freeform.FreeformProject");
205
// List /*<Project>*/ filteredResults = new ArrayList(allProjects.length);
206
// for (int i = 0; i < allProjects.length; i++) {
207
// boolean isEJBModule = false;
208
// J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) allProjects[i].getLookup().lookup(J2eeModuleProvider.class);
209
// if (j2eeModuleProvider != null && j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.CAR)) {
210
// isEJBModule = true;
212
// if ((isEJBModule && !isCallerFreeform) ||
213
// (isCallerFreeform && enterpriseProject.equals(allProjects[i]))) {
214
// filteredResults.add(allProjects[i]);
217
// return (Project []) filteredResults.toArray(new Project[filteredResults.size()]);
220
// // Copied from j2ee/utilities JMIUtils
221
// public static JavaClass findClass(String className) {
222
// JavaClass result = (JavaClass) resolveType(className);
223
// return result instanceof UnresolvedClass ? null : result;
226
// // Copied from j2ee/utilities JMIUtils
227
// public static Type resolveType(String typeName) {
228
// Type type = JavaModel.getDefaultExtent().getType().resolve(typeName);
229
// if (type instanceof UnresolvedClass) {
230
// Type basicType = JavaModel.getDefaultExtent().getType().resolve("java.lang." + typeName); // NOI18N;
231
// if (!(basicType instanceof UnresolvedClass)) {