Search in sources :

Example 31 with IContentTypeManager

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);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) IPath(org.eclipse.core.runtime.IPath) IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) IContentType(org.eclipse.core.runtime.content.IContentType) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 32 with IContentTypeManager

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;
}
Also used : ArrayList(java.util.ArrayList) IContentType(org.eclipse.core.runtime.content.IContentType) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IFileTaskScanner(org.eclipse.wst.sse.core.internal.provisional.tasks.IFileTaskScanner) CoreException(org.eclipse.core.runtime.CoreException) IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) ArrayList(java.util.ArrayList) List(java.util.List)

Example 33 with IContentTypeManager

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));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) IContentTypeManager(org.eclipse.core.runtime.content.IContentTypeManager) IContentType(org.eclipse.core.runtime.content.IContentType)

Aggregations

IContentTypeManager (org.eclipse.core.runtime.content.IContentTypeManager)33 IContentType (org.eclipse.core.runtime.content.IContentType)27 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)8 CoreException (org.eclipse.core.runtime.CoreException)5 InputStream (java.io.InputStream)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)3 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 BufferedInputStream (java.io.BufferedInputStream)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFileInfo (org.eclipse.core.filesystem.IFileInfo)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 ProjectScope (org.eclipse.core.resources.ProjectScope)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1