Why cannot some templates be opened in editor?

In the NetBeans template manager (Tools | Templates) , there is an Open In Editor button that lets the users open the selected template in an editor for custom modifications. But the button is disabled for some templates. In general, this is a conscious design decision by the developers of the relevant module to not support custom modifications for that template.


From  the source code :

...
Set nodes2open = getNodes2Open (nodes);
assert ! nodes2open.isEmpty () : "Selected templates to open cannot by empty for nodes " + Arrays.asList (nodes);
Iterator/\*<Node>\*/ it = nodes2open.iterator ();
while (it.hasNext ()) {
    Node n = (Node) it.next ();
    EditCookie ec = (EditCookie) n.getLookup ().lookup (EditCookie.class);
    if (ec != null) {
        ec.edit ();
    } else {
        OpenCookie oc = (OpenCookie) n.getLookup ().lookup (OpenCookie.class);
        if (oc != null) {
            oc.open ();
        } else {
            assert false : "Node " + n + " has to have a EditCookie or OpenCookie.";
        }
    }
...
 

There are two cases when OpenInEditor is disabled:

  • When the module developer has provided an empty template. In this case, the file is created entirely in code and not using a template. (The module still needs a template to let the users create files of that type via File | New... dialog and hence provides an empty template).
    • In the above case, the module developer is not expected to provide an editor or a viewer for the template. But some modules provide them, which is considered a bug by the NetBeans platform. 
  • When the template is not empty but the module writer has not provided an editor or a viewer. Here again, it is quite likely that, though the module itself starts with a predefined template, the design decisions preclude the module from allowing any customizations.

Are there any workarounds?

No. It is up to the module to provide an editor for its templates. When as users we come across a template that we think would benefit from customizations, we should file an RFE in issuezilla  that would let the module engineers re-evaluate the situation.


Comments:

What if the template consists of multiple files? That's the main reason as far as I know for the Open in Editor button to be disabled.

Posted by Geertjan on October 30, 2008 at 06:20 AM PDT #

- Having multiple files in a single template, by itself, need not make it uneditable; provided the individual pieces can be edited independently. (In this case, the individual sub-templates can have a comment at the top providing info on the other related sub-templates...)

- It is of course possible that the interactions between the sub-templates makes it unadvisable or even impossible, for them to be edited. This would then fall under the case 2 in the above blog; i.e the design decisions have precluded providing an editor or a viewer. (But that may be the case even when the template has only a single file...)

Posted by Karthikeyan Rajeswaran on October 30, 2008 at 06:45 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

A blog for NetBeans users maintained by NetBeans Support team. For professional support, please check out Support Resources.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today