1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
14 import org.eclipse.jface.viewers.IPostSelectionProvider;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.ui.ISelectionListener;
17 import org.eclipse.ui.IWorkbenchPart;
18 import org.eclipse.ui.services.IDisposable;
19 import org.simantics.browsing.ui.GraphExplorer;
21 public class DefaultExplorerSelectionListener implements ISelectionListener, IDisposable {
23 private static final boolean DEBUG = false;
26 GraphExplorer explorer;
27 WorkbenchSelectionFilter filter;
29 public DefaultExplorerSelectionListener(IWorkbenchPart owner, GraphExplorer explorer) {
30 this(owner, explorer, ResourceSelectionFilter.FILTER);
33 public DefaultExplorerSelectionListener(IWorkbenchPart owner, GraphExplorer explorer, WorkbenchSelectionFilter filter) {
35 this.explorer = explorer;
40 public void dispose() {
47 public void selectionChanged(IWorkbenchPart part, ISelection selection) {
48 // Always disregard own selections.
53 System.out.println("[" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection);
54 ISelection s = selection;
55 WorkbenchSelectionFilter filter = this.filter;
57 s = filter.filterSelection(part, selection);
61 System.out.println("** [" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection);
62 System.out.println(" SETTING NEW SELECTION");
64 GraphExplorer explorer = this.explorer;
65 if(explorer != null && !explorer.isDisposed()) {
66 IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);
67 if (selectionProvider != null) {
68 selectionProvider.setSelection(selection);
73 System.out.println("[" + owner + "] discarding selection: part=" + part + ", selection=" + selection);