1 19 package org.netbeans.modules.apisupport.project.metainf; 20 21 import org.netbeans.api.java.project.JavaProjectConstants; 22 import org.netbeans.api.project.ProjectInformation; 23 import org.netbeans.api.project.SourceGroup; 24 import org.netbeans.api.project.Sources; 25 import org.netbeans.modules.apisupport.project.NbModuleProject; 26 import org.netbeans.spi.java.project.support.ui.PackageView; 27 import org.openide.filesystems.FileObject; 28 import org.openide.loaders.DataObject; 29 import org.openide.nodes.Node; 30 import org.openide.nodes.NodeOperation; 31 import org.openide.util.NbBundle; 32 import org.openide.util.UserCancelException; 33 34 38 public class AddServiceDialog extends javax.swing.JPanel { 39 40 42 private NbModuleProject project; 43 44 public AddServiceDialog(NbModuleProject project) { 45 initComponents(); 46 this.project = project; 47 } 48 49 54 private void initComponents() { 56 classField = new javax.swing.JTextField (); 57 browseButton = new javax.swing.JButton (); 58 jLabel1 = new javax.swing.JLabel (); 59 60 org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(AddServiceDialog.class, "CTL_BROWSE")); browseButton.addActionListener(new java.awt.event.ActionListener () { 62 public void actionPerformed(java.awt.event.ActionEvent evt) { 63 browseButtonActionPerformed(evt); 64 } 65 }); 66 67 jLabel1.setLabelFor(classField); 68 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(AddServiceDialog.class, "LBL_CLASS_NAME")); 70 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 71 this.setLayout(layout); 72 layout.setHorizontalGroup( 73 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 74 .add(layout.createSequentialGroup() 75 .addContainerGap() 76 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 77 .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 299, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 78 .add(layout.createSequentialGroup() 79 .add(classField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 299, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 80 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 81 .add(browseButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))) 82 .addContainerGap()) 83 ); 84 layout.setVerticalGroup( 85 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 86 .add(layout.createSequentialGroup() 87 .addContainerGap() 88 .add(jLabel1) 89 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 90 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 91 .add(classField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 92 .add(browseButton)) 93 .addContainerGap()) 94 ); 95 } 97 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) { Sources sources = (Sources) project.getLookup().lookup(Sources.class); 99 SourceGroup groups[] = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 100 101 ProjectInformation inf = (ProjectInformation) project.getLookup().lookup(ProjectInformation.class); 102 if (groups.length > 0) { 103 Node srcNode = PackageView.createPackageView(groups[0]); 104 try { 105 Node node = NodeOperation.getDefault().select(NbBundle.getMessage(AddServiceDialog.class, "MSG_SelectAClass"), 106 inf.getDisplayName(), 107 srcNode ); 108 DataObject dobj = null; 110 do { 111 dobj = (DataObject) node.getLookup().lookup(DataObject.class); 112 node = node.getParentNode(); 113 } while (dobj == null && node != null); 114 if (dobj != null) { 115 FileObject fo = dobj.getPrimaryFile(); 116 if (fo.getExt().equals("java")) { String fileName = fo.getPath(); 118 String className = fileName.substring(project.getSourceDirectory().getPath().length(), 119 fileName.length() - ".java".length()); if (className.startsWith("/")) { className = className.substring(1); 122 } 123 className = className.replace('/','.'); 124 classField.setText(className); 125 } 126 127 } 128 } catch (UserCancelException uc) { 129 } 131 132 } 133 134 } 136 public String getClassName() { 137 return classField.getText(); 138 } 139 140 private javax.swing.JButton browseButton; 142 private javax.swing.JTextField classField; 143 private javax.swing.JLabel jLabel1; 144 146 } 147 | Popular Tags |