Search in sources :

Example 6 with QualifiedName

use of org.eclipse.core.runtime.QualifiedName in project che by eclipse.

the class FileStoreTextFileBuffer method cacheEncodingState.

protected void cacheEncodingState() {
    fEncoding = fExplicitEncoding;
    fHasBOM = false;
    fIsCacheUpdated = true;
    InputStream stream = null;
    try {
        stream = getFileContents(fFileStore);
        if (stream == null)
            return;
        QualifiedName[] options = new QualifiedName[] { IContentDescription.CHARSET, IContentDescription.BYTE_ORDER_MARK };
        //Platform.getContentTypeManager().getDescriptionFor(stream, fFileStore.getName(), options);
        IContentDescription description = null;
        if (description != null) {
            fHasBOM = description.getProperty(IContentDescription.BYTE_ORDER_MARK) != null;
            if (fEncoding == null)
                fEncoding = description.getCharset();
        }
    } catch (CoreException e) {
    // do nothing
    } finally /*catch (IOException e) {
			// do nothing
		}*/
    {
        try {
            if (stream != null)
                stream.close();
        } catch (IOException ex) {
            FileBuffersPlugin.getDefault().log(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.JavaTextFileBuffer_error_closeStream, ex));
        }
    }
    // Use global default
    if (fEncoding == null)
        fEncoding = fManager.getDefaultEncoding();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) QualifiedName(org.eclipse.core.runtime.QualifiedName) IOException(java.io.IOException) IContentDescription(org.eclipse.core.runtime.content.IContentDescription)

Example 7 with QualifiedName

use of org.eclipse.core.runtime.QualifiedName in project dbeaver by serge-rider.

the class NavigatorHandlerObjectCreateCopy method copyResource.

private void copyResource(@NotNull DBRProgressMonitor monitor, @NotNull IResource resource, @NotNull IContainer targetFolder) throws CoreException, IOException {
    final IProgressMonitor nestedMonitor = RuntimeUtils.getNestedMonitor(monitor);
    final String extension = resource.getFileExtension();
    String targetName = resource.getName();
    if (resource.getParent().equals(targetFolder)) {
        String plainName = extension != null && !extension.isEmpty() && targetName.endsWith(extension) ? targetName.substring(0, targetName.length() - extension.length() - 1) : targetName;
        for (int i = 1; ; i++) {
            String testName = plainName + "-" + i;
            if (!CommonUtils.isEmpty(extension)) {
                testName += "." + extension;
            }
            if (targetFolder.findMember(testName) == null) {
                targetName = testName;
                break;
            }
        }
    } else if (targetFolder.findMember(targetName) != null) {
        throw new IOException("Target resource '" + targetName + "' already exists");
    }
    if (resource instanceof IFile) {
        // Copy single file
        final IFile targetFile = targetFolder.getFile(new Path(targetName));
        if (!targetFile.exists()) {
            targetFile.create(new ByteArrayInputStream(new byte[0]), true, nestedMonitor);
        }
        final Map<QualifiedName, String> props = resource.getPersistentProperties();
        if (props != null && !props.isEmpty()) {
            for (Map.Entry<QualifiedName, String> prop : props.entrySet()) {
                targetFile.setPersistentProperty(prop.getKey(), prop.getValue());
            }
        }
        try (InputStream is = ((IFile) resource).getContents()) {
            targetFile.setContents(is, true, true, nestedMonitor);
        }
    } else if (resource instanceof IFolder) {
    // Copy folder with all files and subfolders
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) QualifiedName(org.eclipse.core.runtime.QualifiedName) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Map(java.util.Map) IFolder(org.eclipse.core.resources.IFolder)

Example 8 with QualifiedName

use of org.eclipse.core.runtime.QualifiedName in project ow by vtst.

the class NatureAddingEditorCallback method afterCreatePartControl.

@Override
public void afterCreatePartControl(XtextEditor editor) {
    try {
        super.afterCreatePartControl(editor);
        IResource resource = editor.getResource();
        if (resource == null)
            return;
        IProject project = resource.getProject();
        if (DISABLE.equals(project.getPersistentProperty(new QualifiedName(QUALIFIER, projectNature.getId()))))
            return;
        if (!ProjectNatureUtil.hasNature(getNature().getId(), project) && project.isAccessible()) {
            MessageDialog dialog = new MessageDialog(editor.getEditorSite().getShell(), messages.format("add_nature_to_project_title", getNature().getName()), null, messages.format("add_nature_to_project_message", getNature().getName(), project.getName()), MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            int ret = dialog.open();
            if (ret == 0) {
                ProjectNatureUtil.addNatureRequiringXtext(getNature().getId(), project);
            } else if (ret == 1) {
                project.setPersistentProperty(new QualifiedName(QUALIFIER, projectNature.getId()), DISABLE);
            }
        }
    } catch (CoreException e) {
        ErrorDialog.openError(editor.getSite().getShell(), messages.format("add_nature_to_project_title", getNature().getName()), messages.getString("add_nature_to_project_error"), e.getStatus());
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) QualifiedName(org.eclipse.core.runtime.QualifiedName) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Aggregations

QualifiedName (org.eclipse.core.runtime.QualifiedName)8 CoreException (org.eclipse.core.runtime.CoreException)4 IFile (org.eclipse.core.resources.IFile)3 Map (java.util.Map)2 IContainer (org.eclipse.core.resources.IContainer)2 IProject (org.eclipse.core.resources.IProject)2 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SequenceInputStream (java.io.SequenceInputStream)1 HashMap (java.util.HashMap)1 ZipEntry (java.util.zip.ZipEntry)1 IFolder (org.eclipse.core.resources.IFolder)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1 Status (org.eclipse.core.runtime.Status)1