]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.platform/src/org/simantics/browsing/ui/platform/PropertyPageView.java
Usability fixes for GraphExplorerImpl -related WB selection propagation
[simantics/platform.git] / bundles / org.simantics.browsing.ui.platform / src / org / simantics / browsing / ui / platform / PropertyPageView.java
index 0d4fc055b6ed2e7a8846052faba1e55ff3d3c310..05109c8132bef66da570f2448270949503be2f10 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2018 Association for Decentralized Information Management
  * in Industry THTH ry.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  *******************************************************************************/
 package org.simantics.browsing.ui.platform;
 
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
 import java.util.WeakHashMap;
 import java.util.function.Consumer;
 
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.RegistryFactory;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.resource.LocalResourceManager;
@@ -38,7 +31,6 @@ import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.IWorkbenchPart3;
 import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.contexts.IContextService;
 import org.eclipse.ui.part.IContributedContentsView;
 import org.eclipse.ui.part.IPage;
@@ -49,8 +41,6 @@ import org.simantics.db.management.ISessionContextProvider;
 import org.simantics.selectionview.PropertyPage;
 import org.simantics.ui.workbench.IPropertyPage;
 import org.simantics.ui.workbench.ResourceInput;
-import org.simantics.utils.threads.SWTThread;
-import org.simantics.utils.threads.Throttler;
 import org.simantics.utils.ui.BundleUtils;
 import org.simantics.utils.ui.SWTUtils;
 
@@ -91,19 +81,12 @@ import org.simantics.utils.ui.SWTUtils;
  * @see IPropertyPage
  * @see PropertyPage
  */
-public class PropertyPageView extends PageBookView implements ISelectionListener, IContributedContentsView {
-
-    /**
-     * Extension point used to modify behavior of the view
-     */
-    private static final String                   EXT_POINT                  = "org.eclipse.ui.propertiesView";              //$NON-NLS-1$
+public class PropertyPageView extends PageBookView implements IContributedContentsView {
 
     private static final String                   PROPERTY_VIEW_CONTEXT      = "org.simantics.modeling.ui.properties";
 
     private static final String                   PROP_PINNED                = "pinned";
 
-    protected static final long                   SELECTION_CHANGE_THRESHOLD = 500;
-
     private ISessionContextProvider               contextProvider;
 
     /**
@@ -124,7 +107,7 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
 
     private IWorkbenchPart                        lastPart;
     private ISelection                            lastSelection;
-    private final Map<IWorkbenchPart, ISelection> lastSelections             = new WeakHashMap<IWorkbenchPart, ISelection>();
+    private final Map<IWorkbenchPart, ISelection> lastSelections             = new WeakHashMap<>();
 
     private ResourceManager                       resourceManager;
 
@@ -132,9 +115,10 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
     private ImageDescriptor                       pinned;
 
     /**
-     * Set of workbench parts, which should not be used as a source for PropertySheet
+     * The workbench post-selection listener for this view that changes the
+     * input of the pagebook page for the part which changed its selection. 
      */
-    private Set<String>                           ignoredViews;
+    private ISelectionListener                    selectionListener = this::doSelectionChanged;
 
     @Override
     public void createPartControl(Composite parent) {
@@ -211,13 +195,12 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
         // This prevents the Properties view from providing a selection to other
         // workbench parts, thus making them lose their selections which is not
         // desirable.
-//        site.setSelectionProvider(null);
+        site.setSelectionProvider(null);
 
         contextProvider = Simantics.getSessionContextProvider();
 
         if (!bootstrapOnly) {
-            site.getPage().addSelectionListener(immediateSelectionListener);
-            site.getPage().addPostSelectionListener(this);
+            site.getPage().addPostSelectionListener(selectionListener);
         }
     }
 
@@ -246,8 +229,7 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
 
         // Remove ourselves as a workbench selection listener.
         if (!bootstrapOnly) {
-            getSite().getPage().removePostSelectionListener(this);
-            getSite().getPage().removeSelectionListener(immediateSelectionListener);
+            getSite().getPage().removePostSelectionListener(selectionListener);
         }
 
         if (resourceManager != null) {
@@ -264,7 +246,7 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
         page.createControl(book);
         page.setMessage(Messages.PropertyPageView_noPropertiesAvailable);
         return page;
-         */
+        */
 
         PropertyPage page = new PropertyPage(getSite());
         initPage(page);
@@ -276,7 +258,6 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
 
     @Override
     protected PageRec doCreatePage(IWorkbenchPart part) {
-
         // NOTE: If the default page should be shown, this method must return null.
         if (part == null)
             return null;
@@ -334,37 +315,10 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
         return this == part || ignore;
     }
 
-    private Set<String> getIgnoredViews() {
-        if (ignoredViews == null) {
-            ignoredViews = new HashSet<String>();
-            IExtensionRegistry registry = RegistryFactory.getRegistry();
-            IExtensionPoint ep = registry.getExtensionPoint(EXT_POINT);
-            if (ep != null) {
-                IExtension[] extensions = ep.getExtensions();
-                for (int i = 0; i < extensions.length; i++) {
-                    IConfigurationElement[] elements = extensions[i].getConfigurationElements();
-                    for (int j = 0; j < elements.length; j++) {
-                        if ("excludeSources".equalsIgnoreCase(elements[j].getName())) { //$NON-NLS-1$
-                            String id = elements[j].getAttribute("id"); //$NON-NLS-1$
-                            if (id != null)
-                                ignoredViews.add(id);
-                        }
-                    }
-                }
-            }
-        }
-        return ignoredViews;
-    }
-
-    private boolean isViewIgnored(String partID) {
-        return getIgnoredViews().contains(partID);
-    }
-
     @Override
     protected boolean isImportant(IWorkbenchPart part) {
-        String partID = part.getSite().getId();
-        //System.out.println("isImportant(" + partID + ")");
-        return !isWorkbenchSelectionPinned() && !isPropertyView(part) && !isViewIgnored(partID);
+        //System.out.println("isImportant(" + part.getSite().getId() + ")");
+        return !isWorkbenchSelectionPinned() && !isPropertyView(part);
     }
 
     /**
@@ -417,39 +371,10 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
 //            super.partHidden(part);
     }
 
-    ISelectionListener immediateSelectionListener = new ISelectionListener() {
-       
-       private Throttler throttler = new Throttler(SWTThread.getThreadAccess(PlatformUI.getWorkbench().getDisplay()), 500, 3);
-       
-        @Override
-        public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
-               
-               // Do not process selections from self
-               if(PropertyPageView.this == part) return;
-               
-            throttler.schedule(new Runnable() {
-
-                               @Override
-                               public void run() {
-                                       PropertyPageView.this.doSelectionChanged(part, selection);                              
-                               }
-               
-            });
-            
-        }
-    };
-
     public ISelection getLastSelection() {
         return lastSelection;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart,
-     *      org.eclipse.jface.viewers.ISelection)
-     */
-    @Override
     public void selectionChanged(IWorkbenchPart part, ISelection sel) {
         doSelectionChanged(part, sel);
     }
@@ -461,7 +386,6 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
      *         <code>false</code> otherwise
      */
     boolean doSelectionChanged(IWorkbenchPart part, ISelection sel) {
-       
         // we ignore our own selection or null selection
         if (isPropertyView(part) || sel == null) {
             return false;
@@ -499,8 +423,8 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
                 lastPart.addPropertyListener(partPropertyListener);
             }
 
-            updatePartName(ppage, sel);
             if (!sameSelection) {
+                updatePartName(ppage, sel);
                 ppage.selectionChanged(part, sel);
                 return true;
             }
@@ -516,14 +440,11 @@ public class PropertyPageView extends PageBookView implements ISelectionListener
         // This check is not safe - there might be a burst of changes incoming
         //if (getPartName().equals(parameter)) return;
         //System.out.println("partNameUpdateCallback : " + parameter);
-        SWTUtils.asyncExec(getPageBook(), new Runnable() {
-            @Override
-            public void run() {
-                if (!getPageBook().isDisposed()) {
-                    if (getPartName().equals(parameter)) return;
-                    //System.out.println("doSetParameterName : " + parameter);
-                    doSetPartName(parameter);
-                }
+        SWTUtils.asyncExec(getPageBook(), () -> {
+            if (!getPageBook().isDisposed()) {
+                if (getPartName().equals(parameter)) return;
+                //System.out.println("doSetParameterName : " + parameter);
+                doSetPartName(parameter);
             }
         });
     };