org.eclipse.core.runtime.content.IContentTypeManager Java Examples
The following examples show how to use
org.eclipse.core.runtime.content.IContentTypeManager.
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: ContentProviderRegistry.java From eclipsegraphviz with Eclipse Public License 1.0 | 6 votes |
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 #2
Source File: IsNodeProjectPropertyTester.java From wildwebdeveloper with Eclipse Public License 2.0 | 6 votes |
@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 #3
Source File: ProjectTemplate.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * 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 #4
Source File: PreferenceInitializer.java From IndentGuide with MIT License | 5 votes |
public void initializeDefaultPreferences() { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); store.setDefault(PreferenceConstants.ENABLED, true); store.setDefault(PreferenceConstants.LINE_ALPHA, 50); store.setDefault(PreferenceConstants.LINE_STYLE, SWT.LINE_SOLID); store.setDefault(PreferenceConstants.LINE_WIDTH, 1); store.setDefault(PreferenceConstants.LINE_SHIFT, 3); store.setDefault(PreferenceConstants.LINE_COLOR, "0,0,0"); //$NON-NLS-1$ store.setDefault(PreferenceConstants.DRAW_LEFT_END, true); //$NON-NLS-1$ store.setDefault(PreferenceConstants.DRAW_BLANK_LINE, false); //$NON-NLS-1$ store.setDefault(PreferenceConstants.SKIP_COMMENT_BLOCK, false); //$NON-NLS-1$ store.setDefault(PreferenceConstants.CONTENT_TYPES, IContentTypeManager.CT_TEXT); }
Example #5
Source File: PreviewCascadingMenuGroup.java From birt with Eclipse Public License 1.0 | 5 votes |
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 #6
Source File: SVNUIPlugin.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
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 #7
Source File: IndexManager.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * 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 #8
Source File: AbstractBuildParticipant.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { String rawPriority = config.getAttribute(ATTR_PRIORITY); if (!StringUtil.isEmpty(rawPriority)) { try { this.fPriority = Integer.parseInt(rawPriority); } catch (NumberFormatException e) { IdeLog.logWarning(BuildPathCorePlugin.getDefault(), MessageFormat.format( "Unable to parse priority value ({0}) as an integer, defaulting to 50.", rawPriority), e); //$NON-NLS-1$ } } this.fId = config.getAttribute(ID); this.fName = config.getAttribute(NAME); this.contributor = config.getContributor().getName(); // Read in the content types IContentTypeManager manager = getContentTypeManager(); IConfigurationElement[] rawContentTypes = config.getChildren(CONTENT_TYPE_BINDING); this.contentTypes = new HashSet<IContentType>(rawContentTypes.length); for (IConfigurationElement contentTypeBinding : rawContentTypes) { String contentTypeId = contentTypeBinding.getAttribute(CONTENT_TYPE_ID); IContentType type = manager.getContentType(contentTypeId); if (type != null) { contentTypes.add(type); } } // Read in the associated project natures IConfigurationElement[] rawProjectNatures = config.getChildren(PROJECT_NATURE_BINDING); this.projectNatures = new HashSet<String>(rawContentTypes.length); for (IConfigurationElement projectNatureBinding : rawProjectNatures) { String natureId = projectNatureBinding.getAttribute(NATURE_ID); if (!StringUtil.isEmpty(natureId)) { projectNatures.add(natureId); } } }
Example #9
Source File: IndentGuidePreferencePage.java From IndentGuide with MIT License | 4 votes |
public IndentGuidePreferencePage() { setPreferenceStore(Activator.getDefault().getPreferenceStore()); setDescription(Messages.IndentGuidePreferencePage_description); textType = Platform.getContentTypeManager().getContentType( IContentTypeManager.CT_TEXT); }
Example #10
Source File: ReportPlugin.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * 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: AbstractBuildParticipant.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
protected IContentTypeManager getContentTypeManager() { return Platform.getContentTypeManager(); }
Example #12
Source File: BuildParticipantManager.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * 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 #13
Source File: CommitCommentArea.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
public CommentSpellingReconcileStrategy(AnnotationModel annotationModel) { this.fAnnotationModel = annotationModel; fSpellingContext = new SpellingContext(); fSpellingContext.setContentType(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT)); }
Example #14
Source File: ParserPoolFactory.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * 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 #15
Source File: TextSearchVisitor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
/** * Returns a map from IFile to IDocument for all open, dirty editors. After creation this map * is not modified, so returning a non-synchronized map is ok. * * @return a map from IFile to IDocument for all open, dirty editors */ // private Map<IFile, IDocument> evalNonFileBufferDocuments() { // Map<IFile, IDocument> result= new HashMap<>(); // IWorkbench workbench= SearchPlugin.getDefault().getWorkbench(); // IWorkbenchWindow[] windows= workbench.getWorkbenchWindows(); // for (IWorkbenchWindow window : windows) { // IWorkbenchPage[] pages= window.getPages(); // for (IWorkbenchPage page : pages) { // IEditorReference[] editorRefs= page.getEditorReferences(); // for (IEditorReference editorRef : editorRefs) { // IEditorPart ep= editorRef.getEditor(false); // if (ep instanceof ITextEditor && ep.isDirty()) { // only dirty editors // evaluateTextEditor(result, ep); // } // } // } // } // return result; // } // private void evaluateTextEditor(Map<IFile, IDocument> result, IEditorPart ep) { // IEditorInput input= ep.getEditorInput(); // if (input instanceof IFileEditorInput) { // IFile file= ((IFileEditorInput) input).getFile(); // if (!result.containsKey(file)) { // take the first editor found // ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager(); // ITextFileBuffer textFileBuffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE); // if (textFileBuffer != null) { // // file buffer has precedence // result.put(file, textFileBuffer.getDocument()); // } else { // // use document provider // IDocument document= ((ITextEditor) ep).getDocumentProvider().getDocument(input); // if (document != null) { // result.put(file, document); // } // } // } // } // } private boolean hasBinaryContent(CharSequence seq, IFile file) throws CoreException { IContentDescription desc= file.getContentDescription(); if (desc != null) { IContentType contentType= desc.getContentType(); if (contentType != null && contentType.isKindOf(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT))) { return false; } } // avoid calling seq.length() at it runs through the complete file, // thus it would do so for all binary files. try { int limit= FileCharSequenceProvider.BUFFER_SIZE; for (int i= 0; i < limit; i++) { if (seq.charAt(i) == '\0') { return true; } } } catch (IndexOutOfBoundsException e) { } catch (FileCharSequenceException ex) { if (ex.getCause() instanceof CharConversionException) { return true; } throw ex; } return false; }
Example #16
Source File: SelectLanguageConfigurationWizardPage.java From tm4e with Eclipse Public License 1.0 | 4 votes |
@Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { manager = (IContentTypeManager) newInput; }
Example #17
Source File: ContentTypeHelper.java From tm4e with Eclipse Public License 1.0 | 2 votes |
/** * 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); }