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.core.runtime.IAdaptable;
15 import org.simantics.browsing.ui.NodeContext;
16 import org.simantics.browsing.ui.SelectionDataResolver;
17 import org.simantics.ui.selection.ExplorerInputContentType;
18 import org.simantics.ui.selection.WorkbenchSelectionElement;
19 import org.simantics.ui.utils.ResourceAdaptionUtils;
22 * @author Tuukka Lehtonen
24 public class DefaultSelectionDataResolver implements SelectionDataResolver {
27 public Object resolve(Object o) {
29 if(o instanceof NodeContext)
30 return (NodeContext)o;
31 if(o instanceof IAdaptable) {
32 IAdaptable adaptable = (IAdaptable)o;
33 NodeContext nodeContext = (NodeContext)adaptable.getAdapter(NodeContext.class);
34 if(nodeContext != null)
36 WorkbenchSelectionElement wse = (WorkbenchSelectionElement)adaptable.getAdapter(WorkbenchSelectionElement.class);
38 return wse.getContent(ExplorerInputContentType.INSTANCE);
40 if(o instanceof WorkbenchSelectionElement) {
41 WorkbenchSelectionElement wse = (WorkbenchSelectionElement)o;
42 if(wse != null) return wse.getContent(ExplorerInputContentType.INSTANCE);
44 return ResourceAdaptionUtils.adaptToResource(o);