1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.ui.diagramEditor.handlers;
\r
14 import java.util.ArrayList;
\r
16 import org.eclipse.jface.viewers.IPostSelectionProvider;
\r
17 import org.eclipse.jface.viewers.ISelection;
\r
18 import org.eclipse.jface.viewers.StructuredSelection;
\r
19 import org.eclipse.ui.IWorkbenchPartSite;
\r
20 import org.simantics.db.Resource;
\r
21 import org.simantics.db.common.ResourceArray;
\r
22 import org.simantics.diagram.ui.WorkbenchSelectionProvider;
\r
23 import org.simantics.g2d.element.ElementHints;
\r
24 import org.simantics.g2d.element.IElement;
\r
25 import org.simantics.utils.threads.IThreadWorkQueue;
\r
28 * A canvas participant that listens to the #0 mouse selection and provides it
\r
29 * forward through the {@link IPostSelectionProvider} interface.
\r
31 * @author Tuukka Lehtonen
\r
33 public class WorkbenchStructuralSelectionProvider extends WorkbenchSelectionProvider {
\r
35 ResourceArray suffix;
\r
37 public WorkbenchStructuralSelectionProvider(IThreadWorkQueue swt, ResourceArray appendToSelections) {
\r
38 this(swt, null, appendToSelections);
\r
41 public WorkbenchStructuralSelectionProvider(IThreadWorkQueue swt, IWorkbenchPartSite site, ResourceArray appendToSelections) {
\r
43 this.suffix = appendToSelections;
\r
46 protected ISelection constructAdaptableSelection(Iterable<?> selection) {
\r
47 ArrayList<Object> objects = new ArrayList<Object>();
\r
48 for (Object o : selection) {
\r
49 if (o instanceof IElement) {
\r
50 IElement e = (IElement) o;
\r
51 Object object = e.getHint(ElementHints.KEY_OBJECT);
\r
52 if (object instanceof Resource) {
\r
53 objects.add(suffix.prepended((Resource) object));
\r
55 objects.add(object);
\r
56 objects.add(suffix);
\r
59 System.out.println(" unrecognized selection: " + o.getClass() + ": " + o);
\r
62 return new StructuredSelection(objects);
\r