Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ The update site lands in `com.vogella.examples.updatesite/target/repository`.

- Pomless Tycho 5 build: `.mvn/extensions.xml` loads `tycho-build`, so bundles, the feature and the update site have no `pom.xml` of their own and must not get one.
- The root `pom.xml` holds the module list, the Java release and the target environments (linux, win32, macosx).
- `target-platform/target-platform.target` resolves everything from the Eclipse 2026-09 release repository; a new dependency outside the listed features must be added there as a unit.
- `target-platform/target-platform.target` resolves everything from the Eclipse 4.42 I-build repository, because `com.vogella.rcp.svg.currentcolor` needs `SVGFileFormat.setCurrentColor`, which is newer than the 2026-09 release; switch it to the 2026-12 release repository once that is out. A new dependency outside the listed features must be added there as a unit.
- `com.vogella.examples.feature` includes every example bundle, and `com.vogella.examples.updatesite/category.xml` publishes that feature.
- The e4 examples are PDE template applications (`Application.e4xmi`, handlers, parts) whose `plugin.xml` product extension lets them be launched from the IDE; only `com.vogella.css.fonts` also has a `.product` file, which launches it with just the bundles it needs.
- The e4 examples are PDE template applications (`Application.e4xmi`, handlers, parts) whose `plugin.xml` product extension lets them be launched from the IDE; only `com.vogella.css.fonts` and `com.vogella.rcp.svg.currentcolor` also have a `.product` file, which launches them with just the bundles they need.
- `com.vogella.rcp.perspective.plugin` and `com.vogella.rcp.perspective.addpart` contribute model fragments into `com.vogella.rcp.jface.translation`, so its element ids must stay stable.
- `org.eclipse.jface.nl1` is a fragment of `org.eclipse.jface` that supplies translated messages for the translation example.
- `com.vogella.css.fonts` targets Windows (it reads the win32 `LOGFONT` by reflection) but compiles on every platform.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# vogella Eclipse code examples

Example projects for Eclipse RCP and plug-in development from the [vogella.com](https://www.vogella.com) website.
The bundles are built with Tycho (pomless) against the Eclipse 2026-09 release and published as one p2 update site.
The bundles are built with Tycho (pomless) against the Eclipse 4.42 integration builds and published as one p2 update site.
The integration builds are needed for the SWT API used by `com.vogella.rcp.svg.currentcolor`; the target moves to the 2026-12 release once it is available.

## Examples

Expand All @@ -19,6 +20,7 @@ The bundles are built with Tycho (pomless) against the Eclipse 2026-09 release a
| com.vogella.rcp.jface.translation | Translating JFace wizards at runtime |
| com.vogella.rcp.perspective.addpart | Adding a part to a perspective with a model fragment |
| com.vogella.rcp.perspective.plugin | Contributing a perspective from a plug-in |
| com.vogella.rcp.svg.currentcolor | Setting the `currentColor` of SVG icons with `SVGFileFormat.setCurrentColor` from a `-currentColor` program argument or a login dialog; start it from `svg-currentcolor.product` |
| com.vogella.swt.fonts.roboto | Loading a custom font (Roboto) in SWT |
| com.vogella.swt.widgets | Custom SWT widgets |
| org.eclipse.jface.nl1 | Fragment with JFace translations |
Expand Down
1 change: 1 addition & 0 deletions com.vogella.examples.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<plugin id="com.vogella.rcp.jface.translation" version="0.0.0" unpack="false"/>
<plugin id="com.vogella.rcp.perspective.addpart" version="0.0.0" unpack="false"/>
<plugin id="com.vogella.rcp.perspective.plugin" version="0.0.0" unpack="false"/>
<plugin id="com.vogella.rcp.svg.currentcolor" version="0.0.0" unpack="false"/>
<plugin id="com.vogella.swt.fonts.roboto" version="0.0.0" unpack="false"/>
<plugin id="com.vogella.swt.widgets" version="0.0.0" unpack="false"/>
<plugin id="org.eclipse.jface.nl1" version="0.0.0" fragment="true" unpack="false"/>
Expand Down
7 changes: 7 additions & 0 deletions com.vogella.rcp.svg.currentcolor/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-25"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions com.vogella.rcp.svg.currentcolor/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.vogella.rcp.svg.currentcolor</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=25
org.eclipse.jdt.core.compiler.compliance=25
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=25
43 changes: 43 additions & 0 deletions com.vogella.rcp.svg.currentcolor/Application.e4xmi
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_svgcc_app" elementId="com.vogella.rcp.svg.currentcolor.application" bindingContexts="_svgcc_ctx_dialogAndWindow">
<children xsi:type="basic:TrimmedWindow" xmi:id="_svgcc_window" elementId="com.vogella.rcp.svg.currentcolor.window.main" label="SVG currentColor" iconURI="platform:/plugin/com.vogella.rcp.svg.currentcolor/icons/home.svg" width="700" height="500">
<children xsi:type="basic:PartSashContainer" xmi:id="_svgcc_sash" elementId="com.vogella.rcp.svg.currentcolor.partsashcontainer.main">
<children xsi:type="basic:PartStack" xmi:id="_svgcc_stack" elementId="com.vogella.rcp.svg.currentcolor.partstack.main">
<children xsi:type="basic:Part" xmi:id="_svgcc_part_icons" elementId="com.vogella.rcp.svg.currentcolor.part.icons" contributionURI="bundleclass://com.vogella.rcp.svg.currentcolor/com.vogella.rcp.svg.currentcolor.parts.IconsPart" label="Icons" iconURI="platform:/plugin/com.vogella.rcp.svg.currentcolor/icons/star.svg"/>
<children xsi:type="basic:Part" xmi:id="_svgcc_part_info" elementId="com.vogella.rcp.svg.currentcolor.part.info" contributionURI="bundleclass://com.vogella.rcp.svg.currentcolor/com.vogella.rcp.svg.currentcolor.parts.InfoPart" label="How it works" iconURI="platform:/plugin/com.vogella.rcp.svg.currentcolor/icons/info.svg"/>
</children>
</children>
<mainMenu xmi:id="_svgcc_menu" elementId="org.eclipse.ui.main.menu">
<children xsi:type="menu:Menu" xmi:id="_svgcc_menu_file" elementId="file" label="File">
<children xsi:type="menu:HandledMenuItem" xmi:id="_svgcc_menu_quit" elementId="com.vogella.rcp.svg.currentcolor.handleditem.quit" label="Quit" iconURI="platform:/plugin/com.vogella.rcp.svg.currentcolor/icons/exit.svg" command="_svgcc_cmd_quit"/>
</children>
<children xsi:type="menu:Menu" xmi:id="_svgcc_menu_help" elementId="help" label="Help">
<children xsi:type="menu:HandledMenuItem" xmi:id="_svgcc_menu_about" elementId="com.vogella.rcp.svg.currentcolor.handleditem.about" label="About" iconURI="platform:/plugin/com.vogella.rcp.svg.currentcolor/icons/info.svg" command="_svgcc_cmd_about"/>
</children>
</mainMenu>
<trimBars xmi:id="_svgcc_trimbar" elementId="com.vogella.rcp.svg.currentcolor.trimbar.top">
<children xsi:type="menu:ToolBar" xmi:id="_svgcc_toolbar" elementId="org.eclipse.ui.main.toolbar">
<children xsi:type="menu:HandledToolItem" xmi:id="_svgcc_tool_about" elementId="com.vogella.rcp.svg.currentcolor.handleditem.trimbar.top.about" iconURI="platform:/plugin/com.vogella.rcp.svg.currentcolor/icons/info.svg" tooltip="About" command="_svgcc_cmd_about"/>
<children xsi:type="menu:HandledToolItem" xmi:id="_svgcc_tool_quit" elementId="com.vogella.rcp.svg.currentcolor.handleditem.trimbar.top.quit" iconURI="platform:/plugin/com.vogella.rcp.svg.currentcolor/icons/exit.svg" tooltip="Quit" command="_svgcc_cmd_quit"/>
</children>
</trimBars>
</children>
<handlers xmi:id="_svgcc_handler_quit" elementId="com.vogella.rcp.svg.currentcolor.handler.quitCommand" contributionURI="bundleclass://com.vogella.rcp.svg.currentcolor/com.vogella.rcp.svg.currentcolor.handlers.QuitHandler" command="_svgcc_cmd_quit"/>
<handlers xmi:id="_svgcc_handler_about" elementId="com.vogella.rcp.svg.currentcolor.handler.aboutCommand" contributionURI="bundleclass://com.vogella.rcp.svg.currentcolor/com.vogella.rcp.svg.currentcolor.handlers.AboutHandler" command="_svgcc_cmd_about"/>
<bindingTables xmi:id="_svgcc_bindingtable" elementId="com.vogella.rcp.svg.currentcolor.bindingtable" bindingContext="_svgcc_ctx_dialogAndWindow">
<bindings xmi:id="_svgcc_binding_quit" elementId="com.vogella.rcp.svg.currentcolor.keybinding.m1q" keySequence="M1+Q" command="_svgcc_cmd_quit"/>
</bindingTables>
<rootContext xmi:id="_svgcc_ctx_dialogAndWindow" elementId="org.eclipse.ui.contexts.dialogAndWindow" name="In Dialog and Windows">
<children xmi:id="_svgcc_ctx_window" elementId="org.eclipse.ui.contexts.window" name="In Windows"/>
<children xmi:id="_svgcc_ctx_dialog" elementId="org.eclipse.ui.contexts.dialog" name="In Dialogs"/>
</rootContext>
<commands xmi:id="_svgcc_cmd_quit" elementId="org.eclipse.ui.file.exit" commandName="quitCommand"/>
<commands xmi:id="_svgcc_cmd_about" elementId="org.eclipse.ui.help.aboutAction" commandName="aboutCommand"/>
<addons xmi:id="_svgcc_addon_commands" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
<addons xmi:id="_svgcc_addon_contexts" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
<addons xmi:id="_svgcc_addon_bindings" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
<addons xmi:id="_svgcc_addon_commandmodel" elementId="org.eclipse.e4.ui.workbench.commands.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon"/>
<addons xmi:id="_svgcc_addon_handlermodel" elementId="org.eclipse.e4.ui.workbench.handler.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>
<addons xmi:id="_svgcc_addon_contextmodel" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
<addons xmi:id="_svgcc_addon_bindingmodel" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
</application:Application>
20 changes: 20 additions & 0 deletions com.vogella.rcp.svg.currentcolor/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SVG currentColor
Bundle-SymbolicName: com.vogella.rcp.svg.currentcolor;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: VOGELLA
Require-Bundle: org.eclipse.swt,
org.eclipse.e4.ui.model.workbench,
org.eclipse.jface,
org.eclipse.e4.ui.services,
org.eclipse.e4.ui.workbench,
org.eclipse.e4.core.di,
org.eclipse.e4.ui.di,
org.eclipse.e4.core.contexts,
org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-25
Automatic-Module-Name: com.vogella.rcp.svg.currentcolor
Import-Package: jakarta.annotation;version="[2.1.0,4.0.0)",
jakarta.inject;version="[2.0.0,3.0.0)"
Require-Capability: eclipse.swt;filter:="(image.format=svg)"
7 changes: 7 additions & 0 deletions com.vogella.rcp.svg.currentcolor/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/,\
Application.e4xmi
3 changes: 3 additions & 0 deletions com.vogella.rcp.svg.currentcolor/icons/exit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions com.vogella.rcp.svg.currentcolor/icons/folder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions com.vogella.rcp.svg.currentcolor/icons/home.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions com.vogella.rcp.svg.currentcolor/icons/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions com.vogella.rcp.svg.currentcolor/icons/save.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions com.vogella.rcp.svg.currentcolor/icons/settings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions com.vogella.rcp.svg.currentcolor/icons/star.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions com.vogella.rcp.svg.currentcolor/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

<extension
id="product"
point="org.eclipse.core.runtime.products">
<product
application="org.eclipse.e4.ui.workbench.swt.E4Application"
name="SVG currentColor">
<property
name="lifeCycleURI"
value="bundleclass://com.vogella.rcp.svg.currentcolor/com.vogella.rcp.svg.currentcolor.LifeCycle">
</property>
<property
name="clearPersistedState"
value="true">
</property>
</product>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.vogella.rcp.svg.currentcolor;

import java.util.Optional;

import org.eclipse.swt.graphics.RGB;

/**
* Converts between {@link RGB} and the {@code RRGGBB} notation, with an optional
* leading {@code #}, that the {@code -currentColor} program argument and SWT's
* {@code swt.svg.currentColor} system property use.
*/
public final class CurrentColor {

private CurrentColor() {
}

public static Optional<RGB> parse(String value) {
if (value == null || !value.trim().matches("#?[0-9A-Fa-f]{6}")) {
return Optional.empty();
}
int rgb = Integer.parseInt(value.trim().replaceFirst("^#", ""), 16);
return Optional.of(new RGB((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF));
}

public static String toHex(RGB rgb) {
return "#%02X%02X%02X".formatted(rgb.red, rgb.green, rgb.blue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.vogella.rcp.svg.currentcolor;

import java.io.IOException;
import java.io.InputStream;

import org.eclipse.core.runtime.ILog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

/**
* The SVG icons of this bundle, which all use {@code currentColor}.
*/
public final class Icons {

public static final String[] NAMES = { "home", "folder", "save", "star", "settings", "info", "exit" };

private Icons() {
}

/**
* Creates the icon with the {@code currentColor} that is set now; the caller
* disposes it.
*/
public static Image create(Display display, String name) {
try (InputStream in = Icons.class.getResourceAsStream("/icons/" + name + ".svg")) {
return in != null ? new Image(display, in) : null;
} catch (IOException e) {
ILog.of(Icons.class).error("Could not load icon " + name, e);
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.vogella.rcp.svg.currentcolor;

import java.util.Optional;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Platform;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.internal.image.SVGFileFormat;

/**
* Sets the color SVG images use for {@code currentColor} before the workbench
* window is rendered.
* <p>
* The color comes from the login dialog, which preselects the color of the
* {@code -currentColor RRGGBB} program argument if one is given, otherwise
* SWT's current value (black, or the {@code -Dswt.svg.currentColor=RRGGBB}
* system property).
* </p>
* <p>
* The Eclipse CSS property {@code swt-svg-current-color} is not available yet,
* so the color is set with the SWT method
* {@link SVGFileFormat#setCurrentColor(RGB)}. The color is global and is used
* when an image is rasterized, so it must be set before the first SVG icon is
* created.
* </p>
*/
@SuppressWarnings("restriction")
public class LifeCycle {

static final String CURRENT_COLOR_ARGUMENT = "-currentColor";

/** Context key of the name entered in the login dialog. */
public static final String USER = "com.vogella.rcp.svg.currentcolor.user";

@PostContextCreate
void login(IEclipseContext workbenchContext) {
RGB initialColor = colorFromArguments().orElseGet(SVGFileFormat::getCurrentColor);

LoginDialog dialog = new LoginDialog(null, initialColor);
if (dialog.open() != Window.OK) {
// no workbench window exists yet, so ending the process is the simplest way to cancel the start
System.exit(0);
}

SVGFileFormat.setCurrentColor(dialog.getCurrentColor());
workbenchContext.set(USER, dialog.getUser());
}

private Optional<RGB> colorFromArguments() {
String[] args = Platform.getApplicationArgs();
for (int i = 0; i < args.length - 1; i++) {
if (CURRENT_COLOR_ARGUMENT.equalsIgnoreCase(args[i])) {
Optional<RGB> color = CurrentColor.parse(args[i + 1]);
if (color.isEmpty()) {
ILog.of(getClass()).warn("Ignoring " + CURRENT_COLOR_ARGUMENT + " " + args[i + 1]
+ ", expected a color like 1E88E5");
}
return color;
}
}
return Optional.empty();
}
}
Loading