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.

Bug 246666 - Unable to set namespace in new file wizard.
Summary: Unable to set namespace in new file wizard.
Status: REOPENED
Alias: None
Product: platform
Classification: Unclassified
Component: Templates (show other bugs)
Version: 8.0
Hardware: All All
: P3 normal (vote)
Assignee: Martin Entlicher
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-25 06:37 UTC by vee
Modified: 2018-02-01 14:50 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
New file from my template. No namespace input. (36.00 KB, image/png)
2014-08-25 06:37 UTC, vee
Details
Create file from custom template before restart IDE (36.46 KB, image/png)
2016-01-27 14:14 UTC, eddi13
Details
Create file from custom template after restart IDE (34.27 KB, image/png)
2016-01-27 14:15 UTC, eddi13
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vee 2014-08-25 06:37:29 UTC
Created attachment 148870 [details]
New file from my template. No namespace input.

I have created new template file by duplicate from PHP template that come with Netbeans.

When i'm going to create new file by using this new template the wizard did not show up namespace input like i selected from Netbeans's PHP class template.

This is the template i use in my new template file.

```
<?php
<#assign licenseFirst = "/* ">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "${project.licensePath}">

<#if namespace?? && namespace?length &gt; 0>
namespace ${namespace};
</#if>

/**
 * Description of ${name}
 *
 * @author ${user}
 */
class Controller_${name} extends \Controller_BaseController
{


    //put your code here


}
```

As you see, the name space code was there but no namespace input show up.
Comment 1 Ondrej Brejla 2014-08-25 07:52:39 UTC
Tome?
Comment 2 Tomas Mysik 2014-08-25 08:02:35 UTC
Your template uses a general Wizard UI for custom templates, not the one from the PHP support therefore there is no panel for namespace selection (the Wizard specifies its panels, not the template). It means that you need to provide your own WizardDescriptor [1] (or change the existing template bundled with NetBeans).

Thanks.
[1] http://bits.netbeans.org/dev/javadoc/org-openide-dialogs/org/openide/WizardDescriptor.html
Comment 3 eddi13 2015-07-21 12:12:14 UTC
after creating (duplicate from build-in template e.g. PHP Class) the custom template, is namespase selection field present, it disappears after restart the IDE

IDE v.8.0.2
Windows 7
Comment 4 eddi13 2016-01-27 13:13:32 UTC
the same behavior in v.8.1 (build for PHP):
after creating (duplicate from build-in template e.g. PHP Class) the custom template, is namespase selection field present, it disappears after restart the IDE

Product Version: NetBeans IDE 8.1 (Build 201510222201)
Java: 1.8.0_66; Java HotSpot(TM) 64-Bit Server VM 25.66-b18
Runtime: Java(TM) SE Runtime Environment 1.8.0_66-b18
System: Windows 7 version 6.1 running on amd64; Cp1252; de_DE (nb)
Comment 5 Tomas Mysik 2016-01-27 13:20:53 UTC
(In reply to eddi13 from comment #4)
> the same behavior in v.8.1 (build for PHP):
> after creating (duplicate from build-in template e.g. PHP Class) the custom
> template, is namespase selection field present, it disappears after restart
> the IDE

Where can I find your source code so I can have a look at it? Or at least provide _exact_ steps what you have done so I know how can I reproduce your issue.

Thanks.
Comment 6 eddi13 2016-01-27 14:14:39 UTC
Created attachment 158249 [details]
Create file from custom template before restart IDE
Comment 7 eddi13 2016-01-27 14:15:36 UTC
Created attachment 158250 [details]
Create file from custom template after restart IDE

Hallo Tomas.

I do the following:
1. Tools->Templates
select "PHP Class" (build-in template)
click "Duplicate" (custom template "PHP Class 1" is created)
close Templates

2. rigth click any folder in project -> New -> select File Type "PHP Class 1" -> Next
see scrin custom_tpl_before_restart.png

3. restart IDE

4. (same as 2) rigth click any folder in project -> New -> select File Type "PHP Class 1" -> Next
see scrin custom_tpl_after_restart.png

Field "Namespace" is lost.

Best regards, Eduard.
Comment 8 Tomas Mysik 2016-01-28 06:51:39 UTC
Thanks for the steps, will have a look at it.
Comment 9 Tomas Mysik 2016-08-01 07:38:52 UTC
This is IMO a bug (or an enhancement?) in Templates support (please see the steps in comment
Comment 10 Tomas Mysik 2016-08-01 07:40:05 UTC
(In reply to Tomas Mysik from comment #9)
> This is IMO a bug (or an enhancement?) in Templates support (please see the
> steps in comment

Ignore this comment, my BZ login expired...
Comment 11 Tomas Mysik 2016-08-01 07:40:50 UTC
This is IMO a bug (or an enhancement?) in Templates support (please see the steps in comment #7). The cause is that the copied template does not preserve/duplicate the "instantiatingIterator" attribute. Then, the default one is used instead of the previous custom one (with the namespace field in this case).

Please evaluate, thanks.
Comment 12 eddi13 2016-08-01 09:36:19 UTC
(In reply to Tomas Mysik from comment #11)
> This is IMO a bug (or an enhancement?) in Templates support (please see the
> steps in comment #7). The cause is that the copied template does not
> preserve/duplicate the "instantiatingIterator" attribute. Then, the default
> one is used instead of the previous custom one (with the namespace field in
> this case).
> 
> Please evaluate, thanks.

Hallo Tomas.

Attribute "instantiatingItrator" is copied, I guess he did not readed.
I watched file .nbattrs. If I understand correctly, the content is read at the start of the IDE, and is overwritten when you save / delete custom templates.

Advanced steps (added 3a and info to instantiatingIterator):
1. Tools->Templates
select "PHP Class" (build-in template)
click "Duplicate" (custom template "PHP Class 1" is created)
close Templates
<fileobject name="PHPClass_1.php">...<attr name="instantiatingIterator" newvalue="org.netbeans.modules.php.project.ui.wizards.NewFileWizardIterator"/> is OK.

2. rigth click any folder in project -> New -> select File Type "PHP Class 1" -> Next
see scrin custom_tpl_before_restart.png

3. restart IDE
<fileobject name="PHPClass_1.php">...<attr name="instantiatingIterator" newvalue="org.netbeans.modules.php.project.ui.wizards.NewFileWizardIterator"/> is OK, however...

3a. Tools->Templates
select "PHP Interface" (build-in template)
click "Duplicate" (custom template "PHP Interface 1" is created)
close Templates... and now you can see the effect:
<fileobject name="PHPClass_1.php">...<attr name="instantiatingIterator" newvalue="null"/>
<fileobject name="PHPInterface_1.php">...<attr name="instantiatingIterator" newvalue="org.netbeans.modules.php.project.ui.wizards.NewFileWizardIterator"/>
This means (IMHO) that the attribute has not been read from the file at the start of the IDE

4. (same as 2) rigth click any folder in project -> New -> select File Type "PHP Class 1" -> Next
see scrin custom_tpl_after_restart.png

Field "Namespace" is lost.

I hope this helps
Comment 13 Tomas Mysik 2016-08-01 10:09:44 UTC
Sorry, I was not precise. The problem is that after the IDE restart, code from PHP module (the NewFileWizardIterator class) is not called any more. So I guess that it is replaced by some general/common code (wizard iterator) from Templates support.

Thanks.
Comment 14 eddi13 2016-08-01 12:21:33 UTC
I guess, this code is not called, because the information about it is not loaded in the session configuration.
I can not test it, because I can not get the values of templates configuration from the session, but I believe that the problem in the parser of custom templates configuration.
And this attribute is simply not read from a file (ignored by the parser).

1. Duplicate PHP Class
2. Duplicate PHP Class
<fileobject name="PHPClass_1.php">...<attr name="instantiatingIterator" newvalue="org.netbeans.modules.php.project.ui.wizards.NewFileWizardIterator"/> is OK.
<fileobject name="PHPClass_2.php">...<attr name="instantiatingIterator" newvalue="org.netbeans.modules.php.project.ui.wizards.NewFileWizardIterator"/> is OK.
because the info in config and session is synchronized
3. restart IDE

and here it would be a very useful debug of custom templates configuration, that I can not get.
But I suppose, that in the session configuration the attribute instantiatingIterator in all custom templates will be "null" (It will not be read/parsed from the configuration file)

it would be great if someone could have tested it.

Thanks.
Comment 15 eddi13 2016-10-20 18:22:46 UTC
in the version 8.2 the error is not corrected
Comment 16 vee 2018-02-01 14:50:54 UTC
Hello,

Anyone tell me about how to create WizardDescriptor please?
Where to put it in?
I searched the Google but found no tutorial about this.