Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » How to add custom code templates to my plugin?
How to add custom code templates to my plugin? [message #670307] Fri, 13 May 2011 09:26 Go to next message
Dwight Johnson is currently offline Dwight Johnson
Messages: 19
Registered: March 2011
Junior Member

Hello,

I am working on a plugin myplugin that supports a custom webproject and perspective.

XHTML, CSS en .JS have an adapted syntax.

Code templates need to be provided that must be stored in the plugin in templates/templates.xml.

In templates.xml resides:

   <templates>
      <template autoinsert="true"
             contextTypeId="html_tag"
             description="[Description]"
             id="org.eclipse.jst.jsf.ui.newHtmltag"
             name="testTag" 
             enabled="true" 
             context="html_tag"  >
		Some template content...
     </template>
   </templates>


In plugin.xml we have:

     <extension
       point="org.eclipse.ui.editors.templates">
       <include file="templates/templates.xml"/>
     </extension>


This template does indeed show up in Preferences > Web > HTML files > Editor > Templates under context=HTML Tag.

What I do not understand is: how can I introduce a new HTML context 'CE_HTML' where my new templates will reside under? Changes/additions allowed only in myplugin.

I tried this in plugin.xml:

    <!-- Templates -->
	<extension point="org.eclipse.ui.editors.templates">
		<contextType
			name="%CE_HTML_context_type_Extension_Element.name"
			class="org.eclipse.wst.html.ui.internal.templates.TemplateContextTypeHTML"
			id="html_ce">
		</contextType>
		<include
			file="templates/htmldefault-templates2.xml"
			translations="$nl$/templates/htmldefault-templates.properties">
		</include>
	</extension>

with templates in htmldefault-templates2.xml but nothing shows up.

Any suggestion would be much appreciated.


Re: How to add custom code templates to my plugin? [message #670331 is a reply to message #670307] Fri, 13 May 2011 10:31 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2234
Registered: July 2009
Senior Member
The HTML Templates preference page is only designed to show the template contexts defined by the HTML plug-ins. It sounds like you need to contribute your own subclass of org.eclipse.ui.texteditor.templates.TemplatePreferencePage.

---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: How to add custom code templates to my plugin? [message #670343 is a reply to message #670331] Fri, 13 May 2011 11:20 Go to previous messageGo to next message
Dwight Johnson is currently offline Dwight Johnson
Messages: 19
Registered: March 2011
Junior Member
Nitin Dahyabhai wrote on Fri, 13 May 2011 10:31
The HTML Templates preference page is only designed to show the template contexts defined by the HTML plug-ins. It sounds like you need to contribute your own subclass of org.eclipse.ui.texteditor.templates.TemplatePreferencePage.


Hello Nitin,

That seems to be rather a big task.

Under Windows > Show View > there is a template view.
For some reason it does show templates for java but not for css/js/html.

Anyway, rather than using the preference window, can't I simply display my custom templates (css-templates.xml, js-templates.xml, xhtml-templates.xml) in that view, when the css/js/xhtml files are opened resp. in the context of my custom project?

Is there a simple way of how I could couple these template files to the template view?

Re: How to add custom code templates to my plugin? [message #693380 is a reply to message #670343] Wed, 06 July 2011 07:13 Go to previous messageGo to next message
sulakshana.vasanth is currently offline sulakshana.vasanth
Messages: 11
Registered: July 2011
Junior Member
hello,

Even I am facing same problem... Is there any way out to solve this???

Waiting for reply,
Sulakshana
(no subject) [message #693645 is a reply to message #670343] Wed, 06 July 2011 19:45 Go to previous message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2234
Registered: July 2009
Senior Member
On 5/13/2011 11:20 AM, Dwight Johnson wrote:
> Nitin Dahyabhai wrote on Fri, 13 May 2011 10:31
>> The HTML Templates preference page is only designed to
>> show the template contexts defined by the HTML plug-ins. It sounds
>> like you need to contribute your own subclass of
>> org.eclipse.ui.texteditor.templates.TemplatePreferencePage.
>
>
> Hello Nitin,
>
> That seems to be rather a big task.

Not as much as you think. Besides, our template proposal computers
won't be processing the templates from your contexts anyway.

> Under Windows > Show View > there is a template view. For some reason it
> does show templates for java but not for
> css/js/html.

It's not implemented for those editors since the editors are built in a
way that their viewer configurations and supported content type can be
changed on the fly. The Templates View is locked down in one content
type from the start (possibly before we've figured out which content
type is in the editor), and that's all it ever gets to show.

--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Previous Topic:Web Services, top-down
Next Topic:CustomCompletionProposal
Goto Forum:
  


Current Time: Wed Jul 23 16:12:41 EDT 2014

Powered by FUDForum. Page generated in 0.02538 seconds