| 1 19 package org.netbeans.modules.j2ee.sun.share.configbean.templates; 20 21 import java.io.File ; 22 import javax.swing.JPanel ; 23 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.FileUtil; 26 import org.openide.util.Lookup; 27 import org.openide.util.NbBundle; 28 29 import org.netbeans.api.project.Project; 30 import org.netbeans.api.project.ProjectUtils; 31 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 32 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 33 34 35 39 public final class SunDDVisualPanel extends JPanel { 40 41 private Project project; 42 private String sunDDFileName; 43 private File sunDDFile; 44 private File sunDDLocation; 45 46 public SunDDVisualPanel() { 47 initComponents(); 48 } 49 50 void setProject(final Project project) { 51 this.project = project; 52 53 Lookup lookup = project.getLookup(); 58 J2eeModuleProvider provider = (J2eeModuleProvider) lookup.lookup(J2eeModuleProvider.class); 59 J2eeModule j2eeModule = provider.getJ2eeModule(); 60 sunDDFileName = getConfigFileName(j2eeModule); 61 62 sunDDFile = (sunDDFileName != null) ? provider.getDeploymentConfigurationFile(sunDDFileName) : null; 64 sunDDLocation = (sunDDFile != null) ? sunDDFile.getParentFile() : null; 65 66 textFileName.setText(sunDDFileName); textProjectName.setText(ProjectUtils.getInformation(project).getDisplayName()); 69 70 File projectFolder = FileUtil.toFile(project.getProjectDirectory()); 71 textLocation.setText((sunDDLocation != null) ? getRelativePath(sunDDLocation, projectFolder) : null); 72 textCreatedFile.setText((sunDDLocation != null) ? getRelativePath(sunDDFile, projectFolder) : null); 74 } 75 76 String getFileName() { 77 return sunDDFileName; 78 } 79 80 File getFile() { 81 return sunDDFile; 82 } 83 84 File getSelectedLocation() { 85 return sunDDLocation; 86 } 87 88 public String getName() { 89 return NbBundle.getMessage(SunDDVisualPanel.class, "LBL_CreateSunDeploymentDescriptor"); } 91 92 97 private void initComponents() { 99 java.awt.GridBagConstraints gridBagConstraints; 100 101 labelFileName = new javax.swing.JLabel (); 102 textFileName = new javax.swing.JTextField (); 103 labelProjectName = new javax.swing.JLabel (); 104 textProjectName = new javax.swing.JTextField (); 105 labelLocation = new javax.swing.JLabel (); 106 textLocation = new javax.swing.JTextField (); 107 labelCreatedFile = new javax.swing.JLabel (); 108 textCreatedFile = new javax.swing.JTextField (); 109 filler1 = new javax.swing.JLabel (); 110 111 setLayout(new java.awt.GridBagLayout ()); 112 113 labelFileName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "MNE_Name").charAt(0)); 114 labelFileName.setLabelFor(textFileName); 115 org.openide.awt.Mnemonics.setLocalizedText(labelFileName, org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "LBL_Name")); 116 gridBagConstraints = new java.awt.GridBagConstraints (); 117 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 118 add(labelFileName, gridBagConstraints); 119 120 textFileName.setEditable(false); 121 gridBagConstraints = new java.awt.GridBagConstraints (); 122 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 123 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 124 gridBagConstraints.weightx = 1.0; 125 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 126 add(textFileName, gridBagConstraints); 127 textFileName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCN_Name")); 128 textFileName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCD_Name")); 129 130 labelProjectName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "MNE_Project").charAt(0)); 131 labelProjectName.setLabelFor(textProjectName); 132 org.openide.awt.Mnemonics.setLocalizedText(labelProjectName, org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "LBL_Project")); 133 gridBagConstraints = new java.awt.GridBagConstraints (); 134 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 135 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 136 add(labelProjectName, gridBagConstraints); 137 138 textProjectName.setEditable(false); 139 gridBagConstraints = new java.awt.GridBagConstraints (); 140 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 141 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 142 gridBagConstraints.weightx = 1.0; 143 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 144 add(textProjectName, gridBagConstraints); 145 textProjectName.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCN_Project")); 146 textProjectName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCD_Project")); 147 148 labelLocation.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "MNE_Location").charAt(0)); 149 labelLocation.setLabelFor(textLocation); 150 org.openide.awt.Mnemonics.setLocalizedText(labelLocation, org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "LBL_Location")); 151 gridBagConstraints = new java.awt.GridBagConstraints (); 152 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 153 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 154 add(labelLocation, gridBagConstraints); 155 156 textLocation.setEditable(false); 157 gridBagConstraints = new java.awt.GridBagConstraints (); 158 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 159 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 160 gridBagConstraints.weightx = 1.0; 161 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 162 add(textLocation, gridBagConstraints); 163 textLocation.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCN_Location")); 164 textLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCD_Location")); 165 166 labelCreatedFile.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "MNE_CreatedFile").charAt(0)); 167 labelCreatedFile.setLabelFor(textCreatedFile); 168 org.openide.awt.Mnemonics.setLocalizedText(labelCreatedFile, org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "LBL_CreatedFile")); 169 gridBagConstraints = new java.awt.GridBagConstraints (); 170 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 171 gridBagConstraints.insets = new java.awt.Insets (12, 0, 11, 0); 172 add(labelCreatedFile, gridBagConstraints); 173 174 textCreatedFile.setEditable(false); 175 gridBagConstraints = new java.awt.GridBagConstraints (); 176 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 177 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 178 gridBagConstraints.weightx = 1.0; 179 gridBagConstraints.insets = new java.awt.Insets (12, 12, 11, 0); 180 add(textCreatedFile, gridBagConstraints); 181 textCreatedFile.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCN_CreatedFile")); 182 textCreatedFile.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SunDDVisualPanel.class, "ASCD_CreatedFile")); 183 184 gridBagConstraints = new java.awt.GridBagConstraints (); 185 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 186 gridBagConstraints.weightx = 1.0; 187 gridBagConstraints.weighty = 1.0; 188 add(filler1, gridBagConstraints); 189 190 } 192 193 private javax.swing.JLabel filler1; 195 private javax.swing.JLabel labelCreatedFile; 196 private javax.swing.JLabel labelFileName; 197 private javax.swing.JLabel labelLocation; 198 private javax.swing.JLabel labelProjectName; 199 private javax.swing.JTextField textCreatedFile; 200 private javax.swing.JTextField textFileName; 201 private javax.swing.JTextField textLocation; 202 private javax.swing.JTextField textProjectName; 203 205 206 private String getConfigFileName(J2eeModule j2eeModule) { 207 String result = null; 208 Object moduleType = j2eeModule.getModuleType(); 209 if(J2eeModule.WAR.equals(moduleType)) { 210 result = "sun-web.xml"; } else if(J2eeModule.EJB.equals(moduleType)) { 212 result = "sun-ejb-jar.xml"; } else if(J2eeModule.EAR.equals(moduleType)) { 214 result = "sun-application.xml"; } else if(J2eeModule.CLIENT.equals(moduleType)) { 216 result = "sun-application-client.xml"; } 218 return result; 219 } 220 221 private static String getRelativePath(File file, File base) { 222 String basePath = base.getAbsolutePath(); 223 String filePath = file.getAbsolutePath(); 224 225 if(filePath.startsWith(basePath)) { 226 String prefix = ""; 227 int baseIndex = basePath.lastIndexOf(File.separatorChar); 228 if(baseIndex < 0 || baseIndex >= filePath.length()) { 229 baseIndex = 0; 230 } else { 231 prefix = "..."; } 233 return prefix + filePath.substring(baseIndex); 234 } 235 return filePath; 236 } 237 238 } 239 | Popular Tags |