org.eclipse.core.runtime.content.IContentType Java Examples

The following examples show how to use org.eclipse.core.runtime.content.IContentType. 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: ClassFileJarDocument.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void updateStatus() {

	super.updateStatus();

	if (jarResource == null) {
		jarResource = new JarResource();
	}
	jarResource.setPackageFragmentRoot(classFile.getClass(), classFile);

	IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(getFileName());
	if (contentType != null) {
		contentTypeEncoding = contentType.getDefaultCharset();
	}
	String content = getContentString();
	if (content != null) {
		lineSeparator = LineSeparators.ofContent(new StringReader(content));
	} else {
		// Non source code, don't show.
		currentEncoding = null;
	}
}
 
Example #2
Source File: BuildParticipantManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Determines if a given content type is associated with the filename.
 * 
 * @param filename
 * @param types
 * @return
 */
private boolean hasType(String contentTypeId, Set<IContentType> types)
{
	if (CollectionsUtil.isEmpty(types))
	{
		// FIXME this means if no content type binding is specified then we assume the build participant is valid
		// for all types!
		return true;
	}
	for (IContentType type : types)
	{
		if (type == null)
		{
			continue;
		}
		if (type.getId().equals(contentTypeId))
		{
			return true;
		}
	}
	return false;
}
 
Example #3
Source File: EditorConfigSourceViewerConfiguration.java    From editorconfig-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
public IReconciler getReconciler(ISourceViewer sourceViewer) {
	if (!EditorsUI.getPreferenceStore().getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED))
		return null;

	IReconcilingStrategy strategy = new SpellingReconcileStrategy(sourceViewer, EditorsUI.getSpellingService()) {
		@Override
		protected IContentType getContentType() {
			return EditorConfigTextTools.EDITORCONFIG_CONTENT_TYPE;
		}
	};

	MonoReconciler reconciler = new MonoReconciler(strategy, false);
	reconciler.setDelay(500);
	return reconciler;
}
 
Example #4
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 #5
Source File: PropertiesFileSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IReconciler getReconciler(ISourceViewer sourceViewer) {
	if (!EditorsUI.getPreferenceStore().getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED))
		return null;

	IReconcilingStrategy strategy= new SpellingReconcileStrategy(sourceViewer, EditorsUI.getSpellingService()) {
		@Override
		protected IContentType getContentType() {
			return PROPERTIES_CONTENT_TYPE;
		}
	};

	MonoReconciler reconciler= new MonoReconciler(strategy, false);
	reconciler.setDelay(500);
	return reconciler;
}
 
Example #6
Source File: StorageFileDocument.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void updateStatus() {

	super.updateStatus();

	if (storage != null && storage.getClass().getName().equals("org.eclipse.jdt.internal.core.JarEntryFile")) {
		if (jarResource == null) {
			jarResource = new JarResource();
		}
		jarResource.setPackageFragmentRoot(storage.getClass().getSuperclass(), storage);
	}

	detectedCharset = Charsets.detect(getInputStream());
	IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(getFileName());
	if (contentType != null) {
		contentTypeEncoding = contentType.getDefaultCharset();
	}
	lineSeparator = LineSeparators.ofContent(getInputStream(), getCurrentEncoding());
}
 
Example #7
Source File: XMLEditor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getContentType()
{
	try
	{
		IContentType contentType = ((TextFileDocumentProvider) getDocumentProvider())
				.getContentType(getEditorInput());
		if (contentType != null)
		{
			IContentType baseType = contentType.getBaseType();
			if (baseType != null && IXMLConstants.CONTENT_TYPE_XML.equals(baseType.getId()))
			{
				return contentType.getId();
			}
		}
	}
	catch (Exception e)
	{
	}
	return IXMLConstants.CONTENT_TYPE_XML;
}
 
Example #8
Source File: PreviewToolbarMenuAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private boolean isEnable( )
{
	IEditorPart editor = UIUtil.getActiveEditor( true );
	if ( editor != 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 #9
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean isClassFile(IFile file) {
	IContentDescription contentDescription;
	try {
		contentDescription= file.getContentDescription();
	} catch (CoreException e) {
		contentDescription= null;
	}
	if (contentDescription == null)
		return false;

	IContentType contentType= contentDescription.getContentType();
	if (contentType == null)
		return false;

	return "org.eclipse.jdt.core.javaClass".equals(contentType.getId()); //$NON-NLS-1$
}
 
Example #10
Source File: IndexManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Determines if a given content type is associated with the filename.
 * 
 * @param filename
 * @param types
 * @return
 */
private boolean hasType(String filename, Set<IContentType> types)
{
	if (types == null || types.isEmpty())
	{
		return false;
	}
	for (IContentType type : types)
	{
		if (type == null)
		{
			continue;
		}
		if (type.isAssociatedWith(filename))
		{
			return true;
		}
	}
	return false;
}
 
Example #11
Source File: AbstractThemeableEditor.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public String getContentType()
{
	try
	{
		IContentType contentType = ((TextFileDocumentProvider) getDocumentProvider())
				.getContentType(getEditorInput());
		if (contentType != null)
		{
			return contentType.getId();
		}
	}
	catch (Exception e)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(), e);
	}
	return null;
}
 
Example #12
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 #13
Source File: LanguageConfigurationDefinition.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor for user preferences (loaded from Json with Gson).
 */
public LanguageConfigurationDefinition(IContentType contentType, String path, String pluginId,
		boolean onEnterEnabled, boolean bracketAutoClosingEnabled, boolean matchingPairsEnabled) {
	super(path, pluginId);
	this.contentType = contentType;
	this.onEnterEnabled = onEnterEnabled;
	this.bracketAutoClosingEnabled = bracketAutoClosingEnabled;
	this.matchingPairsEnabled = matchingPairsEnabled;
}
 
Example #14
Source File: BuildParticipantManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public List<IBuildParticipant> getAllBuildParticipants()
{
	Set<IBuildParticipant> participants = new HashSet<IBuildParticipant>();
	Map<IConfigurationElement, Set<IContentType>> participantstoContentTypes = getBuildParticipants();
	for (Map.Entry<IConfigurationElement, Set<IContentType>> entry : participantstoContentTypes.entrySet())
	{
		try
		{
			IBuildParticipant participant = createParticipant(entry.getKey(), entry.getValue());
			if (participant != null)
			{
				participants.add(participant);
			}
		}
		catch (CoreException e)
		{
			IdeLog.logError(BuildPathCorePlugin.getDefault(),
					MessageFormat.format("Unable to generate instance of build participant: {0}", //$NON-NLS-1$
							entry.getKey().getAttribute(ATTR_CLASS)), e);
		}
	}

	List<IBuildParticipant> result = new ArrayList<IBuildParticipant>(participants);
	Collections.sort(result, new Comparator<IBuildParticipant>()
	{
		public int compare(IBuildParticipant arg0, IBuildParticipant arg1)
		{
			// sort higher first
			return arg1.getPriority() - arg0.getPriority();
		}
	});

	return result;
}
 
Example #15
Source File: LanguageConfigurationRegistryManager.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
public CommentSupport getCommentSupport(IContentType contentType) {
	LanguageConfigurationDefinition value = this.getDefinition(contentType);
	if (value == null) {
		return null;
	}
	return value.getCommentSupport();
}
 
Example #16
Source File: LanguageConfigurationRegistryManager.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
private OnEnterSupport _getOnEnterSupport(IContentType contentType) {
	LanguageConfigurationDefinition value = this.getDefinition(contentType);
	if (value == null) {
		return null;
	}
	return value.getOnEnter();

}
 
Example #17
Source File: LanguageConfigurationRegistryManager.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
private CharacterPairSupport _getCharacterPairSupport(IContentType contentType) {
	LanguageConfigurationDefinition value = this.getDefinition(contentType);
	if (value == null) {
		return null;
	}
	return value.getCharacterPair();
}
 
Example #18
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 #19
Source File: LanguageConfigurationAutoEditStrategy.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
private IContentType[] findContentTypes(IDocument document) {
	if (this.document != null && this.document.equals(document)) {
		return contentTypes;
	}
	try {
		ContentTypeInfo info = ContentTypeHelper.findContentTypes(document);
		this.contentTypes = info.getContentTypes();
		this.document = document;
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return contentTypes;
}
 
Example #20
Source File: ToggleLineCommentHandler.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the comment support from the given list of content types and null
 * otherwise.
 * 
 * @param contentTypes
 * @return the comment support from the given list of content types and null
 *         otherwise.
 */
private CommentSupport getCommentSupport(IContentType[] contentTypes) {
	LanguageConfigurationRegistryManager registry = LanguageConfigurationRegistryManager.getInstance();
	for (IContentType contentType : contentTypes) {
		if (!registry.shouldComment(contentType)) {
			continue;
		}
		CommentSupport commentSupport = registry.getCommentSupport(contentType);
		if (commentSupport != null) {
			return commentSupport;
		}
	}
	return null;
}
 
Example #21
Source File: OriginalEditorSelector.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IEditorDescriptor[] overrideEditors(IEditorInput editorInput, IContentType contentType, IEditorDescriptor[] editorDescriptors) {
	IEditorDescriptor xbaseEditor = findXbaseEditor(editorInput, true);
	if (xbaseEditor != null) {
		List<IEditorDescriptor> result = Lists.asList(xbaseEditor, editorDescriptors);
		return (IEditorDescriptor[]) result.toArray(new IEditorDescriptor[result.size()]);
	}
	return editorDescriptors;
}
 
Example #22
Source File: OriginalEditorSelector.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public IEditorDescriptor[] overrideEditors(String fileName, IContentType contentType, IEditorDescriptor[] editorDescriptors) {
	IEditorDescriptor xbaseEditor = findXbaseEditor(fileName, true);
	if (xbaseEditor != null) {
		List<IEditorDescriptor> result = Lists.asList(xbaseEditor, editorDescriptors);
		return (IEditorDescriptor[]) result.toArray(new IEditorDescriptor[result.size()]);
	}
	return editorDescriptors;
}
 
Example #23
Source File: ProfileConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Exports all the profiles to a file.
 * 
 * @since 3.6
 */
private void exportAllButtonPressed() {
	final FileDialog dialog= new FileDialog(fComposite.getShell(), SWT.SAVE);
	dialog.setText(FormatterMessages.CodingStyleConfigurationBlock_export_profiles_dialog_title);
	dialog.setFilterExtensions(new String [] {"*.xml"}); //$NON-NLS-1$
	final String lastPath= JavaPlugin.getDefault().getDialogSettings().get(fLastSaveLoadPathKey + ".loadpath"); //$NON-NLS-1$
	if (lastPath != null) {
		dialog.setFilterPath(lastPath);
	}
	final String path= dialog.open();
	if (path == null)
		return;

	JavaPlugin.getDefault().getDialogSettings().put(fLastSaveLoadPathKey + ".savepath", dialog.getFilterPath()); //$NON-NLS-1$

	final File file= new File(path);
	if (file.exists() && !MessageDialog.openQuestion(fComposite.getShell(), FormatterMessages.CodingStyleConfigurationBlock_export_profiles_overwrite_title, Messages.format(FormatterMessages.CodingStyleConfigurationBlock_export_profiles_overwrite_message, BasicElementLabels.getPathLabel(file)))) {
		return;
	}
	String encoding= ProfileStore.ENCODING;
	final IContentType type= Platform.getContentTypeManager().getContentType("org.eclipse.core.runtime.xml"); //$NON-NLS-1$
	if (type != null)
		encoding= type.getDefaultCharset();
	final Collection<Profile> profiles= new ArrayList<Profile>();
	profiles.addAll(fProfileManager.getSortedProfiles());
	try {
		fProfileStore.writeProfilesToFile(profiles, file, encoding);
	} catch (CoreException e) {
		final String title= FormatterMessages.CodingStyleConfigurationBlock_export_profiles_error_title;
		final String message= FormatterMessages.CodingStyleConfigurationBlock_export_profiles_error_message;
		ExceptionHandler.handle(e, fComposite.getShell(), title, message);
	}

}
 
Example #24
Source File: BuildParticipantManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public List<IBuildParticipant> getBuildParticipants(String contentTypeId)
{
	Set<IBuildParticipant> participants = new HashSet<IBuildParticipant>();
	Map<IConfigurationElement, Set<IContentType>> participantstoContentTypes = getBuildParticipants();
	for (Map.Entry<IConfigurationElement, Set<IContentType>> entry : participantstoContentTypes.entrySet())
	{
		if (hasType(contentTypeId, entry.getValue()))
		{
			try
			{
				IBuildParticipant participant = createParticipant(entry.getKey(), entry.getValue());
				if (participant != null)
				{
					participants.add(participant);
				}
			}
			catch (CoreException e)
			{
				IdeLog.logError(BuildPathCorePlugin.getDefault(),
						MessageFormat.format("Unable to generate instance of build participant: {0}", //$NON-NLS-1$
								entry.getKey().getAttribute(ATTR_CLASS)), e);
			}
		}
	}

	List<IBuildParticipant> result = new ArrayList<IBuildParticipant>(participants);
	Collections.sort(result, new Comparator<IBuildParticipant>()
	{
		public int compare(IBuildParticipant arg0, IBuildParticipant arg1)
		{
			// sort higher first
			return arg1.getPriority() - arg0.getPriority();
		}
	});

	return result;
}
 
Example #25
Source File: BuildParticipantManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Set<IContentType> getContentTypes()
{
	Map<IConfigurationElement, Set<IContentType>> participants = getBuildParticipants();
	Set<IContentType> contentTypes = new HashSet<IContentType>();
	for (Set<IContentType> types : participants.values())
	{
		contentTypes.addAll(types);
	}
	return Collections.unmodifiableSet(contentTypes);
}
 
Example #26
Source File: CreateFileChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void initializeEncoding() {
	if (fEncoding == null) {
		fExplicitEncoding= false;
		IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(fPath);
		if (file != null) {
			try {
				if (file.exists()) {
					fEncoding= file.getCharset(false);
					if (fEncoding == null) {
						fEncoding= file.getCharset(true);
					} else {
						fExplicitEncoding= true;
					}
				} else {
					IContentType contentType= Platform.getContentTypeManager().findContentTypeFor(file.getName());
					if (contentType != null) {
						fEncoding= contentType.getDefaultCharset();
					}
					if (fEncoding == null) {
						fEncoding= file.getCharset(true);
					}
				}
			} catch (CoreException e) {
				fEncoding= ResourcesPlugin.getEncoding();
				fExplicitEncoding= true;
			}
		} else {
			fEncoding= ResourcesPlugin.getEncoding();
			fExplicitEncoding= true;
		}
	}
	Assert.isNotNull(fEncoding);
}
 
Example #27
Source File: DefaultSpellingEngine.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a spelling engine for the given content type or
 * <code>null</code> if none could be found.
 *
 * @param contentType the content type
 * @return a spelling engine for the given content type or
 *         <code>null</code> if none could be found
 */
private ISpellingEngine getEngine(IContentType contentType) {
	if (contentType == null)
		return null;

	if (fEngines.containsKey(contentType))
		return fEngines.get(contentType);

	return getEngine(contentType.getBaseType());
}
 
Example #28
Source File: ExternalFileDocument.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IContentDescription getContentDescription() {
	IContentType contentType = getContentType();
	if (contentType != null) {
		return contentType.getDefaultDescription();
	}
	return null;
}
 
Example #29
Source File: ContentProviderRegistry.java    From eclipsegraphviz with Eclipse Public License 1.0 5 votes vote down vote up
public IProviderDescription findContentProvider(IContentType target,
        Class<? extends IContentProvider> minimumProtocol) {
    for (ContentProviderDescriptor descriptor : providerDescriptors)
        for (IContentType contentType : descriptor.getAssociations())
            if (target.isKindOf(contentType)) {
                if (minimumProtocol != null && minimumProtocol.isInstance(descriptor.getProvider()))
                    return descriptor;
            }
    return null;
}
 
Example #30
Source File: IDEResourcesManager.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Returns the {@link ScriptKindName} from the given file object and null
 * otherwise.
 * 
 * @param fileObject
 * @return the {@link ScriptKindName} from the given file object and null
 *         otherwise.
 */
public ScriptKindName getScriptKind(Object fileObject) {
	String ext = getExtension(fileObject);
	if (ext != null) {
		ext = ext.toLowerCase();
		if (FileUtils.TS_EXTENSION.equals(ext)) {
			return ScriptKindName.TS;
		} else if (FileUtils.TSX_EXTENSION.equals(ext)) {
			return ScriptKindName.TSX;
		} else if (FileUtils.JSX_EXTENSION.equals(ext)) {
			return ScriptKindName.JSX;
		} else if (FileUtils.JS_EXTENSION.equals(ext)) {
			return useJsAsJsx ? ScriptKindName.JSX : ScriptKindName.JS;
		}
	}
	if (fileObject instanceof IFile) {
		try {
			IContentType contentType = ((IFile) fileObject).getContentDescription().getContentType();
			if (contentType != null) {
				String contentTypeId = contentType.getId();
				if (TS_CONTENT_TYPE_ID.equals(contentTypeId)) {
					return ScriptKindName.TS;
				} else if (TSX_CONTENT_TYPE_ID.equals(contentTypeId)) {
					return ScriptKindName.TSX;
				} else if (JSX_CONTENT_TYPE_ID.equals(contentTypeId)) {
					return ScriptKindName.JSX;
				} else if (JS_CONTENT_TYPE_ID.equals(contentTypeId)) {
					return useJsAsJsx ? ScriptKindName.JSX : ScriptKindName.JS;
				}
			}
		} catch (Exception e) {
			return null;
		}
	}
	return null;
}