Search in sources :

Example 1 with XMLNode

use of com.amalto.workbench.widgets.xmlviewer.model.XMLNode in project tmdm-studio-se by Talend.

the class XMLFormattingStrategy method format.

/* (non-Javadoc)
     * @see org.eclipse.jface.text.formatter.IFormattingStrategy#format(java.lang.String, boolean, java.lang.String, int[])
     */
public String format(String content, boolean isLineStart, String indentation, int[] positions) {
    IDocument document = sourceViewer.getDocument();
    sourceViewer.getTreeModel().createTree(document);
    XMLNode rootNode = sourceViewer.getTreeModel().getTree().getRootNode();
    int initialOffset = rootNode.getOffset();
    int length = rootNode.getCorrespondingNode().getOffset() + rootNode.getCorrespondingNode().getLength();
    this.visitor.reset();
    rootNode.accept(visitor);
    sourceViewer.getTreeModel().createTree(document);
    return visitor.getString();
}
Also used : XMLNode(com.amalto.workbench.widgets.xmlviewer.model.XMLNode) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with XMLNode

use of com.amalto.workbench.widgets.xmlviewer.model.XMLNode in project tmdm-studio-se by Talend.

the class XMLDocumentPartitioner method findPreviousNonWhiteSpacePosition.

public TypedPosition findPreviousNonWhiteSpacePosition(int offset) {
    try {
        int index = document.computeIndexInCategory(positionCategory, offset);
        Position[] positions = document.getPositions(positionCategory);
        if (positions.length == 0) {
            return null;
        }
        if (index == positions.length) {
            index--;
        }
        for (; index >= 0; index--) {
            TypedPosition position = (TypedPosition) positions[index];
            if (position instanceof XMLNode) {
                XMLNode node = (XMLNode) position;
                if (!node.isEmpty())
                    return node;
            }
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    } catch (BadPositionCategoryException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : XMLNode(com.amalto.workbench.widgets.xmlviewer.model.XMLNode) TypedPosition(org.eclipse.jface.text.TypedPosition) Position(org.eclipse.jface.text.Position) TypedPosition(org.eclipse.jface.text.TypedPosition) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

XMLNode (com.amalto.workbench.widgets.xmlviewer.model.XMLNode)2 BadLocationException (org.eclipse.jface.text.BadLocationException)1 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)1 IDocument (org.eclipse.jface.text.IDocument)1 Position (org.eclipse.jface.text.Position)1 TypedPosition (org.eclipse.jface.text.TypedPosition)1