Programmatically defining perspectives [message #290661] |
Mon, 29 August 2005 14:19 |
Eclipse User |
|
|
|
Originally posted by: james.willans.xactium.com
Is it possible to programmatically define perspectives?
Also, I know that views can be positioned programmatically, am I right in
thinking that this is not possible with editors?
Thanks.
James
|
|
|
|
Re: Programmatically defining perspectives [message #290744 is a reply to message #290716] |
Wed, 31 August 2005 09:17 |
Eclipse User |
|
|
|
Originally posted by: james.willans.xactium.com
Hi Alex,
Thanks for your reply. I wasn't very clear in my original question, what
I would like to do is contribute perspectives to the workbench
dynamically. So rather than performing the contribution using the
extension point, I would like to do this programmatically.
James
Alex Blewitt wrote:
> You can create the layout of a Perspective via a PerspectiveFactory.
Probably the best place to look is the Eclipse tutorial for RCPs:
>
http://help.eclipse.org/help31/topic/org.eclipse.platform.do c.isv/guide/rcp_perspective.htm
> However, this is only the initial layout; the user is free to change it for
later use.
> Also, although there can be many views, there is only one Editor Area --
though it doesn't have to be visible.
> Does this answer the question?
|
|
|
Re: Programmatically defining perspectives [message #290745 is a reply to message #290744] |
Wed, 31 August 2005 10:26 |
Eclipse User |
|
|
|
Originally posted by: automatic.javalobby.org
I'm not sure if you can create a named perspective on-the-fly, so if you were wanting to create Perspective1, Perspective2, Perspective3 etc. then there'd have to be some hard hackery to make it work.
What you can probably do, if you want to conditionally show a perspective (such as if something is enabled) then there are probably other ways that you can do that; for example, not defining the plugin in the startup and then attempting to load/install it dynamically, or by using features.
I'm intrigued; why do you want to add a perspective programmatically rather than via the extension point? The only benefit that I could see is being able to contribute multiple ones instead of a single one.
|
|
|
|
Re: Programmatically defining perspectives [message #290754 is a reply to message #290748] |
Wed, 31 August 2005 13:43 |
Eclipse User |
|
|
|
Originally posted by: james.willans.xactium.com
Peter,
Thanks for your suggestion, this looks like it might be a great help -
I'll experiment along these lines.
James
Peter Kullmann wrote:
> James Willans wrote:
>> Hi Alex,
>>
>> Thanks for your reply. I wasn't very clear in my original question,
>> what I would like to do is contribute perspectives to the workbench
>> dynamically. So rather than performing the contribution using the
>> extension point, I would like to do this programmatically.
>>
>> James
>>
> What we did is the following (hack):
> 1. Define a default perspective via the extension mechanism
> 2. For every dynamic perspective you save a copy of the default
> perspective (as in the user interface in Window/Save Perspective As...)
> or in code with IPerspectiveRegistry.clonePerspective().
> 3. Whenever such a cloned perspective is opened (by the user or through
> some code) the createInitialLayout method of the default perspective is
> called. In there one must know which perspective is opened (i.e. which
> clone). We do it like that:
> public void createInitialLayout(IPageLayout layout) {
> PageLayout pageLayout = (PageLayout) layout;
> IPerspectiveDescriptor desc = pageLayout.getDescriptor();
> String perspectiveId = desc.getId();
> Now, you are able to set up the dynamic perspective in the usual way
> (layout.addView etc).
> I hope this helps and I'd be greatful to know if you or someone has a
> better solution.
> Peter
|
|
|
Re: Programmatically defining perspectives [message #290778 is a reply to message #290748] |
Wed, 31 August 2005 20:00 |
Eclipse User |
|
|
|
Originally posted by: james.willans.xactium.com
This seems to work. Am I right in thinking that createInitialLayout only
gets called the first time the perspective is shown? If so, do you know
of a way of forcing this to be re evaluated each time the perspective is
shown?
Thanks,
James
> What we did is the following (hack):
> 1. Define a default perspective via the extension mechanism
> 2. For every dynamic perspective you save a copy of the default
> perspective (as in the user interface in Window/Save Perspective As...)
> or in code with IPerspectiveRegistry.clonePerspective().
> 3. Whenever such a cloned perspective is opened (by the user or through
> some code) the createInitialLayout method of the default perspective is
> called. In there one must know which perspective is opened (i.e. which
> clone). We do it like that:
> public void createInitialLayout(IPageLayout layout) {
> PageLayout pageLayout = (PageLayout) layout;
> IPerspectiveDescriptor desc = pageLayout.getDescriptor();
> String perspectiveId = desc.getId();
> Now, you are able to set up the dynamic perspective in the usual way
> (layout.addView etc).
> I hope this helps and I'd be greatful to know if you or someone has a
> better solution.
> Peter
|
|
|
|
Re: Programmatically defining perspectives [message #290794 is a reply to message #290754] |
Thu, 01 September 2005 12:12 |
Eclipse User |
|
|
|
Originally posted by: parsuram.panigrahi.wipro.com
Hi Peter,
I need to open a dynamic prospective. Can you please explain the same?
1) You have defined the perspective in plugin.xml
2) How do you clone the prospective? Where do you call
iPerspectiveRegistry.clonePerspective method?
3) How do you call the cloned perspective from code?
>> What we did is the following (hack):
>> 1. Define a default perspective via the extension mechanism
>> 2. For every dynamic perspective you save a copy of the default
>> perspective (as in the user interface in Window/Save Perspective As...)
>> or in code with IPerspectiveRegistry.clonePerspective().
>> 3. Whenever such a cloned perspective is opened (by the user or through
>> some code) the createInitialLayout method of the default perspective is
>> called. In there one must know which perspective is opened (i.e. which
>> clone). We do it like that:
>> public void createInitialLayout(IPageLayout layout) {
>> PageLayout pageLayout = (PageLayout) layout;
>> IPerspectiveDescriptor desc = pageLayout.getDescriptor();
>> String perspectiveId = desc.getId();
>> Now, you are able to set up the dynamic perspective in the usual way
>> (layout.addView etc).
>> I hope this helps and I'd be greatful to know if you or someone has a
>> better solution.
>> Peter
|
|
|
Re: Programmatically defining perspectives [message #290795 is a reply to message #290794] |
Thu, 01 September 2005 12:26 |
Eclipse User |
|
|
|
Originally posted by: james.willans.xactium.com
IPerspectiveRegistry reg =
(IPerspectiveRegistry)YourPlugin.getDefault().getWorkbench() .getPerspectiveRegistry();
IPerspectiveDescriptor desc =
(IPerspectiveDescriptor)reg.findPerspectiveWithId("your.persp.id ");
reg.clonePerspective("your.new.persp.id","Perspective name",desc);
Parsuram Panigrahi wrote:
> Hi Peter,
> I need to open a dynamic prospective. Can you please explain the same?
> 1) You have defined the perspective in plugin.xml
> 2) How do you clone the prospective? Where do you call
> iPerspectiveRegistry.clonePerspective method?
> 3) How do you call the cloned perspective from code?
|
|
|
Re: Programmatically defining perspectives [message #290868 is a reply to message #290748] |
Fri, 02 September 2005 14:43 |
Eclipse User |
|
|
|
Originally posted by: james.willans.xactium.com
Peter,
We've tried your proposal and although it worked, it lacked the
flexibility we required. Namely it lacked the flexibility to remove
perspectives and to dynamically change them (which can be achieved with an
add/remove API).
> I hope this helps and I'd be greatful to know if you or someone has a
> better solution.
In the end we had to do something which we try very hard to avoid and base
our implementation on accessing internal API. By using the API of the
implementation of IPerspectiveRegistry (PerspectiveRegistry), particularly:
o addPerspective(PerspectiveDescriptor)
o removePerspective(PerspectiveDescriptor)
We are able to implement all our requirements. As I say it is not ideal
because we are using internal API, but we are doing it in a minimal sense.
I plan to post a feature request to augment the public API to provide
access to this, however I suspect I'll have difficulty pushing this
through.
As an aside, we would like to see an Eclipse policy of making all
functionality accessible using XML in manifests also available
programmatically. Our reasoning behind this is the way our technology
works which is once the platform starts, it connects to a standalone
engine describing the tool(s) it should represent. None of the details of
tools are known prior to runtime. However, I digress ...
James
|
|
|
Powered by
FUDForum. Page generated in 0.04951 seconds