Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

Java, the OLPC, and community responsibility

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!
Replies: 10 - Pages: 1  
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

Let every plug-in add view(s) to an RCP perspective

At 7:49 AM on Oct 30, 2005, Mario Scalas Javalobby Newcomers wrote:

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:
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.
  Click to reply to this thread Reply
1. At 9:47 PM on Oct 31, 2005, Ed Burnette Javalobby Junkies wrote:

Re: Let every plug-in add view(s) to an RCP perspective

Nice tip, thanks.
Ed Burnette
Author, Google Web Toolkit, Eclipse IDE Pocket Guide, Eclipse in Action
ZDNet blogger, Dev Connection; former Top Eclipse Ambassador.
  Click to reply to this thread Reply
2. At 8:46 AM on Nov 4, 2005, Marimuthu P Javalobby Newcomers wrote:

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.
  Click to reply to this thread Reply
3. At 4:05 AM on Nov 5, 2005, Mario Scalas Javalobby Newcomers wrote:

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 ;)
  Click to reply to this thread Reply
4. At 5:08 PM on Nov 5, 2005, Ed Burnette Javalobby Junkies wrote:

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?
Ed Burnette
Author, Google Web Toolkit, Eclipse IDE Pocket Guide, Eclipse in Action
ZDNet blogger, Dev Connection; former Top Eclipse Ambassador.
  Click to reply to this thread Reply
5. At 5:29 PM on Jul 30, 2006, Anditri mirosolban Javalobby Newcomers wrote:

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
  Click to reply to this thread Reply
6. At 6:32 PM on Jul 30, 2006, Anditri mirosolban Javalobby Newcomers wrote:

Re: Let every plug-in add view(s) to an RCP perspective

I could not make this work using createFolder
Im using 3.2
you have to use IPlaceholderFolderLayout instead.
  
IPlaceholderFolderLayout leftFolder = layout.createPlaceholderFolder(FI_LEFT, IPageLayout.LEFT,0.35f, editorAreaId);
  Click to reply to this thread Reply
7. At 2:55 AM on Sep 6, 2006, search Occasional Javalobby Visitor wrote:

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?

regards
  Click to reply to this thread Reply
8. At 6:06 PM on May 16, 2007, Gil Collins Javalobby Newcomers wrote:

Re: Let every plug-in add view(s) to an RCP perspective

Thank you for this it works now.
  Click to reply to this thread Reply
9. At 6:07 PM on Sep 15, 2007, bohdan Javalobby Newcomers wrote:

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"..

Regards,
Bohdan.
  Click to reply to this thread Reply
10. At 5:11 PM on Oct 3, 2007, Wim Jongman Javalobby Newcomers wrote:

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

thread.rss_message