use of org.eclipse.core.runtime.content.IContentType in project che by eclipse.
the class CreateFileChange method initializeEncoding.
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);
}
use of org.eclipse.core.runtime.content.IContentType in project tesb-studio-se by Talend.
the class OpenOnSelectionHelper method openEditor.
@Override
protected void openEditor(String resource, String spec) {
//$NON-NLS-1$
String pattern = "platform:/resource";
IWorkbenchPage workbenchPage = WSDLEditorPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editorPart = workbenchPage.getActiveEditor();
String currentEditorId = editorPart.getEditorSite().getId();
if (resource != null && resource.startsWith(pattern)) {
Path path = new Path(resource.substring(pattern.length()));
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
if (editorPart.getEditorInput() instanceof IFileEditorInput && ((IFileEditorInput) editorPart.getEditorInput()).getFile().equals(file)) {
workbenchPage.getNavigationHistory().markLocation(editorPart);
} else {
try {
Item item = ((ServiceEditorInput) editorPart.getEditorInput()).getItem();
// TODO: Use content type as below
if (resource.endsWith("xsd")) {
//$NON-NLS-1$
editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), WSDLEditorPlugin.XSD_EDITOR_ID);
} else {
// Since we are already in the wsdleditor
editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), editorPart.getEditorSite().getId());
}
} catch (PartInitException initEx) {
ExceptionHandler.process(initEx);
}
}
try {
Class<? extends IEditorPart> theClass = editorPart.getClass();
Class<?>[] methodArgs = { String.class };
//$NON-NLS-1$
Method method = theClass.getMethod("openOnSelection", methodArgs);
Object[] args = { spec };
method.invoke(editorPart, args);
workbenchPage.getNavigationHistory().markLocation(editorPart);
} catch (Exception e) {
ExceptionHandler.process(e);
}
} else if (resource != null && resource.startsWith("http")) {
IEditorPart newEditorPart = null;
boolean doOpenWsdlEditor = true;
if (//$NON-NLS-1$
resource.endsWith("xsd")) {
doOpenWsdlEditor = false;
}
try {
IEditorReference[] refs = workbenchPage.getEditorReferences();
int length = refs.length;
// Need to find if an editor on that schema has already been opened
for (int i = 0; i < length; i++) {
IEditorInput input = refs[i].getEditorInput();
if (input instanceof ADTReadOnlyFileEditorInput) {
ADTReadOnlyFileEditorInput readOnlyEditorInput = (ADTReadOnlyFileEditorInput) input;
if (readOnlyEditorInput.getUrlString().equals(resource) && (!doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.XSD_EDITOR_ID) || doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.WSDL_EDITOR_ID))) {
newEditorPart = refs[i].getEditor(true);
workbenchPage.activate(refs[i].getPart(true));
break;
}
}
}
if (newEditorPart == null) {
ADTReadOnlyFileEditorInput readOnlyStorageEditorInput = new ADTReadOnlyFileEditorInput(resource);
IContentType contentType = null;
try (InputStream iStream = readOnlyStorageEditorInput.getStorage().getContents()) {
contentType = Platform.getContentTypeManager().findContentTypeFor(iStream, resource);
}
// content type more reliable check
if (//$NON-NLS-1$
contentType != null && contentType.equals(XSDEditorPlugin.XSD_CONTENT_TYPE_ID) || resource.endsWith("xsd")) {
readOnlyStorageEditorInput.setEditorID(WSDLEditorPlugin.XSD_EDITOR_ID);
//$NON-NLS-1$
workbenchPage.openEditor(readOnlyStorageEditorInput, WSDLEditorPlugin.XSD_EDITOR_ID, true, 0);
} else {
readOnlyStorageEditorInput.setEditorID(currentEditorId);
//$NON-NLS-1$
workbenchPage.openEditor(readOnlyStorageEditorInput, currentEditorId, true, 0);
}
}
} catch (IOException | CoreException e) {
ExceptionHandler.process(e);
}
}
}
use of org.eclipse.core.runtime.content.IContentType in project ow by vtst.
the class LessProjectPropertyPage method createContents.
@Override
protected Control createContents(Composite parent) {
Composite composite = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_BOTH);
Label label = SWTFactory.createLabel(composite, messages.getString("LessProjectPropertyPage_includePaths"), 1);
label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
includePaths.createContents(IContainer.class, composite);
label = SWTFactory.createLabel(composite, messages.getString("LessProjectPropertyPage_roots"), 1);
label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
roots.createContents(IFile.class, composite);
final IContentType lessContentType = Platform.getContentTypeManager().getContentType(LessRuntimeModule.CONTENT_TYPE_ID);
final IProject project = this.getProject();
roots.setAddFilter(new ViewerFilter() {
public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof IProject)
return project.equals(element);
else if (element instanceof IContainer)
return true;
else if (element instanceof IFile) {
IFile file = (IFile) element;
try {
if (file.getContentDescription() == null)
return false;
IContentType fileContentType = file.getContentDescription().getContentType();
if (fileContentType != null && fileContentType.isKindOf(lessContentType))
return true;
} catch (CoreException e) {
}
}
return false;
}
});
try {
includePaths.setCurrentValue(ResourceListProperty.<IContainer>get(IContainer.class, getProject(), new QualifiedName(LessProjectProperty.QUALIFIER, LessProjectProperty.INCLUDE_PATHS)));
roots.setCurrentValue(ResourceListProperty.<IFile>get(IFile.class, getProject(), new QualifiedName(LessProjectProperty.QUALIFIER, LessProjectProperty.ROOTS)));
} catch (CoreException e) {
this.setErrorMessage(e.getMessage());
}
return composite;
}
use of org.eclipse.core.runtime.content.IContentType in project che by eclipse.
the class ExtensionsRegistry method computeBaseContentTypes.
//
// /**
// * Returns a sharable annotation model factory for the given content types.
// *
// * @param contentTypes the content types used to find the factory
// * @return the sharable annotation model factory or <code>null</code>
// */
// private IAnnotationModelFactory doGetAnnotationModelFactory(IContentType[] contentTypes) {
// Set set= null;
// int i= 0;
// while (i < contentTypes.length && set == null) {
// set= (Set) fAnnotationModelFactoryDescriptors.get(new ContentTypeAdapter(contentTypes[i++]));
// }
//
// if (set != null) {
// IConfigurationElement entry= selectConfigurationElement(set);
// return (IAnnotationModelFactory) getExtension(entry, fAnnotationModelFactories, IAnnotationModelFactory.class);
// }
// return null;
// }
// /**
// * Returns a sharable annotation model factory for the given content types.
// * This method considers the base content types of the given set of content
// * types.
// *
// * @param contentTypes the content types used to find the factory
// * @return the sharable annotation model factory or <code>null</code>
// */
// protected IAnnotationModelFactory getAnnotationModelFactory(IContentType[] contentTypes) {
// IAnnotationModelFactory factory= doGetAnnotationModelFactory(contentTypes);
// while (factory == null) {
// contentTypes= computeBaseContentTypes(contentTypes);
// if (contentTypes == null)
// break;
// factory= doGetAnnotationModelFactory(contentTypes);
// }
// return factory;
// }
// /**
// * Returns a sharable annotation model factory for the given file name or file extension.
// *
// * @param extension the name or extension to be used for lookup
// * @return the sharable document factory or <code>null</code>
// */
// protected IAnnotationModelFactory getAnnotationModelFactory(String extension) {
// Set set= (Set) fAnnotationModelFactoryDescriptors.get(extension);
// if (set != null) {
// IConfigurationElement entry= selectConfigurationElement(set);
// return (IAnnotationModelFactory) getExtension(entry, fAnnotationModelFactories, IAnnotationModelFactory.class);
// }
// return null;
// }
// /**
// * Returns the set of content types for the given location.
// *
// * @param location the location for which to look up the content types
// * @param locationKind the kind of the given location
// * @return the set of content types for the location
// * @since 3.3
// */
// protected IContentType[] findContentTypes(IPath location, LocationKind locationKind) {
// Assert.isLegal(locationKind != LocationKind.IFILE);
// return fContentTypeManager.findContentTypesFor(location.lastSegment());
// }
/**
* Returns the set of direct base content types for the given set of content
* types. Returns <code>null</code> if non of the given content types has
* a direct base content type.
*
* @param contentTypes the content types
* @return the set of direct base content types
*/
private IContentType[] computeBaseContentTypes(IContentType[] contentTypes) {
List baseTypes = new ArrayList();
for (int i = 0; i < contentTypes.length; i++) {
IContentType baseType = contentTypes[i].getBaseType();
if (baseType != null)
baseTypes.add(baseType);
}
IContentType[] result = null;
int size = baseTypes.size();
if (size > 0) {
result = new IContentType[size];
baseTypes.toArray(result);
}
return result;
}
use of org.eclipse.core.runtime.content.IContentType in project ow by vtst.
the class ClosureCompiler method isJavaScriptFile.
/**
* Test whether a file is a JavaScript file (by looking at its content type).
* @param file The file to test.
* @return true iif the given file is a JavaScript file.
* @throws CoreException
*/
public static boolean isJavaScriptFile(IFile file) throws CoreException {
IContentDescription contentDescription = file.getContentDescription();
if (contentDescription == null)
return false;
IContentType contentType = contentDescription.getContentType();
if (!contentType.isKindOf(jsContentType))
return false;
if (ClosureFilePropertyRecord.getInstance().generatedByCompiler.get(new ResourcePropertyStore(file, OwJsClosurePlugin.PLUGIN_ID)))
return false;
return true;
}
Aggregations