Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2007 Anyware Technologies 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 Contributors: Anyware Technologies - initial API and implementation $Id:,v 1.2 2008/04/28 08:41:33 jlescot Exp $ /
package org.eclipse.emf.ecoretools.diagram.sheet;
import  org.eclipse.core.runtime.IAdaptable;
Provides a single static method to adapt a given object into an EObject Creation 19 sept. 06

Alfredo Serrano
public final class ObjectAdapter {
	private ObjectAdapter() {
		// Instantiation forbidden

Returns the EObject associated with the given object. Returns null if no such object can be found.

object The object to look up its associated EObject
the EObject associated to the given object, or null if this object does not have any.
	public static EObject adaptObject(Object object) {
		if (object == null) {
			return null;
else if (object instanceof EObject) {
			return (EObjectobject;
else if (object instanceof IAdaptable) {
			// Try IAdaptable
			IAdaptable adapted = (IAdaptable) object;
			Object eObject = adapted.getAdapter(EObject.class);
			if (eObject != null) {
				return (EObjecteObject;
else {
			// Try registered adapter
			Object adapted = Platform.getAdapterManager().getAdapter(objectEObject.class);
			if (adapted != null) {
				return (EObjectadapted;
		return null;
New to GrepCode? Check out our FAQ X