use of org.eclipse.core.runtime.content.IContentDescription in project dbeaver by serge-rider.
the class ProjectExportWizard method saveResourceProperties.
private void saveResourceProperties(IResource resource, XMLBuilder xml) throws CoreException, IOException {
if (resource instanceof IFile) {
final IContentDescription contentDescription = ((IFile) resource).getContentDescription();
if (contentDescription != null && contentDescription.getCharset() != null) {
xml.addAttribute(ExportConstants.ATTR_CHARSET, contentDescription.getCharset());
//xml.addAttribute(ExportConstants.ATTR_CHARSET, contentDescription.getContentType());
}
} else if (resource instanceof IFolder) {
xml.addAttribute(ExportConstants.ATTR_DIRECTORY, true);
}
for (Object entry : resource.getPersistentProperties().entrySet()) {
Map.Entry<?, ?> propEntry = (Map.Entry<?, ?>) entry;
xml.startElement(ExportConstants.TAG_ATTRIBUTE);
final QualifiedName attrName = (QualifiedName) propEntry.getKey();
xml.addAttribute(ExportConstants.ATTR_QUALIFIER, attrName.getQualifier());
xml.addAttribute(ExportConstants.ATTR_NAME, attrName.getLocalName());
xml.addAttribute(ExportConstants.ATTR_VALUE, (String) propEntry.getValue());
xml.endElement();
}
}
use of org.eclipse.core.runtime.content.IContentDescription in project eclipse.platform.text by eclipse.
the class FileStoreTextFileBuffer method cacheEncodingState.
protected void cacheEncodingState() {
fEncoding = fExplicitEncoding;
fHasBOM = false;
fIsCacheUpdated = true;
try (InputStream stream = getFileContents(fFileStore)) {
if (stream == null)
return;
QualifiedName[] options = new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK };
IContentDescription description = Platform.getContentTypeManager().getDescriptionFor(stream, fFileStore.getName(), options);
if (description != null) {
fHasBOM = description.getProperty(IContentDescription.BYTE_ORDER_MARK) != null;
if (fEncoding == null)
fEncoding = description.getCharset();
}
} catch (CoreException e) {
// do nothing
} catch (IOException e) {
// do nothing
}
// Use global default
if (fEncoding == null)
fEncoding = fManager.getDefaultEncoding();
}
use of org.eclipse.core.runtime.content.IContentDescription in project eclipse.platform.text by eclipse.
the class ResourceTextFileBufferManager method isTextFileLocation.
@Override
public boolean isTextFileLocation(IPath location, boolean strict) {
Assert.isNotNull(location);
location = FileBuffers.normalizeLocation(location);
IFile file = FileBuffers.getWorkspaceFileAtLocation(location, true);
if (file != null) {
if (file.exists()) {
try {
IContentDescription description = file.getContentDescription();
if (description != null) {
IContentType type = description.getContentType();
if (type != null)
return type.isKindOf(TEXT_CONTENT_TYPE);
}
} catch (CoreException x) {
// ignore: API specification tells return true if content type can't be determined
}
} else {
IContentTypeManager manager = Platform.getContentTypeManager();
IContentType[] contentTypes = manager.findContentTypesFor(file.getName());
if (contentTypes != null && contentTypes.length > 0) {
for (IContentType contentType : contentTypes) if (contentType.isKindOf(TEXT_CONTENT_TYPE))
return true;
return false;
}
}
return !strict;
}
return isTextFileLocation(FileBuffers.getFileStoreAtLocation(location), strict);
}
use of org.eclipse.core.runtime.content.IContentDescription in project eclipse.platform.text by eclipse.
the class TextFileBufferManager method isTextFileLocation.
/**
* Returns whether a file store at the given location is or can be considered a
* text file. If the file store exists, the concrete content type of the file store is
* checked. If the concrete content type for the existing file store can not be
* determined, this method returns <code>!strict</code>. If the file store does
* not exist, it is checked whether a text content type is associated with
* the given location. If no content type is associated with the location,
* this method returns <code>!strict</code>.
* <p>
* The provided location is either a full path of a workspace resource or an
* absolute path in the local file system. The file buffer manager does not
* resolve the location of workspace resources in the case of linked
* resources.
* </p>
*
* @param fileStore file store to check
* @param strict <code>true</code> if a file with unknown content type
* is not treated as text file, <code>false</code> otherwise
* @return <code>true</code> if the location is a text file location
* @since 3.3
*/
protected boolean isTextFileLocation(IFileStore fileStore, boolean strict) {
if (fileStore == null)
return false;
IContentTypeManager manager = Platform.getContentTypeManager();
IFileInfo fileInfo = fileStore.fetchInfo();
if (fileInfo.exists()) {
try (InputStream is = fileStore.openInputStream(EFS.NONE, null)) {
IContentDescription description = manager.getDescriptionFor(is, fileStore.getName(), IContentDescription.ALL);
if (description != null) {
IContentType type = description.getContentType();
if (type != null)
return type.isKindOf(TEXT_CONTENT_TYPE);
}
} catch (CoreException ex) {
// ignore: API specification tells return true if content type can't be determined
} catch (IOException ex) {
// ignore: API specification tells return true if content type can't be determined
}
return !strict;
}
IContentType[] contentTypes = manager.findContentTypesFor(fileStore.getName());
if (contentTypes != null && contentTypes.length > 0) {
for (IContentType contentType : contentTypes) if (contentType.isKindOf(TEXT_CONTENT_TYPE))
return true;
return false;
}
return !strict;
}
use of org.eclipse.core.runtime.content.IContentDescription in project liferay-ide by liferay.
the class CodePropertyEditorRenderer method createContents.
@Override
protected void createContents(Composite parent) {
PropertyEditorPart part = getPart();
Composite scriptEditorParent = createMainComposite(parent, new CreateMainCompositeDelegate(part) {
@Override
public boolean canScaleVertically() {
return true;
}
});
context.adapt(scriptEditorParent);
int textFieldParentColumns = 1;
SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation(getActionPresentationManager());
boolean actionsToolBarNeeded = toolBarActionsPresentation.hasActions();
if (actionsToolBarNeeded || true)
textFieldParentColumns++;
scriptEditorParent.setLayout(glayout(textFieldParentColumns, 0, 0, 0, 0));
Composite nestedComposite = new Composite(scriptEditorParent, SWT.NONE);
nestedComposite.setLayoutData(gdfill());
nestedComposite.setLayout(glspacing(glayout(2, 0, 0), 2));
this.context.adapt(nestedComposite);
PropertyEditorAssistDecorator decorator = createDecorator(nestedComposite);
decorator.control().setLayoutData(gdvalign(gd(), SWT.TOP));
decorator.addEditorControl(nestedComposite);
/*
* scriptEditorParent.setLayout( new FillLayout( SWT.HORIZONTAL ) );
* scriptEditorParent.setLayoutData( gdhhint( gdfill(), 300 ) );
*/
PropertyEditorInput editorInput = new PropertyEditorInput(part.getLocalModelElement(), (ValueProperty) part.getProperty());
try {
ScriptLanguageType scriptLang = context.getPart().getLocalModelElement().nearest(IScriptable.class).getScriptLanguage().getContent(false);
String fileName = scriptLang.getClass().getField(scriptLang.toString()).getAnnotation(DefaultValue.class).text();
IContentDescription contentDescription = ContentTypeManager.getInstance().getDescriptionFor(editorInput.getStorage().getContents(), fileName, IContentDescription.ALL);
EditorDescriptor defaultEditor = (EditorDescriptor) PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(editorInput.getName(), contentDescription.getContentType());
_textEditor = (ITextEditor) defaultEditor.createEditor();
} catch (Exception e1) {
}
IEditorReference ref = new ScriptEditorReference(_textEditor, editorInput);
IEditorSite site = new ScriptEditorSite(ref, _textEditor, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage());
try {
_textEditor.init(site, editorInput);
_textEditor.getDocumentProvider().getDocument(editorInput).addDocumentListener(new IDocumentListener() {
public void documentAboutToBeChanged(DocumentEvent event) {
}
public void documentChanged(DocumentEvent event) {
String content = event.getDocument().get();
part.getLocalModelElement().write(((ValueProperty) part.getProperty()), content);
}
});
ModelPropertyListener modelListener = new ModelPropertyListener() {
@Override
public void handlePropertyChangedEvent(ModelPropertyChangeEvent event) {
CodePropertyEditorRenderer.this.textEditor.getDocumentProvider().getDocument(editorInput).set(part.getLocalModelElement().read(getProperty()).getText());
}
};
part.getLocalModelElement().addListener(modelListener, part.getProperty().getName());
} catch (PartInitException pie) {
pie.printStackTrace();
}
Control[] prevChildren = scriptEditorParent.getChildren();
// _textEditor.createPartControl( scriptEditorParent );
new Label(scriptEditorParent, SWT.NONE);
Control[] newChildren = scriptEditorParent.getChildren();
decorator.addEditorControl(newChildren[prevChildren.length], true);
if (actionsToolBarNeeded) {
ToolBar toolbar = new ToolBar(scriptEditorParent, SWT.FLAT | SWT.HORIZONTAL);
toolbar.setLayoutData(gdvfill());
toolBarActionsPresentation.setToolBar(toolbar);
toolBarActionsPresentation.render();
context.adapt(toolbar);
decorator.addEditorControl(toolbar);
// relatedControls.add( toolbar );
}
}
Aggregations