diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/TargetEvents.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/TargetEvents.java index da74c97df5..2b2e8097a7 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/TargetEvents.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/core/target/TargetEvents.java @@ -13,20 +13,23 @@ package org.eclipse.pde.core.target; import org.eclipse.e4.core.services.events.IEventBroker; +import org.osgi.service.event.Event; import org.osgi.service.event.EventHandler; /** - * Target events and event topic definitions. Can be used as follows: + * Target events and event topic definitions. + * + *
+ * The following code is an example of to subscribe to the + * {@link #TOPIC_TARGET_SAVED} event: + *
* ** EventHandler eventHandler = event -> { - * Object data = event.getProperty(IEventBroker.DATA); - * if (data instanceof ITargetHandle) { - * ITargetHandle handle = (ITargetHandle) data; + * if (event.getProperty(IEventBroker.DATA) instanceof ITargetHandle handle) { * // Work with the target handle... * } * }; - * * IEclipseContext context = EclipseContextFactory.getServiceContext(bundleContext); * IEventBroker broker = context.get(IEventBroker.class); * if (broker != null) { @@ -54,48 +57,23 @@ public class TargetEvents { public static final String TOPIC_ALL = TOPIC_BASE + "/*"; //$NON-NLS-1$ /** - * Sent when workspace target definition is changed. Can be used as follows: - * - *- * EventHandler eventHandler = event -> { - * Object data = event.getProperty(IEventBroker.DATA); - * if (data instanceof ITargetDefinition) { - * ITargetDefinition definition = (ITargetDefinition) data; - * // Work with the target definition... - * } - * }; - * - * IEclipseContext context = EclipseContextFactory.getServiceContext(bundleContext); - * IEventBroker broker = context.get(IEventBroker.class); - * if (broker != null) { - * broker.subscribe(TargetEvents.TOPIC_WORKSPACE_TARGET_CHANGED, eventHandler); - * // Do not forget to unsubscribe later! - * } - *+ * Sent when workspace target definition is changed. + *+ * The {@link IEventBroker#DATA data} {@link Event#getProperty(String) event + * property} of events with this topic is the changed + * {@link ITargetDefinition}. + *
* * @see ITargetPlatformService#getWorkspaceTargetDefinition() */ public static final String TOPIC_WORKSPACE_TARGET_CHANGED = TOPIC_BASE + "/workspaceTargetChanged"; //$NON-NLS-1$ /** - * Sent when a target is saved. Can be used as follows: - * - *- * EventHandler eventHandler = event -> { - * Object data = event.getProperty(IEventBroker.DATA); - * if (data instanceof ITargetHandle) { - * ITargetHandle handle = (ITargetHandle) data; - * // Work with the target handle... - * } - * }; - * - * IEclipseContext context = EclipseContextFactory.getServiceContext(bundleContext); - * IEventBroker broker = context.get(IEventBroker.class); - * if (broker != null) { - * broker.subscribe(TargetEvents.TOPIC_TARGET_SAVED, eventHandler); - * // Do not forget to unsubscribe later! - * } - *+ * Sent when a target is saved. + *+ * The {@link IEventBroker#DATA data} {@link Event#getProperty(String) event + * property} of events with this topic is the saved {@link ITargetHandle}. + *
* * @see ITargetPlatformService#saveTargetDefinition(ITargetDefinition) * @see IEventBroker @@ -104,24 +82,11 @@ public class TargetEvents { public static final String TOPIC_TARGET_SAVED = TOPIC_BASE + "/targetSaved"; //$NON-NLS-1$ /** - * Sent when a target is deleted. Can be used as follows: - * - *- * EventHandler eventHandler = event -> { - * Object data = event.getProperty(IEventBroker.DATA); - * if (data instanceof ITargetHandle) { - * ITargetHandle handle = (ITargetHandle) data; - * // Work with the target handle... - * } - * }; - * - * IEclipseContext context = EclipseContextFactory.getServiceContext(bundleContext); - * IEventBroker broker = context.get(IEventBroker.class); - * if (broker != null) { - * broker.subscribe(TargetEvents.TOPIC_TARGET_DELETED, eventHandler); - * // Do not forget to unsubscribe later! - * } - *+ * Sent when a target is deleted. + *+ * The {@link IEventBroker#DATA data} {@link Event#getProperty(String) event + * property} of events with this topic is the deleted {@link ITargetHandle}. + *
* * @see ITargetPlatformService#deleteTarget(ITargetHandle) * @since 3.20 diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/AbstractTargetHandle.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/AbstractTargetHandle.java index 6bb76bddc6..ad1af493cc 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/AbstractTargetHandle.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/AbstractTargetHandle.java @@ -56,7 +56,6 @@ public ITargetDefinition getTargetDefinition() throws CoreException { public final void save(ITargetDefinition definition) throws CoreException { doSave(definition); - TargetPlatformService service = (TargetPlatformService) TargetPlatformService.getDefault(); service.scheduleEvent(TargetEvents.TOPIC_TARGET_SAVED, definition.getHandle()); } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetPlatformService.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetPlatformService.java index 01572d71da..755842b837 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetPlatformService.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/target/TargetPlatformService.java @@ -274,8 +274,7 @@ public ITargetDefinition newTarget() { @Override public void saveTargetDefinition(ITargetDefinition definition) throws CoreException { - ITargetHandle handle = definition.getHandle(); - ((AbstractTargetHandle) handle).save(definition); + ((AbstractTargetHandle) definition.getHandle()).save(definition); } @Override diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/targetdefinition/TargetEditor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/targetdefinition/TargetEditor.java index a8e535a566..0feeff949d 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/targetdefinition/TargetEditor.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/targetdefinition/TargetEditor.java @@ -299,7 +299,6 @@ publicT getAdapter(Class adapter) { return adapter.cast(target.getHandle()); } } - return super.getAdapter(adapter); } /**