org.eclipse.xtext.ui.editor.outline.impl.DocumentRootNode Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.outline.impl.DocumentRootNode. 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: CheckOutlineTreeProvider.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void internalCreateChildren(final DocumentRootNode parentNode, final EObject modelElement) {
  CheckCatalog catalog = (CheckCatalog) modelElement;
  if (catalog.getPackageName() != null) {
    getOutlineNodeFactory().createEStructuralFeatureNode(parentNode, catalog, CheckPackage.Literals.CHECK_CATALOG__PACKAGE_NAME, ImageDescriptor.createFromImage(checkImages.forPackage()), catalog.getPackageName(), true);
  }

  if (catalog.getImports() != null && !catalog.getImports().getImportDeclarations().isEmpty()) {
    EStructuralFeatureNode importNode = getOutlineNodeFactory().createEStructuralFeatureNode(parentNode, catalog, CheckPackage.Literals.CHECK_CATALOG__IMPORTS, ImageDescriptor.createFromImage(checkImages.forImportContainer()), "Import declarations", false);
    for (final org.eclipse.xtext.xtype.XImportDeclaration imported : catalog.getImports().getImportDeclarations()) {
      createNode(importNode, imported);
    }
  }

  EObjectNode catalogNode = createNode(parentNode, catalog);

  for (final Category category : catalog.getCategories()) {
    createNode(catalogNode, category);
  }
  for (final Check check : catalog.getChecks()) {
    createNode(catalogNode, check);
  }

}
 
Example #2
Source File: OutlineNodeComparerTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
@Test public void testEquivalentIndex() throws Exception {
	DocumentRootNode rootNode = new DocumentRootNode(image, "Root", null, null);
	EObjectNode node = new EObjectNode(eObject, rootNode, image, "Node", false);

	DocumentRootNode rootNode2 = new DocumentRootNode(image, "Root", null, null);
	EObjectNode node2 = new EObjectNode(eObject, rootNode2, image, "Node", false);
	assertTrue(comparer.equals(node, node2));
	EObjectNode node3 = new EObjectNode(eObject, rootNode2, image, "OtherNode", false);
	assertTrue(comparer.equals(node, node2));
	
	DocumentRootNode rootNode3 = new DocumentRootNode(image, "Root", null, null);
	EObjectNode node4 = new EObjectNode(eObject, rootNode3, image, "OtherNode", false);
	EObjectNode node5 = new EObjectNode(eObject, rootNode3, image, "Node", false);
	assertTrue(comparer.equals(node, node5));
	EObjectNode node6 = new EObjectNode(eObject, rootNode3, image, "OtherNode", false);
	assertFalse(comparer.equals(node, node5));
}
 
Example #3
Source File: SARLOutlineTreeProvider.java    From sarl with Apache License 2.0 6 votes vote down vote up
/** Create a node for the SARL script.
 *
 * @param parentNode the parent node.
 * @param modelElement the feature container for which a node should be created.
 */
protected void _createChildren(DocumentRootNode parentNode, SarlScript modelElement) {
	if (!Strings.isNullOrEmpty(modelElement.getPackage())) {
		// Create the node for the package declaration.
		createEStructuralFeatureNode(
				parentNode, modelElement,
				XtendPackage.Literals.XTEND_FILE__PACKAGE,
				this.imageDispatcher.invoke(getClass().getPackage()),
				// Do not use the text dispatcher below for avoiding to obtain
				// the filename of the script.
				modelElement.getPackage(),
				true);
	}
	// Create the nodes for the import declarations.
	/*if (modelElement.getImportSection() != null && !modelElement.getImportSection().getImportDeclarations().isEmpty()) {
		createNode(parentNode, modelElement.getImportSection());
	}*/
	// Create a node per type declaration.
	for (final XtendTypeDeclaration topElement : modelElement.getXtendTypes()) {
		createNode(parentNode, topElement);
	}
}
 
Example #4
Source File: DotHtmlLabelOutlineTreeProvider.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void _createChildren(DocumentRootNode parentNode,
		EObject modelElement) {
	if (modelElement instanceof HtmlLabel) {
		HtmlLabel htmlLabel = (HtmlLabel) modelElement;
		/**
		 * Skip the root element, represent only its children.
		 */
		for (HtmlContent htmlContent : htmlLabel.getParts()) {
			if (htmlContent.getText() != null
					&& !htmlContent.getText().trim().isEmpty()) {
				createNode(parentNode, htmlContent);
			} else {
				if (htmlContent.getTag() != null) {
					createNode(parentNode, htmlContent.getTag());
				}
			}
		}
	} else {
		super._createChildren(parentNode, modelElement);
	}
}
 
Example #5
Source File: FJOutlineTreeProvider.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected void _createChildren(DocumentRootNode parentNode,
		Program program) {
	for (Class c : program.getClasses()) {
		createNode(parentNode, c);
	}
	if (program.getMain() != null)
		createNode(parentNode, program.getMain());
}
 
Example #6
Source File: AbstractOutlineTreeProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Default for createNodeDispatcher with document root as a parent node.
 *
 * @param parentNode
 *          the {@link DocumentRootNode}
 * @param modelElement
 *          the {@link EObject} model element
 */
// CHECKSTYLE:CHECK-OFF Name (dispatcher enforces names starting with underscore)
protected void _createNode(final DocumentRootNode parentNode, final EObject modelElement) {
  // CHECKSTYLE:CHECK-ON
  Object text = textDispatcher.invoke(modelElement);
  if (text == null) {
    text = modelElement.eResource().getURI().trimFileExtension().lastSegment();
  }
  factory.createEObjectNode(parentNode, modelElement, imageDispatcher.invoke(modelElement), text, isLeafDispatcher.invoke(modelElement));
}
 
Example #7
Source File: AbstractOutlineTreeProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Default for createChildrenDispatcher with outline node as a parent node.
 *
 * @param parentNode
 *          the {@link IOutlineNode}
 * @param modelElement
 *          the {@link EObject} model element
 */
// CHECKSTYLE:CHECK-OFF Name (dispatcher enforces names starting with underscore)
public void _createChildren(final IOutlineNode parentNode, final EObject modelElement) {
  // CHECKSTYLE:CHECK-ON
  if (modelElement != null && parentNode.hasChildren()) {
    if (parentNode instanceof DocumentRootNode) {
      internalCreateChildren((DocumentRootNode) parentNode, modelElement);
    } else if (parentNode instanceof EStructuralFeatureNode) {
      internalCreateChildren((EStructuralFeatureNode) parentNode, modelElement);
    } else {
      internalCreateChildren(parentNode, modelElement);
    }
  }
}
 
Example #8
Source File: ScopeOutlineTreeProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create the child nodes for a given native Context. We only show quick fixes.
 * 
 * @param parentNode
 *          the parent node
 * @param modelElement
 *          the scope model
 */
//CHECKSTYLE:OFF
protected void _createChildren(final DocumentRootNode parentNode, final ScopeModel modelElement) {
  //CHECKSTYLE:ON
  Image importContainerImage = JavaPlugin.getImageDescriptorRegistry().get(JavaPluginImages.DESC_OBJS_IMPCONT);

  if (!modelElement.getImports().isEmpty()) {
    createEStructuralFeatureNode(parentNode, modelElement, ScopePackage.Literals.SCOPE_MODEL__IMPORTS, importContainerImage, "import declarations", false);
  }

  for (EObject content : modelElement.getScopes()) {
    createNode(parentNode, content);
  }
}
 
Example #9
Source File: ValidOutlineTreeProvider.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Do not create Model nodes in the outline. When the valid model is processed it is not
 * added to the outline but its children are.
 * 
 * @param parentNode
 *          the parent node, this should be the tree root
 * @param modelElement
 *          a valid model
 */
// CHECKSTYLE:OFF
protected void _createChildren(final DocumentRootNode parentNode, final ValidModel modelElement) {
  // CHECKSTYLE:ON

  Image importContainerImage = JavaPlugin.getImageDescriptorRegistry().get(JavaPluginImages.DESC_OBJS_IMPCONT);

  if (!modelElement.getImports().isEmpty()) {
    createEStructuralFeatureNode(parentNode, modelElement, ValidPackage.Literals.VALID_MODEL__IMPORTS, importContainerImage, "import declarations", false);
  }
  for (EObject content : modelElement.getCategories()) {
    createNode(parentNode, content);
  }
}
 
Example #10
Source File: XtendOutlineJvmTreeProvider.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IXtendOutlineContext buildXtendNode(EObject modelElement, IXtendOutlineContext context) {
	IXtendOutlineContext resultedContext = super.buildXtendNode(modelElement, context);
	
	if (!context.isShowInherited()) {
		EclipseXtendOutlineContext eclipseXtendOutlineContext = (EclipseXtendOutlineContext) context;
		IOutlineNode parentNode = eclipseXtendOutlineContext.getParentNode();
		if (parentNode instanceof DocumentRootNode) {
			if (modelElement instanceof JvmDeclaredType) {
				JvmDeclaredType jvmDeclaredType = (JvmDeclaredType) modelElement;
				String packageName = jvmDeclaredType.getPackageName();
				if (packageName != null) {
					EObject rootElement = modelElement.eResource().getContents().get(0);
					if (rootElement instanceof XtendFile) {
						XtendFile xtendFile = (XtendFile) rootElement;
						String primaryPackage = xtendFile.getPackage();
						if (!packageName.equals(primaryPackage)) {
							EObjectNode typeNode = (EObjectNode) ((EclipseXtendOutlineContext) resultedContext).getParentNode();
							if (typeNode.getText() instanceof StyledString) {
								typeNode.setText(((StyledString) typeNode.getText()).append(new StyledString(" - "
										+ packageName, StyledString.QUALIFIER_STYLER)));
							}
						}
					}
				}
			}
		}
	}
	return resultedContext;
}
 
Example #11
Source File: XtextOutlineTreeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void _createNode(DocumentRootNode parentNode, Grammar grammar) {
	// Hack: we use this hook to calculate unused rule
	calledRules = Sets.newHashSet();
	if (!grammar.getRules().isEmpty()) {
		UsedRulesFinder usedRulesFinder = new UsedRulesFinder(calledRules);
		usedRulesFinder.compute(grammar);
	}
	super._createNode(parentNode, grammar);
}
 
Example #12
Source File: OutlineNodeComparerTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testPropertyEquality() {
	EObjectNode node = new EObjectNode(eObject, null, image, new StyledString("Node"), false);
	assertFalse(comparer.equals(node, new DocumentRootNode(image, new StyledString("Node"), null, null)));
	assertTrue(comparer.equals(node, new EObjectNode(OutlineTestFactory.eINSTANCE.createElement(), null, image, new StyledString("Node"), false)));
	assertFalse(comparer.equals(node, new EObjectNode(eObject, node, image, new StyledString("Node"), false)));
	assertFalse(comparer.equals(node, new EObjectNode(eObject, null, image2, new StyledString("Node"), false)));
	assertFalse(comparer.equals(node, new EObjectNode(eObject, null, image, new StyledString("Node2"), false)));
	assertTrue(comparer.equals(node, new EObjectNode(eObject, null, image, "Node", false)));
}
 
Example #13
Source File: OutlineTreeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testCreateRoot() throws Exception {
	XtextDocument document = createXtextDocument("element {}");
	IOutlineNode rootNode = treeProvider.createRoot(document);
	assertTrue(rootNode instanceof DocumentRootNode);
	assertEquals(treeProvider, ((DocumentRootNode)rootNode).getTreeProvider());
	assertEquals(new TextRegion(0, 10), rootNode.getFullTextRegion());
	assertEquals(new TextRegion(0, 10), rootNode.getSignificantTextRegion());
	assertEquals(document, ((DocumentRootNode) rootNode).getDocument());
}
 
Example #14
Source File: OutlineNodeTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected DocumentRootNode createRootNode() {
	XtextDocument document = get(XtextDocument.class);
	document.setInput(resource);
	IOutlineTreeStructureProvider treeStructureProvider = new IOutlineTreeStructureProvider() {
		@Override
		public void createChildren(IOutlineNode parentNode, EObject modelElement) {
			new EObjectNode(child0Element, parentNode, (ImageDescriptor) null, "child", false);
		}
	};
	DocumentRootNode rootNode = new DocumentRootNode((ImageDescriptor) null, "root", document, treeStructureProvider);
	return rootNode;
}
 
Example #15
Source File: OutlineNodeTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testStateAccess() {
	DocumentRootNode rootNode = createRootNode();
	EObjectNode parentNode = new EObjectNode(parentElement, rootNode, (ImageDescriptor) null, "parent", false);
	EStructuralFeatureNode featureNode = new EStructuralFeatureNode(parentElement,
			OutlineTestPackage.Literals.ELEMENT__XREFS, parentNode, (ImageDescriptor) null, "eClassifiers", true);
	IUnitOfWork<Boolean, EObject> work = new IUnitOfWork<Boolean, EObject>() {
		@Override
		public Boolean exec(EObject state) throws Exception {
			return state != null;
		}
	};
	assertTrue(rootNode.readOnly(work));
	assertTrue(parentNode.readOnly(work));
	assertTrue(featureNode.readOnly(work));
}
 
Example #16
Source File: OutlineNodeTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testMethodsDelegateToParent() {
	DocumentRootNode rootNode = createRootNode();
	EObjectNode parentNode = new EObjectNode(parentElement, rootNode, (ImageDescriptor) null, "parent", false);
	assertNotNull(parentNode.getDocument());
	assertNotNull(parentNode.getTreeProvider());
	assertEquals(rootNode.getDocument(), parentNode.getDocument());
	assertEquals(rootNode.getTreeProvider(), parentNode.getTreeProvider());
}
 
Example #17
Source File: FjcachedOutlineTreeProvider.java    From xsemantics with Eclipse Public License 1.0 4 votes vote down vote up
protected void _createChildren(DocumentRootNode parentNode,
		FjCachedProgram program) {
	super._createChildren(parentNode, program.getCachedprogram());
}
 
Example #18
Source File: AbstractMultiModeOutlineTreeProvider.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void internalCreateChildren(DocumentRootNode parentNode, EObject modelElement) {
	IXtendOutlineContext context = newContext(parentNode);
	xtendOutlineTreeBuilder.build(modelElement, context);
}
 
Example #19
Source File: DomainmodelOutlineTreeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void _createChildren(DocumentRootNode parentNode, EObject rootElement) {
	for (EObject content : rootElement.eContents()) {
		createNode(parentNode, content);
	}
}
 
Example #20
Source File: OutlineNodeTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test public void testCreateChildrenLazily() {
	DocumentRootNode rootNode = createRootNode();
	EObjectNode parentNode = new EObjectNode(parentElement, rootNode, (ImageDescriptor) null, "parent", false);
	assertFalse(parentNode.getChildren().isEmpty());
}
 
Example #21
Source File: AbstractOutlineTreeProvider.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Do not create Model nodes in the outline if the model node itself is not specified as required element.
 * In that case, when the valid model is processed it is not added to the outline but its children are.
 *
 * @param parentNode
 *          the parent {@link IOutlineNode}
 * @param modelElement
 *          a valid {@link EObject}
 */
@Override
protected void internalCreateChildren(final DocumentRootNode parentNode, final EObject modelElement) {
  if (getRelevantElements().contains(modelElement.eClass())) {
    createNode(parentNode, modelElement);
  } else {
    createChildrenDispatcher.invoke(parentNode, modelElement);
  }
}
 
Example #22
Source File: AbstractOutlineTreeProvider.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Default for createChildrenDispatcher with document root as a parent node.
 *
 * @param parentNode
 *          the {@link DocumentRootNode}
 * @param modelElement
 *          the {@link EObject} model element
 */
// CHECKSTYLE:CHECK-OFF Name (dispatcher enforces names starting with underscore)
public void _createChildren(final DocumentRootNode parentNode, final EObject modelElement) {
  // CHECKSTYLE:CHECK-ON
  internalCreateChildren((IOutlineNode) parentNode, modelElement);
}
 
Example #23
Source File: SARLOutlineTreeProvider.java    From sarl with Apache License 2.0 2 votes vote down vote up
/** Create a node for the given feature container at the root level.
 *
 * @param parentNode the parent node.
 * @param modelElement the feature container for which a node should be created.
 */
protected void _createNode(DocumentRootNode parentNode, XtendTypeDeclaration modelElement) {
	createTypeDeclarationNode(parentNode, modelElement);
}