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?