Java Code Examples for org.eclipse.core.runtime.Platform#getContentTypeManager()

The following examples show how to use org.eclipse.core.runtime.Platform#getContentTypeManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IsNodeProjectPropertyTester.java    From wildwebdeveloper with Eclipse Public License 2.0 6 votes vote down vote up
@Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
	if (IS_NODE_RESOURCE_PROPERTY.equals(property)) {
		IResource resource = Adapters.adapt(receiver, IResource.class);
		if (resource == null) {
			return false;
		}
		if (resource instanceof IFile) {
			IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
			IContentType jsContentType = contentTypeManager.getContentType("org.eclipse.wildwebdeveloper.js");
			IContentType tsContentType = contentTypeManager.getContentType("org.eclipse.wildwebdeveloper.ts");
			try (
				InputStream content = ((IFile) resource).getContents();
			) {
				List<IContentType> contentTypes = Arrays.asList(contentTypeManager.findContentTypesFor(content, resource.getName()));
				return contentTypes.contains(jsContentType) || contentTypes.contains(tsContentType);
			} catch (Exception e) {
				return false;
			}
		}
	}
	return false;
}
 
Example 2
Source File: ProjectTemplate.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns true if the given file can be evaluated for template-variables.<br>
 * There is no good way of detecting what is binary and what is not, so we decide what is supported by checking if
 * the content type is a sub-type of text.
 * 
 * @param file
 * @return true if the file can be processed; false, otherwise.
 */
private static boolean isSupportedFile(IFile file)
{
	IContentTypeManager manager = Platform.getContentTypeManager();
	if (manager == null)
	{
		return false;
	}
	IContentType contentType = manager.findContentTypeFor(file.getName());
	if (contentType == null)
	{
		return false;
	}
	IContentType text = manager.getContentType("org.eclipse.core.runtime.text"); //$NON-NLS-1$
	return contentType.isKindOf(text);
}
 
Example 3
Source File: ContentProviderRegistry.java    From eclipsegraphviz with Eclipse Public License 1.0 6 votes vote down vote up
public ContentProviderDescriptor(IConfigurationElement configElement) {
    this.configElement = configElement;
    IConfigurationElement[] associationElements = configElement.getChildren("association");
    IContentTypeManager pcm = Platform.getContentTypeManager();
    for (IConfigurationElement associationEl : associationElements)
        associations.add(pcm.getContentType(associationEl.getAttribute("contentType")));
    IConfigurationElement[] readerElements = configElement.getChildren("reader");
    for (IConfigurationElement readerEl : readerElements)
        try {
            Object reader = readerEl.createExecutableExtension("class");
            readers.add(reader);
        } catch (CoreException e) {
            LogUtils.logError(ContentSupport.PLUGIN_ID, "Error processing content provider extension "
                    + configElement.getNamespaceIdentifier(), e);
        }
}
 
Example 4
Source File: SVNUIPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static IContentDescription getContentDescription(String name, InputStream stream) throws IOException  {
	// tries to obtain a description for this file contents
	IContentTypeManager contentTypeManager = Platform.getContentTypeManager();
	try {
		return contentTypeManager.getDescriptionFor(stream, name, IContentDescription.ALL);
	} finally {
		if (stream != null)
			try {
				stream.close();
			} catch (IOException e) {
				// Ignore exceptions on close
			}
	}
}
 
Example 5
Source File: IndexManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return a map from classname of the participant to a set of strings for the content type ids it applies to.
 * 
 * @return
 */
private Map<IConfigurationElement, Set<IContentType>> getFileIndexingParticipants()
{
	final Map<IConfigurationElement, Set<IContentType>> map = new HashMap<IConfigurationElement, Set<IContentType>>();
	final IContentTypeManager manager = Platform.getContentTypeManager();

	EclipseUtil.processConfigurationElements(IndexPlugin.PLUGIN_ID, FILE_INDEXING_PARTICIPANTS_ID,
			new IConfigurationElementProcessor()
			{

				public void processElement(IConfigurationElement element)
				{
					Set<IContentType> types = new HashSet<IContentType>();

					IConfigurationElement[] contentTypes = element.getChildren(CONTENT_TYPE_BINDING);
					for (IConfigurationElement contentTypeBinding : contentTypes)
					{
						String contentTypeId = contentTypeBinding.getAttribute(CONTENT_TYPE_ID);
						IContentType type = manager.getContentType(contentTypeId);
						types.add(type);
					}
					map.put(element, types);
				}

				public Set<String> getSupportElementNames()
				{
					return CollectionsUtil.newSet(TAG_FILE_INDEXING_PARTICIPANT);
				}
			});

	return map;
}
 
Example 6
Source File: PreviewCascadingMenuGroup.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isEnable( )
{
	IEditorPart editor = UIUtil.getActiveEditor( true );
	if ( editor == null )
	{
		return false;
	}
	IEditorInput input = editor.getEditorInput();
	if ( input == null )
	{
		return false;
	}
	String name = input.getName();
	if ( name == null )
	{
		return false;
	}
	IContentTypeManager manager = Platform.getContentTypeManager();
	if ( manager != null )
	{
		IContentType[] contentTypes = Platform.getContentTypeManager( )
				.findContentTypesFor( editor.getEditorInput( ).getName( ) );
		for ( IContentType type : contentTypes )
		{
			if ( type.getId( )
					.equals( "org.eclipse.birt.report.designer.ui.editors.reportdesign" ) //$NON-NLS-1$
					|| type.getId( )
							.equals( "org.eclipse.birt.report.designer.ui.editors.reporttemplate" ) ) //$NON-NLS-1$
				return true;
		}
	}
	return false;
}
 
Example 7
Source File: ParserPoolFactory.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * The main use of this class. Pass in a content type and get back an IParserPool to use to "borrow" a parser
 * instance. If the specified content type does not exist in the parser pool, then we work our way up the base
 * content types until we find a parser or fail.
 * 
 * @param contentTypeId
 * @return
 */
public synchronized IParserPool getParserPool(String contentTypeId)
{
	IContentTypeManager ctm = Platform.getContentTypeManager();
	IContentType contentType = ctm.getContentType(contentTypeId);
	IParserPool result = null;

	if (pools == null)
	{
		pools = new HashMap<String, IParserPool>();
	}

	while (result == null && (contentType != null || contentTypeId != null))
	{
		if (contentType != null)
		{
			contentTypeId = contentType.getId(); // $codepro.audit.disable questionableAssignment
		}
		result = pools.get(contentTypeId);

		if (result == null)
		{
			if (parsers == null)
			{
				parsers = getParsers();
			}

			IConfigurationElement parserExtension = parsers.get(contentTypeId);

			if (parserExtension != null)
			{
				result = new ParserPool(parserExtension);
				pools.put(contentTypeId, result);
			}
			else
			{
				contentType = contentType.getBaseType();

				if (contentType == null)
				{
					break;
				}
			}
		}
	}

	return result;
}
 
Example 8
Source File: BuildParticipantManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Return a map from classname of the participant to a set of strings for the content type ids it applies to.
 * 
 * @return
 */
private synchronized Map<IConfigurationElement, Set<IContentType>> getBuildParticipants()
{
	if (buildParticipants == null)
	{
		final Map<IConfigurationElement, Set<IContentType>> map = new HashMap<IConfigurationElement, Set<IContentType>>();
		final IContentTypeManager manager = Platform.getContentTypeManager();

		// TODO Combine the same logic/constants for dealing with children content types from
		// AbstractBuildParticipant!
		EclipseUtil.processConfigurationElements(BuildPathCorePlugin.PLUGIN_ID, EXTENSION_ID,
				new IConfigurationElementProcessor()
				{

					public void processElement(IConfigurationElement element)
					{
						Set<IContentType> types = new HashSet<IContentType>();

						IConfigurationElement[] contentTypes = element.getChildren(CONTENT_TYPE_BINDING);
						for (IConfigurationElement contentTypeBinding : contentTypes)
						{
							String contentTypeId = contentTypeBinding.getAttribute(CONTENT_TYPE_ID);
							IContentType type = manager.getContentType(contentTypeId);
							if (type != null)
							{
								types.add(type);
							}
						}
						map.put(element, types);
					}

					public Set<String> getSupportElementNames()
					{
						return CollectionsUtil.newSet(ELEMENT_PARTICIPANT);
					}
				});

		buildParticipants = map;
	}
	return buildParticipants;
}
 
Example 9
Source File: AbstractBuildParticipant.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
protected IContentTypeManager getContentTypeManager()
{
	return Platform.getContentTypeManager();
}
 
Example 10
Source File: ReportPlugin.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns all available extension names for report design files.
 * 
 * @return the extension name lisr
 */
public List<String> getReportExtensionNameList( )
{
	if ( reportExtensionNames == null )
	{
		reportExtensionNames = new ArrayList<String>( );

		IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry( );
		IConfigurationElement[] elements = extensionRegistry.getConfigurationElementsFor( "org.eclipse.ui.editors" ); //$NON-NLS-1$
		for ( int i = 0; i < elements.length; i++ )
		{

			String id = elements[i].getAttribute( "id" ); //$NON-NLS-1$
			if ( "org.eclipse.birt.report.designer.ui.editors.ReportEditor".equals( id ) ) //$NON-NLS-1$
			{
				if ( elements[i].getAttribute( "extensions" ) != null ) //$NON-NLS-1$
				{
					String[] extensionNames = elements[i].getAttribute( "extensions" ) //$NON-NLS-1$
							//$NON-NLS-1$
							.split( "," ); //$NON-NLS-1$
					for ( int j = 0; j < extensionNames.length; j++ )
					{
						extensionNames[j] = extensionNames[j].trim( );
						if ( !reportExtensionNames.contains( extensionNames[j] ) )
						{
							reportExtensionNames.add( extensionNames[j] );
						}
					}
				}
			}
		}

		IContentTypeManager contentTypeManager = Platform.getContentTypeManager( );
		IContentType contentType = contentTypeManager.getContentType( "org.eclipse.birt.report.designer.ui.editors.reportdesign" ); //$NON-NLS-1$
		String[] fileSpecs = contentType.getFileSpecs( IContentType.FILE_EXTENSION_SPEC );
		for ( int i = 0; i < fileSpecs.length; i++ )
		{
			reportExtensionNames.add( fileSpecs[i] );
		}
	}
	return reportExtensionNames;
}
 
Example 11
Source File: ContentTypeHelper.java    From tm4e with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Find the content type with the given contentTypeId
 * 
 * @param contentTypeId
 * @return matching content type or null
 */
public static IContentType getContentTypeById(String contentTypeId) {
	IContentTypeManager manager = Platform.getContentTypeManager();
	return manager.getContentType(contentTypeId);
}