X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.views.swt.client%2Fsrc%2Forg%2Fsimantics%2Fviews%2Fswt%2Fclient%2Fimpl%2FSWTExplorer.java;h=e196e673267ddaf8d7a17ad6fc78b10c7eda78c2;hp=1666413e9c56d45ee16e8afeda3baf3e07e17446;hb=270834ce3962a4bca3945d06e642a99d21688c16;hpb=79b952a1ea3ae3f299c6d7aa612a98b7ae5db51a diff --git a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTExplorer.java b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTExplorer.java index 1666413e9..e196e6732 100644 --- a/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTExplorer.java +++ b/bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTExplorer.java @@ -10,11 +10,8 @@ import org.eclipse.jface.viewers.IPostSelectionProvider; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; import org.eclipse.ui.IWorkbenchSite; import org.simantics.browsing.ui.Column; import org.simantics.browsing.ui.StatePersistor; @@ -45,9 +42,19 @@ public class SWTExplorer extends SingleSWTViewNode { public Boolean useNodeBrowseContexts; public Boolean useNodeActionContexts; public StatePersistor persistor; - + public ISelection lastSelection; - + + private ISelectionChangedListener internalToExternalSelectionPropagator = event -> { + IWorkbenchSite site = getSite(); + if (site != null) { + ISelectionProvider sp = site.getSelectionProvider(); + if (sp != null) { + sp.setSelection(event.getSelection()); + } + } + }; + @Override public void createControls(Composite parent) { @@ -70,80 +77,30 @@ public class SWTExplorer extends SingleSWTViewNode { if (uiContext != null) { control.setUiContexts(Collections.singleton(uiContext)); } - + control.setStatePersistor(persistor); - + control.finish(); setProperties(); - + control.setInputSource(PassThruInputSource.INSTANCE); - ISelectionProvider sp = (ISelectionProvider)control.getExplorer().getAdapter(ISelectionProvider.class); - sp.addSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - if (site != null) { - ISelectionProvider sp = site.getSelectionProvider(); - if (sp != null) { - sp.setSelection(event.getSelection()); - } - } - } - - }); - - IPostSelectionProvider psp = (IPostSelectionProvider)control.getExplorer().getAdapter(IPostSelectionProvider.class); - psp.addPostSelectionChangedListener(new ISelectionChangedListener() { - - @Override - public void selectionChanged(SelectionChangedEvent event) { - -// ISelection selection = (ISelection)control.getExplorer().getWidgetSelection(); - if (site != null) { - ISelectionProvider sp = site.getSelectionProvider(); - if (sp != null) { - sp.setSelection(event.getSelection()); - } - } - - } - - }); - - control.addListenerToControl(SWT.Selection, new Listener() { - - @Override - public void handleEvent(Event event) { - - if(selectionListener != null) - selectionListener.apply(event); - - ISelection selection = (ISelection)control.getExplorer().getWidgetSelection(); - // [Tuukka@2012-04-08] Disabled this because it was causing - // horrible selection feedback effects in the Model Browser - // view that is using it. It causes the browser to react to - // external selections which were initially published as its own - // with a delay. - //System.out.println("selection: " + selection); -// if(publishSelection != null && publishSelection) { -// if (site != null) { -// ISelectionProvider sp = site.getSelectionProvider(); -// if (sp != null) { -// sp.setSelection(selection); -// } -// } -// } - - propertyCallback.apply("selection", selection); - - lastSelection = selection; - - } - + ISelectionProvider isp = (ISelectionProvider)control.getExplorer().getAdapter(ISelectionProvider.class); + if (isp instanceof IPostSelectionProvider) { + ((IPostSelectionProvider) isp).addPostSelectionChangedListener(internalToExternalSelectionPropagator); + } else { + isp.addSelectionChangedListener(internalToExternalSelectionPropagator); + } + + control.addListenerToControl(SWT.Selection, event -> { + if(selectionListener != null) + selectionListener.apply(event); + ISelection selection = (ISelection)control.getExplorer().getWidgetSelection(); + propertyCallback.apply("selection", selection); + lastSelection = selection; }); - + } public void synchronizeColumnsVisible(Boolean columnsVisible) { @@ -191,5 +148,16 @@ public class SWTExplorer extends SingleSWTViewNode { final public void synchronizeLayout(LayoutBean layout) { } - + + @Override + public void dispose() { + ISelectionProvider isp = (ISelectionProvider)control.getExplorer().getAdapter(ISelectionProvider.class); + if (isp instanceof IPostSelectionProvider) { + ((IPostSelectionProvider) isp).removePostSelectionChangedListener(internalToExternalSelectionPropagator); + } else { + isp.removeSelectionChangedListener(internalToExternalSelectionPropagator); + } + super.dispose(); + } + }