Java Code Examples for org.eclipse.emf.ecore.EObject#eAdapters()

The following examples show how to use org.eclipse.emf.ecore.EObject#eAdapters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadAndWriteTracking.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected InitializedMarker getInitializedMarker(EObject object) {
	for (Adapter a : object.eAdapters()) {
		if (a instanceof InitializedMarker) {
			return (InitializedMarker) a;
		}
	}
	return null;
}
 
Example 2
Source File: NodeModelUtils.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the node that is directly associated with the given object by means of an EMF-Adapter.
 * 
 * @param object the semantic object whose direct node should be provided.
 * @return the node that is directly associated with the given object.
 * @see NodeModelUtils#findActualNodeFor(EObject)
 */
/* @Nullable */
public static ICompositeNode getNode(/* @Nullable */ EObject object) {
	if (object == null)
		return null;
	List<Adapter> adapters = object.eAdapters();
	for (int i = 0; i < adapters.size(); i++) {
		Adapter adapter = adapters.get(i);
		if (adapter instanceof ICompositeNode)
			return (ICompositeNode) adapter;
	}
	return null;
}
 
Example 3
Source File: SourceAdapter.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public static SourceAdapter find(EObject object) {
	for(Adapter adapter: object.eAdapters()) {
		if (adapter instanceof SourceAdapter)
			return (SourceAdapter) adapter;
	}
	return null;
}
 
Example 4
Source File: NodeModelTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testNavigabilityNode2Ast() throws Exception {
	EObject object = getModel(MODEL);
	EList<Adapter> adapters = object.eAdapters();
	assertEquals(1 /* compositeNode */ + 1 /* cache */, adapters.size());
	ICompositeNode rootNode = (ICompositeNode) adapters.get(0);
	assertTrue(rootNode.getParent() == null);
	checkNavigabilityNode2Ast(rootNode);
	for (Iterator<INode> i = rootNode.getAsTreeIterable().iterator(); i.hasNext();) {
		checkNavigabilityNode2Ast(i.next());
	}
}
 
Example 5
Source File: NodeModelTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void checkNavigabilityNode2Ast(INode node) {
	if (node.hasDirectSemanticElement()) {
		EObject astElement = node.getSemanticElement();
		EList<Adapter> adapters = astElement.eAdapters();
		assertEquals(1 /* compositeNode */ + 1 /* cache */, adapters.size());
		ICompositeNode adapter = (ICompositeNode) adapters.get(0);
		assertEquals(node, adapter);
	} 
}
 
Example 6
Source File: ProxyCompositeNode.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
private static ProxyCompositeNode uninstallProxyNode(final EObject eObject) {
  EList<Adapter> adapters = eObject.eAdapters();
  int size = adapters.size();
  for (int i = 0; i < size; ++i) {
    Adapter adapter = adapters.get(i);
    if (adapter.isAdapterForType(ProxyCompositeNode.class)) {
      if (adapter instanceof ProxyCompositeNode) {
        return (ProxyCompositeNode) adapters.remove(i);
      }
      break;
    }
  }
  return null;
}
 
Example 7
Source File: NodeModelTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
private void checkNavigabilityAst2Node(EObject object) {
	EList<Adapter> adapters = object.eAdapters();
	assertEquals(1 /* compositeNode */ + 1 /* cache */, adapters.size());
	ICompositeNode adapter = (ICompositeNode) adapters.get(0);
	assertEquals(object, adapter.getSemanticElement());
}
 
Example 8
Source File: TaskSelectType.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected void updateAdapters( )
{
	EObject model = getChartModelObject( );
	
	if ( container instanceof ChartWizard )
	{
		// Refresh all adapters
		EContentAdapter adapter = ( (ChartWizard) container ).getAdapter( );

		model.eAdapters( ).remove( adapter );
		TreeIterator<EObject> iterator = model.eAllContents( );
		while ( iterator.hasNext( ) )
		{
			EObject oModel = iterator.next( );
			oModel.eAdapters( ).remove( adapter );
		}
		model.eAdapters( ).add( adapter );
	}
	else
	{
		// For extension case, create an adapter and add change listener
		EList<Adapter> adapters = model.eAdapters( );
		if ( adapters.isEmpty( ) )
		{
			// Get the previous adapter if existent
			if ( adapter == null )
			{
				adapter = new ChartAdapter( container );
				adapter.addListener( this );
			}
			adapters.add( adapter );
		}
		else
		{
			if ( adapters.get( 0 ) instanceof ChartAdapter )
			{
				( (ChartAdapter) adapters.get( 0 ) ).addListener( this );
			}
		}
	}
}