I'm developing an Eclipse plugin where the user can create perspectives from scratch. The user must enter a name for the perspective among other things and I need to check if the name already exists, so I need to read the information about the perspectives. I also need to add the perspective to the list programatically.
Do you know which class is related with the perspectives (not the UI)?
IPerspectiveRegistry perspectives = PlatformUI.getWorkbench ().getPerspectiveRegistry ();
if (perspectives.findPerspectiveWithLabel (name) != null){
//Error
}
Related
I want to delete perspectives which I have created. But here I don't want to use Eclipse's own page. I want to create my own page and display list of Perspectives and give option to delete it or make it default. I don't want to use default Eclipse page because I don't need "Fast View" and other options for perspectives. That's why I decided to create my own page list only what I need. But I don't know how to get list of perspectives and methods to make it default and delete.
This the page which I am displaying right now in my application:
You use the IPerspectiveRegistry to manipulate the perspective registry:
IPerspectiveRegistry perspectiveRegistry = PlatformUI.getWorkbench().getPerspectiveRegistry();
You can get the list of perspectives from the registry with:
IPerspectiveDescriptor [] perspectives = perspectiveRegistry.getPerspectives();
You can delete a perspective by calling the registry method
public void deletePerspective(IPerspectiveDescriptor persp)
but note that the JavaDoc says:
Deletes a perspective. Has no effect if the perspective is defined in
an extension.
In my standalone RCP Application (which I start using a product configuration) I would like to add a menu entry "show view" that lists all views I have defined in my persistent application model (an application.e4xmi file) being closed.
Currently I do not have any Advisor Classes in use.
What I did was to manually add HandledMenuItems for each view and added a CoreExpression as Visible-When Expression.
This expression tests for a special key value pair in the application context. The problem here is that I would need a special expression for each view.
What would be a good pattern to solve this problem?
Or is there a way to parametrize the core expression?
Could I use any predefined eclipse plugins / commands / handlers?
Update: Instead it would also be okay to have the Window > Show View structure in my standalone RCP application - exactly like it exists in the Eclipse workbench. Is there a way to add this menu (entry) by using any predefined / available means?
I'm not sure if this helps you, because it's eclipse 3.7 code, but you can give it a try.
I added a dynamic menu contribution to the View menu like so:
<menu id="x.y.menu.views label="%menu.window.label">
<dynamic class="x.y.menu.ViewListMenuContribution" id="viewlist" />
</menu>
In that class, I used one of the the eclipse menu factories to actually fill the menu:
#Override
public void fill(Menu menu, int index)
{
super.fill(menu, index);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IContributionItem item = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
if (item != null)
item.fill(menu, index);
}
This should show all views that are currently closed.
There is currently no way to do that, except keeping track of the parts yourself and reopening them with the EPartService
I use CNF to make a view like Project Explorer in my RCP app. I'm done showing new menu and its submenu when user right clicks on a project in the view.
But when user click on a submenu (for this case, a method library going to be created), I need to know which project object that user has right-clicked on.
My question is how can I do that? Please help me.
Thank you all,
Nautilus
I think the wiki page E4/EAS/Selection should provide a way to query the right selection.
In Eclipse 3.x, the org.eclipse.ui.ISelectionService allows workbench parts to query the active selection in addition to attaching listeners for monitoring selection changes.
(see this example)
In the e4 world, selection is propagated with the ESelectionService.
Thank VonC,
Now I got the resource object that user has right-clicked on by doing this:
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
CommonNavigator view = (CommonNavigator)page.findView("spe.ui.navigator.view");
selection = (IStructuredSelection) view.getSite().getSelectionProvider().getSelection();
But I'm really not happy completely with the solution. Note that I open a INewWizard after the action. In the INewWizard we have public void init(IWorkbench workbench, IStructuredSelection selection). I really want to use this method but I don't how to make it work.
Please, someone help me.
Thanks
I have an eclipse RCP application that uses and Editor Area. I have a few things that I would like to do programatically but cannot find any documentation:
1) Do not restore editor sash layout. I.e., I like to use rcp saveAndRestore functionality, but for my perspectives, views, and other momentos. I do not however want to restore the editor area multiple tab groups at all. I choose not to implement the IPersistableEditor interface, and therefore my editor sessions are not restored, but when my application restarts, it still has split windows (swt sashes for multiple tab groups), etc, and i wish it was just 1 editor area tab group like default.
2) I would like to programaticaly split/duplicate an editor into another tab group, for example I would like a button that says "Split Horizontal" and that opens a new editor in a new tab group beside the current one.
Any help is much appreciated! Happy Coding!
/P
1) Funny, seems like a bug in the platform.
You can explicitly close all editors upon workbench window close. One option to do this would be to override the preWindowShellClose method in your WorkbenchWindowAdvisor:
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
#Override
public boolean preWindowShellClose() {
getWindowConfigurer().getWindow().getActivePage().closeAllEditors(true);
return super.preWindowShellClose();
}
}
If you don't have access to the ApplicationWorkbenchWindowAdvisor, you can try to do the same with the IPerspectiveListenerX
2) I think there is no public API for this. The editor area behavior is defined in the presentation factory (see org.eclipse.ui.presentationFactories extension-point). You could clone the RCP standard presentation and implement the desired split-editor-area-on-demand functionality.
Basically, I have an eclipse plug-in which, among other things, adds three tabs to the Properties View, by using the extension points provided by eclipse (org.eclipse.ui.views.properties.tabbed.propertyContributor, org.eclipse.ui.views.properties.tabbed.propertyTabs and org.eclipse.ui.views.properties.tabbed.propertySections).
I am creating a plug-in to add a new tab (and some different properties) (see image).
Can you please give me some indications on how to do this, considering that there are no extension points offered by this plug-in for this. Is it possible to create a new tab by using the extension points provided by eclipse (mentioned above) in such a way that my tab appears under the three already added?
(I am pretty new in the plug-in area... all the tutorials I found showed how to create some tabs from scratch, where there is nothing added in the Properties View already).
Many thanks!
Here is the solution I found so far (I still need to explore it a bit more - I might be able to add some more details):
I created a fragment - the trick with the fragment is to either set the "host plugin" the RCP plugin or, if you set the "host plugin" a different plugin than the RCP, but which is in the Dependencies list of the RCP, you have to export the product first; don't forget to include the fragment in the Dependencies list of the product.
I extended the plugin org.eclipse.ui.views.properties.tabbed.propertyTabs and set the same contributorId as in the original plugin (the one with the 3 tabs) and created my new tab ("My Tab" in the image)
I created the sections I needed for this tab, again setting the same contributorId