]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultSelectionDataResolver.java
Use RuntimeEnvironmentRequest2 where applicable
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / DefaultSelectionDataResolver.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
13
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;
20
21 /**
22  * @author Tuukka Lehtonen
23  */
24 public class DefaultSelectionDataResolver implements SelectionDataResolver {
25
26     @Override
27     public Object resolve(Object o) {
28                 
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)
35                 return nodeContext;
36             WorkbenchSelectionElement wse = (WorkbenchSelectionElement)adaptable.getAdapter(WorkbenchSelectionElement.class);
37             if(wse != null)
38                 return wse.getContent(ExplorerInputContentType.INSTANCE);
39         }
40         if(o instanceof WorkbenchSelectionElement) {
41                 WorkbenchSelectionElement wse = (WorkbenchSelectionElement)o;
42                 if(wse != null) return wse.getContent(ExplorerInputContentType.INSTANCE);
43         }
44         return ResourceAdaptionUtils.adaptToResource(o);
45         
46         }
47
48 }