/*******************************************************************************
- * 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;
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;
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;
* @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;
/**
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;
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) {
// 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);
}
}
// Remove ourselves as a workbench selection listener.
if (!bootstrapOnly) {
- getSite().getPage().removePostSelectionListener(selectionListener);
+ getSite().getPage().removePostSelectionListener(this);
+ getSite().getPage().removeSelectionListener(immediateSelectionListener);
}
if (resourceManager != null) {
page.createControl(book);
page.setMessage(Messages.PropertyPageView_noPropertiesAvailable);
return page;
- */
+ */
PropertyPage page = new PropertyPage(getSite());
initPage(page);
@Override
protected PageRec doCreatePage(IWorkbenchPart part) {
+
// NOTE: If the default page should be shown, this method must return null.
if (part == null)
return null;
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);
}
/**
// 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);
}
* <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;
lastPart.addPropertyListener(partPropertyListener);
}
+ updatePartName(ppage, sel);
if (!sameSelection) {
- updatePartName(ppage, sel);
ppage.selectionChanged(part, sel);
return true;
}
// 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);
+ }
}
});
};