diff options
author | Paul Webster | 2012-10-25 13:26:50 +0000 |
---|---|---|
committer | Paul Webster | 2012-10-25 13:26:50 +0000 |
commit | bdc5129ba5bac8adfc9bb422d22ee7b93dcb9fda (patch) | |
tree | 2177ff49a596ea8a9bed5eef920a1526ea200479 | |
parent | d0db74decc489cafceb460f9db074d09e9eb84ac (diff) | |
parent | b15862f11203af2f54e6371e5ede8b2b16f89367 (diff) | |
download | eclipse.platform.ui-bdc5129ba5bac8adfc9bb422d22ee7b93dcb9fda.tar.gz eclipse.platform.ui-bdc5129ba5bac8adfc9bb422d22ee7b93dcb9fda.tar.xz eclipse.platform.ui-bdc5129ba5bac8adfc9bb422d22ee7b93dcb9fda.zip |
Merge remote branch 'origin/R4_2_maintenance'v20121025-132650
5 files changed, 205 insertions, 12 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java index 16cc2f7ea66..85abdaf75ea 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionAggregator.java @@ -39,9 +39,12 @@ import org.osgi.service.event.EventHandler; public class SelectionAggregator { static final String OUT_SELECTION = "org.eclipse.ui.output.selection"; //$NON-NLS-1$ + static final String OUT_POST_SELECTION = "org.eclipse.ui.output.postSelection"; //$NON-NLS-1$ private ListenerList genericListeners = new ListenerList(); + private ListenerList genericPostListeners = new ListenerList(); private Map<String, ListenerList> targetedListeners = new HashMap<String, ListenerList>(); + private Map<String, ListenerList> targetedPostListeners = new HashMap<String, ListenerList>(); private Set<IEclipseContext> tracked = new HashSet<IEclipseContext>(); private EventHandler eventHandler = new EventHandler() { @@ -80,7 +83,9 @@ public class SelectionAggregator { @PreDestroy void preDestroy() { genericListeners.clear(); + genericPostListeners.clear(); targetedListeners.clear(); + targetedPostListeners.clear(); eventBroker.unsubscribe(eventHandler); } @@ -96,7 +101,11 @@ public class SelectionAggregator { activePart = part; IEclipseContext partContext = part.getContext(); // only notify listeners if the part actually posts selections - if (partContext.containsKey(OUT_SELECTION)) { + if (partContext.containsKey(OUT_POST_SELECTION)) { + Object selection = partContext.get(OUT_POST_SELECTION); + context.set(IServiceConstants.ACTIVE_SELECTION, selection); + notifyPostListeners(part, selection); + } else if (partContext.containsKey(OUT_SELECTION)) { Object selection = partContext.get(OUT_SELECTION); context.set(IServiceConstants.ACTIVE_SELECTION, selection); notifyListeners(part, selection); @@ -142,6 +151,43 @@ public class SelectionAggregator { } } + private void notifyPostListeners(final MPart part, final Object selection) { + for (Object listener : genericPostListeners.getListeners()) { + final ISelectionListener myListener = (ISelectionListener) listener; + SafeRunner.run(new ISafeRunnable() { + public void run() throws Exception { + myListener.selectionChanged(part, selection); + } + + public void handleException(Throwable exception) { + logger.error(exception); + } + }); + } + notifyTargetedPostListeners(part, selection); + } + + private void notifyTargetedPostListeners(final MPart part, final Object selection) { + String id = part.getElementId(); + if (id != null) { + ListenerList listenerList = targetedPostListeners.get(id); + if (listenerList != null) { + for (Object listener : listenerList.getListeners()) { + final ISelectionListener myListener = (ISelectionListener) listener; + SafeRunner.run(new ISafeRunnable() { + public void run() throws Exception { + myListener.selectionChanged(part, selection); + } + + public void handleException(Throwable exception) { + logger.error(exception); + } + }); + } + } + } + } + private void track(final MPart part) { final IEclipseContext myContext = this.context; IEclipseContext context = part.getContext(); @@ -182,7 +228,8 @@ public class SelectionAggregator { // we don't need to keep tracking non-active parts unless // they have targeted listeners String partId = part.getElementId(); - boolean continueTracking = targetedListeners.containsKey(partId); + boolean continueTracking = targetedListeners.containsKey(partId) + || targetedPostListeners.containsKey(partId); if (!continueTracking) { tracked.remove(part.getContext()); } @@ -191,6 +238,40 @@ public class SelectionAggregator { return true; } }); + context.runAndTrack(new RunAndTrack() { + private boolean initial = true; + + public boolean changed(IEclipseContext context) { + final Object postSelection = context.get(OUT_POST_SELECTION); + if (initial) { + initial = false; + if (postSelection == null) { + return true; + } + } + + if (activePart == part) { + runExternalCode(new Runnable() { + public void run() { + notifyPostListeners(part, postSelection); + } + }); + } else { + runExternalCode(new Runnable() { + public void run() { + notifyTargetedPostListeners(part, postSelection); + } + }); + // we don't need to keep tracking non-active parts unless + // they have targeted listeners + String partId = part.getElementId(); + boolean continueTracking = targetedListeners.containsKey(partId) + || targetedPostListeners.containsKey(partId); + return continueTracking; + } + return true; + } + }); } } @@ -202,6 +283,10 @@ public class SelectionAggregator { genericListeners.add(listener); } + public void addPostSelectionListener(ISelectionListener listener) { + genericPostListeners.add(listener); + } + public void removeSelectionListener(ISelectionListener listener) { // we may have been destroyed already, see bug 310113 if (context != null) { @@ -209,6 +294,13 @@ public class SelectionAggregator { } } + public void removePostSelectionListener(ISelectionListener listener) { + // we may have been destroyed already, see bug 310113 + if (context != null) { + genericPostListeners.remove(listener); + } + } + public void addSelectionListener(String partId, ISelectionListener listener) { ListenerList listeners = targetedListeners.get(partId); if (listeners == null) { @@ -222,6 +314,19 @@ public class SelectionAggregator { track(part); } + public void addPostSelectionListener(String partId, ISelectionListener listener) { + ListenerList listeners = targetedPostListeners.get(partId); + if (listeners == null) { + listeners = new ListenerList(); + targetedPostListeners.put(partId, listeners); + } + listeners.add(listener); + + MPart part = partService.findPart(partId); + if (part != null) + track(part); + } + public void removeSelectionListener(String partId, ISelectionListener listener) { // we may have been destroyed already, see bug 310113 if (context != null) { @@ -232,6 +337,16 @@ public class SelectionAggregator { } } + public void removePostSelectionListener(String partId, ISelectionListener listener) { + // we may have been destroyed already, see bug 310113 + if (context != null) { + ListenerList listeners = targetedPostListeners.get(partId); + if (listeners != null) { + listeners.remove(listener); + } + } + } + public Object getSelection(String partId) { MPart part = partService.findPart(partId); if (part == null) { diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionServiceImpl.java index 93c99b01f1e..8655d75276b 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/SelectionServiceImpl.java @@ -30,6 +30,10 @@ public class SelectionServiceImpl implements ESelectionService { context.set(SelectionAggregator.OUT_SELECTION, selection); } + public void setPostSelection(Object selection) { + context.set(SelectionAggregator.OUT_POST_SELECTION, selection); + } + public Object getSelection() { return getServiceAggregator().getSelection(); } @@ -54,6 +58,22 @@ public class SelectionServiceImpl implements ESelectionService { getServiceAggregator().removeSelectionListener(partId, listener); } + public void addPostSelectionListener(ISelectionListener listener) { + getServiceAggregator().addPostSelectionListener(listener); + } + + public void removePostSelectionListener(ISelectionListener listener) { + getServiceAggregator().removePostSelectionListener(listener); + } + + public void addPostSelectionListener(String partId, ISelectionListener listener) { + getServiceAggregator().addPostSelectionListener(partId, listener); + } + + public void removePostSelectionListener(String partId, ISelectionListener listener) { + getServiceAggregator().removePostSelectionListener(partId, listener); + } + private SelectionAggregator getServiceAggregator() { SelectionAggregator aggregator = context.get(SelectionAggregator.class); if (aggregator != null) diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/ESelectionService.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/ESelectionService.java index c2040e0907f..bd7d22c0f63 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/ESelectionService.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/workbench/modeling/ESelectionService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 IBM Corporation and others. + * Copyright (c) 2009, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -28,6 +28,8 @@ public interface ESelectionService { public void setSelection(Object selection); + public void setPostSelection(Object selection); + public Object getSelection(); public Object getSelection(String partId); @@ -39,4 +41,12 @@ public interface ESelectionService { public void addSelectionListener(String partId, ISelectionListener listener); public void removeSelectionListener(String partId, ISelectionListener listener); + + public void addPostSelectionListener(ISelectionListener listener); + + public void removePostSelectionListener(ISelectionListener listener); + + public void addPostSelectionListener(String partId, ISelectionListener listener); + + public void removePostSelectionListener(String partId, ISelectionListener listener); } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java index 6dac921de3f..7089dd253bc 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java @@ -165,7 +165,14 @@ public abstract class CompatibilityPart implements ISelectionChangedListener { if (selectionProvider instanceof IPostSelectionProvider) { ((IPostSelectionProvider) selectionProvider) - .addPostSelectionChangedListener(this); + .addPostSelectionChangedListener(new ISelectionChangedListener() { + + public void selectionChanged(SelectionChangedEvent e) { + ESelectionService selectionService = (ESelectionService) part + .getContext().get(ESelectionService.class.getName()); + selectionService.setPostSelection(e.getSelection()); + } + }); } } } diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/SelectionService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/SelectionService.java index bf376aeb88b..a51e044dd2e 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/SelectionService.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/SelectionService.java @@ -54,7 +54,9 @@ public class SelectionService implements ISelectionChangedListener, ISelectionSe private IWorkbenchPart activePart; private ListenerList listeners = new ListenerList(); + private ListenerList postSelectionListeners = new ListenerList(); private Map<String, Set<ISelectionListener>> targetedListeners = new HashMap<String, Set<ISelectionListener>>(); + private Map<String, Set<ISelectionListener>> targetedPostSelectionListeners = new HashMap<String, Set<ISelectionListener>>(); private org.eclipse.e4.ui.workbench.modeling.ISelectionListener listener = new org.eclipse.e4.ui.workbench.modeling.ISelectionListener() { public void selectionChanged(MPart part, Object selection) { @@ -74,6 +76,19 @@ public class SelectionService implements ISelectionChangedListener, ISelectionSe } }; + private org.eclipse.e4.ui.workbench.modeling.ISelectionListener postListener = new org.eclipse.e4.ui.workbench.modeling.ISelectionListener() { + public void selectionChanged(MPart part, Object selection) { + selection = createCompatibilitySelection(selection); + + Object client = part.getObject(); + if (client instanceof CompatibilityPart) { + IWorkbenchPart workbenchPart = ((CompatibilityPart) client).getPart(); + notifyPostSelectionListeners(part.getElementId(), workbenchPart, + (ISelection) selection); + } + } + }; + private static ISelection createCompatibilitySelection(Object selection) { if (selection instanceof ISelection) { return (ISelection) selection; @@ -102,6 +117,7 @@ public class SelectionService implements ISelectionChangedListener, ISelectionSe } notifyListeners(activePart.getSite().getId(), activePart, selection); + notifyPostSelectionListeners(activePart.getSite().getId(), activePart, selection); } } } @@ -122,10 +138,12 @@ public class SelectionService implements ISelectionChangedListener, ISelectionSe void setSelectionService(@Optional ESelectionService selectionService) { if (this.selectionService != null) { this.selectionService.removeSelectionListener(listener); + this.selectionService.removePostSelectionListener(postListener); } if (selectionService != null) { selectionService.addSelectionListener(listener); + selectionService.addPostSelectionListener(postListener); this.selectionService = selectionService; } } @@ -149,6 +167,25 @@ public class SelectionService implements ISelectionChangedListener, ISelectionSe } } + private void notifyPostSelectionListeners(String id, IWorkbenchPart workbenchPart, ISelection selection) { + for (Object listener : postSelectionListeners.getListeners()) { + if (selection != null || listener instanceof INullSelectionListener) { + ((ISelectionListener) listener).selectionChanged(workbenchPart, selection); + } + } + + if (id != null) { + Set<ISelectionListener> listeners = targetedPostSelectionListeners.get(id); + if (listeners != null) { + for (ISelectionListener listener : listeners) { + if (selection != null || listener instanceof INullSelectionListener) { + listener.selectionChanged(workbenchPart, selection); + } + } + } + } + } + /* * (non-Javadoc) * @@ -184,8 +221,7 @@ public class SelectionService implements ISelectionChangedListener, ISelectionSe * .ui.ISelectionListener) */ public void addPostSelectionListener(ISelectionListener listener) { - // TODO compat addPostSelectionListener - addSelectionListener(listener); + postSelectionListeners.add(listener); } /* @@ -196,8 +232,12 @@ public class SelectionService implements ISelectionChangedListener, ISelectionSe * , org.eclipse.ui.ISelectionListener) */ public void addPostSelectionListener(String partId, ISelectionListener listener) { - // TODO compat addPostSelectionListener - addSelectionListener(partId, listener); + Set<ISelectionListener> listeners = targetedPostSelectionListeners.get(partId); + if (listeners == null) { + listeners = new HashSet<ISelectionListener>(); + targetedPostSelectionListeners.put(partId, listeners); + } + listeners.add(listener); } /* @@ -265,8 +305,7 @@ public class SelectionService implements ISelectionChangedListener, ISelectionSe * .ui.ISelectionListener) */ public void removePostSelectionListener(ISelectionListener listener) { - // TODO compat removePostSelectionListener - removeSelectionListener(listener); + postSelectionListeners.remove(listener); } /* @@ -277,8 +316,10 @@ public class SelectionService implements ISelectionChangedListener, ISelectionSe * .String, org.eclipse.ui.ISelectionListener) */ public void removePostSelectionListener(String partId, ISelectionListener listener) { - // TODO compat removePostSelectionListener - removeSelectionListener(partId, listener); + Set<ISelectionListener> listeners = targetedPostSelectionListeners.get(partId); + if (listeners != null) { + listeners.remove(listener); + } } /* |