X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.platform%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fplatform%2FPropertyPageView.java;h=05109c8132bef66da570f2448270949503be2f10;hp=4376ae370b50a3d2fb4a97c205a81d1d6c00c62d;hb=ad19e1843992541da78dc19f5da2eaf1aebd000a;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 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 4376ae370..05109c813 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, 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 @@ -11,17 +11,10 @@ *******************************************************************************/ 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,19 +31,16 @@ 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; import org.eclipse.ui.part.IPageBookViewPage; import org.eclipse.ui.part.PageBook; +import org.simantics.Simantics; import org.simantics.db.management.ISessionContextProvider; import org.simantics.selectionview.PropertyPage; -import org.simantics.ui.SimanticsUI; 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 lastSelections = new WeakHashMap(); + private final Map 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 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 = SimanticsUI.getSessionContextProvider(); + 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 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) { - 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 * false 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); } }); };