Skip to content

Commit

Permalink
Update Eclipse RCP FAQ entry
Browse files Browse the repository at this point in the history
  • Loading branch information
vogella committed Mar 5, 2024
1 parent 23b8a04 commit 95db236
Showing 1 changed file with 48 additions and 29 deletions.
77 changes: 48 additions & 29 deletions docs/FAQ/FAQ_How_do_I_create_a_Rich_Client_application.md
@@ -1,42 +1,60 @@
FAQ: How do I create a Rich Client Application?
===============================================

An Eclipse RCP application in Eclipse 4 (e4) leverages the application model for defining the user interface and behavior.
Unlike Eclipse 3.x, where WorkbenchAdvisor played a central role, Eclipse 4 RCP applications are more declarative, using application models and dependency injection.

FAQ How do I create a Rich Client application?
==============================================
## Step 1: Set Up Your Project

An Eclipse RCP application has full control over how the user interface is created. The locus of control for an RCP application-the place where all configuration starts-is the WorkbenchAdvisor class. Your subclass of WorkbenchAdvisor controls the initial layout and appearance of the workbench window, as well as what commands appear in the menus and toolbars. Here is an example of a bare-bones RCP application:
Create an Eclipse 4 RCP Project: Use the Eclipse IDE to create a new Eclipse 4 RCP project via the wizard, which sets up the basic structure and required dependencies for an e4 application.

public class MinimalRCPApp extends WorkbenchAdvisor
implements IPlatformRunnable {
public String getInitialWindowPerspectiveId() {
return "org.eclipse.faq.minimalperspective";
}
public void preWindowOpen(
IWorkbenchWindowConfigurer wwc) {
configurer.setShowMenuBar(false);
configurer.setShowFastViewBars(false);
configurer.setShowStatusLine(false);
configurer.setShowCoolBar(false);
}
public Object run(Object args) throws Exception {
Display d = PlatformUI.createDisplay();
int ret = PlatformUI.createAndRunWorkbench(d, this);
if (ret == PlatformUI.RETURN_RESTART)
return EXIT_RESTART;
return EXIT_OK;
## Step 2: Define the Application Model

The application model defines the UI structure (views, menus, toolbars, etc.) and is typically designed within the Eclipse IDE using the Application Model Editor.

Open the Application Model Editor: Navigate to the Application.e4xmi file in your project.
Design Your UI: Use the editor to add and configure parts, perspectives, menus, and other UI components.

## Step 3: Implement Business Logic

In Eclipse 4, you implement your application's business logic in classes annotated for dependency injection (e.g., @Inject for services or UI components).

Example of an Eclipse 4 RCP Application Entry Point for a handler called via a menu.

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.swt.widgets.Shell;

public class Application {
@Execute
public void run(Shell shell) {
// Your application logic here
}
}
}


This application creates a blank workbench window with no toolbars, no menus, no status line, and no views or editors (Figure 13.1). The application will run until the user closes the workbench window.
The @Execute annotation marks the method to be run once the menu entry connnected with this handler is called.

## Step 4: Configure Your Application in the plugin.xml

The application's run method is the one we've seen in previous application examples. You need to specify the name of the class with this method when declaring your application in the plugin.xml file. This example creates a workbench and runs the event loop by calling createAndRunWorkbench. The preWindowOpen method is your opportunity to customize the basic appearance of the window. Finally, the getInitialWindowPerspectiveId method must specify the ID of the initial perspective to be displayed.
Unlike Eclipse 3.x, most of the configuration in Eclipse 4 is done through the application model (Application.e4xmi). However, you still need to define your application's ID and point to the application model in your plugin.xml:

That's all there is to it! The rest of an RCP application is developed just like any other plug-in. You need to create one or more perspectives and populate them with the views and editors that apply for your application. These are created by using the standard org.eclipse.ui extension points, all of which are available in a custom application.
<extension
id="application"
point="org.eclipse.core.runtime.applications">
<application>
<run class="org.eclipse.e4.ui.internal.workbench.swt.E4Application">
<parameter
name="org.eclipse.e4.ui.workbench.swt.E4Application"
value="path/to/your/Application.e4xmi">
</parameter>
</run>
</application>
</extension>


A binary download of the RCP can be obtained for any Eclipse build from the eclipse.org downloads page. This download does not contain an application, but it can be set as the target platform for your own RCP application from the **Plug-in Development >** Target Platform **preference page.**
Make sure to replace "path/to/your/Application.e4xmi" with the actual path to your application model file.


## Conclusion
Eclipse 4 RCP development focuses on the application model and dependency injection, providing a more flexible and modular approach to building rich client applications compared to the traditional Eclipse 3.x RCP. The rest of your RCP application development involves creating and populating perspectives, views, and other UI components using the Eclipse 4 application model.

See Also:
---------
Expand All @@ -45,3 +63,4 @@ See Also:

[FAQ\_How\_do\_I\_create\_an\_application?](./FAQ_How_do_I_create_an_application.md "FAQ How do I create an application?")

[Building Eclipse RCP applications](https://www.vogella.com/tutorials/EclipseRCP/article.html)

0 comments on commit 95db236

Please sign in to comment.