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();
}
}
}
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();
}
}
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());
}
}
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();
}
}
}
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();
}
Aggregations