Search in sources :

Example 6 with IStructuredFormatProcessor

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.

the class XSDDOMHelper method formatChild.

public static void formatChild(Node 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 7 with IStructuredFormatProcessor

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.

the class XMLNodeActionManager method reformat.

@Override
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 8 with IStructuredFormatProcessor

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor 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 9 with IStructuredFormatProcessor

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor 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 10 with IStructuredFormatProcessor

use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor 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)

Aggregations

IStructuredFormatProcessor (org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor)16 FormatProcessorXML (org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)8 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)6 IContentType (org.eclipse.core.runtime.content.IContentType)5 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)5 CoreException (org.eclipse.core.runtime.CoreException)4 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)4 IOException (java.io.IOException)2 IContainer (org.eclipse.core.resources.IContainer)2 IFile (org.eclipse.core.resources.IFile)2 IStatus (org.eclipse.core.runtime.IStatus)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 Status (org.eclipse.core.runtime.Status)2 MalformedInputExceptionWithDetail (org.eclipse.wst.sse.core.internal.exceptions.MalformedInputExceptionWithDetail)2 Iterator (java.util.Iterator)1 Vector (java.util.Vector)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 IContentTypeManager (org.eclipse.core.runtime.content.IContentTypeManager)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 DocumentRewriteSession (org.eclipse.jface.text.DocumentRewriteSession)1