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=1666413e9c56d45ee16e8afeda3baf3e07e17446;hp=e196e673267ddaf8d7a17ad6fc78b10c7eda78c2;hb=b7250834202635a09dd18e25370ed9b4c32b1380;hpb=dfd710b04c7d7cdfab7747ba9a650b2cdc650092 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 e196e6732..1666413e9 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,8 +10,11 @@ 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; @@ -42,19 +45,9 @@ 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) { @@ -77,30 +70,80 @@ public class SWTExplorer extends SingleSWTViewNode { if (uiContext != null) { control.setUiContexts(Collections.singleton(uiContext)); } - + control.setStatePersistor(persistor); - + control.finish(); setProperties(); - + control.setInputSource(PassThruInputSource.INSTANCE); - 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; + 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; + + } + + }); + } public void synchronizeColumnsVisible(Boolean columnsVisible) { @@ -148,16 +191,5 @@ 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(); - } - + }