Contributing a template to Eclipse via a Plugin to the Java Editor, but should vary based on the context -
Contributing a template to Eclipse via a Plugin to the Java Editor, but should vary based on the context -
so wrote plugin contribute template java editor in eclipse using extension "org.eclipse.ui.editors.templates". adds template. that's not want. want replace existing template new one, based on condition.
for example, if file name "john.java", within file if type "sysout", want template show rather default one. ideas how might able ?
ok. found work around. jdt plugin not offer extension point trying do. got templatestore , modified suit needs.
@override public void sessionstarted() { filtertemplates(); } private void filtertemplates() { templatestore = gettemplatestore(); file = getfilethatsvisibleintheeditor(); if (//file name john.java) { deletetemplate(templatestore, "org.eclipse.jdt.ui.templates.sysout"); } else { deletetemplate(templatestore, "com.eclipse.jdt.ui.templates.sysout"); } seek { templatestore.save(); } grab (ioexception e) { } } private void deletetemplate(templatestore templatestore, string id) { templatepersistencedata templatedata = templatestore.gettemplatedata(id); if (templatedata != null) { templatestore.delete(templatedata); } } @override public void sessionended() { gettemplatestore().restoredeleted(); } private templatestore gettemplatestore() { if (templatestore == null) { final contributioncontexttyperegistry registry = new contributioncontexttyperegistry(javaui.id_cu_editor); final ipreferencestore store = preferenceconstants.getpreferencestore(); templatestore = new contributiontemplatestore(registry, store, "org.eclipse.jdt.ui.text.custom_templates"); seek { templatestore.load(); } grab (ioexception e) { } templatestore.startlisteningforpreferencechanges(); } homecoming templatestore; }
this whole written within class extends ijavacompletionproposalcomputer. every time press ctrl+space, code executed , flavor of template executed.
in above code, have replaced normal java sysout 1 plugin contributes based on condition, @ point in time 1 version of 'sysout' shown in proposal. hack, got things done.
eclipse templates plugins editor jdt
Comments
Post a Comment