1 19 package org.netbeans.modules.j2ee.ddloaders.multiview; 20 21 import org.netbeans.api.java.project.JavaProjectConstants; 22 import org.netbeans.api.project.FileOwnerQuery; 23 import org.netbeans.api.project.ProjectUtils; 24 import org.netbeans.api.project.SourceGroup; 25 import org.netbeans.api.project.Sources; 26 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider; 27 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; 28 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 29 import org.netbeans.modules.j2ee.dd.api.ejb.Entity; 30 import org.netbeans.modules.j2ee.ddloaders.multiview.ui.BrowseFolders; 31 import org.netbeans.modules.j2ee.spi.ejbjar.support.J2eeProjectView; 32 import org.openide.DialogDisplayer; 41 import org.openide.NotifyDescriptor; 42 import org.openide.cookies.OpenCookie; 43 import org.openide.filesystems.FileObject; 44 import org.openide.filesystems.FileStateInvalidException; 45 import org.openide.filesystems.FileUtil; 46 import org.openide.loaders.DataObject; 47 import org.openide.loaders.DataObjectNotFoundException; 48 import org.openide.nodes.Node; 49 import org.openide.util.Lookup; 50 import org.openide.util.NbBundle; 51 import org.openide.util.Utilities; 52 import org.openide.util.lookup.AbstractLookup; 53 import org.openide.util.lookup.InstanceContent; 54 55 import javax.swing.*; 56 import java.awt.*; 57 import java.beans.PropertyChangeListener ; 58 import java.io.IOException ; 59 import java.net.URL ; 60 import java.rmi.RemoteException ; 61 import java.util.LinkedList ; 62 import java.util.List ; 63 import java.util.Iterator ; 64 import org.netbeans.api.java.classpath.ClassPath; 65 66 69 public class Utils { 70 71 public static final String ICON_BASE_DD_VALID = 72 "org/netbeans/modules/j2ee/ddloaders/resources/DDValidIcon"; public static final String ICON_BASE_DD_INVALID = 74 "org/netbeans/modules/j2ee/ddloaders/resources/DDInvalidIcon"; public static final String ICON_BASE_EJB_MODULE_NODE = 76 "org/netbeans/modules/j2ee/ddloaders/resources/EjbModuleNodeIcon"; public static final String ICON_BASE_ENTERPRISE_JAVA_BEANS_NODE = 78 "org/netbeans/modules/j2ee/ddloaders/resources/EjbContainerNodeIcon"; public static final String ICON_BASE_SESSION_NODE = 80 "org/netbeans/modules/j2ee/ddloaders/resources/SessionNodeIcon"; public static final String ICON_BASE_ENTITY_NODE = 82 "org/netbeans/modules/j2ee/ddloaders/resources/EntityNodeIcon"; public static final String ICON_BASE_MESSAGE_DRIVEN_NODE = 84 "org/netbeans/modules/j2ee/ddloaders/resources/MessageNodeIcon"; public static final String ICON_BASE_MISC_NODE = 86 "org/netbeans/modules/j2ee/ddloaders/resources/MiscNodeIcon"; 88 private static BrowseFolders.FileObjectFilter imageFileFilter = new BrowseFolders.FileObjectFilter() { 89 public boolean accept(FileObject fileObject) { 90 return fileObject.getMIMEType().startsWith("image/"); } 92 }; 93 94 public static String browseIcon(EjbJarMultiViewDataObject dataObject) { 95 FileObject fileObject = org.netbeans.modules.j2ee.ddloaders.multiview.ui.BrowseFolders.showDialog( 96 dataObject.getSourceGroups(), imageFileFilter); 97 String relativePath; 98 if (fileObject != null) { 99 FileObject projectDirectory = dataObject.getProjectDirectory(); 100 relativePath = FileUtil.getRelativePath(projectDirectory, fileObject); 101 } else { 102 relativePath = null; 103 } 104 return relativePath; 105 } 106 107 public static Color getErrorColor() { 108 Color c = UIManager.getColor("nb.errorForeground"); return c == null ? new Color(89, 79, 191) : c; 111 } 112 113 public static JTree findTreeComponent(Component component) { 114 if (component instanceof JTree) { 115 return (JTree) component; 116 } 117 if (component instanceof Container) { 118 Component[] components = ((Container) component).getComponents(); 119 for (int i = 0; i < components.length; i++) { 120 JTree tree = findTreeComponent(components[i]); 121 if (tree != null) { 122 return tree; 123 } 124 } 125 } 126 return null; 127 } 128 129 public static void scrollToVisible(JComponent component) { 130 org.netbeans.modules.xml.multiview.Utils.scrollToVisible(component); 131 } 132 133 public static String getBundleMessage(String messageId) { 134 return NbBundle.getMessage(Utils.class, messageId); 135 } 136 137 public static String getBundleMessage(String messageId, Object param1) { 138 return NbBundle.getMessage(Utils.class, messageId, param1); 139 } 140 141 public static String getBundleMessage(String messageId, Object param1, Object param2) { 142 return NbBundle.getMessage(Utils.class, messageId, param1, param2); 143 } 144 145 public static String getBundleMessage(String messageId, Object param1, Object param2, Object param3) { 146 return NbBundle.getMessage(Utils.class, messageId, param1, param2, param3); 147 } 148 149 public static boolean isJavaIdentifier(String id) { 150 return Utilities.isJavaIdentifier(id); 151 } 152 153 159 public static boolean isValidPackageName(String packageName) { 160 String [] strings = packageName.split("[.]"); if (strings.length == 0) { 162 return false; 163 } 164 for (int i = 0; i < strings.length; i++) { 165 if (!isJavaIdentifier(strings[i])) { 166 return false; 167 } 168 } 169 return packageName.charAt(packageName.length() - 1) != '.'; 170 } 171 172 public static void removeClass(ClassPath classPath, String className) { 173 FileObject sourceFile = getSourceFile(classPath, className); 174 if (sourceFile != null) { 175 } 183 } 184 185 public static FileObject getPackageFile(ClassPath classPath, String packageName) { 186 return classPath.findResource(packageToPath(packageName)); 187 } 188 189 private static String packageToPath(String packageName) { 190 return packageName.replace('.', '/'); 191 } 192 193 public static String getPackage(String ejbClass) { 194 final int i = ejbClass.lastIndexOf('.'); 195 if (i < 0) { 196 return ""; 197 } else { 198 return ejbClass.substring(0, i); 199 } 200 201 } 202 203 public static void notifyError(Exception ex) { 204 NotifyDescriptor ndd = new NotifyDescriptor.Message(ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE); 205 DialogDisplayer.getDefault().notify(ndd); 206 } 207 208 public static FileObject getSourceFile(ClassPath classPath, String className) { 209 return classPath.findResource(packageToPath(className) + ".java"); 210 } 211 212 225 233 245 249 333 public static String getEjbDisplayName(Ejb ejb) { 334 String name = ejb.getDefaultDisplayName(); 335 if (name == null) { 336 name = ejb.getEjbName(); 337 if (name == null) { 338 name = " "; } 340 } 341 return name; 342 } 343 344 370 374 public static void runInAwtDispatchThread(Runnable runnable) { 375 org.netbeans.modules.xml.multiview.Utils.runInAwtDispatchThread(runnable); 376 } 377 378 393 } 442 | Popular Tags |