private void transferListeners(IModel source, IModel target) { if (source instanceof IModelChangeProviderExtension && target instanceof IModelChangeProviderExtension) { IModelChangeProviderExtension smodel = (IModelChangeProviderExtension) source; IModelChangeProviderExtension tmodel = (IModelChangeProviderExtension) target; // first fire one last event to all the listeners to // refresh smodel.fireModelChanged( new ModelChangedEvent(smodel, IModelChangedEvent.WORLD_CHANGED, null, null)); // now pass the listener to the target model smodel.transferListenersTo( tmodel, new IModelChangedListenerFilter() { @Override public boolean accept(IModelChangedListener listener) { if (listener instanceof IFormPart || listener instanceof FormOutlinePage) return true; return false; } }); } }
@Override public void transferListenersTo( IModelChangeProviderExtension target, IModelChangedListenerFilter filter) { ArrayList<IModelChangedListener> removed = new ArrayList<>(); for (int i = 0; i < fListeners.size(); i++) { IModelChangedListener listener = fListeners.get(i); if (filter == null || filter.accept(listener)) { target.addModelChangedListener(listener); removed.add(listener); } } fListeners.removeAll(removed); }