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.modeling.ui.diagramEditor.handlers;
14 import java.util.ArrayList;
16 import org.eclipse.jface.viewers.IPostSelectionProvider;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.jface.viewers.StructuredSelection;
19 import org.eclipse.ui.IWorkbenchPartSite;
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.ResourceArray;
22 import org.simantics.diagram.ui.WorkbenchSelectionProvider;
23 import org.simantics.g2d.element.ElementHints;
24 import org.simantics.g2d.element.IElement;
25 import org.simantics.utils.threads.IThreadWorkQueue;
28 * A canvas participant that listens to the #0 mouse selection and provides it
29 * forward through the {@link IPostSelectionProvider} interface.
31 * @author Tuukka Lehtonen
33 public class WorkbenchStructuralSelectionProvider extends WorkbenchSelectionProvider {
37 public WorkbenchStructuralSelectionProvider(IThreadWorkQueue swt, ResourceArray appendToSelections) {
38 this(swt, null, appendToSelections);
41 public WorkbenchStructuralSelectionProvider(IThreadWorkQueue swt, IWorkbenchPartSite site, ResourceArray appendToSelections) {
43 this.suffix = appendToSelections;
46 protected ISelection constructAdaptableSelection(Iterable<?> selection) {
47 ArrayList<Object> objects = new ArrayList<Object>();
48 for (Object o : selection) {
49 if (o instanceof IElement) {
50 IElement e = (IElement) o;
51 Object object = e.getHint(ElementHints.KEY_OBJECT);
52 if (object instanceof Resource) {
53 objects.add(suffix.prepended((Resource) object));
59 System.out.println(" unrecognized selection: " + o.getClass() + ": " + o);
62 return new StructuredSelection(objects);