createExecutableExtension with parameters [message #452457] |
Thu, 06 July 2006 04:23 |
Eclipse User |
|
|
|
Originally posted by: kent.126.com
Hi,
According to the IConfigurationElement javadoc, it always use
0-parameter public constructor to instantiate the class specified in
Executable Extension .
But in my application ,the class need to be instantiated with two
parameters, So is it possible to create an Executable Extension with
parameters? How to deal the case that need to be instantiated with
parameters?
Thanks,
Kent.
|
|
|
Re: createExecutableExtension with parameters [message #716761 is a reply to message #452457] |
Thu, 18 August 2011 11:14 |
|
Hi there,
An old Question but still relevant. At least for me.
I am currently struggeling with the same issue. I solved it using reflection, which is not the most beatiful way, but it works for me at the moment.
IConfigurationElement[] configElements = Platform.getExtensionRegistry).getConfigurationElementsFor(EXTENSION_DETAIL_CONTRIBUTION);
try {
for (IConfigurationElement configElement : configElements) {
String id = configElement.getAttribute(DETAIL_CONTRIBUTION_ID);
String name = configElement.getAttribute(DETAIL_CONTRIBUTION_NAME);
String clazz = configElement.getAttribute(DETAIL_CONTRIBUTION_CLASS);
Class<DetailItem> detailItem= (Class<DetailItem>) Class.forName(clazz);
Constructor constructor = detailItem.getConstructors()[0];
DetailItem detailItem = (DetailItem) constructor.newInstance(this, id, name);
}
} catch ...
So if anyone has a better idea, please let us know. I guess there is a better way for this kind of Problem.
Cheers
Phil
|
|
|
|
Powered by
FUDForum. Page generated in 0.03299 seconds