1 19 20 package org.netbeans.modules.projectimport.eclipse.wizard; 21 22 import java.awt.Color ; 23 import java.io.File ; 24 import javax.swing.JFileChooser ; 25 import javax.swing.JPanel ; 26 import javax.swing.UIManager ; 27 import javax.swing.event.DocumentEvent ; 28 import javax.swing.event.DocumentListener ; 29 import org.netbeans.modules.projectimport.eclipse.EclipseUtils; 30 31 36 final class SelectionPanel extends JPanel { 37 38 private String errorMessage; 39 40 41 public SelectionPanel() { 42 super(); 43 initComponents(); 44 Color lblBgr = UIManager.getColor("Label.background"); wsDescription.setBackground(lblBgr); 46 note.setBackground(lblBgr); 47 workspaceDir.getDocument().addDocumentListener(new DocumentListener () { 48 public void insertUpdate(DocumentEvent e) { workspaceChanged(); } 49 public void removeUpdate(DocumentEvent e) { workspaceChanged(); } 50 public void changedUpdate(DocumentEvent e) {} 51 }); 52 projectDir.getDocument().addDocumentListener(new DocumentListener () { 53 public void insertUpdate(DocumentEvent e) { projectChanged(); } 54 public void removeUpdate(DocumentEvent e) { projectChanged(); } 55 public void changedUpdate(DocumentEvent e) {} 56 }); 57 projectDestDir.getDocument().addDocumentListener(new DocumentListener () { 58 public void insertUpdate(DocumentEvent e) { projectChanged(); } 59 public void removeUpdate(DocumentEvent e) { projectChanged(); } 60 public void changedUpdate(DocumentEvent e) {} 61 }); 62 setWorkspaceEnabled(workspaceButton.isSelected()); 63 } 64 65 66 String getWorkspaceDir() { 67 return workspaceDir.getText().trim(); 68 } 69 70 private void workspaceChanged() { 71 String workspace = getWorkspaceDir().trim(); 72 if ("".equals(workspace)) { 73 setErrorMessage(ProjectImporterWizard.getMessage( 74 "MSG_ChooseWorkspace")); return; 76 } 77 boolean wsValid = EclipseUtils.isRegularWorkSpace(getWorkspaceDir()); 78 setErrorMessage(wsValid ? null : ProjectImporterWizard.getMessage( 79 "MSG_NotRegularWorkspace", getWorkspaceDir())); } 81 82 private void projectChanged() { 83 String project = getProjectDir(); 85 if ("".equals(project)) { 86 setErrorMessage(ProjectImporterWizard.getMessage( 87 "MSG_ChooseProject")); return; 89 } 90 File projectDirFile = new File (project); 91 if (!EclipseUtils.isRegularProject(projectDirFile)) { 92 setErrorMessage(ProjectImporterWizard.getMessage( 93 "MSG_NotRegularProject", project)); return; 95 } 96 97 String projectDest = getProjectDestinationDir(); 99 if ("".equals(projectDest)) { 100 setErrorMessage(ProjectImporterWizard.getMessage( 101 "MSG_ChooseProjectDestination")); return; 103 } 104 File projectDestFile = new File (projectDest, projectDirFile.getName()); 105 if (projectDestFile.exists()) { 106 setErrorMessage(ProjectImporterWizard.getMessage( 107 "MSG_ProjectExist", projectDestFile.getName())); return; 109 } 110 111 setErrorMessage(null); 113 } 114 115 void setErrorMessage(String newMessage) { 116 String oldMessage = this.errorMessage; 117 this.errorMessage = newMessage; 118 firePropertyChange("errorMessage", oldMessage, newMessage); 119 } 120 121 boolean isWorkspaceChosen() { 122 return workspaceButton.isSelected(); 123 } 124 125 126 public String getProjectDir() { 127 return projectDir.getText().trim(); 128 } 129 130 131 public String getProjectDestinationDir() { 132 return projectDestDir.getText().trim(); 133 } 134 135 140 private void initComponents() { 142 java.awt.GridBagConstraints gridBagConstraints; 143 144 buttonGroup = new javax.swing.ButtonGroup (); 145 workspaceDir = new javax.swing.JTextField (); 146 worskpaceBrowse = new javax.swing.JButton (); 147 workSpaceLBL = new javax.swing.JLabel (); 148 projectDir = new javax.swing.JTextField (); 149 projectBrowse = new javax.swing.JButton (); 150 projectLBL = new javax.swing.JLabel (); 151 projectButton = new javax.swing.JRadioButton (); 152 workspaceButton = new javax.swing.JRadioButton (); 153 projectDestLBL = new javax.swing.JLabel (); 154 projectDestDir = new javax.swing.JTextField (); 155 projectDestBrowse = new javax.swing.JButton (); 156 wsDescription = new javax.swing.JTextArea (); 157 note = new javax.swing.JTextArea (); 158 159 setLayout(new java.awt.GridBagLayout ()); 160 161 gridBagConstraints = new java.awt.GridBagConstraints (); 162 gridBagConstraints.gridx = 1; 163 gridBagConstraints.gridy = 2; 164 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 165 gridBagConstraints.weightx = 1.0; 166 add(workspaceDir, gridBagConstraints); 167 168 org.openide.awt.Mnemonics.setLocalizedText(worskpaceBrowse, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "CTL_BrowseButton_B")); 169 worskpaceBrowse.addActionListener(new java.awt.event.ActionListener () { 170 public void actionPerformed(java.awt.event.ActionEvent evt) { 171 worskpaceBrowseActionPerformed(evt); 172 } 173 }); 174 175 gridBagConstraints = new java.awt.GridBagConstraints (); 176 gridBagConstraints.gridx = 2; 177 gridBagConstraints.gridy = 2; 178 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 179 gridBagConstraints.insets = new java.awt.Insets (0, 11, 0, 0); 180 add(worskpaceBrowse, gridBagConstraints); 181 182 workSpaceLBL.setLabelFor(workspaceDir); 183 org.openide.awt.Mnemonics.setLocalizedText(workSpaceLBL, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "LBL_Workspace")); 184 gridBagConstraints = new java.awt.GridBagConstraints (); 185 gridBagConstraints.gridx = 0; 186 gridBagConstraints.gridy = 2; 187 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 188 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 189 gridBagConstraints.insets = new java.awt.Insets (0, 14, 0, 12); 190 add(workSpaceLBL, gridBagConstraints); 191 192 gridBagConstraints = new java.awt.GridBagConstraints (); 193 gridBagConstraints.gridx = 1; 194 gridBagConstraints.gridy = 4; 195 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 196 gridBagConstraints.weightx = 1.0; 197 add(projectDir, gridBagConstraints); 198 199 org.openide.awt.Mnemonics.setLocalizedText(projectBrowse, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "CTL_BrowseButton_R")); 200 projectBrowse.addActionListener(new java.awt.event.ActionListener () { 201 public void actionPerformed(java.awt.event.ActionEvent evt) { 202 projectBrowseActionPerformed(evt); 203 } 204 }); 205 206 gridBagConstraints = new java.awt.GridBagConstraints (); 207 gridBagConstraints.gridx = 2; 208 gridBagConstraints.gridy = 4; 209 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 210 gridBagConstraints.insets = new java.awt.Insets (0, 11, 0, 0); 211 add(projectBrowse, gridBagConstraints); 212 213 projectLBL.setLabelFor(projectDir); 214 org.openide.awt.Mnemonics.setLocalizedText(projectLBL, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "LBL_Project")); 215 gridBagConstraints = new java.awt.GridBagConstraints (); 216 gridBagConstraints.gridx = 0; 217 gridBagConstraints.gridy = 4; 218 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 219 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 220 gridBagConstraints.insets = new java.awt.Insets (0, 14, 0, 12); 221 add(projectLBL, gridBagConstraints); 222 223 buttonGroup.add(projectButton); 224 org.openide.awt.Mnemonics.setLocalizedText(projectButton, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "CTL_ProjectButton")); 225 projectButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 226 projectButton.setMargin(new java.awt.Insets (0, 0, 0, 0)); 227 projectButton.addActionListener(new java.awt.event.ActionListener () { 228 public void actionPerformed(java.awt.event.ActionEvent evt) { 229 projectButtonActionPerformed(evt); 230 } 231 }); 232 233 gridBagConstraints = new java.awt.GridBagConstraints (); 234 gridBagConstraints.gridx = 0; 235 gridBagConstraints.gridy = 3; 236 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 237 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 238 gridBagConstraints.insets = new java.awt.Insets (11, 0, 6, 0); 239 add(projectButton, gridBagConstraints); 240 241 buttonGroup.add(workspaceButton); 242 workspaceButton.setSelected(true); 243 org.openide.awt.Mnemonics.setLocalizedText(workspaceButton, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "CTL_WorkspaceButton")); 244 workspaceButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 245 workspaceButton.setMargin(new java.awt.Insets (0, 0, 0, 0)); 246 workspaceButton.addActionListener(new java.awt.event.ActionListener () { 247 public void actionPerformed(java.awt.event.ActionEvent evt) { 248 workspaceButtonActionPerformed(evt); 249 } 250 }); 251 252 gridBagConstraints = new java.awt.GridBagConstraints (); 253 gridBagConstraints.gridx = 0; 254 gridBagConstraints.gridy = 1; 255 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 256 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 257 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 258 add(workspaceButton, gridBagConstraints); 259 260 projectDestLBL.setLabelFor(projectDestDir); 261 org.openide.awt.Mnemonics.setLocalizedText(projectDestLBL, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "LBL_ProjectDestination")); 262 gridBagConstraints = new java.awt.GridBagConstraints (); 263 gridBagConstraints.gridx = 0; 264 gridBagConstraints.gridy = 5; 265 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 266 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 267 gridBagConstraints.insets = new java.awt.Insets (0, 14, 0, 12); 268 add(projectDestLBL, gridBagConstraints); 269 270 gridBagConstraints = new java.awt.GridBagConstraints (); 271 gridBagConstraints.gridx = 1; 272 gridBagConstraints.gridy = 5; 273 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 274 gridBagConstraints.weightx = 1.0; 275 add(projectDestDir, gridBagConstraints); 276 277 org.openide.awt.Mnemonics.setLocalizedText(projectDestBrowse, org.openide.util.NbBundle.getMessage(SelectionPanel.class, "CTL_BrowseButton_S")); 278 projectDestBrowse.addActionListener(new java.awt.event.ActionListener () { 279 public void actionPerformed(java.awt.event.ActionEvent evt) { 280 projectDestBrowseActionPerformed(evt); 281 } 282 }); 283 284 gridBagConstraints = new java.awt.GridBagConstraints (); 285 gridBagConstraints.gridx = 2; 286 gridBagConstraints.gridy = 5; 287 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 288 gridBagConstraints.insets = new java.awt.Insets (0, 11, 0, 0); 289 add(projectDestBrowse, gridBagConstraints); 290 291 wsDescription.setEditable(false); 292 wsDescription.setLineWrap(true); 293 wsDescription.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/projectimport/eclipse/wizard/Bundle").getString("LBL_SpecifyWorkspaceDescription")); 294 wsDescription.setWrapStyleWord(true); 295 gridBagConstraints = new java.awt.GridBagConstraints (); 296 gridBagConstraints.gridx = 0; 297 gridBagConstraints.gridy = 0; 298 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 299 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 300 gridBagConstraints.insets = new java.awt.Insets (0, 0, 24, 0); 301 add(wsDescription, gridBagConstraints); 302 303 note.setEditable(false); 304 note.setLineWrap(true); 305 note.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/projectimport/eclipse/wizard/Bundle").getString("LBL_NoteAboutWorkspaceAdvantage")); 306 note.setWrapStyleWord(true); 307 gridBagConstraints = new java.awt.GridBagConstraints (); 308 gridBagConstraints.gridx = 0; 309 gridBagConstraints.gridy = 6; 310 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 311 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 312 gridBagConstraints.weighty = 1.0; 313 gridBagConstraints.insets = new java.awt.Insets (24, 0, 0, 0); 314 add(note, gridBagConstraints); 315 316 } private void projectDestBrowseActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (projectDestDir.getText()); 319 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 320 int ret = chooser.showOpenDialog(this); 321 if (ret == JFileChooser.APPROVE_OPTION) { 322 projectDestDir.setText(chooser.getSelectedFile().getAbsolutePath()); 323 } 324 } 326 private void projectButtonActionPerformed(java.awt.event.ActionEvent evt) { setWorkspaceEnabled(false); 328 projectChanged(); 329 projectDir.requestFocusInWindow(); 330 firePropertyChange("workspaceChoosen", true, false); } 333 private void workspaceButtonActionPerformed(java.awt.event.ActionEvent evt) { setWorkspaceEnabled(true); 335 workspaceChanged(); 336 firePropertyChange("workspaceChoosen", false, true); } 339 private void setWorkspaceEnabled(boolean enabled) { 340 workSpaceLBL.setEnabled(enabled); 341 worskpaceBrowse.setEnabled(enabled); 342 workspaceDir.setEnabled(enabled); 343 projectLBL.setEnabled(!enabled); 344 projectBrowse.setEnabled(!enabled); 345 projectDir.setEnabled(!enabled); 346 projectDestBrowse.setEnabled(!enabled); 347 projectDestDir.setEnabled(!enabled); 348 projectDestLBL.setEnabled(!enabled); 349 } 350 351 private void projectBrowseActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (projectDir.getText()); 353 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 354 int ret = chooser.showOpenDialog(this); 355 if (ret == JFileChooser.APPROVE_OPTION) { 356 projectDir.setText(chooser.getSelectedFile().getAbsolutePath()); 357 } 358 } 360 private void worskpaceBrowseActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (getWorkspaceDir()); 362 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 363 int ret = chooser.showOpenDialog(this); 364 if (ret == JFileChooser.APPROVE_OPTION) { 365 workspaceDir.setText(chooser.getSelectedFile().getAbsolutePath()); 366 } 367 } 369 370 private javax.swing.ButtonGroup buttonGroup; 372 private javax.swing.JTextArea note; 373 private javax.swing.JButton projectBrowse; 374 private javax.swing.JRadioButton projectButton; 375 private javax.swing.JButton projectDestBrowse; 376 private javax.swing.JTextField projectDestDir; 377 private javax.swing.JLabel projectDestLBL; 378 private javax.swing.JTextField projectDir; 379 private javax.swing.JLabel projectLBL; 380 private javax.swing.JLabel workSpaceLBL; 381 private javax.swing.JRadioButton workspaceButton; 382 private javax.swing.JTextField workspaceDir; 383 private javax.swing.JButton worskpaceBrowse; 384 private javax.swing.JTextArea wsDescription; 385 } 387 | Popular Tags |