Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » createExecutableExtension with parameters
createExecutableExtension with parameters [message #452457] Thu, 06 July 2006 00:23 Go to next message
Eclipse UserFriend
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 07:14 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: createExecutableExtension with parameters [message #1006574 is a reply to message #716761] Thu, 31 January 2013 15:32 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is what do do when we want return the static singleton we know is
declared in the interface rather than invoke a constructor:

Class<?> javaClass =
Platform.getBundle(element.getDeclaringExtension().getContributor().getName()).loadClass(element.getAttribute(attributeName));
Field field = javaClass.getField("eINSTANCE");
Object result = field.get(null);
return (EPackage)result;

So you can use this same approach to load the class and then use normal
Java reflection to invoke some other constructor.

Previous Topic:track changes made before activation of plugin
Next Topic:Get the Command id in a PropertyTester
Goto Forum:
  


Current Time: Sat Jul 05 06:55:44 EDT 2025

Powered by FUDForum. Page generated in 0.04174 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top