Search in sources :

Example 1 with IDocumentPartitionerExtension2

use of org.eclipse.jface.text.IDocumentPartitionerExtension2 in project webtools.sourceediting by eclipse.

the class BasicStructuredDocument method getPartition.

public ITypedRegion getPartition(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException {
    if ((0 > offset) || (offset > getLength()))
        throw new BadLocationException();
    ITypedRegion result = null;
    IDocumentPartitioner partitioner = getDocumentPartitioner(partitioning);
    if (partitioner instanceof IDocumentPartitionerExtension2) {
        result = ((IDocumentPartitionerExtension2) partitioner).getPartition(offset, preferOpenPartitions);
    } else if (partitioner != null) {
        result = partitioner.getPartition(offset);
    } else if (IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING.equals(partitioning)) {
        result = new TypedRegion(0, getLength(), DEFAULT_CONTENT_TYPE);
    } else
        throw new BadPartitioningException();
    return result;
}
Also used : BadPartitioningException(org.eclipse.jface.text.BadPartitioningException) IDocumentPartitionerExtension2(org.eclipse.jface.text.IDocumentPartitionerExtension2) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) ITypedRegion(org.eclipse.jface.text.ITypedRegion) TypedRegion(org.eclipse.jface.text.TypedRegion) ITypedRegion(org.eclipse.jface.text.ITypedRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with IDocumentPartitionerExtension2

use of org.eclipse.jface.text.IDocumentPartitionerExtension2 in project tmdm-studio-se by Talend.

the class XMLTreeModel method createTree.

public void createTree(IDocument document) {
    this.fireDocumentAboutToBeChanged(this.getTree());
    IDocumentPartitioner partitioner = document.getDocumentPartitioner();
    String[] categories = ((IDocumentPartitionerExtension2) partitioner).getManagingPositionCategories();
    this.sourceViewer.getCodeTagContainersRegistry().clear();
    for (int iCat = 0; iCat < categories.length; iCat++) {
        String category = categories[iCat];
        Position[] positions = null;
        try {
            positions = document.getPositions(category);
            this.rootNode = new XMLRootNode(0, 0, IXMLPartitions.XML_TAG, document, sourceViewer);
            ElementsToRelate.currentNode = this.rootNode;
            ElementsToRelate.parentNode = null;
            for (int j = 0; j < positions.length; j++) {
                Position pos = positions[j];
                ElementsToRelate.node = (XMLNode) pos;
                ElementsToRelate.node.getChildren().clear();
                ElementsToRelate.node.setCorrespondingNode(null);
                ElementsToRelate.node.setSourceViewer(this.sourceViewer);
                if (ElementsToRelate.currentNode != null && ElementsToRelate.currentNode.isTag()) {
                    String nodeType = ElementsToRelate.node.getType();
                    RelateElementsCommand command = this.commands.get(nodeType);
                    if (command != null) {
                        command.excecute(this.rootNode, this.sourceViewer.getCodeTagContainersRegistry());
                    }
                }
            }
        } catch (BadPositionCategoryException e) {
            e.printStackTrace();
        }
    }
    this.fireDocumentChanged(this.getTree());
}
Also used : IDocumentPartitionerExtension2(org.eclipse.jface.text.IDocumentPartitionerExtension2) RelateElementsCommand(com.amalto.workbench.widgets.xmlviewer.model.commands.RelateElementsCommand) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) Position(org.eclipse.jface.text.Position) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException)

Aggregations

IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)2 IDocumentPartitionerExtension2 (org.eclipse.jface.text.IDocumentPartitionerExtension2)2 RelateElementsCommand (com.amalto.workbench.widgets.xmlviewer.model.commands.RelateElementsCommand)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 BadPartitioningException (org.eclipse.jface.text.BadPartitioningException)1 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)1 ITypedRegion (org.eclipse.jface.text.ITypedRegion)1 Position (org.eclipse.jface.text.Position)1 TypedRegion (org.eclipse.jface.text.TypedRegion)1