]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.platform/src/org/simantics/browsing/ui/platform/PropertyPageView.java
Revert "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 05109c8132bef66da570f2448270949503be2f10..0d4fc055b6ed2e7a8846052faba1e55ff3d3c310 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2018 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2010 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;
@@ -31,6 +38,7 @@ 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;
@@ -41,6 +49,8 @@ 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;
 
@@ -81,12 +91,19 @@ import org.simantics.utils.ui.SWTUtils;
  * @see IPropertyPage
  * @see PropertyPage
  */
-public class PropertyPageView extends PageBookView implements IContributedContentsView {
+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$
 
     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;
 
     /**
@@ -107,7 +124,7 @@ public class PropertyPageView extends PageBookView implements IContributedConten
 
     private IWorkbenchPart                        lastPart;
     private ISelection                            lastSelection;
-    private final Map<IWorkbenchPart, ISelection> lastSelections             = new WeakHashMap<>();
+    private final Map<IWorkbenchPart, ISelection> lastSelections             = new WeakHashMap<IWorkbenchPart, ISelection>();
 
     private ResourceManager                       resourceManager;
 
@@ -115,10 +132,9 @@ public class PropertyPageView extends PageBookView implements IContributedConten
     private ImageDescriptor                       pinned;
 
     /**
-     * The workbench post-selection listener for this view that changes the
-     * input of the pagebook page for the part which changed its selection. 
+     * Set of workbench parts, which should not be used as a source for PropertySheet
      */
-    private ISelectionListener                    selectionListener = this::doSelectionChanged;
+    private Set<String>                           ignoredViews;
 
     @Override
     public void createPartControl(Composite parent) {
@@ -195,12 +211,13 @@ public class PropertyPageView extends PageBookView implements IContributedConten
         // 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().addPostSelectionListener(selectionListener);
+            site.getPage().addSelectionListener(immediateSelectionListener);
+            site.getPage().addPostSelectionListener(this);
         }
     }
 
@@ -229,7 +246,8 @@ public class PropertyPageView extends PageBookView implements IContributedConten
 
         // Remove ourselves as a workbench selection listener.
         if (!bootstrapOnly) {
-            getSite().getPage().removePostSelectionListener(selectionListener);
+            getSite().getPage().removePostSelectionListener(this);
+            getSite().getPage().removeSelectionListener(immediateSelectionListener);
         }
 
         if (resourceManager != null) {
@@ -246,7 +264,7 @@ public class PropertyPageView extends PageBookView implements IContributedConten
         page.createControl(book);
         page.setMessage(Messages.PropertyPageView_noPropertiesAvailable);
         return page;
-        */
+         */
 
         PropertyPage page = new PropertyPage(getSite());
         initPage(page);
@@ -258,6 +276,7 @@ public class PropertyPageView extends PageBookView implements IContributedConten
 
     @Override
     protected PageRec doCreatePage(IWorkbenchPart part) {
+
         // NOTE: If the default page should be shown, this method must return null.
         if (part == null)
             return null;
@@ -315,10 +334,37 @@ public class PropertyPageView extends PageBookView implements IContributedConten
         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) {
-        //System.out.println("isImportant(" + part.getSite().getId() + ")");
-        return !isWorkbenchSelectionPinned() && !isPropertyView(part);
+        String partID = part.getSite().getId();
+        //System.out.println("isImportant(" + partID + ")");
+        return !isWorkbenchSelectionPinned() && !isPropertyView(part) && !isViewIgnored(partID);
     }
 
     /**
@@ -371,10 +417,39 @@ public class PropertyPageView extends PageBookView implements IContributedConten
 //            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);
     }
@@ -386,6 +461,7 @@ public class PropertyPageView extends PageBookView implements IContributedConten
      *         <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;
@@ -423,8 +499,8 @@ public class PropertyPageView extends PageBookView implements IContributedConten
                 lastPart.addPropertyListener(partPropertyListener);
             }
 
+            updatePartName(ppage, sel);
             if (!sameSelection) {
-                updatePartName(ppage, sel);
                 ppage.selectionChanged(part, sel);
                 return true;
             }
@@ -440,11 +516,14 @@ public class PropertyPageView extends PageBookView implements IContributedConten
         // 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(), () -> {
-            if (!getPageBook().isDisposed()) {
-                if (getPartName().equals(parameter)) return;
-                //System.out.println("doSetParameterName : " + parameter);
-                doSetPartName(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);
+                }
             }
         });
     };