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 52-57 Link Here
52
import java.util.Iterator;
52
import java.util.Iterator;
53
import java.util.List;
53
import java.util.List;
54
import java.util.StringTokenizer;
54
import java.util.StringTokenizer;
55
import javax.lang.model.SourceVersion;
55
import javax.swing.event.ChangeEvent;
56
import javax.swing.event.ChangeEvent;
56
import javax.swing.event.ChangeListener;
57
import javax.swing.event.ChangeListener;
57
import org.netbeans.api.java.queries.SourceLevelQuery;
58
import org.netbeans.api.java.queries.SourceLevelQuery;
Lines 379-393 Link Here
379
        return true;
380
        return true;
380
    }
381
    }
381
    
382
    
382
    static boolean isValidTypeIdentifier(String ident) {
383
       static String getTypeFromFQN(String name) {
383
        if (ident == null || "".equals(ident) || !Utilities.isJavaIdentifier( ident ) ) {
384
	int lastIndexOf = name.lastIndexOf('.');
384
            return false;
385
	final boolean isFQN = (lastIndexOf > 0 && lastIndexOf< name.length());
385
        }
386
	if (isFQN) {
386
        else {
387
	    return name.substring(lastIndexOf + 1);
387
            return true;
388
	}
388
        }
389
	return null;
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;
389
    }
398
    }
390
    
399
    
400
    static boolean isValidTypeIdentifier(String ident) {
401
	final boolean javaIdentifier = Utilities.isJavaIdentifier( ident );
402
	final boolean javaIdenfifierWithinFQN=isValidTypeIdentifierWithinFQN(ident);
403
	return ident != null && !"".equals(ident) && (javaIdentifier || javaIdenfifierWithinFQN);
404
    }
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 (-25 / +67 lines)
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) {

Return to bug 227877