blob: 7f7809fec3397210f4f72cda5f472d59e5ae52f2 [file] [log] [blame]
/**
* Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.ecview.dsl.scope;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.osbp.ecview.semantic.uimodel.UiBeanSlot;
import org.eclipse.osbp.ecview.semantic.uimodel.UiView;
import org.eclipse.xtext.resource.EObjectDescription;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.impl.AbstractScope;
public class TypedBindableScope extends AbstractScope {
private EObject context;
protected TypedBindableScope(EObject context) {
super(IScope.NULLSCOPE, true);
this.context = context;
}
@Override
protected Iterable<IEObjectDescription> getAllLocalElements() {
List<IEObjectDescription> result = new ArrayList<IEObjectDescription>();
UiView view = findView(context);
if (view != null) {
TreeIterator<EObject> iterator = EcoreUtil.getAllProperContents(
view, false);
while (iterator.hasNext()) {
EObject object = iterator.next();
if (object instanceof UiBeanSlot) {
UiBeanSlot bindable = (UiBeanSlot) object;
result.add(EObjectDescription.create(bindable.getName(),
bindable));
}
}
}
return result;
}
private UiView findView(EObject def) {
UiView result = null;
while (def.eContainer() != null) {
def = def.eContainer();
if (def instanceof UiView) {
result = (UiView) def;
break;
}
}
return result;
}
}