This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 227877
Collapse All | Expand All

(-)a/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanel.java (-7 / +26 lines)
Lines 379-393 Link Here
379
        return true;
379
        return true;
380
    }
380
    }
381
    
381
    
382
    static String getTypeFromFQN(String name) {
383
        int lastIndexOf = name.lastIndexOf('.');
384
        final boolean isFQN = (lastIndexOf > 0 && lastIndexOf < name.length());
385
        if (isFQN) {
386
            return name.substring(lastIndexOf + 1);
387
        }
388
        return null;
389
    }
390
391
    static String getPackageFromFQN(String name) {
392
        int lastIndexOf = name.lastIndexOf('.');
393
        final boolean isFQN = (lastIndexOf > 0 && lastIndexOf < name.length());
394
        if (isFQN) {
395
            return name.substring(0, lastIndexOf);
396
        }
397
        return null;
398
    }
399
382
    static boolean isValidTypeIdentifier(String ident) {
400
    static boolean isValidTypeIdentifier(String ident) {
383
        if (ident == null || "".equals(ident) || !Utilities.isJavaIdentifier( ident ) ) {
401
        final boolean javaIdentifier = Utilities.isJavaIdentifier(ident);
384
            return false;
402
        final boolean javaIdenfifierWithinFQN = isValidTypeIdentifierWithinFQN(ident);
385
        }
403
        return ident != null && !"".equals(ident) && (javaIdentifier || javaIdenfifierWithinFQN);
386
        else {
387
            return true;
388
        }
389
    }
404
    }
390
    
405
406
    static boolean isValidTypeIdentifierWithinFQN(String ident) {
407
        String type = getTypeFromFQN(ident);
408
        return type != null && Utilities.isJavaIdentifier(type);
409
    }
391
    // helper methods copied from project/ui/ProjectUtilities
410
    // helper methods copied from project/ui/ProjectUtilities
392
    /** Checks if the given file name can be created in the target folder.
411
    /** Checks if the given file name can be created in the target folder.
393
     *
412
     *
(-)a/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanelGUI.form (-1 / +1 lines)
Lines 1-4 Link Here
1
<?xml version="1.1" encoding="UTF-8" ?>
1
<?xml version="1.0" encoding="UTF-8" ?>
2
2
3
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3
<Form version="1.2" maxVersion="1.2" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4
  <AccessibilityProperties>
4
  <AccessibilityProperties>
(-)a/java.project/src/org/netbeans/modules/java/project/JavaTargetChooserPanelGUI.java (-1 / +44 lines)
Lines 60-65 Link Here
60
import javax.swing.event.ChangeEvent;
60
import javax.swing.event.ChangeEvent;
61
import javax.swing.event.ChangeListener;
61
import javax.swing.event.ChangeListener;
62
import javax.swing.event.DocumentListener;
62
import javax.swing.event.DocumentListener;
63
import javax.swing.text.Document;
63
import org.netbeans.api.project.Project;
64
import org.netbeans.api.project.Project;
64
import org.netbeans.api.project.ProjectUtils;
65
import org.netbeans.api.project.ProjectUtils;
65
import org.netbeans.api.project.SourceGroup;
66
import org.netbeans.api.project.SourceGroup;
Lines 72-77 Link Here
72
import org.openide.loaders.DataObjectNotFoundException;
73
import org.openide.loaders.DataObjectNotFoundException;
73
import org.openide.util.NbBundle;
74
import org.openide.util.NbBundle;
74
import org.openide.util.RequestProcessor;
75
import org.openide.util.RequestProcessor;
76
import static org.netbeans.modules.java.project.JavaTargetChooserPanel.getPackageFromFQN;
77
import static org.netbeans.modules.java.project.JavaTargetChooserPanel.getTypeFromFQN;
75
78
76
/**
79
/**
77
 * Permits user to select a package to place a Java class (or other resource) into.
80
 * Permits user to select a package to place a Java class (or other resource) into.
Lines 267-273 Link Here
267
    }    
270
    }    
268
    
271
    
269
    public String getTargetName() {
272
    public String getTargetName() {
270
        String text = documentNameTextField.getText().trim();
273
        String text;
274
        String nameFromFQN = getTypeFromFQN(documentNameTextField.getText().trim());
275
        if (null != nameFromFQN) {
276
            text = nameFromFQN;
277
        } else {
278
            text = documentNameTextField.getText().trim();
279
        }
271
        
280
        
272
        if ( text.length() == 0 ) {
281
        if ( text.length() == 0 ) {
273
            return null;
282
            return null;
Lines 525-530 Link Here
525
        });                
534
        });                
526
    }
535
    }
527
        
536
        
537
    private boolean wasPreviouslyFQN = false;
538
    private String originalPackageName;
528
    private void updateText() {
539
    private void updateText() {
529
        final Object selectedItem =  rootComboBox.getSelectedItem();
540
        final Object selectedItem =  rootComboBox.getSelectedItem();
530
        String createdFileName;
541
        String createdFileName;
Lines 533-544 Link Here
533
            FileObject rootFolder = g.getRootFolder();
544
            FileObject rootFolder = g.getRootFolder();
534
            String packageName = getPackageFileName();
545
            String packageName = getPackageFileName();
535
            String documentName = documentNameTextField.getText().trim();
546
            String documentName = documentNameTextField.getText().trim();
547
            if (Type.FILE.equals(type)) {
548
                final boolean isFQN = null != getTypeFromFQN(documentName);
549
                if (isFQN) {
550
                    if (!wasPreviouslyFQN) {
551
                        //backup the original package name
552
                        originalPackageName = getPackageName();
553
                    }
554
                    //set the textfield from the parsed FQN text
555
                    packageName = getPackageFromFQN(documentName);
556
                    documentName = getTypeFromFQN(documentName);
557
                    setPackageFieldWithoutNotifyingListeners(null != packageName ? packageName : "");
558
                    wasPreviouslyFQN = true;
559
                } else {
560
                    if (wasPreviouslyFQN) {
561
                        //reset the package name, if the user reverts his previously entered FQN
562
                        setPackageFieldWithoutNotifyingListeners(originalPackageName);
563
                        wasPreviouslyFQN = false;
564
                    }
565
                }
566
                packageComboBox.setEnabled(!isFQN);
567
            }
536
            if (type == Type.PACKAGE) {
568
            if (type == Type.PACKAGE) {
537
                documentName = documentName.replace( '.', '/' ); // NOI18N
569
                documentName = documentName.replace( '.', '/' ); // NOI18N
538
            }
570
            }
539
            else if ( documentName.length() > 0 ) {
571
            else if ( documentName.length() > 0 ) {
540
                documentName = documentName + expectedExtension;
572
                documentName = documentName + expectedExtension;
541
            }
573
            }
574
            packageName = packageName.replace('.', '/');
542
            createdFileName = FileUtil.getFileDisplayName( rootFolder ) +
575
            createdFileName = FileUtil.getFileDisplayName( rootFolder ) +
543
                ( packageName.startsWith("/") || packageName.startsWith( File.separator ) ? "" : "/" ) + // NOI18N
576
                ( packageName.startsWith("/") || packageName.startsWith( File.separator ) ? "" : "/" ) + // NOI18N
544
                packageName +
577
                packageName +
Lines 596-601 Link Here
596
            return name;
629
            return name;
597
        }        
630
        }        
598
    }
631
    }
632
633
    void setPackageFieldWithoutNotifyingListeners(final String text) {
634
	Component packageEditor = packageComboBox.getEditor().getEditorComponent();
635
	if (packageEditor instanceof javax.swing.JTextField) {
636
	    Document document = ((javax.swing.JTextField) packageEditor).getDocument();
637
	    document.removeDocumentListener(this);
638
	    ((javax.swing.JTextField) packageEditor).setText(text);
639
	    document.addDocumentListener(this);
640
	}
641
    }
599
    
642
    
600
    // Private innerclasses ----------------------------------------------------
643
    // Private innerclasses ----------------------------------------------------
601
644

Return to bug 227877