use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.
the class FormatProcessorsExtensionReader method getFormatProcessor.
public IStructuredFormatProcessor getFormatProcessor(String contentTypeId) {
if (contentTypeId == null)
return null;
IStructuredFormatProcessor formatProcessor = null;
if (map.containsKey(contentTypeId)) {
formatProcessor = (IStructuredFormatProcessor) map.get(contentTypeId);
} else {
IContentTypeManager manager = Platform.getContentTypeManager();
IContentType queryContentType = manager.getContentType(contentTypeId);
boolean found = false;
for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) {
String elementContentTypeId = (String) iter.next();
IContentType elementContentType = manager.getContentType(elementContentTypeId);
if (queryContentType.isKindOf(elementContentType)) {
formatProcessor = (IStructuredFormatProcessor) map.get(elementContentTypeId);
map.put(contentTypeId, formatProcessor);
found = true;
break;
}
}
if (!found)
map.put(contentTypeId, null);
}
return formatProcessor;
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.
the class FormatProcessorsExtensionReader method readElement.
/*
* (non-Javadoc)
*
* @see org.eclipse.wst.sse.ui.internal.extension.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
*/
protected boolean readElement(IConfigurationElement element) {
if (element.getName().equals("processor")) {
// $NON-NLS-1$
// $NON-NLS-1$
String contentTypeId = element.getAttribute("contentTypeId");
// $NON-NLS-1$
String processorClassName = element.getAttribute("class");
String pluginID = element.getDeclaringExtension().getNamespace();
Bundle bundle = Platform.getBundle(pluginID);
try {
IStructuredFormatProcessor processor = (IStructuredFormatProcessor) bundle.loadClass(processorClassName).newInstance();
map.put(contentTypeId, processor);
return true;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
return false;
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.
the class FormatActionDelegate method format.
protected void format(IProgressMonitor monitor, IFile file) {
if (monitor == null || monitor.isCanceled())
return;
try {
monitor.beginTask("", 100);
IContentDescription contentDescription = file.getContentDescription();
monitor.worked(5);
if (contentDescription != null) {
IContentType contentType = contentDescription.getContentType();
IStructuredFormatProcessor formatProcessor = getFormatProcessor(contentType.getId());
if (formatProcessor != null && (monitor == null || !monitor.isCanceled())) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_3, new String[] { file.getFullPath().toString().substring(1) });
monitor.subTask(message);
formatProcessor.setProgressMonitor(monitor);
formatProcessor.formatFile(file);
}
}
monitor.worked(95);
monitor.done();
} catch (MalformedInputExceptionWithDetail e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_5, new String[] { file.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
} catch (IOException e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
} catch (CoreException e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
}
}
use of org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor 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.sse.core.internal.format.IStructuredFormatProcessor in project webtools.sourceediting by eclipse.
the class FormatHandler method format.
protected void format(IProgressMonitor monitor, IFile file) {
if (monitor == null || monitor.isCanceled())
return;
try {
monitor.beginTask("", 100);
IContentDescription contentDescription = file.getContentDescription();
monitor.worked(5);
if (contentDescription != null) {
IContentType contentType = contentDescription.getContentType();
IStructuredFormatProcessor formatProcessor = getFormatProcessor(contentType.getId());
if (formatProcessor != null && (monitor == null || !monitor.isCanceled())) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_3, new String[] { file.getFullPath().toString().substring(1) });
monitor.subTask(message);
formatProcessor.setProgressMonitor(new SubProgressMonitor(monitor, 95));
formatProcessor.formatFile(file);
}
}
monitor.done();
} catch (MalformedInputExceptionWithDetail e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_5, new String[] { file.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
} catch (IOException e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
} catch (CoreException e) {
String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[] { file.getFullPath().toString() });
fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
}
}
Aggregations