X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.browsing.ui.platform%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fplatform%2FPropertyPageView.java;h=0d4fc055b6ed2e7a8846052faba1e55ff3d3c310;hb=d47f93197f84f8e5afd2bd9e1f12984be0e1ff8c;hp=ed78ebc339004e7743a533c748801ea86d2461ac;hpb=61f2633b2846d5250f7110676fe72af3880c0e19;p=simantics%2Fplatform.git
diff --git a/bundles/org.simantics.browsing.ui.platform/src/org/simantics/browsing/ui/platform/PropertyPageView.java b/bundles/org.simantics.browsing.ui.platform/src/org/simantics/browsing/ui/platform/PropertyPageView.java
index ed78ebc33..0d4fc055b 100644
--- a/bundles/org.simantics.browsing.ui.platform/src/org/simantics/browsing/ui/platform/PropertyPageView.java
+++ b/bundles/org.simantics.browsing.ui.platform/src/org/simantics/browsing/ui/platform/PropertyPageView.java
@@ -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
@@ -11,10 +11,17 @@
*******************************************************************************/
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,10 +49,10 @@ 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;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* This is a version of the standard eclipse PropertySheet
view a
@@ -83,14 +91,19 @@ import org.slf4j.LoggerFactory;
* @see IPropertyPage
* @see PropertyPage
*/
-public class PropertyPageView extends PageBookView implements IContributedContentsView {
+public class PropertyPageView extends PageBookView implements ISelectionListener, IContributedContentsView {
- private static final Logger LOGGER = LoggerFactory.getLogger(PropertyPageView.class);
+ /**
+ * 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;
/**
@@ -111,7 +124,7 @@ public class PropertyPageView extends PageBookView implements IContributedConten
private IWorkbenchPart lastPart;
private ISelection lastSelection;
- private final Map lastSelections = new WeakHashMap<>();
+ private final Map lastSelections = new WeakHashMap();
private ResourceManager resourceManager;
@@ -119,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 ignoredViews;
@Override
public void createPartControl(Composite parent) {
@@ -196,10 +208,16 @@ public class PropertyPageView extends PageBookView implements IContributedConten
//System.out.println("PPV init: " + this);
super.init(site);
+ // 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);
+
contextProvider = Simantics.getSessionContextProvider();
if (!bootstrapOnly) {
- site.getPage().addPostSelectionListener(selectionListener);
+ site.getPage().addSelectionListener(immediateSelectionListener);
+ site.getPage().addPostSelectionListener(this);
}
}
@@ -228,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) {
@@ -245,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);
@@ -257,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;
@@ -314,10 +334,37 @@ public class PropertyPageView extends PageBookView implements IContributedConten
return this == part || ignore;
}
+ private Set getIgnoredViews() {
+ if (ignoredViews == null) {
+ ignoredViews = new HashSet();
+ 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);
}
/**
@@ -370,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);
}
@@ -385,8 +461,7 @@ public class PropertyPageView extends PageBookView implements IContributedConten
* false
otherwise
*/
boolean doSelectionChanged(IWorkbenchPart part, ISelection sel) {
- LOGGER.trace("doSelectionChanged({}): incoming selection {}", part, sel);
-
+
// we ignore our own selection or null selection
if (isPropertyView(part) || sel == null) {
return false;
@@ -424,9 +499,8 @@ public class PropertyPageView extends PageBookView implements IContributedConten
lastPart.addPropertyListener(partPropertyListener);
}
+ updatePartName(ppage, sel);
if (!sameSelection) {
- LOGGER.trace("doSelectionChanged({}): updating page input selection to {}", part, sel);
- updatePartName(ppage, sel);
ppage.selectionChanged(part, sel);
return true;
}
@@ -442,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);
+ }
}
});
};