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 141886
Collapse All | Expand All

(-)a/php.project/src/org/netbeans/modules/php/project/ui/wizards/Bundle.properties (-3 lines)
Lines 46-54 Link Here
46
Templates/Scripting/PHPClass=PHP Class
46
Templates/Scripting/PHPClass=PHP Class
47
Templates/Scripting/PHPInterface=PHP Interface
47
Templates/Scripting/PHPInterface=PHP Interface
48
48
49
# new file wizard
50
TXT_FileExists=File {0} already exists!
51
52
# PHP project wizards
49
# PHP project wizards
53
TXT_PhpProject=PHP Project
50
TXT_PhpProject=PHP Project
54
TXT_ExistingPhpProject=PHP Project with Existing Sources
51
TXT_ExistingPhpProject=PHP Project with Existing Sources
(-)a/php.project/src/org/netbeans/modules/php/project/ui/wizards/NewFileWizardIterator.java (-32 / +2 lines)
Lines 65-71 Link Here
65
import org.openide.filesystems.FileUtil;
65
import org.openide.filesystems.FileUtil;
66
import org.openide.loaders.DataFolder;
66
import org.openide.loaders.DataFolder;
67
import org.openide.loaders.DataObject;
67
import org.openide.loaders.DataObject;
68
import org.openide.util.NbBundle;
69
68
70
/**
69
/**
71
 * Just as simple wrapper for the standard new file iterator as possible.
70
 * Just as simple wrapper for the standard new file iterator as possible.
Lines 88-120 Link Here
88
87
89
        DataFolder dataFolder = DataFolder.findFolder(dir);
88
        DataFolder dataFolder = DataFolder.findFolder(dir);
90
        DataObject dataTemplate = DataObject.find(template);
89
        DataObject dataTemplate = DataObject.find(template);
91
        String fname = Templates.getTargetName(wizard);
90
        DataObject createdFile = dataTemplate.createFromTemplate(dataFolder, Templates.getTargetName(wizard), wizardProps);
92
        String ext = FileUtil.getExtension(fname);
93
94
        FileObject foo = FileUtil.createData(FileUtil.createMemoryFileSystem().getRoot(), fname);
95
        if (foo == null || !FileUtils.isPhpFile(foo)) {
96
            if (!StringUtils.hasText(ext)) {
97
                Templates.setTargetName(wizard, fname + ".php"); // NOI18N
98
                fname = Templates.getTargetName(wizard);
99
                ext = FileUtil.getExtension(fname);
100
            }
101
        }
102
        if (StringUtils.hasText(ext)) {
103
            String name = fname.substring(0, fname.length() - ext.length() - 1);
104
            name = name.replaceAll("\\W", ""); // NOI18N
105
            wizardProps.put("name", name); // NOI18N
106
107
            // #168723
108
            String templateExt = FileUtil.getExtension(template.getNameExt());
109
            if (StringUtils.hasText(templateExt)) {
110
                Templates.setTargetName(wizard, name);
111
            }
112
        }
113
        String targetName = Templates.getTargetName(wizard);
114
        if (dir.getFileObject(targetName) != null) {
115
            throw new IOException(NbBundle.getMessage(NewFileWizardIterator.class, "TXT_FileExists", targetName));
116
        }
117
        DataObject createdFile = dataTemplate.createFromTemplate(dataFolder, targetName, wizardProps);
118
91
119
        return Collections.singleton(createdFile.getPrimaryFile());
92
        return Collections.singleton(createdFile.getPrimaryFile());
120
    }
93
    }
Lines 133-141 Link Here
133
                Templates.setTargetFolder(wizard, srcDir);
106
                Templates.setTargetFolder(wizard, srcDir);
134
            }
107
            }
135
        }
108
        }
136
        FileObject template = Templates.getTemplate(wizard);
137
        String targetName = targetFolder != null ? FileUtil.findFreeFileName(targetFolder, template.getName(), "php") : template.getName(); // NOI18N
138
        Templates.setTargetName(wizard, targetName + ".php"); // NOI18N
139
        wizardPanels = getPanels();
109
        wizardPanels = getPanels();
140
110
141
        // Make sure list of steps is accurate.
111
        // Make sure list of steps is accurate.
Lines 271-277 Link Here
271
                    new IllegalStateException("No source roots found (attach your IDE log to https://netbeans.org/bugzilla/show_bug.cgi?id=180054)"));
241
                    new IllegalStateException("No source roots found (attach your IDE log to https://netbeans.org/bugzilla/show_bug.cgi?id=180054)"));
272
            groups = null;
242
            groups = null;
273
        }
243
        }
274
        WizardDescriptor.Panel<WizardDescriptor> simpleTargetChooserPanel = Templates.createSimpleTargetChooser(p, groups);
244
        WizardDescriptor.Panel<WizardDescriptor> simpleTargetChooserPanel = Templates.buildSimpleTargetChooser(p, groups).freeFileExtension().create();
275
245
276
        @SuppressWarnings("unchecked") // Generic Array Creation
246
        @SuppressWarnings("unchecked") // Generic Array Creation
277
        WizardDescriptor.Panel<WizardDescriptor>[] panels = new WizardDescriptor.Panel[] {
247
        WizardDescriptor.Panel<WizardDescriptor>[] panels = new WizardDescriptor.Panel[] {
(-)a/projectui/src/org/netbeans/modules/project/ui/NewFileIterator.java (-2 / +2 lines)
Lines 107-115 Link Here
107
            currentProject = project;
107
            currentProject = project;
108
            Sources sources = ProjectUtils.getSources(project);
108
            Sources sources = ProjectUtils.getSources(project);
109
            if (isFolder) {
109
            if (isFolder) {
110
                panel = new SimpleTargetChooserPanel(project, sources.getSourceGroups(Sources.TYPE_GENERIC), null, true);
110
                panel = new SimpleTargetChooserPanel(project, sources.getSourceGroups(Sources.TYPE_GENERIC), null, true, false);
111
            } else {
111
            } else {
112
                panel = Templates.createSimpleTargetChooser(project, sources.getSourceGroups(Sources.TYPE_GENERIC));
112
                panel = Templates.buildSimpleTargetChooser(project, sources.getSourceGroups(Sources.TYPE_GENERIC)).create();
113
            }
113
            }
114
        }
114
        }
115
        return panel;
115
        return panel;
(-)a/projectui/src/org/netbeans/modules/project/ui/NewFileWizard.java (-1 / +1 lines)
Lines 143-149 Link Here
143
143
144
    protected WizardDescriptor.Panel<WizardDescriptor> createTargetChooser() {
144
    protected WizardDescriptor.Panel<WizardDescriptor> createTargetChooser() {
145
        Sources c = ProjectUtils.getSources(getCurrentProject());
145
        Sources c = ProjectUtils.getSources(getCurrentProject());
146
        return Templates.createSimpleTargetChooser(getCurrentProject(), c.getSourceGroups(Sources.TYPE_GENERIC));
146
        return Templates.buildSimpleTargetChooser(getCurrentProject(), c.getSourceGroups(Sources.TYPE_GENERIC)).create();
147
    }
147
    }
148
}
148
}
149
 
149
 
(-)a/projectui/src/org/netbeans/modules/project/ui/ProjectChooserFactoryImpl.java (-2 / +3 lines)
Lines 62-69 Link Here
62
        return ProjectChooserAccessory.createProjectChooser( false );
62
        return ProjectChooserAccessory.createProjectChooser( false );
63
    }
63
    }
64
64
65
    public @Override WizardDescriptor.Panel<WizardDescriptor> createSimpleTargetChooser(Project project, SourceGroup[] folders, WizardDescriptor.Panel<WizardDescriptor> bottomPanel) {
65
    public @Override WizardDescriptor.Panel<WizardDescriptor> createSimpleTargetChooser(Project project, SourceGroup[] folders,
66
        return new SimpleTargetChooserPanel( project, folders, bottomPanel, false );
66
            WizardDescriptor.Panel<WizardDescriptor> bottomPanel, boolean freeFileExtension) {
67
        return new SimpleTargetChooserPanel(project, folders, bottomPanel, false, freeFileExtension);
67
    }
68
    }
68
69
69
    public @Override File getProjectsFolder() {
70
    public @Override File getProjectsFolder() {
(-)a/projectui/src/org/netbeans/modules/project/ui/ProjectUtilities.java (-2 / +3 lines)
Lines 322-328 Link Here
322
     *                           is allowed in the newObjectName
322
     *                           is allowed in the newObjectName
323
     * @return localized error message or null if all right
323
     * @return localized error message or null if all right
324
     */    
324
     */    
325
    public static String canUseFileName (FileObject targetFolder, String folderName, String newObjectName, String extension, boolean allowFileSeparator) {
325
    public static String canUseFileName (FileObject targetFolder, String folderName, String newObjectName,
326
            String extension, boolean allowFileSeparator, boolean freeFileExtension) {
326
        assert newObjectName != null; // SimpleTargetChooserPanel.isValid returns false if it is... XXX should it use an error label instead?
327
        assert newObjectName != null; // SimpleTargetChooserPanel.isValid returns false if it is... XXX should it use an error label instead?
327
328
328
        boolean allowSlash = false;
329
        boolean allowSlash = false;
Lines 372-378 Link Here
372
        }
373
        }
373
        relFileName.append(newObjectName);
374
        relFileName.append(newObjectName);
374
        String ext = "";
375
        String ext = "";
375
        if (extension != null && extension.length() != 0) {
376
        if (extension != null && extension.length() != 0 && (!freeFileExtension || newObjectName.indexOf('.') == -1)) {
376
            ext = "." + extension;
377
            ext = "." + extension;
377
            relFileName.append(ext);
378
            relFileName.append(ext);
378
        }
379
        }
(-)a/projectui/src/org/netbeans/modules/project/ui/SimpleTargetChooserPanel.java (-3 / +7 lines)
Lines 69-77 Link Here
69
    private WizardDescriptor.Panel<WizardDescriptor> bottomPanel;
69
    private WizardDescriptor.Panel<WizardDescriptor> bottomPanel;
70
    private WizardDescriptor wizard;
70
    private WizardDescriptor wizard;
71
    private boolean isFolder;
71
    private boolean isFolder;
72
    private boolean freeFileExtension;
72
    
73
    
73
    @SuppressWarnings("LeakingThisInConstructor")
74
    @SuppressWarnings("LeakingThisInConstructor")
74
    SimpleTargetChooserPanel(Project project, SourceGroup[] folders, WizardDescriptor.Panel<WizardDescriptor> bottomPanel, boolean isFolder) {
75
    SimpleTargetChooserPanel(Project project, SourceGroup[] folders,
76
            WizardDescriptor.Panel<WizardDescriptor> bottomPanel, boolean isFolder, boolean freeFileExtension) {
75
        this.folders = folders;
77
        this.folders = folders;
76
        if (folders != null && folders.length == 0) {
78
        if (folders != null && folders.length == 0) {
77
            throw new IllegalArgumentException("Attempting to create panel with an empty folders list"); // #161478
79
            throw new IllegalArgumentException("Attempting to create panel with an empty folders list"); // #161478
Lines 82-93 Link Here
82
            bottomPanel.addChangeListener( this );
84
            bottomPanel.addChangeListener( this );
83
        }
85
        }
84
        this.isFolder = isFolder;
86
        this.isFolder = isFolder;
87
        this.freeFileExtension = freeFileExtension;
85
        this.gui = null;
88
        this.gui = null;
86
    }
89
    }
87
90
88
    public @Override Component getComponent() {
91
    public @Override Component getComponent() {
89
        if (gui == null) {
92
        if (gui == null) {
90
            gui = new SimpleTargetChooserPanelGUI( project, folders, bottomPanel == null ? null : bottomPanel.getComponent(), isFolder );
93
            gui = new SimpleTargetChooserPanelGUI(project, folders, bottomPanel == null ? null : bottomPanel.getComponent(), isFolder, freeFileExtension);
91
            gui.addChangeListener(this);
94
            gui.addChangeListener(this);
92
        }
95
        }
93
        return gui;
96
        return gui;
Lines 117-123 Link Here
117
        // check if the file name can be created
120
        // check if the file name can be created
118
        FileObject template = Templates.getTemplate( wizard );
121
        FileObject template = Templates.getTemplate( wizard );
119
122
120
        String errorMessage = ProjectUtilities.canUseFileName (gui.getTargetGroup().getRootFolder(), gui.getTargetFolder(), gui.getTargetName(), template.getExt (), isFolder);
123
        String errorMessage = ProjectUtilities.canUseFileName(gui.getTargetGroup().getRootFolder(),
124
                gui.getTargetFolder(), gui.getTargetName(), template.getExt(), isFolder, freeFileExtension);
121
        wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, errorMessage);
125
        wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, errorMessage);
122
126
123
        return errorMessage == null;
127
        return errorMessage == null;
(-)a/projectui/src/org/netbeans/modules/project/ui/SimpleTargetChooserPanelGUI.java (-2 / +4 lines)
Lines 85-97 Link Here
85
    private final ChangeSupport changeSupport = new ChangeSupport(this);
85
    private final ChangeSupport changeSupport = new ChangeSupport(this);
86
    private SourceGroup[] folders;
86
    private SourceGroup[] folders;
87
    private boolean isFolder;
87
    private boolean isFolder;
88
    private boolean freeFileExtension;
88
    
89
    
89
    /** Creates new form SimpleTargetChooserGUI */
90
    /** Creates new form SimpleTargetChooserGUI */
90
    @SuppressWarnings("LeakingThisInConstructor")
91
    @SuppressWarnings("LeakingThisInConstructor")
91
    public SimpleTargetChooserPanelGUI( Project project, SourceGroup[] folders, Component bottomPanel, boolean isFolder ) {
92
    public SimpleTargetChooserPanelGUI( Project project, SourceGroup[] folders, Component bottomPanel, boolean isFolder, boolean freeFileExtension) {
92
        this.project = project;
93
        this.project = project;
93
        this.folders = folders.clone();
94
        this.folders = folders.clone();
94
        this.isFolder = isFolder;
95
        this.isFolder = isFolder;
96
        this.freeFileExtension = freeFileExtension;
95
        initComponents();
97
        initComponents();
96
        
98
        
97
        locationComboBox.setRenderer( CELL_RENDERER );
99
        locationComboBox.setRenderer( CELL_RENDERER );
Lines 425-431 Link Here
425
            ( folderName.startsWith("/") || folderName.startsWith( File.separator ) ? "" : "/" ) + // NOI18N
427
            ( folderName.startsWith("/") || folderName.startsWith( File.separator ) ? "" : "/" ) + // NOI18N
426
            folderName + 
428
            folderName + 
427
            ( folderName.endsWith("/") || folderName.endsWith( File.separator ) || folderName.length() == 0 ? "" : "/" ) + // NOI18N
429
            ( folderName.endsWith("/") || folderName.endsWith( File.separator ) || folderName.length() == 0 ? "" : "/" ) + // NOI18N
428
            documentName + expectedExtension;
430
            documentName + (!freeFileExtension || documentName.indexOf('.') == -1 ? expectedExtension : "");
429
            
431
            
430
        fileTextField.setText( createdFileName.replace( '/', File.separatorChar ) ); // NOI18N    
432
        fileTextField.setText( createdFileName.replace( '/', File.separatorChar ) ); // NOI18N    
431
            
433
            
(-)a/projectui/test/unit/src/org/netbeans/modules/project/ui/ProjectUtilitiesTest.java (-17 / +23 lines)
Lines 268-298 Link Here
268
        FileObject d = FileUtil.toFileObject(getWorkDir());
268
        FileObject d = FileUtil.toFileObject(getWorkDir());
269
        FileObject p1 = d.getFileObject("project1");
269
        FileObject p1 = d.getFileObject("project1");
270
        assertNotNull(p1);
270
        assertNotNull(p1);
271
        assertNull("normal file addition", ProjectUtilities.canUseFileName(p1, null, "foo", "java", false));
271
        assertNull("normal file addition", ProjectUtilities.canUseFileName(p1, null, "foo", "java", false, false));
272
        assertNull("normal file addition with no extension is OK", ProjectUtilities.canUseFileName(p1, null, "foo", null, false));
272
        assertNull("normal file addition with no extension is OK", ProjectUtilities.canUseFileName(p1, null, "foo", null, false, false));
273
        assertNull("normal file addition in an existing subdir", ProjectUtilities.canUseFileName(d, "project1", "foo", "java", false));
273
        assertNull("normal file addition in an existing subdir", ProjectUtilities.canUseFileName(d, "project1", "foo", "java", false, false));
274
        assertNull("normal file addition in a new subdir", ProjectUtilities.canUseFileName(d, "dir", "foo", "java", false));
274
        assertNull("normal file addition in a new subdir", ProjectUtilities.canUseFileName(d, "dir", "foo", "java", false, false));
275
        //assertNotNull("no target name", ProjectUtilities.canUseFileName(d, "dir", null, "java"));
275
        //assertNotNull("no target name", ProjectUtilities.canUseFileName(d, "dir", null, "java"));
276
        assertNotNull("no target folder", ProjectUtilities.canUseFileName(null, "dir", "foo", "java", false));
276
        assertNotNull("no target folder", ProjectUtilities.canUseFileName(null, "dir", "foo", "java", false, false));
277
        assertNotNull("file already exists", ProjectUtilities.canUseFileName(p1, null, "f1_1", "java", false));
277
        assertNotNull("file already exists", ProjectUtilities.canUseFileName(p1, null, "f1_1", "java", false, false));
278
        assertNotNull("file already exists in subdir", ProjectUtilities.canUseFileName(d, "project1", "f1_1", "java", false));
278
        assertNotNull("file already exists in subdir", ProjectUtilities.canUseFileName(d, "project1", "f1_1", "java", false, false));
279
        assertNull("similar file already exists in subdir", ProjectUtilities.canUseFileName(d, "project1", "f1_1", "properties", false));
279
        assertNull("similar file already exists in subdir", ProjectUtilities.canUseFileName(d, "project1", "f1_1", "properties", false, false));
280
        assertNull("similar file already exists in subdir", ProjectUtilities.canUseFileName(d, "project1", "f1_1", null, false));
280
        assertNull("similar file already exists in subdir", ProjectUtilities.canUseFileName(d, "project1", "f1_1", null, false, false));
281
        d = new XMLFileSystem().getRoot();
281
        d = new XMLFileSystem().getRoot();
282
        assertNotNull("FS is r/o", ProjectUtilities.canUseFileName(d, null, "foo", "java", false));
282
        assertNotNull("FS is r/o", ProjectUtilities.canUseFileName(d, null, "foo", "java", false, false));
283
        // #59876: deal with non-disk-based filesystems sensibly
283
        // #59876: deal with non-disk-based filesystems sensibly
284
        d = FileUtil.createMemoryFileSystem().getRoot();
284
        d = FileUtil.createMemoryFileSystem().getRoot();
285
        d.createData("bar.java");
285
        d.createData("bar.java");
286
        FileUtil.createData(d, "sub/dir/foo.java");
286
        FileUtil.createData(d, "sub/dir/foo.java");
287
        assertNull("can create file in non-disk FS", ProjectUtilities.canUseFileName(d, null, "foo", "java", false));
287
        assertNull("can create file in non-disk FS", ProjectUtilities.canUseFileName(d, null, "foo", "java", false, false));
288
        assertNotNull("file already exists", ProjectUtilities.canUseFileName(d, null, "bar", "java", false));
288
        assertNotNull("file already exists", ProjectUtilities.canUseFileName(d, null, "bar", "java", false, false));
289
        assertNotNull("file already exists in subsubdir", ProjectUtilities.canUseFileName(d, "sub/dir", "foo", "java", false));
289
        assertNotNull("file already exists in subsubdir", ProjectUtilities.canUseFileName(d, "sub/dir", "foo", "java", false, false));
290
        assertNull("can otherwise create file in subsubdir", ProjectUtilities.canUseFileName(d, "sub/dir", "bar", "java", false));
290
        assertNull("can otherwise create file in subsubdir", ProjectUtilities.canUseFileName(d, "sub/dir", "bar", "java", false, false));
291
        //#66792: allow to create whole directory tree at once using Folder Template:
291
        //#66792: allow to create whole directory tree at once using Folder Template:
292
        assertNull("can create directory subtree", ProjectUtilities.canUseFileName(d, null, "a/b/c", null, true));
292
        assertNull("can create directory subtree", ProjectUtilities.canUseFileName(d, null, "a/b/c", null, true, false));
293
        //#59654: do not allow slash and backslash for common templates:
293
        //#59654: do not allow slash and backslash for common templates:
294
        assertNotNull("cannot create file with slashes", ProjectUtilities.canUseFileName(d, null, "a/b/c", "txt", false));
294
        assertNotNull("cannot create file with slashes", ProjectUtilities.canUseFileName(d, null, "a/b/c", "txt", false, false));
295
        assertNotNull("cannot create file with backslashes", ProjectUtilities.canUseFileName(d, null, "a\\b\\c", "txt", false));
295
        assertNotNull("cannot create file with backslashes", ProjectUtilities.canUseFileName(d, null, "a\\b\\c", "txt", false, false));
296
        // Check freeFileExtension mode:
297
        assertNull(ProjectUtilities.canUseFileName(d, null, "foo", "java", false, true));
298
        assertNotNull(ProjectUtilities.canUseFileName(d, null, "bar", "java", false, true));
299
        assertNotNull(ProjectUtilities.canUseFileName(d, null, "bar.java", "java", false, true));
300
        assertNull(ProjectUtilities.canUseFileName(d, null, "bar.java", "java", false, false));
301
296
    }
302
    }
297
    
303
    
298
    public void testNavigatorIsNotClosed() throws Exception {
304
    public void testNavigatorIsNotClosed() throws Exception {
(-)a/projectuiapi/src/org/netbeans/modules/project/uiapi/ProjectChooserFactory.java (-1 / +2 lines)
Lines 67-72 Link Here
67
67
68
    public JFileChooser createProjectChooser(); 
68
    public JFileChooser createProjectChooser(); 
69
    
69
    
70
    public WizardDescriptor.Panel<WizardDescriptor> createSimpleTargetChooser(Project project, SourceGroup[] folders, WizardDescriptor.Panel<WizardDescriptor> bottomPanel);
70
    public WizardDescriptor.Panel<WizardDescriptor> createSimpleTargetChooser(Project project, SourceGroup[] folders,
71
            WizardDescriptor.Panel<WizardDescriptor> bottomPanel, boolean freeFileExtension);
71
            
72
            
72
}
73
}
(-)a/projectuiapi/src/org/netbeans/spi/project/ui/templates/support/Templates.java (-17 / +66 lines)
Lines 200-229 Link Here
200
    }
200
    }
201
            
201
            
202
    /**
202
    /**
203
     * Create a basic target chooser suitable for many kinds of templates.
203
     * @deprecated Use {@link #buildSimpleTargetChooser} instead.
204
     * The user is prompted to choose a location for the new file and a (base) name.
204
     */
205
    @Deprecated
206
    public static WizardDescriptor.Panel<WizardDescriptor> createSimpleTargetChooser( Project project, SourceGroup[] folders ) {        
207
        return buildSimpleTargetChooser(project, folders).create();
208
    }
209
    
210
    /**
211
     * @deprecated Use {@link #buildSimpleTargetChooser} instead.
212
     */
213
    @Deprecated
214
    public static WizardDescriptor.Panel<WizardDescriptor> createSimpleTargetChooser(Project project, SourceGroup[] folders, WizardDescriptor.Panel<WizardDescriptor> bottomPanel) {
215
        return buildSimpleTargetChooser(project, folders).bottomPanel(bottomPanel).create();
216
    }
217
218
    /**
219
     * Builder for simple target choosers.
220
     * The chooser is suitable for many kinds of templates.
221
     * The user is prompted to choose a location for the new file and a name.
205
     * Instantiation is handled by {@link DataObject#createFromTemplate}.
222
     * Instantiation is handled by {@link DataObject#createFromTemplate}.
206
     * @param project The project to work on.
223
     * @param project The project to work on.
207
     * @param folders a list of possible roots to create the new file in
224
     * @param folders a list of possible roots to create the new file in
208
     * @return a wizard panel(s) prompting the user to choose a name and location
225
     * @return a builder which can be used to customize and then create the target chooser
226
     * @since XXX
209
     */
227
     */
210
    public static WizardDescriptor.Panel<WizardDescriptor> createSimpleTargetChooser( Project project, SourceGroup[] folders ) {        
228
    public static SimpleTargetChooserBuilder buildSimpleTargetChooser(Project project, SourceGroup[] folders) {
211
        return createSimpleTargetChooser( project, folders, null );
229
        return new SimpleTargetChooserBuilder(project, folders);
212
    }
230
    }
213
    
231
214
    /**
232
    /**
215
     * Create a basic target chooser suitable for many kinds of templates.
233
     * A builder for simple target choosers.
216
     * The user is prompted to choose a location for the new file and a (base) name.
234
     * @see #buildSimpleTargetChooser
217
     * Instantiation is handled by {@link DataObject#createFromTemplate}.
235
     * @since XXX
218
     * Resulting panel can be decorated with additional panel placed below the standard target 
219
     * chooser.
220
     * @param project The project to work on.
221
     * @param folders a list of possible roots to create the new file in
222
     * @param bottomPanel panel which should be placed underneth the default chooser
223
     * @return a wizard panel(s) prompting the user to choose a name and location
224
     */
236
     */
225
    public static WizardDescriptor.Panel<WizardDescriptor> createSimpleTargetChooser(Project project, SourceGroup[] folders, WizardDescriptor.Panel<WizardDescriptor> bottomPanel) {
237
    public static final class SimpleTargetChooserBuilder {
226
        return Utilities.getProjectChooserFactory().createSimpleTargetChooser( project, folders, bottomPanel );
238
        final Project project;
239
        final SourceGroup[] folders;
240
        WizardDescriptor.Panel<WizardDescriptor> bottomPanel;
241
        boolean freeFileExtension;
242
        SimpleTargetChooserBuilder(Project project, SourceGroup[] folders) {
243
            this.project = project;
244
            this.folders = folders;
245
        }
246
        /**
247
         * Sets a panel which should be placed underneath the default chooser.
248
         * @param bottomPanel a custom bottom panel
249
         * @return this builder
250
         */
251
        public SimpleTargetChooserBuilder bottomPanel(WizardDescriptor.Panel<WizardDescriptor> bottomPanel) {
252
            this.bottomPanel = bottomPanel;
253
            return this;
254
        }
255
        /**
256
         * Permits the file extension of the created file to be customized by the user.
257
         * By default, the file extension is fixed to be the same as that of the template:
258
         * whatever is entered for the filename is taken to be a base name only.
259
         * In this mode, the GUI makes it possible to use an alternate extension: it
260
         * simply checks for a file name containing a period (<samp>.</samp>) and
261
         * suppresses the automatic appending of the template's extension,
262
         * taking the entered filename as complete.
263
         * @return this builder
264
         */
265
        public SimpleTargetChooserBuilder freeFileExtension() {
266
            this.freeFileExtension = true;
267
            return this;
268
        }
269
        /**
270
         * Creates the target chooser panel.
271
         * @return a wizard panel prompting the user to choose a name and location
272
         */
273
        public WizardDescriptor.Panel<WizardDescriptor> create() {
274
            return Utilities.getProjectChooserFactory().createSimpleTargetChooser(project, folders, bottomPanel, freeFileExtension);
275
        }
227
    }
276
    }
228
        
277
        
229
}
278
}

Return to bug 141886