Skip to content

Commit

Permalink
[FIXUP] Suggestions for improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Nov 9, 2024
1 parent 2bd18cb commit 71139e3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>
* The following code is an example of to subscribe to the
* {@link #TOPIC_TARGET_SAVED} event:
* </p>
*
* <pre>
* 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) {
Expand Down Expand Up @@ -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:
*
* <pre>
* 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!
* }
* </pre>
* Sent when workspace target definition is changed.
* <p>
* The {@link IEventBroker#DATA data} {@link Event#getProperty(String) event
* property} of events with this topic is the changed
* {@link ITargetDefinition}.
* </p>
*
* @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:
*
* <pre>
* 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!
* }
* </pre>
* Sent when a target is saved.
* <p>
* The {@link IEventBroker#DATA data} {@link Event#getProperty(String) event
* property} of events with this topic is the saved {@link ITargetHandle}.
* </p>
*
* @see ITargetPlatformService#saveTargetDefinition(ITargetDefinition)
* @see IEventBroker
Expand All @@ -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:
*
* <pre>
* 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!
* }
* </pre>
* Sent when a target is deleted.
* <p>
* The {@link IEventBroker#DATA data} {@link Event#getProperty(String) event
* property} of events with this topic is the deleted {@link ITargetHandle}.
* </p>
*
* @see ITargetPlatformService#deleteTarget(ITargetHandle)
* @since 3.20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ public <T> T getAdapter(Class<T> adapter) {
return adapter.cast(target.getHandle());
}
}

return super.getAdapter(adapter);
}
/**
Expand Down

0 comments on commit 71139e3

Please sign in to comment.