Lines 72-77
Link Here
|
72 |
import org.openide.loaders.DataObjectNotFoundException; |
72 |
import org.openide.loaders.DataObjectNotFoundException; |
73 |
import org.openide.util.NbBundle; |
73 |
import org.openide.util.NbBundle; |
74 |
import org.openide.util.RequestProcessor; |
74 |
import org.openide.util.RequestProcessor; |
|
|
75 |
import static org.netbeans.modules.java.project.JavaTargetChooserPanel.getPackageFromFQN; |
76 |
import static org.netbeans.modules.java.project.JavaTargetChooserPanel.getTypeFromFQN; |
75 |
|
77 |
|
76 |
/** |
78 |
/** |
77 |
* Permits user to select a package to place a Java class (or other resource) into. |
79 |
* Permits user to select a package to place a Java class (or other resource) into. |
Lines 267-273
Link Here
|
267 |
} |
269 |
} |
268 |
|
270 |
|
269 |
public String getTargetName() { |
271 |
public String getTargetName() { |
270 |
String text = documentNameTextField.getText().trim(); |
272 |
String text; |
|
|
273 |
String nameFromFQN = getTypeFromFQN(documentNameTextField.getText().trim()); |
274 |
if (null != nameFromFQN) { |
275 |
text = nameFromFQN; |
276 |
} else { |
277 |
text = documentNameTextField.getText().trim(); |
278 |
} |
271 |
|
279 |
|
272 |
if ( text.length() == 0 ) { |
280 |
if ( text.length() == 0 ) { |
273 |
return null; |
281 |
return null; |
Lines 524-554
Link Here
|
524 |
} |
532 |
} |
525 |
}); |
533 |
}); |
526 |
} |
534 |
} |
527 |
|
535 |
|
|
|
536 |
boolean isUpdating=false; |
537 |
boolean wasPreviouslyFQN=false; |
528 |
private void updateText() { |
538 |
private void updateText() { |
529 |
final Object selectedItem = rootComboBox.getSelectedItem(); |
539 |
if (isUpdating) { |
530 |
String createdFileName; |
540 |
return; |
531 |
if (selectedItem instanceof SourceGroup) { |
541 |
} |
532 |
SourceGroup g = (SourceGroup) selectedItem; |
542 |
try { |
533 |
FileObject rootFolder = g.getRootFolder(); |
543 |
isUpdating = true; |
534 |
String packageName = getPackageFileName(); |
544 |
final Object selectedItem = rootComboBox.getSelectedItem(); |
535 |
String documentName = documentNameTextField.getText().trim(); |
545 |
String createdFileName; |
536 |
if (type == Type.PACKAGE) { |
546 |
if (selectedItem instanceof SourceGroup) { |
537 |
documentName = documentName.replace( '.', '/' ); // NOI18N |
547 |
SourceGroup g = (SourceGroup) selectedItem; |
538 |
} |
548 |
FileObject rootFolder = g.getRootFolder(); |
539 |
else if ( documentName.length() > 0 ) { |
549 |
String packageName = getPackageFileName(); |
540 |
documentName = documentName + expectedExtension; |
550 |
String documentName = documentNameTextField.getText().trim(); |
541 |
} |
551 |
if (Type.FILE.equals(type)) { |
542 |
createdFileName = FileUtil.getFileDisplayName( rootFolder ) + |
552 |
final boolean isFQN = null != getTypeFromFQN(documentName); |
543 |
( packageName.startsWith("/") || packageName.startsWith( File.separator ) ? "" : "/" ) + // NOI18N |
553 |
if (isFQN) { |
544 |
packageName + |
554 |
//set the textfield from the parsed FQN text |
545 |
( packageName.endsWith("/") || packageName.endsWith( File.separator ) || packageName.length() == 0 ? "" : "/" ) + // NOI18N |
555 |
packageName = getPackageFromFQN(documentName); |
546 |
documentName; |
556 |
documentName = getTypeFromFQN(documentName); |
547 |
} else { |
557 |
|
548 |
//May be null iff nothing selected |
558 |
Component packageEditor = packageComboBox.getEditor().getEditorComponent(); |
549 |
createdFileName = ""; //NOI18N |
559 |
if (packageEditor instanceof javax.swing.JTextField) { |
550 |
} |
560 |
((javax.swing.JTextField) packageEditor).setText(null!=packageName?packageName:""); |
551 |
fileTextField.setText( createdFileName.replace( '/', File.separatorChar ) ); // NOI18N |
561 |
} |
|
|
562 |
wasPreviouslyFQN = true; |
563 |
}else{ |
564 |
if (wasPreviouslyFQN) { |
565 |
//reset the package name, if the user reverts his previously entered FQN |
566 |
Component packageEditor = packageComboBox.getEditor().getEditorComponent(); |
567 |
if (packageEditor instanceof javax.swing.JTextField) { |
568 |
((javax.swing.JTextField) packageEditor).setText(""); |
569 |
} |
570 |
wasPreviouslyFQN=false; |
571 |
} |
572 |
} |
573 |
packageComboBox.setEnabled(!isFQN); |
574 |
} |
575 |
if (type == Type.PACKAGE) { |
576 |
documentName = documentName.replace('.', '/'); // NOI18N |
577 |
} else if (documentName.length() > 0) { |
578 |
documentName = documentName + expectedExtension; |
579 |
} |
580 |
packageName=packageName.replace('.', '/'); |
581 |
createdFileName = FileUtil.getFileDisplayName(rootFolder) |
582 |
+ (packageName.startsWith("/") || packageName.startsWith(File.separator) ? "" : "/") + // NOI18N |
583 |
packageName |
584 |
+ (packageName.endsWith("/") || packageName.endsWith(File.separator) || packageName.length() == 0 ? "" : "/") + // NOI18N |
585 |
documentName; |
586 |
} else { |
587 |
//May be null iff nothing selected |
588 |
createdFileName = ""; //NOI18N |
589 |
} |
590 |
fileTextField.setText(createdFileName.replace('/', File.separatorChar)); // NOI18N |
591 |
} finally { |
592 |
isUpdating = false; |
593 |
} |
552 |
} |
594 |
} |
553 |
|
595 |
|
554 |
private SourceGroup getPreselectedGroup(FileObject folder) { |
596 |
private SourceGroup getPreselectedGroup(FileObject folder) { |