Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Make Perspective from Model Fragment as pre-defined(Making a perspective defined in a Model Fragment as a pre-defined extension)
Make Perspective from Model Fragment as pre-defined [message #1776303] Wed, 15 November 2017 08:41 Go to next message
Ovidiu Tomuta is currently offline Ovidiu TomutaFriend
Messages: 12
Registered: September 2017
Junior Member
If a Perspective is defined in an extension point from a plugin.xml, the PerspectiveRegistry sees it as a pre-defined perspective. But if it only defined in a e4xmi Model Fragment then it is considered to be a custom perspective (check the code bellow).

private Map<String, PerspectiveDescriptor> descriptors = new HashMap<>();

@PostConstruct
void postConstruct(MApplication application) {
IExtensionPoint point = extensionRegistry.getExtensionPoint("org.eclipse.ui.perspectives"); //$NON-NLS-1$
for (IConfigurationElement element : point.getConfigurationElements()) {
String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID);
descriptors.put(id, new PerspectiveDescriptor(id, element));
}

List<MUIElement> snippets = application.getSnippets();
for (MUIElement snippet : snippets) {
if (snippet instanceof MPerspective) {
MPerspective perspective = (MPerspective) snippet;
String id = perspective.getElementId();

// See if the clone is customizing an a predefined perspective without changing its name
PerspectiveDescriptor existingDescriptor = descriptors.get(id);

if (existingDescriptor == null) {
// A custom perspective with its own name.
createDescriptor(perspective);
} else {
// A custom perspecitve with a name of a pre-defined perspective
existingDescriptor.setHasCustomDefinition(true);
}
}
}

Is this intended ? From my understanding in E4 we are supposed to use the Model Fragment when contributing with perspectives, parts etc.; but I want my perspective to be considered as a pre-defined one. If I define it in both the plugin.xml and modelFragment.e4xmi then I sometimes get the "no duplicates" constraint violation when starting in a persisted mode. How can I do this ? Thanks.
Re: Make Perspective from Model Fragment as pre-defined [message #1776342 is a reply to message #1776303] Wed, 15 November 2017 13:44 Go to previous messageGo to next message
Matthias Goebel is currently offline Matthias GoebelFriend
Messages: 7
Registered: July 2017
Junior Member
Sounds like a job for a model processor that switches the default perspective to the one your fragment defines.

You can also use the lifeCycleManager to change your model after application model is complete.
Re: Make Perspective from Model Fragment as pre-defined [message #1776404 is a reply to message #1776342] Thu, 16 November 2017 08:31 Go to previous messageGo to next message
Ovidiu Tomuta is currently offline Ovidiu TomutaFriend
Messages: 12
Registered: September 2017
Junior Member
@Matthias Thanks for taking your time to answer. Just to clarify: I don't want my perspective to be the default perspective (i.e. the one that opens when the app. starts). From my understanding this is what processors / lifeCycle are used for right ?
I just want it to be seen as a pre-defined perspective by the PerspectiveRegistry (one that was not created by the user using Perspective->Save As..). Is your proposal still holding for this case ? Sorry for the missunderstanding.
Re: Make Perspective from Model Fragment as pre-defined [message #1776480 is a reply to message #1776404] Thu, 16 November 2017 20:07 Go to previous messageGo to next message
Matthias Goebel is currently offline Matthias GoebelFriend
Messages: 7
Registered: July 2017
Junior Member
Oh sorry, I've missed that you use the PerspectiveRegistry.
In my last rcp development I build this functionality by my own. After the application model has been merged (hook in lifeCycleManager), I scan the model for defined perspectives and put them into a menu contribution. So I couldn't really help you with your issue :-/
Re: Make Perspective from Model Fragment as pre-defined [message #1776523 is a reply to message #1776480] Fri, 17 November 2017 09:30 Go to previous messageGo to next message
Ovidiu Tomuta is currently offline Ovidiu TomutaFriend
Messages: 12
Registered: September 2017
Junior Member
@Matthias No problem. If you don't mind, how do you make the difference between the perspectives that were defined in the Model Fragment and those that were created by the user , in your application ? Or you're not doing the separation ? From my understanding they are both saved in the MApplication Snippet list. Are you hardcode checking for their name ? (i.e. the Perspective's label). Thanks
Re: Make Perspective from Model Fragment as pre-defined [message #1776744 is a reply to message #1776523] Tue, 21 November 2017 04:44 Go to previous messageGo to next message
Eclipse UserFriend
I haven't traced through the code to see exactly what the following code does:
// A custom perspective with its own name.
createDescriptor(perspective);

But realize that the E3.x Workbench's notion of a perspective is different from the E4 MPerspective: the E3.x perspective is a specification whereas the E4 MPerspective is a representation. E3.x treats a perspective like a stamp or mould: when a perspective is applied, the window page contents (the editors and views) are organized into a particular layout. After that, the perspective is basically ignored: there is no public representation of the current layout.

On the flip side, E4 doesn't have a specification of how a perspective should look. You can use an MPerspective as a snippet, and clone it or use it as an exemplar.
Re: Make Perspective from Model Fragment as pre-defined [message #1776755 is a reply to message #1776744] Tue, 21 November 2017 08:40 Go to previous message
Matthias Goebel is currently offline Matthias GoebelFriend
Messages: 7
Registered: July 2017
Junior Member
Brian's suggestion is right the way I'm doing it. I have several perspective snippets for creating a perspective - in my case on application startup. Unfortunately I have no custom perspectives yet. But I would bet the approach keeps working for that.
For identifying a concrete perspective I use the element id in combination with tags applied to the MPerspective snippet.
Previous Topic:E4 + SWT renderer in FullScreen mode?
Next Topic:E4Application ActiveChild RAT
Goto Forum:
  


Current Time: Tue Apr 16 06:31:41 GMT 2024

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

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

Back to the top