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