Skip to content

Commit

Permalink
Updating pde.spy.event to latest databinding API
Browse files Browse the repository at this point in the history
As the planned deletion of the databinding API would break the PDE
build, this is a quick fix to make PDE compile again and to ensure the
event spy still works. This is done under time pressure so I'm sure that
this can be solved nicer (without copying code from the deleted classes
into the event spy).

Fixes eclipse-pde#339
  • Loading branch information
vogella committed Sep 21, 2022
1 parent 9b826a2 commit 070c89a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ui/org.eclipse.pde.spy.event/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jface.databinding,
org.eclipse.core.databinding.observable,
org.eclipse.core.databinding.beans,
org.eclipse.pde.spy.core
org.eclipse.pde.spy.core,
org.eclipse.core.databinding.property;bundle-version="1.9.0"
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-ActivationPolicy: lazy
Import-Package: javax.annotation;version="1.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

import java.util.ArrayList;

import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.beans.typed.PojoProperties;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.core.databinding.observable.masterdetail.IObservableFactory;
import org.eclipse.core.databinding.observable.set.IObservableSet;
import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider;
import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
import org.eclipse.jface.databinding.viewers.TreeStructureAdvisor;
Expand Down Expand Up @@ -96,7 +97,7 @@ public CapturedEventTree(Composite parent) {
new CapturedEventsObservableFactory(), new CapturedEventsTreeStructureAdvisor());
setContentProvider(contentProvider);

IObservableMap[] attributes = PojoObservables.observeMaps(contentProvider.getKnownElements(), IEventItem.class,
IObservableMap[] attributes = observeMaps(contentProvider.getKnownElements(), IEventItem.class,
new String[] { Messages.CapturedEventTree_Name, Messages.CapturedEventTree_Param1, Messages.CapturedEventTree_Param2 });
setLabelProvider(new ObservableMapLabelProvider(attributes));

Expand All @@ -117,14 +118,30 @@ public Boolean hasChildren(CapturedEvent element) {
}
}


private static IObservableMap[] observeMaps(IObservableSet domain,
Class pojoClass, String[] propertyNames) {
IObservableMap[] result = new IObservableMap[propertyNames.length];
for (int i = 0; i < propertyNames.length; i++) {
result[i] = observeMap(domain, pojoClass, propertyNames[i]);
}
return result;
}

private static IObservableMap observeMap(IObservableSet domain,
Class pojoClass, String propertyName) {
return PojoProperties.value(pojoClass, propertyName).observeDetail(
domain);
}

private static class CapturedEventsObservableFactory implements IObservableFactory {
@Override
public IObservable createObservable(Object target) {
if (target instanceof IObservableList) {
return (IObservableList) target;
}
if (target instanceof CapturedEvent) {
return PojoObservables.observeList(target, "parameters"); //$NON-NLS-1$
PojoProperties.list("parameters").observe(target);
}
return null;
}
Expand Down

0 comments on commit 070c89a

Please sign in to comment.