View does not displayed - eclipse-rcp

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.

Related

Eclipse RCP 4.x show view

I'm working for a short time on the libraries of eclipse 4.x someone could tell me how can I open a view through from the context menu? Thank you in advance.
To show a part anywhere you should define a command in the application model and a handler for the command. To show a part in the handler use:
#Execute
public void execute(EPartService partService)
{
MPart mpart = partService.showPart(part id, PartState.ACTIVATE);
}
In the application Part definition for your part add a Popup Menu to the Menus section. In the popup menu define a HandledMenuItem for your command.
To register the popup menu as the context menu for a control (tree, table etc) use:
#Inject
private EMenuService;
...
menuService.registerContextMenu(control, menu id);

Integrating EMF and view in plugin project

I created an EMF project and tested using <>.editor project generated by .genmodel file by creating a new project and a file through "Example EMF Model Creation Wizards". Is there any way that a view (in plugin project) can be created directly (probably project & file are automatically created when user runs the application)? I dont want the user to create these things. It should be automated and presented in a view.
In the .genmodel file, set .genmodel --> All ---> Runtime Platform to RCP. This creates an RCP app that does not use all the plugins of the IDE. If you want, you can generate your app to run in the IDE... However, for this answer I will simplify and assume you generated an RCP app. Go into the XXX.editor generated plugin, and into the .plugin file --> extensions. Add a new (org.eclipse.ui.views) View by declaring a new View extension -- see the Sample View for a template. Make sure to keep track of the ID you give this new View extension. Similarly add a new PerspectiveExtension extension. Add a reference to this new PerspectiveExtension with your unique View ID. In the View extension, click on the class link, this will create a skeleton ViewPart class. It is a good idea to put a public static final String YOUR_VIEW_ID = "com.yourplugin.ViewID" in that class.
This will get you started and if you added your new view to your perspective, it should be visible when running your EMF based RCP app.

How can I create a view using the E4 programming model to be a plug-in for Eclipse 4.2 or above?

Most of the existing Eclipse plug-ins use the extension registry and subclasses of ViewPart, coupled with the compatibility layer. As a result, writing a new view (especially using the new plug-in wizard in PDE) results in plug-ins that look like:
<plugin>
<extension point="org.eclipse.ui.views">
<view name="Example View" class="org.example.ExampleView"/>
</extension>
</plugin>
public class ExampleView extends ViewPart {
public void createPartControl(Composite parent) {
...
}
}
Is it possible to take advantage of the E4 programming model to create a view like:
public class Example {
#Inject
public Example(Composite parent) {
...
}
}
and have that hooked into an existing Eclipse 4.2 instance, so that it shows up in the 'Show View' menu? If so, how is it declaratively wired in (since that the LegacyIDE.e4xmi is immutable and can't be added to).
Look at the code I've written for the e4 model editor (http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x).
I've a set of wrappers for this at http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.compat for 4.3 we plan on direct support.

Refreshing the workbench

HI,
I am facing some problem.. I want to hide the menu when eclipse workbench starts.
But the problem is menu is not hiding when the eclipse workbench starts. It is hiding only
when some refresh is happened. for example: when I change the default perspective to some other perspective, I am getting the desired out put. That means menu is hiding.
But when the eclipse workbench is loaded it is not hiding the menu. Below is my code.
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
try {
IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow()
if(window instanceof WorkbenchWindow) {
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
IContributionItem[] items = menuManager.getItems();
for(IContributionItem item:items){
System.out.println("item.getId()::: "+item.getId());
menuManager.remove("org.eclipse.ui.run");
menuManager.remove("help");
menuManager.remove("project");
}
}
}`
}
};
Given that you are looking to hide some features, I don't think that this is the best approach. (Not I am using the term feature here in the colloquial way, not as an Eclipse feature.
I would recommend one of two avenues:
Perspectives: See the extension point org.eclipse.ui.perspectives. This allows you to create a new perspective like the debug perspective or the Java perspective. Using a perspective, you can select exactly what menu items and views are shown and which ones are hidden.
Capabilities (aka activites): See the extension point org.eclipse.ui.activities. This allows you to have some fairly fine-grained control over what features are available in the workspace. See more info here: http://wiki.eclipse.org/Galileo_Capabilities
Put Your code in org.eclipse.ui.startup extention point. Make a Startup class after implementing the interface IStartup. For Details follow this link:-
Eclipse plugin : disable/enable dynamically an action from main menubar

Programmatically showing a View from an Eclipse Plug-in

I have a plug-in to an Eclipse RCP application that has a view. After an event occurs in the RCP application, the plug-in is instantiated, its methods are called to populate the plug-in's model, but I cannot find how to make the view appear without going to the "Show View..." menu.
I would think that there would be something in the workbench singleton that could handle this, but I have not found out how anywhere.
You are probably looking for this:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("viewId");
If called from handler of a command
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);
would be better, as I know.
I found the need to bring the view to the front after it had been opened and pushed to the background. The activate method does the trick.
PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.activate(workbenchPartToActivate);
NOTE: The workbenchPartToActivate is an instance of IWorkbenchPart.
In e4, the EPartService is responsible for opening Parts. This can also be used to open e3 ViewParts. Instantiate the following class through your IEclipseContext, call the openPart-Method, and you should see the Eclipse internal browser view.
public class Opener {
#Inject
EPartService partService;
public void openPart() {
MPart part = partService.createPart("org.eclipse.ui.browser.view");
part.setLabel("Browser");
partService.showPart(part, PartState.ACTIVATE);
}
}
Here you can find an example of how this works together with your Application.e4xmi.