Search in sources :

Example 1 with PathEditorInput

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

the class HexEditor method performSaveAs.

/**
 * @param progressMonitor the progress monitor to be used
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    IEditorInput input = getEditorInput();
    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    String stringOriginal = null;
    if (input instanceof IPathEditorInput) {
        stringOriginal = ((IPathEditorInput) input).getPath().toFile().getName();
    }
    if (stringOriginal != null) {
        // 
        // External file
        // 
        dialog.setFileName(stringOriginal);
    } else {
        // 
        // Shouldn't occur - ERROR
        // 
        // $NON-NLS-1$
        EhepPlugin.log("ERROR in performSaveAs()!");
        String message = MessageFormat.format(Messages.HexEditor_6, (Object[]) null);
        ErrorDialog errorDialog = new ErrorDialog(shell, message, message, null, ErrorDialog.CANCEL);
        errorDialog.open();
        return;
    }
    // else
    String path = dialog.open();
    if (path == null) {
        if (progressMonitor != null)
            progressMonitor.setCanceled(true);
        return;
    }
    IPath filePath = new Path(path);
    IWorkspace workspace = EhepPlugin.getWorkspace();
    IFile file = workspace.getRoot().getFile(filePath);
    final IEditorInput newInput = new PathEditorInput(filePath);
    boolean success = false;
    fileManager.saveFile(this, hexEditorControl.getHexTable(), filePath.toFile(), progressMonitor, true);
    try {
        file.refreshLocal(IResource.DEPTH_ONE, progressMonitor);
    } catch (CoreException e) {
        EhepPlugin.log(e);
    }
    success = true;
    if (success) {
        setInput(newInput);
    }
    if (progressMonitor != null) {
        progressMonitor.setCanceled(!success);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ErrorDialog(org.eclipse.jface.dialogs.ErrorDialog) IPathEditorInput(org.eclipse.ui.IPathEditorInput) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) FileDialog(org.eclipse.swt.widgets.FileDialog) IEditorInput(org.eclipse.ui.IEditorInput) IPathEditorInput(org.eclipse.ui.IPathEditorInput) PathEditorInput(org.jcryptool.core.operations.util.PathEditorInput)

Example 2 with PathEditorInput

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

the class AbstractEditorService method createOutputFile.

/**
 * Same as createOutputFile(InputStream is) but with custom name and file extension.
 *
 * @param name the name of the file
 * @param extension the extension 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, InputStream content) {
    File outputFile = new File(new File(DirectoryService.getTempDir()), name + getFormatedFilenumber(outputNumber++) + extension);
    RandomAccessFile raf = null;
    try {
        // $NON-NLS-1$
        raf = new RandomAccessFile(outputFile, "rw");
        int i;
        while ((i = content.read()) != -1) {
            raf.write(i);
        }
        content.close();
        raf.close();
    } catch (FileNotFoundException e) {
        // $NON-NLS-1$
        LogUtil.logError(OperationsPlugin.PLUGIN_ID, "Exception while initializing a RAF", e, false);
    } catch (IOException e) {
        // $NON-NLS-1$
        LogUtil.logError(OperationsPlugin.PLUGIN_ID, "IOException while reading/writing from a 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) RandomAccessFile(java.io.RandomAccessFile) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) PathEditorInput(org.jcryptool.core.operations.util.PathEditorInput)

Example 3 with PathEditorInput

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

the class FileExplorerView method openFile.

public boolean openFile(String path) {
    File file = new File(path);
    if (!file.exists()) {
        showErrorDialog(Messages.FileExplorerView_2);
        return false;
    }
    if (!file.canRead()) {
        showErrorDialog(Messages.FileExplorerView_3);
        return false;
    }
    if (file.isDirectory()) {
        showErrorDialog(Messages.FileExplorerView_4);
        return false;
    }
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        page.openEditor(new PathEditorInput(new Path(path)), EDITOR_ID_HEX, true, IWorkbenchPage.MATCH_NONE);
    } catch (PartInitException ex) {
        LogUtil.logError(ex);
        return false;
    }
    return true;
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) File(java.io.File) PathEditorInput(org.jcryptool.core.operations.util.PathEditorInput)

Example 4 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())), HexEditorConstants.EditorID, 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)

Example 5 with PathEditorInput

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

the class JCTTextEditor method performSaveAs.

protected void performSaveAs(IProgressMonitor monitor) {
    String queriedFilePath = queryFilePath();
    IPath path;
    if (queriedFilePath != null) {
        path = new Path(queriedFilePath);
    } else
        return;
    final IEditorInput newInput = new PathEditorInput(new Path(path.toOSString()));
    final String name = getEditorInput().getName();
    if (Pattern.matches(Messages.JCTTextEditor_4, name) || Pattern.matches(IConstants.OUTPUT_REGEXP, name)) {
        // we need the isDirty flag true to follow the default property changed order
        isDirty = true;
    }
    final boolean overwrite = checkOverwrite(queriedFilePath);
    if (!overwrite) {
        return;
    }
    final boolean success = saveFile(path.toFile(), monitor, true);
    if (success) {
        isHot = false;
        setInput(newInput);
    }
    if (monitor != null) {
        monitor.setCanceled(!success);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IEditorInput(org.eclipse.ui.IEditorInput) 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