]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.views.swt.client/src/org/simantics/views/swt/client/impl/SWTExplorer.java
Revert "Usability fixes for GraphExplorerImpl -related WB selection propagation"
[simantics/platform.git] / bundles / org.simantics.views.swt.client / src / org / simantics / views / swt / client / impl / SWTExplorer.java
index e196e673267ddaf8d7a17ad6fc78b10c7eda78c2..1666413e9c56d45ee16e8afeda3baf3e07e17446 100644 (file)
@@ -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.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.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;
 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<ModelBrowser> {
        public Boolean useNodeBrowseContexts;
        public Boolean useNodeActionContexts;
        public StatePersistor persistor;
        public Boolean useNodeBrowseContexts;
        public Boolean useNodeActionContexts;
        public StatePersistor persistor;
-
+       
        public ISelection lastSelection;
        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) {
 
        @Override
        public void createControls(Composite parent) {
 
@@ -77,30 +70,80 @@ public class SWTExplorer extends SingleSWTViewNode<ModelBrowser> {
                if (uiContext != null) {
                        control.setUiContexts(Collections.singleton(uiContext));
                }
                if (uiContext != null) {
                        control.setUiContexts(Collections.singleton(uiContext));
                }
-
+               
                control.setStatePersistor(persistor);
                control.setStatePersistor(persistor);
-
+               
                control.finish();
 
                setProperties();
                control.finish();
 
                setProperties();
-
+               
                control.setInputSource(PassThruInputSource.INSTANCE);
 
                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) {
        }
 
        public void synchronizeColumnsVisible(Boolean columnsVisible) {
@@ -148,16 +191,5 @@ public class SWTExplorer extends SingleSWTViewNode<ModelBrowser> {
 
        final public void synchronizeLayout(LayoutBean layout) {
        }
 
        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();
-       }
-
+       
 }
 }