use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.
the class FormatHandler method processorAvailable.
/* (non-Javadoc)
* @see org.eclipse.wst.sse.ui.internal.actions.ResourceActionDelegate#processorAvailable(org.eclipse.core.resources.IResource)
*/
protected boolean processorAvailable(IResource resource) {
boolean result = false;
if (resource.isAccessible()) {
try {
if (resource instanceof IFile) {
IFile file = (IFile) resource;
IStructuredFormatProcessor formatProcessor = null;
IContentDescription contentDescription = file.getContentDescription();
if (contentDescription != null) {
IContentType contentType = contentDescription.getContentType();
formatProcessor = getFormatProcessor(contentType.getId());
}
if (formatProcessor != null)
result = true;
} else if (resource instanceof IContainer) {
IContainer container = (IContainer) resource;
IResource[] members;
members = container.members();
for (int i = 0; i < members.length; i++) {
boolean available = processorAvailable(members[i]);
if (available) {
result = true;
break;
}
}
}
} catch (CoreException e) {
Logger.logException(e);
}
}
return result;
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.
the class HTMLNodeActionManager 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 HTMLFormatProcessorImpl();
formatProcessor.formatNode(newElement);
} finally {
// tell the model that we are done with the big model change
fModel.changedModel();
}
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.
the class AbstractStructuredCleanupProcessor method cleanupModel.
public void cleanupModel(IStructuredModel structuredModel, int start, int length, Object context) {
if (structuredModel != null) {
if ((start >= 0) && (length <= structuredModel.getStructuredDocument().getLength())) {
Vector activeNodes = getActiveNodes(structuredModel, start, length);
if (activeNodes.size() > 0) {
Node firstNode = (Node) activeNodes.firstElement();
Node lastNode = (Node) activeNodes.lastElement();
boolean done = false;
Node eachNode = firstNode;
Node nextNode = null;
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=123621
// if doing any sort of cleanup, set up rewrite session/modelchanged
IDocumentExtension4 docExt4 = null;
if (structuredModel.getStructuredDocument() instanceof IDocumentExtension4) {
docExt4 = (IDocumentExtension4) structuredModel.getStructuredDocument();
}
DocumentRewriteSession rewriteSession = null;
try {
// whenever formatting model, fire
// abouttochange/modelchanged
structuredModel.aboutToChangeModel();
rewriteSession = (docExt4 == null || docExt4.getActiveRewriteSession() != null) ? null : docExt4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
while (!done) {
// update "done"
done = (eachNode == lastNode);
// get next sibling before cleanup because eachNode
// may
// be deleted,
// for example when it's an empty text node
nextNode = eachNode.getNextSibling();
// cleanup selected node(s)
cleanupNode(eachNode);
// update each node
if (nextNode != null && nextNode.getParentNode() == null)
// nextNode is deleted during cleanup
eachNode = eachNode.getNextSibling();
else
eachNode = nextNode;
// We don't want an infinite loop here.
if (eachNode == null)
done = true;
}
// format source
if (getFormatSourcePreference(structuredModel)) {
// format the document
IFormattingDelegate delegate = getFormattingDelegate();
if (context != null && delegate != null) {
delegate.format(context);
} else {
IStructuredFormatProcessor formatProcessor = getFormatProcessor();
formatProcessor.formatModel(structuredModel);
}
}
} finally {
// we need two finally's, just in case first fails
try {
if ((docExt4 != null) && (rewriteSession != null))
docExt4.stopRewriteSession(rewriteSession);
} finally {
// always make sure to fire changedmodel when done
structuredModel.changedModel();
}
}
}
}
}
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.
the class FormatActionDelegate method processorAvailable.
/* (non-Javadoc)
* @see org.eclipse.wst.sse.ui.internal.actions.ResourceActionDelegate#processorAvailable(org.eclipse.core.resources.IResource)
*/
protected boolean processorAvailable(IResource resource) {
boolean result = false;
if (resource.isAccessible()) {
try {
if (resource instanceof IFile) {
IFile file = (IFile) resource;
IStructuredFormatProcessor formatProcessor = null;
IContentDescription contentDescription = file.getContentDescription();
if (contentDescription != null) {
IContentType contentType = contentDescription.getContentType();
formatProcessor = getFormatProcessor(contentType.getId());
}
if (formatProcessor != null)
result = true;
} else if (resource instanceof IContainer) {
IContainer container = (IContainer) resource;
IResource[] members;
members = container.members();
for (int i = 0; i < members.length; i++) {
boolean available = processorAvailable(members[i]);
if (available) {
result = true;
break;
}
}
}
} catch (CoreException e) {
Logger.logException(e);
}
}
return result;
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.
the class XSDCommonUIUtils 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();
}
}
}
Aggregations