Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Programmatically add an extension to a plug-in
Programmatically add an extension to a plug-in [message #509677] Sun, 24 January 2010 16:28 Go to next message
Steve is currently offline Steve
Messages: 16
Registered: July 2009
Junior Member
Hi,
I need to programmatically add an extension to a plug-in project. This is part of the code I am using:

IPluginModelBase model = PluginRegistry.findModel(project);
IPluginExtension extension = createExtension(model, info.getExtensionPointId(),true);
IPluginElement element = model.getPluginFactory().createElement(extension);
element.setName(info.getName());


The element.setName() call is throwing an exception because the model is not editable. How do I create an editable model or is there a better way to add an extension?

Thanks,
Steve

Re: Programmatically add an extension to a plug-in [message #509889 is a reply to message #509677] Mon, 25 January 2010 16:42 Go to previous messageGo to next message
Louis Rose is currently offline Louis Rose
Messages: 440
Registered: July 2009
Location: York, United Kingdom
Senior Member
Hi Steve,

Did you figure out how to do this? I'm trying to do the same.

Best,
Louis.
Re: Programmatically add an extension to a plug-in [message #509948 is a reply to message #509889] Mon, 25 January 2010 21:09 Go to previous messageGo to next message
Steve is currently offline Steve
Messages: 16
Registered: July 2009
Junior Member
Hi Louis,

No, sorry, not yet. And I can't seem to find anything on the Internet about this. I would think this is a common practice, but I sure am having trouble. Please let me know if you figure out an answer and I will do the same.

Thanks,
Steve
Re: Programmatically add an extension to a plug-in [message #510020 is a reply to message #509948] Tue, 26 January 2010 09:09 Go to previous messageGo to next message
Louis Rose is currently offline Louis Rose
Messages: 440
Registered: July 2009
Location: York, United Kingdom
Senior Member
Hi Steve,

That'd be great, thanks. I'm tempted to simply generate a plugin.xml file, as we will always be generating a new project from scratch. If this would be helpful for you, I can share the code?

Cheers,
Louis.
Re: Programmatically add an extension to a plug-in [message #510066 is a reply to message #510020] Tue, 26 January 2010 12:55 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen Zschaler
Messages: 228
Registered: July 2009
Senior Member
Hi,

That's what I've been doing in some project that generated plugin
projects. As long as you have the plugin manifest builder associated
with that plugin project, saving plugin.xml seems to lead to
recompilation and correct reconfiguration of the project's metadata.

Steffen

On 26/01/2010 09:09, Louis Rose wrote:
> Hi Steve,
>
> That'd be great, thanks. I'm tempted to simply generate a plugin.xml
> file, as we will always be generating a new project from scratch. If
> this would be helpful for you, I can share the code?
>
> Cheers,
> Louis.
Re: Programmatically add an extension to a plug-in [message #510083 is a reply to message #510066] Tue, 26 January 2010 14:02 Go to previous messageGo to next message
Louis Rose is currently offline Louis Rose
Messages: 440
Registered: July 2009
Location: York, United Kingdom
Senior Member
Great, thanks Steffen.

Steffen Zschaler wrote on Tue, 26 January 2010 07:55
Hi,

That's what I've been doing in some project that generated plugin
projects. As long as you have the plugin manifest builder associated
with that plugin project, saving plugin.xml seems to lead to
recompilation and correct reconfiguration of the project's metadata.

Steffen

On 26/01/2010 09:09, Louis Rose wrote:
> Hi Steve,
>
> That'd be great, thanks. I'm tempted to simply generate a plugin.xml
> file, as we will always be generating a new project from scratch. If
> this would be helpful for you, I can share the code?
>
> Cheers,
> Louis.

Re: Programmatically add an extension to a plug-in [message #510103 is a reply to message #510020] Tue, 26 January 2010 14:42 Go to previous messageGo to next message
Steve is currently offline Steve
Messages: 16
Registered: July 2009
Junior Member
Louis,
Thanks, but my case is a bit different. I need to update an existing plug-in project. I am able to get the model and add the extension if it that extension does not already exist. But, if I try to add an element (IPluginElement) to an existing extension I get the read-only exception.
Thanks,
Steve
Re: Programmatically add an extension to a plug-in [message #510336 is a reply to message #510103] Wed, 27 January 2010 10:09 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen Zschaler
Messages: 228
Registered: July 2009
Senior Member
Hi Steve,

But you could parse the plugin.xml, extend the AST and print it back as
an XML file, couldn't you?

I'm assuming that we are talking about a project open in the workspace
here, rather than a plugin deployed into the system?

Steffen

On 26/01/2010 14:42, Steve wrote:
> Louis,
> Thanks, but my case is a bit different. I need to update an existing
> plug-in project. I am able to get the model and add the extension if
> it that extension does not already exist. But, if I try to add an
> element (IPluginElement) to an existing extension I get the read-only
> exception.
> Thanks,
> Steve
Re: Programmatically add an extension to a plug-in [message #513206 is a reply to message #510336] Tue, 09 February 2010 11:19 Go to previous messageGo to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
If Steve is talking about adding and extention in a project open in workspace...

Then it should be possible because PDE does that only...

But if steve is talkin about plugins deployed into the system
Then...
@Steve
Why do you need to add extensions programmatically??

There is somthing seriously wrong with your design or what ever you are trying to do....
(pardon me for being so vague)

If your info or what ever you are going to do is decided at runtime,
then creating extention points for the task and adding them at runtime is like touching your nose from all the way around your head....



Can you please explain your implemention a bit...


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Wed, 10 February 2010 07:40]

Report message to a moderator

Re: Programmatically add an extension to a plug-in [message #513535 is a reply to message #513206] Wed, 10 February 2010 14:14 Go to previous messageGo to next message
Steve is currently offline Steve
Messages: 16
Registered: July 2009
Junior Member
I am adding some key bindings to an existing plug-in project in the workspace, not plug-ins deployed in the system. We have a Toolkit that enables a user to create plug-in projects. There are cases where you change something in your plug-in project and our Toolkit automatically updates yourplugin-in projects plugin.xml. I was able to get this working by using a WorkspacePluginModel. This model can be edited. But, when you create this model you do not get the extensions. I had to get the extensions using the model returned from a call to PluginRegistry.findModel(project). I then added all of those extensions to my WorkspacePluginModel model. Now, another gotcha was that if I tried to edit any extension returned by the call to PluginRegistry.findModel() I received a read-only exception. For any extension I needed to edit, I had to create a new extension, based on the original extension, and add that extension to my model. Because this is a new extension I was able to edit it. Finally, after making all of my changes, I saved my model. I tried using a straight XML approach, but ran in to some problems with that. This approach seems to work fine.

Thanks,
Steve
Re: Programmatically add an extension to a plug-in [message #604374 is a reply to message #509889] Mon, 25 January 2010 21:09 Go to previous messageGo to next message
Steve is currently offline Steve
Messages: 16
Registered: July 2009
Junior Member
Hi Louis,

No, sorry, not yet. And I can't seem to find anything on the Internet about this. I would think this is a common practice, but I sure am having trouble. Please let me know if you figure out an answer and I will do the same.

Thanks,
Steve
Re: Programmatically add an extension to a plug-in [message #604377 is a reply to message #604374] Tue, 26 January 2010 09:09 Go to previous messageGo to next message
Louis Rose is currently offline Louis Rose
Messages: 440
Registered: July 2009
Location: York, United Kingdom
Senior Member
Hi Steve,

That'd be great, thanks. I'm tempted to simply generate a plugin.xml file, as we will always be generating a new project from scratch. If this would be helpful for you, I can share the code?

Cheers,
Louis.
Re: Programmatically add an extension to a plug-in [message #604379 is a reply to message #604377] Tue, 26 January 2010 12:55 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen Zschaler
Messages: 228
Registered: July 2009
Senior Member
Hi,

That's what I've been doing in some project that generated plugin
projects. As long as you have the plugin manifest builder associated
with that plugin project, saving plugin.xml seems to lead to
recompilation and correct reconfiguration of the project's metadata.

Steffen

On 26/01/2010 09:09, Louis Rose wrote:
> Hi Steve,
>
> That'd be great, thanks. I'm tempted to simply generate a plugin.xml
> file, as we will always be generating a new project from scratch. If
> this would be helpful for you, I can share the code?
>
> Cheers,
> Louis.
Re: Programmatically add an extension to a plug-in [message #604383 is a reply to message #510066] Tue, 26 January 2010 14:02 Go to previous messageGo to next message
Louis Rose is currently offline Louis Rose
Messages: 440
Registered: July 2009
Location: York, United Kingdom
Senior Member
Great, thanks Steffen.

Steffen Zschaler wrote on Tue, 26 January 2010 07:55
> Hi,
>
> That's what I've been doing in some project that generated plugin
> projects. As long as you have the plugin manifest builder associated
> with that plugin project, saving plugin.xml seems to lead to
> recompilation and correct reconfiguration of the project's metadata.
>
> Steffen
>
> On 26/01/2010 09:09, Louis Rose wrote:
> > Hi Steve,
> >
> > That'd be great, thanks. I'm tempted to simply generate a plugin.xml
> > file, as we will always be generating a new project from scratch. If
> > this would be helpful for you, I can share the code?
> >
> > Cheers,
> > Louis.
Re: Programmatically add an extension to a plug-in [message #604387 is a reply to message #604377] Tue, 26 January 2010 14:42 Go to previous messageGo to next message
Steve is currently offline Steve
Messages: 16
Registered: July 2009
Junior Member
Louis,
Thanks, but my case is a bit different. I need to update an existing plug-in project. I am able to get the model and add the extension if it that extension does not already exist. But, if I try to add an element (IPluginElement) to an existing extension I get the read-only exception.
Thanks,
Steve
Re: Programmatically add an extension to a plug-in [message #604403 is a reply to message #604387] Wed, 27 January 2010 10:09 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen Zschaler
Messages: 228
Registered: July 2009
Senior Member
Hi Steve,

But you could parse the plugin.xml, extend the AST and print it back as
an XML file, couldn't you?

I'm assuming that we are talking about a project open in the workspace
here, rather than a plugin deployed into the system?

Steffen

On 26/01/2010 14:42, Steve wrote:
> Louis,
> Thanks, but my case is a bit different. I need to update an existing
> plug-in project. I am able to get the model and add the extension if
> it that extension does not already exist. But, if I try to add an
> element (IPluginElement) to an existing extension I get the read-only
> exception.
> Thanks,
> Steve
Re: Programmatically add an extension to a plug-in [message #604544 is a reply to message #510336] Tue, 09 February 2010 11:19 Go to previous messageGo to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
Why do you guys require to add extensions programmatically??

There is somthing seriously wrong with your design....
(pardon me for being so vague)

If your info or what ever you are going to do is decided at runtime,
then creating extention points for the task and adding them at runtime is like touching your nose from all the way around your head....

Can you please explain your implemention a bit...


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Programmatically add an extension to a plug-in [message #604578 is a reply to message #604544] Wed, 10 February 2010 14:14 Go to previous message
Steve is currently offline Steve
Messages: 16
Registered: July 2009
Junior Member
I am adding some key bindings to an existing plug-in project in the workspace, not plug-ins deployed in the system. We have a Toolkit that enables a user to create plug-in projects. There are cases where you change something in your plug-in project and our Toolkit automatically updates yourplugin-in projects plugin.xml. I was able to get this working by using a WorkspacePluginModel. This model can be edited. But, when you create this model you do not get the extensions. I had to get the extensions using the model returned from a call to PluginRegistry.findModel(project). I then added all of those extensions to my WorkspacePluginModel model. Now, another gotcha was that if I tried to edit any extension returned by the call to PluginRegistry.findModel() I received a read-only exception. For any extension I needed to edit, I had to create a new extension, based on the original extension, and add that extension to my model. Because this is a new extension I was able to edit it. Finally, after making all of my changes, I saved my model. I tried using a straight XML approach, but ran in to some problems with that. This approach seems to work fine.

Thanks,
Steve
Previous Topic:my nature methods are never executed
Next Topic:produce baseLocation from target definition
Goto Forum:
  


Current Time: Tue Sep 23 06:23:33 GMT 2014

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

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