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.simantics.browsing.ui.GraphExplorer;
20 public class DefaultExplorerSelectionListener implements ISelectionListener {
22 private static final boolean DEBUG = false;
25 GraphExplorer explorer;
26 WorkbenchSelectionFilter filter;
28 public DefaultExplorerSelectionListener(IWorkbenchPart owner, GraphExplorer explorer) {
29 this(owner, explorer, ResourceSelectionFilter.FILTER);
32 public DefaultExplorerSelectionListener(IWorkbenchPart owner, GraphExplorer explorer, WorkbenchSelectionFilter filter) {
34 this.explorer = explorer;
39 public void selectionChanged(IWorkbenchPart part, ISelection selection) {
40 // Always disregard own selections.
45 System.out.println("[" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection);
46 ISelection s = selection;
48 s = filter.filterSelection(part, selection);
52 System.out.println("** [" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection);
53 System.out.println(" SETTING NEW SELECTION");
55 if(!explorer.isDisposed()) {
56 IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);
57 selectionProvider.setSelection(selection);
61 System.out.println("[" + owner + "] discarding selection: part=" + part + ", selection=" + selection);