diff --git a/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanel.java b/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanel.java --- a/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanel.java +++ b/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanel.java @@ -52,6 +52,7 @@ import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; +import javax.lang.model.SourceVersion; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import org.netbeans.api.java.queries.SourceLevelQuery; @@ -379,15 +380,33 @@ return true; } - static boolean isValidTypeIdentifier(String ident) { - if (ident == null || "".equals(ident) || !Utilities.isJavaIdentifier( ident ) ) { - return false; - } - else { - return true; - } + static String getTypeFromFQN(String name) { + int lastIndexOf = name.lastIndexOf('.'); + final boolean isFQN = (lastIndexOf > 0 && lastIndexOf< name.length()); + if (isFQN) { + return name.substring(lastIndexOf + 1); + } + return null; + } + static String getPackageFromFQN(String name) { + int lastIndexOf = name.lastIndexOf('.'); + final boolean isFQN = (lastIndexOf > 0 && lastIndexOf < name.length()); + if (isFQN) { + return name.substring(0, lastIndexOf); + } + return null; } + static boolean isValidTypeIdentifier(String ident) { + final boolean javaIdentifier = Utilities.isJavaIdentifier( ident ); + final boolean javaIdenfifierWithinFQN=isValidTypeIdentifierWithinFQN(ident); + return ident != null && !"".equals(ident) && (javaIdentifier || javaIdenfifierWithinFQN); + } + + static boolean isValidTypeIdentifierWithinFQN(String ident) { + String type = getTypeFromFQN(ident); + return type != null && Utilities.isJavaIdentifier(type); + } // helper methods copied from project/ui/ProjectUtilities /** Checks if the given file name can be created in the target folder. * diff --git a/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanelGUI.form b/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanelGUI.form --- a/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanelGUI.form +++ b/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanelGUI.form @@ -1,4 +1,4 @@ - +
diff --git a/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanelGUI.java b/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanelGUI.java --- a/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanelGUI.java +++ b/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanelGUI.java @@ -72,6 +72,8 @@ import org.openide.loaders.DataObjectNotFoundException; import org.openide.util.NbBundle; import org.openide.util.RequestProcessor; +import static org.netbeans.modules.java.project.JavaTargetChooserPanel.getPackageFromFQN; +import static org.netbeans.modules.java.project.JavaTargetChooserPanel.getTypeFromFQN; /** * Permits user to select a package to place a Java class (or other resource) into. @@ -267,7 +269,13 @@ } public String getTargetName() { - String text = documentNameTextField.getText().trim(); + String text; + String nameFromFQN = getTypeFromFQN(documentNameTextField.getText().trim()); + if (null != nameFromFQN) { + text = nameFromFQN; + } else { + text = documentNameTextField.getText().trim(); + } if ( text.length() == 0 ) { return null; @@ -524,31 +532,65 @@ } }); } - + + boolean isUpdating=false; + boolean wasPreviouslyFQN=false; private void updateText() { - final Object selectedItem = rootComboBox.getSelectedItem(); - String createdFileName; - if (selectedItem instanceof SourceGroup) { - SourceGroup g = (SourceGroup) selectedItem; - FileObject rootFolder = g.getRootFolder(); - String packageName = getPackageFileName(); - String documentName = documentNameTextField.getText().trim(); - if (type == Type.PACKAGE) { - documentName = documentName.replace( '.', '/' ); // NOI18N - } - else if ( documentName.length() > 0 ) { - documentName = documentName + expectedExtension; - } - createdFileName = FileUtil.getFileDisplayName( rootFolder ) + - ( packageName.startsWith("/") || packageName.startsWith( File.separator ) ? "" : "/" ) + // NOI18N - packageName + - ( packageName.endsWith("/") || packageName.endsWith( File.separator ) || packageName.length() == 0 ? "" : "/" ) + // NOI18N - documentName; - } else { - //May be null iff nothing selected - createdFileName = ""; //NOI18N - } - fileTextField.setText( createdFileName.replace( '/', File.separatorChar ) ); // NOI18N + if (isUpdating) { + return; + } + try { + isUpdating = true; + final Object selectedItem = rootComboBox.getSelectedItem(); + String createdFileName; + if (selectedItem instanceof SourceGroup) { + SourceGroup g = (SourceGroup) selectedItem; + FileObject rootFolder = g.getRootFolder(); + String packageName = getPackageFileName(); + String documentName = documentNameTextField.getText().trim(); + if (Type.FILE.equals(type)) { + final boolean isFQN = null != getTypeFromFQN(documentName); + if (isFQN) { + //set the textfield from the parsed FQN text + packageName = getPackageFromFQN(documentName); + documentName = getTypeFromFQN(documentName); + + Component packageEditor = packageComboBox.getEditor().getEditorComponent(); + if (packageEditor instanceof javax.swing.JTextField) { + ((javax.swing.JTextField) packageEditor).setText(null!=packageName?packageName:""); + } + wasPreviouslyFQN = true; + }else{ + if (wasPreviouslyFQN) { + //reset the package name, if the user reverts his previously entered FQN + Component packageEditor = packageComboBox.getEditor().getEditorComponent(); + if (packageEditor instanceof javax.swing.JTextField) { + ((javax.swing.JTextField) packageEditor).setText(""); + } + wasPreviouslyFQN=false; + } + } + packageComboBox.setEnabled(!isFQN); + } + if (type == Type.PACKAGE) { + documentName = documentName.replace('.', '/'); // NOI18N + } else if (documentName.length() > 0) { + documentName = documentName + expectedExtension; + } + packageName=packageName.replace('.', '/'); + createdFileName = FileUtil.getFileDisplayName(rootFolder) + + (packageName.startsWith("/") || packageName.startsWith(File.separator) ? "" : "/") + // NOI18N + packageName + + (packageName.endsWith("/") || packageName.endsWith(File.separator) || packageName.length() == 0 ? "" : "/") + // NOI18N + documentName; + } else { + //May be null iff nothing selected + createdFileName = ""; //NOI18N + } + fileTextField.setText(createdFileName.replace('/', File.separatorChar)); // NOI18N + } finally { + isUpdating = false; + } } private SourceGroup getPreselectedGroup(FileObject folder) {