Search in sources :

Example 6 with PathEditorInput

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

the class CryptoHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    getPreferenceValues();
    if (openSourceFile) {
        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())), FileExplorerView.EDITOR_ID_HEX, 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 7 with PathEditorInput

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

the class FileOpener method open.

public static void open(String filename) {
    final IPath path = new Path(filename);
    final String editorId = getEditorId(path.toOSString());
    if (editorId != null) {
        try {
            if (editorId.equals(TEXT_EDITOR)) {
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new PathEditorInput(path.toOSString()), editorId, true, IWorkbenchPage.MATCH_NONE);
            } else if (editorId.equals(HEX_EDITOR)) {
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new PathEditorInput(path.toOSString()), editorId, true, IWorkbenchPage.MATCH_NONE);
            }
        } catch (final PartInitException ex) {
            MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.OpenFileAction_title_could_not_open, NLS.bind(Messages.OpenFileAction_message_could_not_open, editorId));
            LogUtil.logError(ex);
        }
    } else {
        // no editor is associated
        MessageDialog.openInformation(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.OpenFileAction_title_could_not_open, NLS.bind(Messages.OpenFileAction_message_assign_editor, path.getFileExtension()));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) PartInitException(org.eclipse.ui.PartInitException) PathEditorInput(org.jcryptool.core.operations.util.PathEditorInput)

Example 8 with PathEditorInput

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

the class AlgorithmTreeViewer method openFile.

public boolean openFile(String path) {
    File file = new File(path);
    if (!file.exists()) {
        showErrorDialog(Messages.AlgorithmTreeViewer_error, Messages.AlgorithmTreeViewer_1);
        return false;
    }
    if (!file.canRead()) {
        showErrorDialog(Messages.AlgorithmTreeViewer_error, Messages.AlgorithmTreeViewer_2);
        return false;
    }
    if (file.isDirectory()) {
        showErrorDialog(Messages.AlgorithmTreeViewer_error, Messages.AlgorithmTreeViewer_3);
        return false;
    }
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        page.openEditor(new PathEditorInput(new Path(path)), IOperationsConstants.ID_HEX_EDITOR);
    } 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 9 with PathEditorInput

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

the class EditorDragListener method dragSetData.

public void dragSetData(DragSourceEvent event) {
    Object selected = viewer.getTree().getSelection()[0].getData();
    if (selected instanceof InputNode) {
        InputNode node = (InputNode) selected;
        // $NON-NLS-1$
        LogUtil.logInfo("Input: " + node.getInput());
        if (!node.getInput().equals("-1") && !node.getInput().equals(Messages.InputType)) {
            // $NON-NLS-1$
            EditorInputTransfer.EditorInputData data = EditorInputTransfer.createEditorInputData(IOperationsConstants.ID_HEX_EDITOR, // $NON-NLS-1$
            new PathEditorInput(node.getInput()));
            event.data = new EditorInputTransfer.EditorInputData[] { data };
        }
    } else if (selected instanceof OutputNode) {
        OutputNode node = (OutputNode) selected;
        // $NON-NLS-1$
        LogUtil.logInfo("Output: " + node.getOutput());
        if (!node.getOutput().equals("-1") && !node.getOutput().equals("<Editor>")) {
            // $NON-NLS-1$
            EditorInputTransfer.EditorInputData data = EditorInputTransfer.createEditorInputData(IOperationsConstants.ID_HEX_EDITOR, // $NON-NLS-1$
            new PathEditorInput(node.getOutput()));
            event.data = new EditorInputTransfer.EditorInputData[] { data };
        }
    }
}
Also used : InputNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.InputNode) EditorInputTransfer(org.eclipse.ui.part.EditorInputTransfer) OutputNode(org.jcryptool.crypto.flexiprovider.operations.ui.views.nodes.io.OutputNode) PathEditorInput(org.jcryptool.core.operations.util.PathEditorInput)

Example 10 with PathEditorInput

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

the class SecureRandomEngine method perform.

@Override
public void perform(KeyObject usedKey) {
    if (initialized) {
        // $NON-NLS-1$
        LogUtil.logInfo("performing a secure random");
        OutputStream outputStream = initOutput(operation.getOutput());
        try {
            if (operation.getOutput().equals("<Editor>")) {
                // $NON-NLS-1$
                byte[][] alphabet = ((SecureRandomDescriptor) operation.getAlgorithmDescriptor()).getAlphabet();
                if (alphabet == null) {
                    random.nextBytes(value);
                    outputStream.write(value);
                    outputStream.close();
                    EditorsManager.getInstance().openNewHexEditor(AbstractEditorService.createOutputFile(new FileInputStream(new File(getOutputURI()))));
                } else {
                    value = new byte[1];
                    int log = (int) Math.pow(2, Math.ceil((Math.log(alphabet.length) / Math.log(2))));
                    for (int i = 0; i < ((SecureRandomDescriptor) operation.getAlgorithmDescriptor()).getLength(); i++) {
                        boolean found = false;
                        while (!found) {
                            random.nextBytes(value);
                            // modulo
                            int r = (int) ((int) value[0] & (log - 1));
                            if (r < 0)
                                r += log;
                            if (r < alphabet.length) {
                                outputStream.write(alphabet[r]);
                                found = true;
                                if ((i + 1) % 20 == 0)
                                    // $NON-NLS-1$
                                    outputStream.write("\n".getBytes());
                            }
                        }
                    }
                    outputStream.close();
                    EditorsManager.getInstance().openNewTextEditor(new PathEditorInput(URIUtil.toPath(getOutputURI())));
                }
            }
        } catch (IOException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "IOException while performing a secure random", e, false);
        } catch (PartInitException e) {
            LogUtil.logError(FlexiProviderEnginesPlugin.PLUGIN_ID, "Failed to open the Hexeditor", e, true);
        }
    }
}
Also used : SecureRandomDescriptor(org.jcryptool.crypto.flexiprovider.descriptors.algorithms.SecureRandomDescriptor) OutputStream(java.io.OutputStream) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) File(java.io.File) FileInputStream(java.io.FileInputStream) 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