Search in sources :

Example 11 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project tdi-studio-se by Talend.

the class ActiveJvm method saveJvmProperties.

/**
     * Saves the JVM properties.
     */
public void saveJvmProperties() {
    IFileStore fileStore;
    try {
        fileStore = Util.getFileStore(IJvm.PROPERTIES_FILE, getBaseDirectory());
        if (fileStore.fetchInfo().exists()) {
            return;
        }
    } catch (JvmCoreException e) {
        Activator.log(IStatus.ERROR, Messages.savePropertiesFileFailedMsg, e);
        return;
    }
    Properties props = new Properties();
    OutputStream os = null;
    try {
        os = fileStore.openOutputStream(EFS.NONE, null);
        int pid = getPid();
        int port = getPort();
        String mainClass = getMainClass();
        props.setProperty(IJvm.PID_PROP_KEY, String.valueOf(pid));
        props.setProperty(IJvm.PORT_PROP_KEY, String.valueOf(port));
        if (mainClass != null) {
            props.setProperty(IJvm.MAIN_CLASS_PROP_KEY, mainClass);
        }
        props.setProperty(IJvm.HOST_PROP_KEY, getHost().getName());
        //$NON-NLS-1$
        props.storeToXML(os, "JVM Properties");
    } catch (CoreException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.openOutputStreamFailedMsg, fileStore.toURI().getPath()), e);
    } catch (IOException e) {
        try {
            fileStore.delete(EFS.NONE, null);
        } catch (CoreException e1) {
        // do nothing
        }
        Activator.log(IStatus.ERROR, NLS.bind(Messages.writePropertiesFileFailedMsg, fileStore.toURI().getPath()), e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException) OutputStream(java.io.OutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) Properties(java.util.Properties) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 12 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project KaiZen-OpenAPI-Editor by RepreZen.

the class DocumentUtils method getExternalFile.

public static IFileStore getExternalFile(IPath path) {
    IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
    IFileInfo fileInfo = fileStore.fetchInfo();
    return fileInfo != null && fileInfo.exists() ? fileStore : null;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFileStore(org.eclipse.core.filesystem.IFileStore)

Example 13 with IFileStore

use of org.eclipse.core.filesystem.IFileStore in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method performSaveAs.

/**
	 * 执行另存为
	 * @param progressMonitor
	 *            进度条;
	 */
private void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    final IEditorInput input = getEditorInput();
    // 新的EditorInput
    final IEditorInput newInput;
    // 原始的file
    final File oldFile;
    // if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) { // 外部文件
    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    URI uri = ((IURIEditorInput) input).getURI();
    IPath oldPath = URIUtil.toPath(uri);
    if (oldPath != null) {
        dialog.setFileName(oldPath.lastSegment());
        // 设置所在文件夹
        dialog.setFilterPath(oldPath.removeLastSegments(1).toOSString());
        oldFile = oldPath.toFile();
    } else {
        oldFile = new File(uri);
    }
    // 得到保存路径
    String newPath = dialog.open();
    if (newPath == null) {
        if (progressMonitor != null)
            progressMonitor.setCanceled(true);
        return;
    }
    // 检查文件是否存在,如果存在则确认是否覆盖
    final File localFile = new File(newPath);
    if (localFile.exists()) {
        String msg = MessageFormat.format(Messages.getString("editor.XLIFFEditorImplWithNatTable.msg1"), newPath);
        MessageDialog overwriteDialog = new MessageDialog(shell, Messages.getString("editor.XLIFFEditorImplWithNatTable.overwriteDialog"), null, msg, MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1);
        if (overwriteDialog.open() != MessageDialog.OK) {
            if (progressMonitor != null) {
                progressMonitor.setCanceled(true);
                return;
            }
        }
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    // 得到新文件
    IFile file = root.getFileForLocation(URIUtil.toPath(localFile.toURI()));
    if (file != null) {
        // 是“WorkSpace”内的文件
        newInput = new FileEditorInput(file);
    } else {
        // 不是“WorkSpace”内的文件
        try {
            IFileStore fileStore = EFS.getStore(localFile.toURI());
            newInput = new FileStoreEditorInput(fileStore);
        } catch (CoreException ex) {
            // EditorsPlugin.log(ex.getStatus());
            LOGGER.error("", ex);
            String title = Messages.getString("editor.XLIFFEditorImplWithNatTable.msgTitle1");
            String msg = MessageFormat.format(Messages.getString("editor.XLIFFEditorImplWithNatTable.msg2"), ex.getMessage());
            MessageDialog.openError(shell, title, msg);
            return;
        }
    }
    // } else {
    // SaveAsDialog dialog = new SaveAsDialog(shell);
    // // 源文件
    // IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
    // if (original != null) {
    // dialog.setOriginalFile(original); // 添加源文件信息
    // oldFile = original.getLocation().toFile();
    // if ((!oldFile.exists() || !oldFile.canRead()) && original != null) {
    // String message = MessageFormat.format(
    // "The original file ''{0}'' has been deleted or is not accessible.", original.getName());
    // dialog.setErrorMessage(null);
    // dialog.setMessage(message, IMessageProvider.WARNING);
    // }
    // } else {
    // oldFile = null;
    // }
    // dialog.create();
    //
    // if (dialog.open() == MessageDialog.CANCEL) { // 打开“另存为”对话框,用户点击了“取消”按钮
    // if (progressMonitor != null)
    // progressMonitor.setCanceled(true);
    // return;
    // }
    //
    // IPath filePath = dialog.getResult(); // 获得用户选择的路径
    // if (filePath == null) { // 检查路径
    // if (progressMonitor != null)
    // progressMonitor.setCanceled(true);
    // return;
    // }
    //
    // IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    // IFile file = root.getFile(filePath);
    // newInput = new FileEditorInput(file);
    // }
    saveAs(newInput, oldFile, progressMonitor);
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) URI(java.net.URI) Shell(org.eclipse.swt.widgets.Shell) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IFileStore(org.eclipse.core.filesystem.IFileStore) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 14 with IFileStore

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

the class FileBufferFunctions method test5.

/*
	 * Tests getModificationStamp.
	 */
@Test
public void test5() throws Exception {
    fManager.connect(fPath, LocationKind.NORMALIZE, null);
    try {
        ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
        long modificationStamp = fileBuffer.getModificationStamp();
        IFileStore fileStore = FileBuffers.getFileStoreAtLocation(fPath);
        IFileInfo fileInfo = fileStore.fetchInfo();
        assertEquals(modificationStamp != IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP, fileInfo.exists());
        fileInfo.setLastModified(1000);
        if (fileInfo.exists())
            fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
        long lastModified = fileStore.fetchInfo().getLastModified();
        assertTrue(lastModified == EFS.NONE || modificationStamp != fileBuffer.getModificationStamp());
    } finally {
        fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) Test(org.junit.Test)

Example 15 with IFileStore

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

the class FileBuffersForExternalFiles method setReadOnly.

@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)178 CoreException (org.eclipse.core.runtime.CoreException)80 IOException (java.io.IOException)49 IPath (org.eclipse.core.runtime.IPath)42 IFileInfo (org.eclipse.core.filesystem.IFileInfo)33 URI (java.net.URI)30 Path (org.eclipse.core.runtime.Path)30 IFile (org.eclipse.core.resources.IFile)28 PartInitException (org.eclipse.ui.PartInitException)25 File (java.io.File)22 InputStream (java.io.InputStream)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)21 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)18 InputStreamReader (java.io.InputStreamReader)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)14 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)14 BufferedInputStream (java.io.BufferedInputStream)13 BufferedReader (java.io.BufferedReader)13 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)11 IStatus (org.eclipse.core.runtime.IStatus)11