Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Cloning Custom Perspectives(Workbench PerspectiveRegistry.clonePerspective())
Cloning Custom Perspectives [message #666197] Tue, 19 April 2011 08:51 Go to next message
Rob Stark is currently offline Rob Stark
Messages: 7
Registered: March 2011
Junior Member
I am building a UI Framework that uses the EClipse RCP in support of standing up a new UI development team.

We're using Eclipse as we like the use of sessions(workbench)/perspectives/widgets etc. We have a need to expose in the UI a button that allows the user to "copy" a given perspective. I can easily clone a perspective using the IPerspectiveRegistry.clonPerspective() method. There are no issues when you clone a default perspecive defined in the plug-in file. You get the associated viewParts no problem.

Lets say the user clones a default perspective, adds a few views (ViewParts) to it (creating a custom perspective) and then wants to clone this custom perspective. The problem is that the added ViewParts are not included in the cloned object.

(1) Do you have any suggestions as to how I can completely clone a custom perspective? I am calling window.getActivePage().savePerspective() anytime a view is added/removed from a perspective.

I have tried a number of approaches to solve this problem. Some efforts I knew going in were a bad idea as it had me mucking with eclipse internal (workbench) objects...creating a perspectiveDescriptor, adding it to the registry etc... Currently my util method stands as folows:


<PerspectiveUtils>
public static IPerspectiveDescriptor clonePerspective( IWokbenchWindow window, String originalId, String newPerspectiveId, String name ) {

    IPerspectiveRegistry perspectiveRegistry = window.getWorkbench().getPerspectiveRegistry();
    IPerspectiveDescriptor descriptor = perspectiveRegistry.findPerspectiveWithId( originalId );
    return perspectiveRegistry.clonePerspective( newPerspectiveId.replaceAll(" ", "_"), name, descriptor );
}



I suspect, based on reading the source code, that the RCP framework was not designed with this type of behavior in mind. For example, the PerspectiveRegistry.clonePerspective() method does not include in the clone the copying of the configElement attribute (on the PerspectiveDescriptor object). (2) Is there a reason for that?

I did notice that the cloned object maintains a reference to the originalId, which has me wondering if somehow when the new (cloned) perspective is shown (ie window.getWorkbench().showPerspective()) that the original ViewParts from the original plug-in definition perspective are loaded and not the immediate parental custom object (viewParts).

Ok - have to ask, (3) is there a reason that no setter() method is exposed for the label attribute on the PerspectiveDescriptor? (IE supporting renaming the Perspective)

Thanks for your time. Please advise if you have any ideas how to do a deep clone of a custom perspective.
Regards,

~Rob.

[Updated on: Tue, 19 April 2011 08:58]

Report message to a moderator

Re: Cloning Custom Perspectives [message #666203 is a reply to message #666197] Tue, 19 April 2011 09:14 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

In our SavePerspectiveHandler there's one more step ... would something
like this not work:

public static IPerspectiveDescriptor clonePerspective( IWokbenchWindow
window, String originalId, String newPerspectiveId, String name ) {

IPerspectiveRegistry perspectiveRegistry =
window.getWorkbench().getPerspectiveRegistry();
IPerspectiveDescriptor descriptor =
perspectiveRegistry.findPerspectiveWithId( originalId );
IPerspectiveDescriptor newDesc =
perspectiveRegistry.clonePerspective( newPerspectiveId.replaceAll(" ",
"_"), name, descriptor );
window.getActivePage().savePerspectiveAs(newDesc);
return newDesc;
}

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Cloning Custom Perspectives [message #666207 is a reply to message #666203] Tue, 19 April 2011 09:30 Go to previous messageGo to next message
Rob Stark is currently offline Rob Stark
Messages: 7
Registered: March 2011
Junior Member
Thanks for the reply...but that doesn't solve the problem of deep cloning custom perspectives...

I previously tried both the

window.getActivePage().savePerspectiveAs(newDesc);

and
window.getActivePage().savePerspective();


After showing the cloned perspective, I don't see the added perspectives displayed...

I am using Eclipse RCP (Helios) version 3.6 SR1...not sure that matters tho.
Re: Cloning Custom Perspectives [message #666251 is a reply to message #666207] Tue, 19 April 2011 11:39 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 04/19/2011 09:30 AM, Robbio123 wrote:
> I previously tried both the
>
> window.getActivePage().savePerspectiveAs(newDesc);

....

> After showing the cloned perspective, I don't see the added perspectives
> displayed...

You cloned the perspective to a new ID, label (something obvious), and
desc, and then savePerspectiveAs(newDesc).

Your new perspective should show up in Window>Open Perspective>Other...

Does it show up there at all? If you select it, does it look like the
one you saved from (include the user changes)?

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Cloning Custom Perspectives [message #666523 is a reply to message #666251] Wed, 20 April 2011 12:56 Go to previous messageGo to next message
Rob Stark is currently offline Rob Stark
Messages: 7
Registered: March 2011
Junior Member
The newly cloned perspective is available.

It is just that it doesn't contain all the ViewPages the immediate Parent Perspective it was cloned from. Rather it has the ViewPages laid out defined by the GrandParent perspective.
Re: Cloning Custom Perspectives [message #666532 is a reply to message #666523] Wed, 20 April 2011 14:03 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Hmmm, I would expect it to contain the view as laid out in the current
page, as that's what the saveAs is supposed to do. It won't reflect the
perspective it was cloned from if you do a saveAs on it.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Cloning Custom Perspectives [message #666649 is a reply to message #666532] Thu, 21 April 2011 09:09 Go to previous messageGo to next message
Rob Stark is currently offline Rob Stark
Messages: 7
Registered: March 2011
Junior Member
First off - you were right. Thank you!

After reading your last post, I went back double checking my notes and what I tried and retried your suggestion of using the IPerspectiveRegistry.savePerspectiveAs( newDesc )...

This in fact does resolve the issue. Sorry to have belabored the point.

Apparently I misunderstood what you were fundamentally saying. Previously, I tried calling the savePerspectiveAs() on the wrong descriptor not realizing why you were saying what was being said.

I've been working on this problem for 5 days and I'm now a believer in the community forum. I'll try to be an active participant where I can.

Thanks.

~Rob.



Re: Cloning Custom Perspectives [message #666672 is a reply to message #666649] Thu, 21 April 2011 10:01 Go to previous message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 04/21/2011 09:09 AM, Robbio123 wrote:
> First off - you were right. Thank you!
>

Glad it worked out :-)

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Previous Topic:Migrate RCP Application from Eclipse 3.3 to Eclipse 3.6
Next Topic:Completely lost.... any ideas? (Unable to launch application - errors attached)
Goto Forum:
  


Current Time: Sat Aug 23 01:53:11 EDT 2014

Powered by FUDForum. Page generated in 0.03227 seconds