1 19 20 package org.netbeans.modules.j2ee.ejbjarproject; 21 import java.util.ArrayList ; 22 import org.netbeans.api.project.ui.OpenProjects; 23 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 24 import org.openide.DialogDisplayer; 25 import org.openide.NotifyDescriptor; 26 import org.openide.WizardDescriptor; 27 import javax.swing.*; 28 import java.io.File ; 29 import java.util.Arrays ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import java.util.Set ; 33 import org.netbeans.api.java.classpath.GlobalPathRegistry; 34 import org.netbeans.api.project.FileOwnerQuery; 35 import org.netbeans.api.project.Project; 36 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeAppProvider; 37 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 38 import org.openide.filesystems.FileObject; 39 40 41 public class Utils { 42 43 private static final String WIZARD_PANEL_CONTENT_DATA = "WizardPanel_contentData"; private static final String WIZARD_PANEL_CONTENT_SELECTED_INDEX = "WizardPanel_contentSelectedIndex"; 46 public static String toClasspathString(File [] classpathEntries) { 47 if (classpathEntries == null) { 48 return ""; 49 } 50 StringBuffer classpath = new StringBuffer (); 51 for (int i = 0; i < classpathEntries.length; i++) { 52 classpath.append(classpathEntries[i].getAbsolutePath()); 53 if (i + 1 < classpathEntries.length) { 54 classpath.append(":"); } 56 } 57 return classpath.toString(); 58 } 59 60 public static void notifyError(Exception ex) { 61 NotifyDescriptor ndd = new NotifyDescriptor.Message(ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE); 62 DialogDisplayer.getDefault().notify(ndd); 63 } 64 65 public static void mergeSteps(WizardDescriptor wizard, WizardDescriptor.Panel[] panels, String [] steps) { 66 Object prop = wizard.getProperty (WIZARD_PANEL_CONTENT_DATA); 67 String [] beforeSteps; 68 int offset; 69 if (prop instanceof String []) { 70 beforeSteps = (String []) prop; 71 offset = beforeSteps.length; 72 if (offset > 0 && ("...".equals(beforeSteps[offset - 1]))) { offset--; 74 } 75 } else { 76 beforeSteps = null; 77 offset = 0; 78 } 79 String [] resultSteps = new String [ (offset) + panels.length]; 80 for (int i = 0; i < offset; i++) { 81 resultSteps[i] = beforeSteps[i]; 82 } 83 setSteps(panels, steps, resultSteps, offset); 84 } 85 86 private static void setSteps(WizardDescriptor.Panel[] panels, String [] steps, String [] resultSteps, int offset) { 87 int n = steps == null ? 0 : steps.length; 88 for (int i = 0; i < panels.length; i++) { 89 final JComponent component = (JComponent) panels[i].getComponent(); 90 String step = i < n ? steps[i] : null; 91 if (step == null) { 92 step = component.getName(); 93 } 94 component.putClientProperty (WIZARD_PANEL_CONTENT_DATA, resultSteps); 95 component.putClientProperty(WIZARD_PANEL_CONTENT_SELECTED_INDEX, new Integer (i)); 96 component.getAccessibleContext().setAccessibleDescription (step); 97 resultSteps[i + offset] = step; 98 } 99 } 100 101 public static void setSteps(WizardDescriptor.Panel[] panels, String [] steps) { 102 setSteps(panels, steps, steps, 0); 103 } 104 105 public static boolean areInSameJ2EEApp(Project p1, Project p2) { 106 Set globalPath = GlobalPathRegistry.getDefault().getSourceRoots(); 107 Iterator iter = globalPath.iterator(); 108 while (iter.hasNext()) { 109 FileObject sourceRoot = (FileObject)iter.next(); 110 Project project = FileOwnerQuery.getOwner(sourceRoot); 111 if (project != null) { 112 Object j2eeAppProvider = project.getLookup().lookup(J2eeAppProvider.class); 113 if (j2eeAppProvider != null) { J2eeAppProvider j2eeApp = (J2eeAppProvider)j2eeAppProvider; 115 J2eeModuleProvider[] j2eeModules = j2eeApp.getChildModuleProviders(); 116 if ((j2eeModules != null) && (j2eeModules.length > 0)) { J2eeModuleProvider affectedPrjProvider1 = 118 (J2eeModuleProvider)p1.getLookup().lookup(J2eeModuleProvider.class); 119 J2eeModuleProvider affectedPrjProvider2 = 120 (J2eeModuleProvider)p2.getLookup().lookup(J2eeModuleProvider.class); 121 if (affectedPrjProvider1 != null && affectedPrjProvider2 != null) { 122 List childModules = Arrays.asList(j2eeModules); 123 if (childModules.contains(affectedPrjProvider1) && 124 childModules.contains(affectedPrjProvider2)) { 125 return true; 126 } 127 } 128 } 129 } 130 } 131 } 132 return false; 133 } 134 135 137 139 140 141 145 public static Project [] getCallableEjbProjects (Project enterpriseProject) { 146 Project[] allProjects = OpenProjects.getDefault().getOpenProjects(); 147 148 boolean isCallerEJBModule = false; 149 J2eeModuleProvider callerJ2eeModuleProvider = (J2eeModuleProvider) enterpriseProject.getLookup().lookup(J2eeModuleProvider.class); 150 if (callerJ2eeModuleProvider != null && callerJ2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.EJB)) { 151 isCallerEJBModule = true; 154 } 155 boolean isCallerFreeform = enterpriseProject.getClass().getName().equals("org.netbeans.modules.ant.freeform.FreeformProject"); 158 159 List filteredResults = new ArrayList (allProjects.length); 160 for (int i = 0; i < allProjects.length; i++) { 161 boolean isEJBModule = false; 162 J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) allProjects[i].getLookup().lookup(J2eeModuleProvider.class); 163 if (j2eeModuleProvider != null && j2eeModuleProvider.getJ2eeModule().getModuleType().equals(J2eeModule.EJB)) { 164 isEJBModule = true; 165 } 166 if ((isEJBModule && !isCallerFreeform) || 167 (isCallerFreeform && enterpriseProject.equals(allProjects[i]))) { 168 filteredResults.add(allProjects[i]); 169 } 170 } 171 return (Project []) filteredResults.toArray(new Project[filteredResults.size()]); 172 } 173 174 } 175 | Popular Tags |