use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.
the class AddExternalFileAction method run.
@Override
public void run() {
String lastUsedPath = getDialogSetting(LAST_PATH_SETTING);
if (lastUsedPath == null) {
// $NON-NLS-1$
lastUsedPath = "";
}
FileDialog dialog = new FileDialog(getShell(), SWT.MULTI);
dialog.setText(Messages.AddExternalFileAction_Selection_3);
dialog.setFilterPath(lastUsedPath);
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
IContentType contentType = contentTypeManager.getContentType(XSLCore.XSL_CONTENT_TYPE);
String[] xslContentTypes = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
// add *. to front
for (int i = 0; i < xslContentTypes.length; i++) {
String string = xslContentTypes[i];
// $NON-NLS-1$
xslContentTypes[i] = "*." + string;
}
dialog.setFilterExtensions(xslContentTypes);
String res = dialog.open();
if (res == null) {
return;
}
IPath filterPath = new Path(dialog.getFilterPath());
LaunchTransform[] lts = new LaunchTransform[1];
IPath path = new Path(res).makeAbsolute();
lts[0] = new LaunchTransform(path.toPortableString(), LaunchTransform.EXTERNAL_TYPE);
setDialogSetting(LAST_PATH_SETTING, filterPath.toOSString());
addTransforms(lts);
}
use of org.eclipse.core.runtime.content.IContentTypeManager in project webtools.sourceediting by eclipse.
the class FileTaskScannerRegistryReader method loadScanners.
private ScannerInfo[] loadScanners(IContentType contentType) {
List elements = new ArrayList(0);
ScannerInfo[] scannerInfos = null;
IConfigurationElement[] delegateElements = fScannerElements;
if (contentType != null) {
IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
for (int j = 0; j < delegateElements.length; j++) {
if (!delegateElements[j].getName().equals(NAME_SCANNER))
continue;
String[] supportedContentTypeIds = StringUtils.unpack(delegateElements[j].getAttribute(ATT_CONTENT_TYPES));
IContentType[] supportedContentTypes = new IContentType[supportedContentTypeIds.length];
for (int k = 0; k < supportedContentTypeIds.length; k++) {
supportedContentTypes[k] = contentTypeManager.getContentType(supportedContentTypeIds[k].trim());
}
for (int k = 0; k < supportedContentTypeIds.length; k++) {
// allow subtypes to be returned as well
if (supportedContentTypes[k] != null && contentType.isKindOf(supportedContentTypes[k])) {
elements.add(delegateElements[j]);
}
}
}
// instantiate and save the scanners
List scannerInfoList = new ArrayList(elements.size());
for (int i = 0; i < elements.size(); i++) {
try {
IFileTaskScanner scanner = (IFileTaskScanner) ((IConfigurationElement) elements.get(i)).createExecutableExtension(ATT_CLASS);
if (scanner != null) {
scannerInfoList.add(new ScannerInfo(((IConfigurationElement) elements.get(i)).getAttribute(ATT_ID), scanner));
}
} catch (CoreException e) {
// $NON-NLS-1$
Logger.logException("Non-fatal exception creating task scanner for " + contentType.getId(), e);
}
}
scannerInfos = (ScannerInfo[]) scannerInfoList.toArray(new ScannerInfo[scannerInfoList.size()]);
fScannerInfos.put(contentType.getId(), scannerInfos);
if (Logger.DEBUG_TASKSREGISTRY) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("Created " + scannerInfos.length + " task scanner for " + contentType.getId());
}
}
return scannerInfos;
}
use of org.eclipse.core.runtime.content.IContentTypeManager in project arduino-eclipse-plugin by Sloeber.
the class Activator method addFileAssociations.
/**
* Add the .ino and .pde as file extensions to the cdt environment
*/
private static void addFileAssociations() {
// add the extension to the content type manager as a binary
final IContentTypeManager ctm = Platform.getContentTypeManager();
final IContentType ctbin = ctm.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
try {
ctbin.addFileSpec("ino", IContentTypeSettings.FILE_EXTENSION_SPEC);
ctbin.addFileSpec("pde", IContentTypeSettings.FILE_EXTENSION_SPEC);
} catch (CoreException e) {
Common.log(new Status(IStatus.WARNING, Activator.getId(), "Failed to add *.ino and *.pde as file extensions.", e));
}
}
Aggregations