Search in sources :

Example 11 with PathEditorInput

use of org.jcryptool.core.operations.util.PathEditorInput in project core by jcryptool.

the class AbstractEditorService method createOutputFile.

/**
 * Same as createOutputFile(String content) but with custom name.
 *
 * @param name the name of the file
 * @param content the content of the file
 * @return An IEditorInput of an output file
 */
public static final IEditorInput createOutputFile(String name, String content) {
    File outputFile = new File(new File(DirectoryService.getTempDir()), name + getFormatedFilenumber(outputNumber++) + IConstants.TXT_FILE_TYPE_EXTENSION);
    try {
        PrintWriter p = new PrintWriter(outputFile);
        p.print(content);
        p.flush();
        p.close();
    } catch (IOException e) {
        // $NON-NLS-1$
        LogUtil.logError(OperationsPlugin.PLUGIN_ID, "Exception while writing to an output stream", e, false);
    }
    outputFile.deleteOnExit();
    return new PathEditorInput(new Path(outputFile.getAbsolutePath()));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) PrintWriter(java.io.PrintWriter) PathEditorInput(org.jcryptool.core.operations.util.PathEditorInput)

Example 12 with PathEditorInput

use of org.jcryptool.core.operations.util.PathEditorInput in project core by jcryptool.

the class AbstractEditorService method createOutputFile.

/**
 * Same as createOutputFile(byte[] name) but with custom name.
 *
 * @param name the name of the file
 * @param content the content of the file
 * @return An IEditorInput of an output file
 */
public static final IEditorInput createOutputFile(String name, String extension, byte[] content) {
    File outputFile = new File(new File(DirectoryService.getTempDir()), name + getFormatedFilenumber(outputNumber++) + extension);
    try {
        FileOutputStream fos = new FileOutputStream(outputFile);
        fos.write(content);
        fos.flush();
        fos.close();
    } catch (IOException ex) {
        LogUtil.logError(OperationsPlugin.PLUGIN_ID, ex);
    }
    outputFile.deleteOnExit();
    return new PathEditorInput(new Path(outputFile.getAbsolutePath()));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) PathEditorInput(org.jcryptool.core.operations.util.PathEditorInput)

Example 13 with PathEditorInput

use of org.jcryptool.core.operations.util.PathEditorInput in project core by jcryptool.

the class OpenEditorHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        IFileStore file = (IFileStore) ((IStructuredSelection) selection).getFirstElement();
        if (file != null) {
            try {
                page.openEditor(new PathEditorInput(new Path(file.toURI().getPath())), JCTTextEditor.ID, true, IWorkbenchPage.MATCH_NONE);
            } catch (PartInitException ex) {
                LogUtil.logError(ex);
            }
        }
    }
    return null;
}
Also used : Path(org.eclipse.core.runtime.Path) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFileStore(org.eclipse.core.filesystem.IFileStore) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) PathEditorInput(org.jcryptool.core.operations.util.PathEditorInput)

Aggregations

PathEditorInput (org.jcryptool.core.operations.util.PathEditorInput)13 Path (org.eclipse.core.runtime.Path)11 PartInitException (org.eclipse.ui.PartInitException)7 File (java.io.File)6 IPath (org.eclipse.core.runtime.IPath)6 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)5 IOException (java.io.IOException)4 RandomAccessFile (java.io.RandomAccessFile)3 IFileStore (org.eclipse.core.filesystem.IFileStore)3 ISelection (org.eclipse.jface.viewers.ISelection)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 IEditorInput (org.eclipse.ui.IEditorInput)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 IFile (org.eclipse.core.resources.IFile)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 CoreException (org.eclipse.core.runtime.CoreException)1