Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [Dltk-dev] How should I allow my plugin to accept multiple template content types?

Hi Gabriel,

ScriptTemplateAccess could have any number of contexts. One of them is specified by the getContextTypeId() method, but nothing prevents you to add additional ones.

The only place this method was called is:

public ContextTypeRegistry getContextTypeRegistry() {
	if (fRegistry == null) {
		fRegistry = new ContributionContextTypeRegistry();
		fRegistry.addContextType(getContextTypeId());
	}
	return fRegistry;
}

I have just changed it to the 

public ContextTypeRegistry getContextTypeRegistry() {
	if (fRegistry == null) {
		fRegistry = createContextTypeRegistry();
	}
	return fRegistry;
}
protected ContextTypeRegistry createContextTypeRegistry() {
	final ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry();
	registry.addContextType(getContextTypeId());
	return registry;
}
So it would be easier to override.

Btw, since 3.5 there is a new org.eclipse.ui.editors.templates/contextTypeRegistry extension point element, so all contexts could be specified in the declarative way and collected with the "new ContributionContextTypeRegistry(String registryId)" call. Just one more example to to drop eclipse 3.3 compatibility and go with 3.5 :-)

There is no need to have multiple TemplateAccess classes, so the whole picture remains relatively simple.

Also it looks for me that every context should have its own ScriptTemplateCompletionProcessor instance, so I suppose we should extends ScriptCompletionProposalComputer to call multiple ScriptTemplateCompletionProcessors. I am going to do it tomorrow.

Regards,
Alex 

----- Original Message ----- 
From: "Gabriel Petrovay" <gabriel.petrovay@xxxxxxxxxx> 
To: "dltk-dev" <dltk-dev@xxxxxxxxxxx> 
Sent: Wednesday, April 1, 2009 9:51:13 PM GMT +06:00 Almaty, Novosibirsk 
Subject: [Dltk-dev] How should I allow my plugin to accept multiple template content types? 

Hi all, 

I have defined my ScriptTemplatePreferencePage. This needs a ScriptTemplateAccess, which I have implemented as well. But this latter class is bound to one single templace content type do to the method: ScriptTemplateAccess.getContextTypeId(). 

The ScriptTemplateAccess clas defined the registry of template context types, and, since the same class is also needed for the code completion (in ScriptTemplateCompletionProcessor.getTemplates()), I have extended my ScriptTemplateAccess implementation to accept multiple context types. 

Now I am overriding the ScriptTemplateCompletionProcessor.computeCompletionProposals() implementation not to filter the templates by this processor's context type. 


Is there a better way to do this? If I implement multiple template processors, I will have to implement multiple Template Access classes. This propagates further to the template preference page which is also bound to one template access. 


Which way do you think is better to go? 

Thanks! 
-- 
MSc Gabriel Petrovay 
MCSA, MCDBA, MCAD 
Mobile: +41(0)787978034 

_______________________________________________ dltk-dev mailing list dltk-dev@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/dltk-dev 


Back to the top