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;
}
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()));
}
}
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;
}
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 };
}
}
}
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);
}
}
}
Aggregations