I got a custom perspecitve with an editor area declared in plugin.xml only.
In addtion, I got a custom view, that is opened programatically. I want to stack this view with the editor area.
If I set it in the perspective extension as initially visible, everything works fine.
<view
id="my.viewID"
minimized="false"
relationship="stack"
relative="org.eclipse.ui.editorss"
visible="false">
</view>
However, if I set visible="false", and use the following code to open it programmatically, it always appears in the bottom area stacked with the ConsoleView.
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView("my.viewID", "secondID", IWorkbenchPage.VIEW_ACTIVATE);
Does anybody know how to have an initially invisble view stacked to the editor area when opened programmatically?
I already tried the recommendations given in this thread but without any success: Eclipse RCP - relative field of view perspective extension not working
Sometimes you can't imagine how simple solutions can be:
Simply adding :* at the end of the view id in the plugin.xml solved this issue:
<view
id="my.viewID:*"
minimized="false"
relationship="stack"
relative="org.eclipse.ui.editorss"
visible="false">
</view>
Unbelievable how many times you find people saying this would not be possible at all...
Well, I've read most stuff about placing a view over the editor area, and none worked. The Answer 1 above causes the plugin.xml to have warnings. In Eclipse Luna, this works however when your perspective is initialized:
public void createInitialLayout(IPageLayout layout) {
if ( layout instanceof org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout ) {
org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout layout4=(org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout)layout;
layout4.stackView(ID+":*",layout.getEditorArea(),false);
}
...
The code above adds a view with "ID" that is a multiple view, added to the stack of editors hidden (last parameter is false="not visible").
It may also work with other Eclipse versions, but I haven't tried it.
Good luck!
The simplest way to achieve this is to add the view to the perspective extensions like this:
<extension point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension targetID="org.my.perspective">
<view id="org.my.view"
minimized="false"
relationship="stack"
relative="org.eclipse.ui.editorss"
visible="false">
</view>
</perspectiveExtension>
</extension>
and then calling IWorkbenchPage::showView() without a secondary ID, i.e. only with one argument like this:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.my.view");
Related
I have made Hello World RCP application and got the following class structure:
ApplicationActionBarAdvisor.java
ApplicationWorkbenchAdvisor.java
ApplicationWorkbenchWindowAdvisor.java
Application.java
Perspective.java
Further I tried to add some view to the perspective.
Add extension point to my plugin.xml:
<extension point="org.eclipse.ui.views">
<view
class="first.rcp.application.MainView"
id="first.rcp.application.MainView"
name="name"
restorable="true">
</view>
</extension>
and created class MainView.java.
Add additional code to Perspective.createInitialLayout():
layout.addStandaloneView(MainView.ID, true, IPageLayout.LEFT, 1.0f, layout.getEditorArea());
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
try {
activePage.showView(MainView.ID);
} catch (PartInitException e) {
e.printStackTrace();
}
But view does not displayed.
I set breakpoint into Perspective.createInitialLayout() and found that it is not performed.
I tried to add showPerspective() method to ApplicationWorkbenchWindowAdvisor() and set PERSPECTIVE_ID in ApplicationWorkbenchAdvisor to the id of my perspective.
But the code into Perspective.createInitialLayout() still not performed.
Which point it should be called from?
Eclipse IDE have Java perspective with number of views opened by default. I.e. createInitialLayout() of the Java perspective is called during launching of eclipse IDE. How is it implemented? May be there are some configuration file?
My perspective declaration is:
<extension point="org.eclipse.ui.perspectives">
<perspective
name="RCP Perspective"
class="first.rcp.application.Perspective"
id="first.rcp.application.Perspective">
</perspective>
</extension>
The code in ApplicationWorkbenchAdvisor.getInitialWindowPerspectiveId() is:
public String getInitialWindowPerspectiveId() {
return PERSPECTIVE_ID;
}
private static final String PERSPECTIVE_ID = "first.rcp.application.Perspective";
Solution №1.
Go through the New Plug-in project wizard, make sure 'would you like to create a rich client application' is set to Yes, make sure 'Generate an activator, a Java class that controls the plug-in lifecycle' is cheked and select 'Hello RCP' on the Available Template page.
Go to MANIFEST.MF, Extensions. Add new extension 'org.eclipse.ui.views', add an appropriate class.
Add new extension 'org.eclipse.ui.perspectiveExtensions' with the view. Specify view id to the id of the previously created view.
Solution №2.
Go through the New Plug-in project wizard, make sure 'would you like to create a rich client application' is set to Yes, make sure 'Generate an activator, a Java class that controls the plug-in lifecycle' is cheked and select 'RCP application with a view' on the Available Template page.
In Eclipse Window>Show View, in the bottom we can see a text saying "use f2 to display the description for a selected view" now if we select any view and press f2, it always show "no description available" .
Now I have created a View and that view is available in showView eclipse menu , but I want to set the description for the same.
So in ViewPart, where exactly I need to do the description setting.
According to this bug report, the description is set in the description tag of the view in the plugin.xml.
An example:
<view
name="Sample View"
icon="icons/sample.gif"
category="test"
class="test.views.SampleView"
id="test.views.SampleView">
<description>A very long descriptive text.
With a new line comes still more.
And more ... and more.</description>
</view>
Result:
I want to show views (multiple) in my plugin source code using:
showView(id, id2, IWorkbenchPage.VIEW_ACTIVATE)
This view is first closed, shown after my proccess completed.
I defined the view and its positon in plugin.xml as below:
name="..."
icon="..."
category="..."
class="..."
allowMultiple="true"
id="myid"
extension
point="org.eclipse.ui.perspectiveExtensions"
perspectiveExtension
targetID="org.eclipse.jdt.ui.JavaPerspective"
view
ratio="0.5"
relative="org.eclipse.ui.views.ContentOutline"
relationship="stack"
visible="false"
id="myid"
I want to show them top right area of perspective (the same as Outline view).
If I set visible true or open my view manually in GUI, it appears top right as I expected,
but when I use "showView()" above, views always appears at the bottom (console, problems, etc.)
How can I show my views always top right programmably?
You need to add placeholders for the rest of your views, that have a secondary ID. Another entry in your perspectiveExtension with a compound ID and a wildcard should work: myid:*. See IPageLayout javadoc for more information.
How to add a fast view to my eclipse rcp applicatio?
You can add the right button, as in this thread:
that can be done by adding a button to fast view bar and by opening a standard view in button event
Button button =
new Button ((Composite)((WorkbenchWindow) window).getFastViewBar ().getControl (), SWT.PUSH);
to avoid overlapping in button event first create folder layout for this view with reference to initial view and then call the action to add view.
IFolderLayout ViewLayout1 = layout.createFolder ( "ViewLayout1",
IPageLayout.BOTTOM,
0.50f, initalView.ID);
OpenViewAction ov = new OpenViewAction (window, "label", secondview.ID);
ov.run ();
Showing and minimizing a fast view programmatically should be done through command "org.eclipse.ui.views.showView" with the parameter "org.eclipse.ui.views.showView.makeFast".
See Eclipse RCP: open a view via standard command org.eclipse.ui.handlers.ShowViewHandler:
Eclipse provides the standard command org.eclipse.ui.views.showView to open an arbitrary view.
The default handler is org.eclipse.ui.handlers.ShowViewHandler. This handler is a nice example how you could add your own command with arguments. It takes two parameters:
The first has the ID org.eclipse.ui.views.showView.viewId and identifies the view ID which should be opened,
the next one has the ID org.eclipse.ui.views.showView.makeFast and determines if the view should be open as a fast view.
Without parameters the command will let the user choose which view to open.
See Parameter for commands for some examples
Lets see the real world example: "Show View" command. The command is generic and can show any view. The view id is given to the command as a parameter:
<command
name="%command.showView.name"
description="%command.showView.description"
categoryId="org.eclipse.ui.category.views"
id="org.eclipse.ui.views.showView"
defaultHandler="org.eclipse.ui.handlers.ShowViewHandler">
<commandParameter
id="org.eclipse.ui.views.showView.viewId"
name="%command.showView.viewIdParameter"
values="org.eclipse.ui.internal.registry.ViewParameterValues" />
<commandParameter
id="org.eclipse.ui.views.showView.makeFast"
name="%command.showView.makeFastParameter"
optional="true"/>
</command>
The list of all possible values of the parameter is given by the class ViewParameterValues. The class would iterate through the view registry and return it.
Note: just to be complete, in theory (this thread)
RCP apps can disable fast views by calling WorkbenchWindowConfigurer.setShowFastViewBar(false) from their
WorkbenchAdvisor's preWindowOpen() method.
This not only hides the fast view bar, but also hides the Fast View menu item on views.
The simple way to add a fast view to an Eclipse RCP or RAP application begins with creating a normal view. In the plugins xml, add a new extension for the view (I'll call it fast.view), with the correct attributes.
<view
closable="true"
id="fast.view"
minimized="true"
ratio=".30f"
relationship="fast" <--- This attribute tells the view to be a fast view.
relative="other.view"
</view>
After adding this extension, we must also show the fast view bar in the workspace. To do this, edit the ApplicationWorkbenhWindowAdvisor (or other advisor that launches your workbench window), and add the following lines to your preWindowOpen() method:
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setShowFastViewBars(true);
If you already have an IWorkbenchWindowsConfigurer, you don't need to make a new one. This method tells the workbench to display the fast bar, and your new fast view perspective extension should be there when it starts.
I got this information from an Eclipse Papercuts article written by Lars Vogel: http://www.vogella.de/blog/2009/09/15/fastview-eclipse-rcp/
We have an application in which some views only work when attached to certain perspectives.
We want to remove those views from the Window -> Show View dialog so that users cannot add them to perspectives where they don't work.
Any ideas on how to do this either programmatically or declaratively?
I have tried using <visibleWhen />, but the views are still showing in the dialog:
<view class="com.mycompany.ViewClass"
id="com.mycompany.ViewId"
name="View Name"
restorable="true">
<visibleWhen>
<with variable="activeWorkbenchWindow.activePerspective">
<equals value="com.mycompany.MyPerspective"/>
</with>
</visibleWhen>
</view>
I don't think there is any problem with the <visibleWhen /> clause, so I'm wondering if it can be used with a View?
It should be treated as a menu contribution, using the <visibleWhen/> to only display that option when a certain condition is met.
See the wiki article "Menu Contribution" for more.
Unfortunately, it seems that Eclipse already does this for the Introduction view by calling the private ViewContentProvider.removeIntroView on the content provider for the Show Views dialog. A way to get around this limitation is to define activities by adding to the org.eclipse.ui.activities extension point (see activityPatternBinding on how activities can be mapped to UI contributions). Doing this will not only remove the views from the Show Views dialog, but it will also prevent them from showing in the perspectives themselves. The views can then be shown programmatically. I had to also enable the activities in the ApplicationWorkbenchAdvisor.preStartup method because of limitations in our application:
Set<String> activityIds = new HashSet<String>();
activityIds.add("com.my.activity.id");
IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport();
activitySupport.setEnabledActivityIds(activityIds);
In this case, the activity has to be disabled before showing the dialog, so the Show Views menu contribution has to be modified to do this as well.
Hopefully an extension point will be added to the next version of Eclipse to provide the option for developers to remove views from the dialog declaratively.