Search in sources :

Example 61 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project bndtools by bndtools.

the class NewTypeWizardPage method typeNameChanged.

/**
     * Hook method that gets called when the type name has changed. The method validates the type name and returns the
     * status of the validation.
     * <p>
     * Subclasses may extend this method to perform their own validation.
     * </p>
     *
     * @return the status of the validation
     */
protected IStatus typeNameChanged() {
    StatusInfo status = new StatusInfo();
    fCurrType = null;
    String typeNameWithParameters = getTypeName();
    // must not be empty
    if (typeNameWithParameters.length() == 0) {
        status.setError(NewWizardMessages.NewTypeWizardPage_error_EnterTypeName);
        return status;
    }
    String typeName = getTypeNameWithoutParameters();
    if (typeName.indexOf('.') != -1) {
        status.setError(NewWizardMessages.NewTypeWizardPage_error_QualifiedName);
        return status;
    }
    IJavaProject project = getJavaProject();
    IStatus val = validateJavaTypeName(typeName, project);
    if (val.getSeverity() == IStatus.ERROR) {
        status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, val.getMessage()));
        return status;
    } else if (val.getSeverity() == IStatus.WARNING) {
        status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged, val.getMessage()));
    // continue checking
    }
    // must not exist
    if (!isEnclosingTypeSelected()) {
        IPackageFragment pack = getPackageFragment();
        if (pack != null) {
            ICompilationUnit cu = pack.getCompilationUnit(getCompilationUnitName(typeName));
            fCurrType = cu.getType(typeName);
            IResource resource = cu.getResource();
            if (resource.exists()) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
                return status;
            }
            if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameFiltered);
                return status;
            }
            URI location = resource.getLocationURI();
            if (location != null) {
                try {
                    IFileStore store = EFS.getStore(location);
                    if (store.fetchInfo().exists()) {
                        status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExistsDifferentCase);
                        return status;
                    }
                } catch (CoreException e) {
                    status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_uri_location_unkown, BasicElementLabels.getURLPart(Resources.getLocationString(resource))));
                }
            }
        }
    } else {
        IType type = getEnclosingType();
        if (type != null) {
            fCurrType = type.getType(typeName);
            if (fCurrType.exists()) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
                return status;
            }
        }
    }
    if (!typeNameWithParameters.equals(typeName) && project != null) {
        if (!JavaModelUtil.is50OrHigher(project)) {
            status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeParameters);
            return status;
        }
        //$NON-NLS-1$//$NON-NLS-2$
        String typeDeclaration = "class " + typeNameWithParameters + " {}";
        ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        parser.setSource(typeDeclaration.toCharArray());
        parser.setProject(project);
        CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
        IProblem[] problems = compilationUnit.getProblems();
        if (problems.length > 0) {
            status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage()));
            return status;
        }
    }
    return status;
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IStatus(org.eclipse.core.runtime.IStatus) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) URI(java.net.URI) IProblem(org.eclipse.jdt.core.compiler.IProblem) IType(org.eclipse.jdt.core.IType) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) StatusInfo(org.eclipse.jdt.internal.ui.dialogs.StatusInfo) IFileStore(org.eclipse.core.filesystem.IFileStore) ASTParser(org.eclipse.jdt.core.dom.ASTParser) IResource(org.eclipse.core.resources.IResource)

Example 62 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method performSaveAs.

/**
 * This implementation asks the user for the workspace path of a file resource and saves the document there.
 *
 * @param progressMonitor the progress monitor to be used
 * @since 3.2
 */
@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
    final IEditorInput input = getEditorInput();
    IDocumentProvider provider = getDocumentProvider();
    final IEditorInput newInput;
    if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) {
        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
        if (oldPath != null && !oldPath.isEmpty()) {
            dialog.setFileName(oldPath.lastSegment());
            dialog.setFilterPath(oldPath.removeLastSegments(1).toOSString());
        }
        String path = dialog.open();
        if (path == null) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }
        // Check whether file exists and if so, confirm overwrite
        final File localFile = new File(path);
        if (localFile.exists()) {
            MessageDialog overwriteDialog = new MessageDialog(shell, TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_title, null, NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_message, path), MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, // 'No' is the default
            1);
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }
        IFileStore fileStore;
        try {
            fileStore = EFS.getStore(localFile.toURI());
        } catch (CoreException ex) {
            EditorsPlugin.log(ex.getStatus());
            String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
            String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message, ex.getMessage());
            MessageDialog.openError(shell, title, msg);
            return;
        }
        IFile file = getWorkspaceFile(fileStore);
        if (file != null)
            newInput = new FileEditorInput(file);
        else
            newInput = new FileStoreEditorInput(fileStore);
    } else {
        SaveAsDialog dialog = new SaveAsDialog(shell);
        IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
        if (original != null)
            dialog.setOriginalFile(original);
        else
            dialog.setOriginalName(input.getName());
        dialog.create();
        if (provider.isDeleted(input) && original != null) {
            String message = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_warning_saveAs_deleted, original.getName());
            dialog.setErrorMessage(null);
            dialog.setMessage(message, IMessageProvider.WARNING);
        }
        if (dialog.open() == Window.CANCEL) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }
        IPath filePath = dialog.getResult();
        if (filePath == null) {
            if (progressMonitor != null)
                progressMonitor.setCanceled(true);
            return;
        }
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IFile file = workspace.getRoot().getFile(filePath);
        newInput = new FileEditorInput(file);
    }
    if (provider == null) {
        // editor has programmatically been  closed while the dialog was open
        return;
    }
    boolean success = false;
    try {
        provider.aboutToChange(newInput);
        provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
        success = true;
    } catch (CoreException x) {
        final IStatus status = x.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
            String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message, x.getMessage());
            MessageDialog.openError(shell, title, msg);
        }
    } finally {
        provider.changed(newInput);
        if (success)
            setInput(newInput);
    }
    if (progressMonitor != null)
        progressMonitor.setCanceled(!success);
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkspace(org.eclipse.core.resources.IWorkspace) IFileStore(org.eclipse.core.filesystem.IFileStore) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 63 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.

the class FileBufferFunctions method testGetFileStoreAnnotationModel.

/*
	 * Tests isSynchronized.
	 */
@Test
public void testGetFileStoreAnnotationModel() throws Exception {
    IFileStore fileStore = EFS.getNullFileSystem().getStore(new Path("/dev/null"));
    assertNotNull(fileStore);
    fManager.connectFileStore(fileStore, null);
    try {
        ITextFileBuffer fileBuffer = fManager.getFileStoreTextFileBuffer(fileStore);
        IAnnotationModel model = fileBuffer.getAnnotationModel();
        Class<IAnnotationModel> clazz = getAnnotationModelClass();
        if (clazz != null)
            assertTrue(clazz.isInstance(model));
        else
            assertNotNull(model);
    } finally {
        fManager.disconnectFileStore(fileStore, null);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Test(org.junit.Test)

Example 64 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.

the class FileBuffersForFilesInLinkedFolders method modifyUnderlyingFile.

@Override
protected boolean modifyUnderlyingFile() throws Exception {
    IFileStore fileStore = FileBuffers.getFileStoreAtLocation(getPath());
    assertTrue(fileStore.fetchInfo().exists());
    OutputStream out = fileStore.openOutputStream(EFS.NONE, null);
    try {
        out.write("Changed content of file in linked folder".getBytes());
        out.flush();
    } catch (IOException x) {
        fail();
    } finally {
        out.close();
    }
    IFileInfo fileInfo = fileStore.fetchInfo();
    fileInfo.setLastModified(1000);
    fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
    IFile iFile = FileBuffers.getWorkspaceFileAtLocation(getPath());
    iFile.refreshLocal(IResource.DEPTH_INFINITE, null);
    return true;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFile(org.eclipse.core.resources.IFile) OutputStream(java.io.OutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException)

Example 65 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project eclipse.platform.text by eclipse.

the class FileBuffersForNonExistingExternalFiles method setReadOnly.

/*
	 * @see org.eclipse.core.filebuffers.tests.FileBufferFunctions#markReadOnly()
	 */
@Override
protected void setReadOnly(boolean state) throws Exception {
    IFileStore fileStore = FileBuffers.getFileStoreAtLocation(getPath());
    assertNotNull(fileStore);
    fileStore.fetchInfo().setAttribute(EFS.ATTRIBUTE_READ_ONLY, state);
}
Also used : IFileStore(org.eclipse.core.filesystem.IFileStore)

Aggregations

IFileStore (org.eclipse.core.filesystem.IFileStore)105 CoreException (org.eclipse.core.runtime.CoreException)49 IPath (org.eclipse.core.runtime.IPath)29 IOException (java.io.IOException)26 IFileInfo (org.eclipse.core.filesystem.IFileInfo)25 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)18 URI (java.net.URI)16 InputStream (java.io.InputStream)14 Path (org.eclipse.core.runtime.Path)14 IFile (org.eclipse.core.resources.IFile)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)12 InputStreamReader (java.io.InputStreamReader)11 PartInitException (org.eclipse.ui.PartInitException)11 BufferedReader (java.io.BufferedReader)10 URISyntaxException (java.net.URISyntaxException)10 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)10 Test (org.junit.Test)10 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)9 IStatus (org.eclipse.core.runtime.IStatus)9