Java Code Examples for org.eclipse.xtext.EcoreUtil2#eAllContentsAsList()

The following examples show how to use org.eclipse.xtext.EcoreUtil2#eAllContentsAsList() . 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: STextExtensions.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Searches for the given surrogate element coming from an embedded fake
 * resource in the given statechart.
 */
public EObject findElement(EObject surrogate, Statechart statechart) {
	boolean checkScope = surrogate.eContainer() instanceof StatechartScope;
	List<EObject> eAllContentsAsList = EcoreUtil2.eAllContentsAsList(statechart);
	for (EObject modelElement : eAllContentsAsList) {
		if (EcoreUtil2.equals(modelElement, surrogate)) {
			if (!checkScope || EcoreUtil2.equals(modelElement.eContainer(), surrogate.eContainer())) {
				return modelElement;
			}
		}
	}
	return null;
}
 
Example 2
Source File: CreationWizard.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected boolean openDiagram(Resource diagram) throws PartInitException {
	String path = diagram.getURI().toPlatformString(true);
	IResource workspaceResource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path));
	if (workspaceResource instanceof IFile) {
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		StatechartDiagramEditor editor = (StatechartDiagramEditor) page
				.openEditor(new FileEditorInput((IFile) workspaceResource), getEditorID());
		if (editor != null) {
			List<EObject> allNotationElements = EcoreUtil2.eAllContentsAsList(diagram);
			for (EObject eObject : allNotationElements) {
				if (eObject instanceof View && ((View) eObject).getType().equals(SemanticHints.STATE_NAME)) {
					IGraphicalEditPart editPart = EditPartUtils.findEditPartForSemanticElement(
							editor.getDiagramGraphicalViewer().getRootEditPart(), ((View) eObject).getElement());
					editPart = editPart.getChildBySemanticHint(SemanticHints.STATE_NAME);
					if (editPart != null) {
						final DirectEditRequest request = new DirectEditRequest();
						request.setDirectEditFeature(BasePackage.Literals.NAMED_ELEMENT__NAME);
						editPart.performRequest(request);
						break;
					}
				}
			}
			return false;
		}
	}
	return false;
}
 
Example 3
Source File: PackratParserGenUtil.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
private static String getElementIndex(AbstractElement element, EObject parent) {
	List<EObject> elements = EcoreUtil2.eAllContentsAsList(parent);
	return '$' + Integer.toString(elements.indexOf(element));
}