/** * {@inheritDoc} * * @see org.eclipse.mylyn.docs.intent.mapping.content.IFileTypeRegistry#getFileType(java.lang.String) */ public IFileType getFileType(String typeID) { final IFileType res; final IFileType delegateFileType = registry.getFileType(typeID); if (delegateFileType == null) { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); final IContentType contentType = contentTypeManager.getContentType(typeID); if (contentType != null) { res = new FileType(contentType.getId()); } else { res = null; } } else { res = delegateFileType; } return res; }
/** * 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); }
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); } }
private void setupContentTypes(final TreeItem parent, final IContentType baseType) { final IContentTypeManager manager = Platform.getContentTypeManager(); final IContentType[] contentTypes = manager.getAllContentTypes(); for (final IContentType type : contentTypes) { if (equals(type.getBaseType(), baseType) && type.isKindOf(textType)) { TreeItem item = null; if (parent == null) { item = new TreeItem(contentTypesTree, SWT.NONE); } else { item = new TreeItem(parent, SWT.NONE); } item.setText(type.getName()); item.setData(type.getId()); setupContentTypes(item, type); } } }
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 } } }
@Test public void getContentType() { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); final IContentType contentType = contentTypeManager.getContentType("org.eclipse.emf.ecore.xmi"); final IFileType expected = MappingUtils.getFileTypeRegistry().getFileType(contentType.getId()); assertEquals(expected, delegate.getFileType()); }
@Test public void getContentType() { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); final IContentType contentType = contentTypeManager.getContentType(IContentTypeManager.CT_TEXT); final IFileType expected = MappingUtils.getFileTypeRegistry().getFileType(contentType.getId()); assertEquals(expected, delegate.getFileType()); }
/** * {@inheritDoc} * * @see org.eclipse.mylyn.docs.intent.mapping.content.IFileTypeRegistry#isKindOf(java.lang.String, * java.lang.String) */ public boolean isKindOf(String typeID, String superTypeID) { final boolean res; if (registry.isKindOf(typeID, superTypeID)) { res = true; } else { final IContentTypeManager contentTypeManager = Platform.getContentTypeManager(); final IContentType contentType = contentTypeManager.getContentType(typeID); final IContentType superContentType = contentTypeManager.getContentType(superTypeID); res = contentType != null && contentType.isKindOf(superContentType); } return res; }
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; }
/** * 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; }
private ContentTypeFileNamePredicate(String fileName, String contentTypeId) { this.fileName = fileName; IContentTypeManager contentTypeManager = Platform .getContentTypeManager(); this.contentType = contentTypeManager.getContentType(contentTypeId); }
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; }
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; }
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); }
public CommentSpellingReconcileStrategy(AnnotationModel annotationModel) { this.fAnnotationModel = annotationModel; fSpellingContext = new SpellingContext(); fSpellingContext.setContentType(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT)); }
/** * 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; }
/** * 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; }
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); } } }
protected IContentTypeManager getContentTypeManager() { return Platform.getContentTypeManager(); }
/** * 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; }
public IndentGuidePreferencePage() { setPreferenceStore(Activator.getDefault().getPreferenceStore()); setDescription(Messages.IndentGuidePreferencePage_description); textType = Platform.getContentTypeManager().getContentType( IContentTypeManager.CT_TEXT); }