Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Dynamically Perspectives in RCP application(dynamic contribution to extension point org.eclipse.ui.perspective)
Dynamically Perspectives in RCP application [message #1724556] Wed, 24 February 2016 15:23
Fabry Fabry is currently offline Fabry FabryFriend
Messages: 1
Registered: February 2016
Junior Member
I've an RCP appliaction.
What I would like to do is to create and add dynamically some perspectives, reading a configuration files.

Width the standard way (add the exentsion to plugin.xml) everything works fine:
<extension
         name="sasa"
         point="org.eclipse.ui.perspectives">
      <perspective
            class="mypkg.Perspective"
            id="mypkg.perspective.p1"
            name="P1">
      </perspective>
      <perspective
            class="mypkg.Perspective"
            id="mypkg.perspective.p2"
            name="P2">
      </perspective>
   </extension>


I would like to load all the perspective reading a configuration file:
....
perspectives:P1,P2,P3....P100
...

I wrote the following code (without remove the previous perspectives from plugin.xml):

class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor
{  
  public ApplicationWorkbenchAdvisor()
 {
  addPerspectives();
 }
  
private void addPerspectives()
  {  
    StringBuffer sb = new StringBuffer();
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    sb.append("<plugin>");
    sb.append(" <extension ");
    sb.append("   name=\"sasa\"");
    sb.append("   point=\"org.eclipse.ui.perspectives\">");
    sb.append("   <perspective ");
    sb.append("     class=\"mypkg.Perspective\"");
    sb.append("     id=\"mypkg.perspective.P3\"");
    sb.append("     name=\"P3\">");
    sb.append("   </perspective>");
    sb.append(" </extension>");
    sb.append("</plugin>");
    System.out.println(sb.toString());
    try
    {
      byte[] bytes = sb.toString().getBytes("UTF-8");
      InputStream is = new ByteArrayInputStream(bytes);
      IExtensionRegistry registry = RegistryFactory.getRegistry();
      Object key = ((ExtensionRegistry) registry).getTemporaryUserToken();
      Bundle bunlde = Activator.getDefault().getBundle();
      IContributor contributor = ContributorFactoryOSGi.createContributor(bunlde);      
      try
      {
        if(!registry.addContribution(is, contributor ,false, null, null, key))
        {
          System.err.println("### Error"); 
        }
        else
        {
          System.out.println("#### addeddd");
        }
      }
      catch (IllegalArgumentException e) 
      {
        e.printStackTrace();
      }
    }
    catch (UnsupportedEncodingException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }


I can see the new Perspective listed in the perspective bar, but when I try to switch to this new perspective I have a message dialog with this error:
"Problems opening perspective 'mypkg.perspective.P3'"
In the console log of eclipse there aren't errors.

Can you help me?

Previous Topic:Re-creating CoolBar
Next Topic:How to add a Composite to a Menu?
Goto Forum:
  


Current Time: Fri Dec 04 05:51:40 GMT 2020

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

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

Back to the top