package com.wireframesketcher.model.xtext;

import org.eclipse.emf.ecore.EObject;

import com.wireframesketcher.model.NameSupport;
import com.wireframesketcher.model.impl.ModelXMLResourceImpl;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;

public class BoomslangWFSModelXMLResourceImpl extends ModelXMLResourceImpl {

	@Override
	public EObject getEObject(String uriFragment) {
		EList<EObject> contents = getContents();
		String name = URI.decode(uriFragment);
		for (int i = 0; i < contents.size(); i++) {
			EObject root = contents.get(i);
			if (root instanceof NameSupport
					&& name.equals(((NameSupport) root).getName()))
				return root;
		}

		return super.getEObject(uriFragment);
	}

	public BoomslangWFSModelXMLResourceImpl(URI uri) {
		super(uri);
	}

	public BoomslangWFSModelXMLResourceImpl() {
	  super();
	}

}

@@ -124,16 +124,107 @@
 upport;%0A
+import com.wireframesketcher.model.Widget;%0Aimport com.wireframesketcher.model.WidgetGroup;%0A
 import c
@@ -277,16 +277,16 @@
 ceImpl;%0A
-
 %0Aimport 
@@ -499,16 +499,74 @@
 ment) %7B%0A
+%09%09//First enhancement to handle screens with name support%0A
 %09%09EList%3C
@@ -809,16 +809,17 @@
 Name()))
+%7B
 %0A%09%09%09%09ret
@@ -828,16 +828,484 @@
 n root;%0A
+%09%09%09%7D%0A%09%09%09//Second enhancement to handle Widgets in WidgetGroups%0A%09%09%09//TODO Consider WidgetGroups in WidgetGroups%0A%09%09%09EList%3CEObject%3E children = root.eContents();%0A%09%09%09for (int j = 0; j %3C children.size(); j++) %7B%0A%09%09%09%09EObject child = children.get(j);%0A%09%09%09%09if(child instanceof WidgetGroup)%7B%0A%09%09%09%09%09EList%3CWidget%3E widgets = ((WidgetGroup)child).getWidgets();%0A%09%09%09%09%09for(Widget widget : widgets)%7B%0A%09%09%09%09%09%09if(name.equals(widget.getName()))%7B%0A%09%09%09%09%09%09%09return widget;%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D%0A
 %09%09%7D%0A%0A%09%09r

Handle widgets in widgetgroups