X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FdiagramEditor%2Fhandlers%2FWorkbenchStructuralSelectionProvider.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2FdiagramEditor%2Fhandlers%2FWorkbenchStructuralSelectionProvider.java;h=4b46b9b2ac8fa9aa11cadc9978a50526039a8d37;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/WorkbenchStructuralSelectionProvider.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/WorkbenchStructuralSelectionProvider.java new file mode 100644 index 000000000..4b46b9b2a --- /dev/null +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagramEditor/handlers/WorkbenchStructuralSelectionProvider.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * 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.modeling.ui.diagramEditor.handlers; + +import java.util.ArrayList; + +import org.eclipse.jface.viewers.IPostSelectionProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.IWorkbenchPartSite; +import org.simantics.db.Resource; +import org.simantics.db.common.ResourceArray; +import org.simantics.diagram.ui.WorkbenchSelectionProvider; +import org.simantics.g2d.element.ElementHints; +import org.simantics.g2d.element.IElement; +import org.simantics.utils.threads.IThreadWorkQueue; + +/** + * A canvas participant that listens to the #0 mouse selection and provides it + * forward through the {@link IPostSelectionProvider} interface. + * + * @author Tuukka Lehtonen + */ +public class WorkbenchStructuralSelectionProvider extends WorkbenchSelectionProvider { + + ResourceArray suffix; + + public WorkbenchStructuralSelectionProvider(IThreadWorkQueue swt, ResourceArray appendToSelections) { + this(swt, null, appendToSelections); + } + + public WorkbenchStructuralSelectionProvider(IThreadWorkQueue swt, IWorkbenchPartSite site, ResourceArray appendToSelections) { + super(swt, site); + this.suffix = appendToSelections; + } + + protected ISelection constructAdaptableSelection(Iterable selection) { + ArrayList objects = new ArrayList(); + for (Object o : selection) { + if (o instanceof IElement) { + IElement e = (IElement) o; + Object object = e.getHint(ElementHints.KEY_OBJECT); + if (object instanceof Resource) { + objects.add(suffix.prepended((Resource) object)); + } else { + objects.add(object); + objects.add(suffix); + } + } else { + System.out.println(" unrecognized selection: " + o.getClass() + ": " + o); + } + } + return new StructuredSelection(objects); + } + +}