Search in sources :

Example 16 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project webtools.sourceediting by eclipse.

the class CreateElementAction method formatChild.

protected void formatChild(Element child) {
    if (child instanceof IDOMNode) {
        IDOMModel model = ((IDOMNode) child).getModel();
        try {
            // tell the model that we are about to make a big model change
            model.aboutToChangeModel();
            IStructuredFormatProcessor formatProcessor = new FormatProcessorXML();
            formatProcessor.formatNode(child);
        } finally {
            // tell the model that we are done with the big model change
            model.changedModel();
        }
    }
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 17 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project webtools.sourceediting by eclipse.

the class XMLNodeActionManager method reformat.

public void reformat(Node newElement, boolean deep) {
    try {
        // tell the model that we are about to make a big model change
        fModel.aboutToChangeModel();
        // format selected node
        IStructuredFormatProcessor formatProcessor = new FormatProcessorXML();
        formatProcessor.formatNode(newElement);
    } finally {
        // tell the model that we are done with the big model change
        fModel.changedModel();
    }
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 18 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project webtools.sourceediting by eclipse.

the class SurroundWithNewElementQuickAssistProposal method apply.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer,
	 *      char, int, int)
	 */
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
    try {
        int startTagOffset = offset;
        int endTagOffset = offset + viewer.getSelectedRange().y;
        // surround the node if no selection
        if (startTagOffset == endTagOffset) {
            IDOMNode cursorNode = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset);
            // use parent node if text node is empty
            if ((cursorNode.getNodeType() == Node.TEXT_NODE) && (cursorNode.getNodeValue().trim().length() == 0)) {
                cursorNode = (IDOMNode) cursorNode.getParentNode();
            }
            startTagOffset = cursorNode.getStartOffset();
            endTagOffset = cursorNode.getEndOffset();
        }
        // insert new element
        MultiTextEdit multiTextEdit = new MultiTextEdit();
        // element tag name cannot be DBCS, do not translate "<element>"
        // and "</element>"
        // $NON-NLS-1$ //$NON-NLS-2$
        final String startElement = "<" + ELEMENT_NAME + ">";
        multiTextEdit.addChild(new InsertEdit(startTagOffset, startElement));
        // $NON-NLS-1$ //$NON-NLS-2$
        multiTextEdit.addChild(new InsertEdit(endTagOffset, "</" + ELEMENT_NAME + ">"));
        multiTextEdit.apply(viewer.getDocument());
        Position start = new Position(startTagOffset);
        Position end = new Position(endTagOffset + startElement.length());
        try {
            viewer.getDocument().addPosition(start);
            viewer.getDocument().addPosition(end);
            // get new element node
            IDOMNode newElementNode = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, startTagOffset);
            IStructuredFormatProcessor formatProcessor = new FormatProcessorXML();
            formatProcessor.formatNode(newElementNode);
            // rename new element
            apply(viewer, trigger, stateMask, start, end, ELEMENT_NAME.length());
        } finally {
            viewer.getDocument().removePosition(start);
            viewer.getDocument().removePosition(end);
        }
    } catch (MalformedTreeException e) {
        // log for now, unless find reason not to
        Logger.log(Logger.INFO, e.getMessage());
    } catch (BadLocationException e) {
        // log for now, unless find reason not to
        Logger.log(Logger.INFO, e.getMessage());
    }
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) InsertEdit(org.eclipse.text.edits.InsertEdit) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) LinkedPosition(org.eclipse.jface.text.link.LinkedPosition) Position(org.eclipse.jface.text.Position) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 19 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project webtools.sourceediting by eclipse.

the class BaseCommand method formatChild.

protected void formatChild(Element child) {
    if (child instanceof IDOMNode) {
        IDOMModel model = ((IDOMNode) child).getModel();
        try {
            // tell the model that we are about to make a big model change
            model.aboutToChangeModel();
            IStructuredFormatProcessor formatProcessor = new FormatProcessorXML();
            formatProcessor.formatNode(child);
        } finally {
            // tell the model that we are done with the big model change
            model.changedModel();
        }
    }
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 20 with FormatProcessorXML

use of org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML in project webtools.sourceediting by eclipse.

the class TestFormatProcessorXML method setUp.

protected void setUp() throws Exception {
    formatProcessor = new FormatProcessorXML();
    fStringCompareUtil = new StringCompareUtil();
}
Also used : StringCompareUtil(org.eclipse.wst.xml.core.tests.util.StringCompareUtil) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Aggregations

FormatProcessorXML (org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)28 Element (org.w3c.dom.Element)16 Node (org.w3c.dom.Node)14 NodeList (org.w3c.dom.NodeList)9 IStructuredFormatProcessor (org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor)8 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)6 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)6 CoreException (org.eclipse.core.runtime.CoreException)3 IWebProject (com.liferay.ide.core.IWebProject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IFile (org.eclipse.core.resources.IFile)2 ITemplateContext (com.liferay.ide.core.templates.ITemplateContext)1 ITemplateOperation (com.liferay.ide.core.templates.ITemplateOperation)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IFolder (org.eclipse.core.resources.IFolder)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1