X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FDefaultExplorerSelectionListener.java;h=713b28297e67856ba0841f263aeb12a9f0028aa3;hb=HEAD;hp=d127e8d4455c0db4e80f0e776b16adfd21fb8c33;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultExplorerSelectionListener.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultExplorerSelectionListener.java index d127e8d44..713b28297 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultExplorerSelectionListener.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultExplorerSelectionListener.java @@ -1,64 +1,76 @@ -/******************************************************************************* - * 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.browsing.ui.swt; - -import org.eclipse.jface.viewers.IPostSelectionProvider; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.ISelectionListener; -import org.eclipse.ui.IWorkbenchPart; -import org.simantics.browsing.ui.GraphExplorer; - -public class DefaultExplorerSelectionListener implements ISelectionListener { - - private static final boolean DEBUG = false; - - IWorkbenchPart owner; - GraphExplorer explorer; - WorkbenchSelectionFilter filter; - - public DefaultExplorerSelectionListener(IWorkbenchPart owner, GraphExplorer explorer) { - this(owner, explorer, ResourceSelectionFilter.FILTER); - } - - public DefaultExplorerSelectionListener(IWorkbenchPart owner, GraphExplorer explorer, WorkbenchSelectionFilter filter) { - this.owner = owner; - this.explorer = explorer; - this.filter = filter; - } - - @Override - public void selectionChanged(IWorkbenchPart part, ISelection selection) { - // Always disregard own selections. - if (part == owner) - return; - - if (DEBUG) - System.out.println("[" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection); - ISelection s = selection; - if (filter != null) - s = filter.filterSelection(part, selection); - - if (s != null) { - if (DEBUG) { - System.out.println("** [" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection); - System.out.println(" SETTING NEW SELECTION"); - } - if(!explorer.isDisposed()) { - IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class); - selectionProvider.setSelection(selection); - } - } else { - if (DEBUG) - System.out.println("[" + owner + "] discarding selection: part=" + part + ", selection=" + selection); - } - } -} +/******************************************************************************* + * 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.swt; + +import org.eclipse.jface.viewers.IPostSelectionProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.services.IDisposable; +import org.simantics.browsing.ui.GraphExplorer; + +public class DefaultExplorerSelectionListener implements ISelectionListener, IDisposable { + + private static final boolean DEBUG = false; + + IWorkbenchPart owner; + GraphExplorer explorer; + WorkbenchSelectionFilter filter; + + public DefaultExplorerSelectionListener(IWorkbenchPart owner, GraphExplorer explorer) { + this(owner, explorer, ResourceSelectionFilter.FILTER); + } + + public DefaultExplorerSelectionListener(IWorkbenchPart owner, GraphExplorer explorer, WorkbenchSelectionFilter filter) { + this.owner = owner; + this.explorer = explorer; + this.filter = filter; + } + + @Override + public void dispose() { + owner = null; + explorer = null; + filter = null; + } + + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + // Always disregard own selections. + if (part == owner) + return; + + if (DEBUG) + System.out.println("[" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection); + ISelection s = selection; + WorkbenchSelectionFilter filter = this.filter; + if (filter != null) + s = filter.filterSelection(part, selection); + + if (s != null) { + if (DEBUG) { + System.out.println("** [" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection); + System.out.println(" SETTING NEW SELECTION"); + } + GraphExplorer explorer = this.explorer; + if(explorer != null && !explorer.isDisposed()) { + IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class); + if (selectionProvider != null) { + selectionProvider.setSelection(selection); + } + } + } else { + if (DEBUG) + System.out.println("[" + owner + "] discarding selection: part=" + part + ", selection=" + selection); + } + } +}