The "One Laptop Per Child" project has a great device ready to ship, but there's no Java on there. Let's think about working together to put Java on OLPC!
So, you want your plug-ins (present and future) to add view(s) to some perspective you have defined. You can do this by the means of the
org.eclipse.ui.perspectiveExtensions
extension point and targeting you
chosen perspective's id
and providing the
view
elements at will.
In my context, I just wanted to define a generic initial layout (that is, subdivided the perspective's whole area in zones) and let the plug-ins fill the specific areas. Something like this:
Which is archieved by a
PerspectiveFactory
which defines three area (left, top and bottom). In code terms:
publicclass DefaultPerspective implements IPerspectiveFactory {
/** The standard perspecive used in the application. */
publicstaticfinal String PERSPECTIVE_ID = UiPlugin.ID
+ ".perspectives.defaultPerspective";
/** Left folder's id. */
publicstaticfinal String FI_LEFT = PERSPECTIVE_ID + ".leftFolder";
/** Top folder's id. */
publicstaticfinal String FI_TOP = PERSPECTIVE_ID + ".topFolder";
/** Top folder's id. */
publicstaticfinal String FI_BOTTOM = PERSPECTIVE_ID + ".bottomFolder";
private IPageLayout layout;
/**
* We replace the editor area with three application folders that can be used for placing views.
*
* @param the layout
*/
publicvoid createInitialLayout( IPageLayout layout ) {
this.layout = layout;
String editorAreaId = layout.getEditorArea();
layout.setEditorAreaVisible( false );
layout.setFixed( false );
layout.createFolder( FI_LEFT, IPageLayout.LEFT, 0.25f, editorAreaId );
layout.createFolder( FI_TOP,IPageLayout.TOP, 0.60f, editorAreaId );
layout.createFolder( FI_BOTTOM, IPageLayout.BOTTOM, 0.10f, editorAreaId );
}
/**
* @return Returns the layout.
*/
public IPageLayout getLayout() {
return layout;
}
}
We define the three areas by creating three
known
IFolderLayout
objects: later this ids will be useful when placing our views.
Every plug-in defines a view element which attach the view to a specific perspective and provides additional info. In example:
Note the
relative
attribute: this is the key for the correct placing. It requires another view's id which is present in the perspective (maybe defined in the same way) but it works with named
IFolderLayout
objects too. In this example we place the new view in the bottom folder and when the application shows up, this is the result we get:
In this case I used the
relationship="stack"
placement but you could put your view on top / bottom and to the left / right, of your
relative
object.
You can do the same for an arbitrary number of plug-ins or for plug-ins which define more than one view.
Hope this will help some other people when trying to avoid strict coupling among the perspective layout and the views that may compose it.
Re: Let every plug-in add view(s) to an RCP perspective
That's odd: in my app even if I close all the views the empty folder layouts persist on the workbench (no folder will expand / contract). Though, I'm using eclipse 3.1.1 under linux/gtk and haven't tried other target platforms :S
But if I would have got the same behaviour as yours, I'm in troubles since I've no answer
Re: Let every plug-in add view(s) to an RCP perspective
hi
what would i be using that for? i'm having the same troubles as described earlier in this thread. when i close my last view all the others expand. using the iplaceholderfolderlayout i got still the same problem. how did you do that guys?
Re: Let every plug-in add view(s) to an RCP perspective
Hi Gil Collins You said it works, what works? Did you get IFolder to keep staying open when all views where closed? How? Doesn't work for me ... Eclipse 3.3 (Europa)
Btw, can anybody suggest why EditorArea is special? Can I add just any view to it or not? Because it seems to behave properly regarding that "folder closing issue"..
Re: Let every plug-in add view(s) to an RCP perspective
This does not work for a "out of the template" RCP application in 3.3. I created one and used your perspective class to place the views; no success.
After changing the method call from createFolder to createPlaceHolderFolder things worked as expected. I did this after reading bug 125442 in eclipse bugs.
Let every plug-in add view(s) to an RCP perspective
At 7:49 AM on Oct 30, 2005, Mario Scalas
wrote:
In my context, I just wanted to define a generic initial layout (that is, subdivided the perspective's whole area in zones) and let the plug-ins fill the specific areas. Something like this:
Which is archieved by a PerspectiveFactory which defines three area (left, top and bottom). In code terms:
public class DefaultPerspective implements IPerspectiveFactory { /** The standard perspecive used in the application. */ public static final String PERSPECTIVE_ID = UiPlugin.ID + ".perspectives.defaultPerspective"; /** Left folder's id. */ public static final String FI_LEFT = PERSPECTIVE_ID + ".leftFolder"; /** Top folder's id. */ public static final String FI_TOP = PERSPECTIVE_ID + ".topFolder"; /** Top folder's id. */ public static final String FI_BOTTOM = PERSPECTIVE_ID + ".bottomFolder"; private IPageLayout layout; /** * We replace the editor area with three application folders that can be used for placing views. * * @param the layout */ public void createInitialLayout( IPageLayout layout ) { this.layout = layout; String editorAreaId = layout.getEditorArea(); layout.setEditorAreaVisible( false ); layout.setFixed( false ); layout.createFolder( FI_LEFT, IPageLayout.LEFT, 0.25f, editorAreaId ); layout.createFolder( FI_TOP,IPageLayout.TOP, 0.60f, editorAreaId ); layout.createFolder( FI_BOTTOM, IPageLayout.BOTTOM, 0.10f, editorAreaId ); } /** * @return Returns the layout. */ public IPageLayout getLayout() { return layout; } }We define the three areas by creating three known IFolderLayout objects: later this ids will be useful when placing our views.
Every plug-in defines a view element which attach the view to a specific perspective and provides additional info. In example:
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> <plugin> <extension point="org.eclipse.ui.views"> <category name="eConference Views" id="it.uniba.di.cdg.econference.ui"> </category> <view id="it.uniba.di.cdg.econference.ui.handraising.handRaisingView" name="Hand raising" icon="icons/view_icon.png" category="it.uniba.di.cdg.econference.core.ui" class="it.uniba.di.cdg.econference.ui.handraising.HandRaisingView" /> </extension> <extension point="org.eclipse.ui.perspectiveExtensions"> <perspectiveExtension targetID="it.uniba.di.cdg.econference.core.ui.perspectives.defaultPerspective"> <view id="it.uniba.di.cdg.econference.ui.handraising.handRaisingView" ratio="0.60" relationship="stack" relative="it.uniba.di.cdg.econference.core.ui.perspectives.defaultPerspective.bottomFolder"/> </perspectiveExtension> </extension> </plugin>Note the relative attribute: this is the key for the correct placing. It requires another view's id which is present in the perspective (maybe defined in the same way) but it works with named IFolderLayout objects too. In this example we place the new view in the bottom folder and when the application shows up, this is the result we get:
In this case I used the relationship="stack" placement but you could put your view on top / bottom and to the left / right, of your relative object.
You can do the same for an arbitrary number of plug-ins or for plug-ins which define more than one view.
Hope this will help some other people when trying to avoid strict coupling among the perspective layout and the views that may compose it.
10 replies so far (
Post your own)
Re: Let every plug-in add view(s) to an RCP perspective
Nice tip, thanks.Author, Google Web Toolkit, Eclipse IDE Pocket Guide, Eclipse in Action
ZDNet blogger, Dev Connection; former Top Eclipse Ambassador.
Re: Let every plug-in add view(s) to an RCP perspective
How do I make an area always visible even if the views are closed?For example
I have place two more views say on the top left and top right along with the Hand Rising View.
If I close the Hand Rising View, the top right view will expand and the bottom folder layout would not be visible any more.
But I require this bottom area to be always even if all the views are closed.
How would I make a area always fixed like the editor area?
Thanks in advance.
Re: Let every plug-in add view(s) to an RCP perspective
That's odd: in my app even if I close all the views the empty folder layouts persist on the workbench (no folder will expand / contract). Though, I'm using eclipse 3.1.1 under linux/gtk and haven't tried other target platforms :SBut if I would have got the same behaviour as yours, I'm in troubles since I've no answer
Re: Let every plug-in add view(s) to an RCP perspective
Is it possible one of you is using an editor area and the other is not?Author, Google Web Toolkit, Eclipse IDE Pocket Guide, Eclipse in Action
ZDNet blogger, Dev Connection; former Top Eclipse Ambassador.
Re: Let every plug-in add view(s) to an RCP perspective
Ive tried this in 3.2 but it seems that is not longer possible to stack a view into an IFolder using PerspectiveExtensions.Can you plese confirm
Re: Let every plug-in add view(s) to an RCP perspective
I could not make this work using createFolderIm using 3.2
you have to use IPlaceholderFolderLayout instead.
Re: Let every plug-in add view(s) to an RCP perspective
hiwhat would i be using that for? i'm having the same troubles as described earlier in this thread. when i close my last view all the others expand. using the iplaceholderfolderlayout i got still the same problem. how did you do that guys?
regards
Re: Let every plug-in add view(s) to an RCP perspective
Thank you for this it works now.Re: Let every plug-in add view(s) to an RCP perspective
Hi Gil CollinsDid you get IFolder to keep staying open when all views where closed? How? Doesn't work for me ... Eclipse 3.3 (Europa)
Btw, can anybody suggest why EditorArea is special? Can I add just any view to it or not? Because it seems to behave properly regarding that "folder closing issue"..
Regards,
Bohdan.
Re: Let every plug-in add view(s) to an RCP perspective
This does not work for a "out of the template" RCP application in 3.3. I created one and used your perspective class to place the views; no success.After changing the method call from createFolder to createPlaceHolderFolder things worked as expected. I did this after reading bug 125442 in eclipse bugs.
However, thanks for the pointer!
Wim