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