use of org.eclipse.ui.dialogs.SaveAsDialog in project tdi-studio-se by Talend.
the class AbstractTalendEditor method doSaveAs.
@Override
public void doSaveAs() {
SaveAsDialog dialog = new SaveAsDialog(getSite().getWorkbenchWindow().getShell());
dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile());
dialog.open();
IPath path = dialog.getResult();
if (path == null) {
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IFile file = workspace.getRoot().getFile(path);
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
@Override
public void execute(final IProgressMonitor monitor) throws CoreException {
try {
savePreviewPictures();
getProcess().saveXmlFile();
// file.refreshLocal(IResource.DEPTH_ONE, monitor);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
};
try {
new ProgressMonitorDialog(getSite().getWorkbenchWindow().getShell()).run(false, true, op);
// setInput(new FileEditorInput((IFile) file));
getCommandStack().markSaveLocation();
setDirty(false);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.eclipse.ui.dialogs.SaveAsDialog in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method performSaveAs.
/**
* This implementation asks the user for the workspace path of a file resource and saves the document there.
*
* @param progressMonitor the progress monitor to be used
* @since 3.2
*/
@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {
Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
final IEditorInput input = getEditorInput();
IDocumentProvider provider = getDocumentProvider();
final IEditorInput newInput;
if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) {
FileDialog dialog = new FileDialog(shell, SWT.SAVE);
IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
if (oldPath != null && !oldPath.isEmpty()) {
dialog.setFileName(oldPath.lastSegment());
dialog.setFilterPath(oldPath.removeLastSegments(1).toOSString());
}
String path = dialog.open();
if (path == null) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
return;
}
// Check whether file exists and if so, confirm overwrite
final File localFile = new File(path);
if (localFile.exists()) {
MessageDialog overwriteDialog = new MessageDialog(shell, TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_title, null, NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_message, path), MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, // 'No' is the default
1);
if (overwriteDialog.open() != Window.OK) {
if (progressMonitor != null) {
progressMonitor.setCanceled(true);
return;
}
}
}
IFileStore fileStore;
try {
fileStore = EFS.getStore(localFile.toURI());
} catch (CoreException ex) {
EditorsPlugin.log(ex.getStatus());
String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message, ex.getMessage());
MessageDialog.openError(shell, title, msg);
return;
}
IFile file = getWorkspaceFile(fileStore);
if (file != null)
newInput = new FileEditorInput(file);
else
newInput = new FileStoreEditorInput(fileStore);
} else {
SaveAsDialog dialog = new SaveAsDialog(shell);
IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
if (original != null)
dialog.setOriginalFile(original);
else
dialog.setOriginalName(input.getName());
dialog.create();
if (provider.isDeleted(input) && original != null) {
String message = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_warning_saveAs_deleted, original.getName());
dialog.setErrorMessage(null);
dialog.setMessage(message, IMessageProvider.WARNING);
}
if (dialog.open() == Window.CANCEL) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
return;
}
IPath filePath = dialog.getResult();
if (filePath == null) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IFile file = workspace.getRoot().getFile(filePath);
newInput = new FileEditorInput(file);
}
if (provider == null) {
// editor has programmatically been closed while the dialog was open
return;
}
boolean success = false;
try {
provider.aboutToChange(newInput);
provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
success = true;
} catch (CoreException x) {
final IStatus status = x.getStatus();
if (status == null || status.getSeverity() != IStatus.CANCEL) {
String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message, x.getMessage());
MessageDialog.openError(shell, title, msg);
}
} finally {
provider.changed(newInput);
if (success)
setInput(newInput);
}
if (progressMonitor != null)
progressMonitor.setCanceled(!success);
}
use of org.eclipse.ui.dialogs.SaveAsDialog in project yamcs-studio by yamcs.
the class OPIEditor method doSaveAs.
/**
* {@inheritDoc}
*/
@Override
public void doSaveAs() {
SaveAsDialog saveAsDialog = new SaveAsDialog(getEditorSite().getShell());
if (getEditorInput() instanceof FileEditorInput)
saveAsDialog.setOriginalFile(((FileEditorInput) getEditorInput()).getFile());
else if (getEditorInput() instanceof FileStoreEditorInput)
saveAsDialog.setOriginalName(((FileStoreEditorInput) getEditorInput()).getName());
int ret = saveAsDialog.open();
try {
if (ret == Window.OK) {
IPath targetPath = saveAsDialog.getResult();
IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(targetPath);
if (!targetFile.exists()) {
targetFile.create(null, true, null);
}
FileEditorInput editorInput = new FileEditorInput(targetFile);
setInput(editorInput);
setPartName(targetFile.getName());
performSave();
}
} catch (CoreException e) {
MessageDialog.openError(getSite().getShell(), "IO Error", e.getMessage());
// $NON-NLS-1$
OPIBuilderPlugin.getLogger().log(Level.WARNING, "File save error", e);
}
}
use of org.eclipse.ui.dialogs.SaveAsDialog in project org.csstudio.display.builder by kasemir.
the class DisplayEditorPart method promptForFile.
/**
* Prompt for file name used to 'save'
* @param shell Shell
* @param orig_input Original input
* @return File in workspace or <code>null</code>
*/
public static IFile promptForFile(final Shell shell, final IEditorInput orig_input) {
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
final SaveAsDialog dlg = new SaveAsDialog(shell);
dlg.setBlockOnOpen(true);
if (orig_input instanceof FileEditorInput) {
IPath orig_path = ((FileEditorInput) orig_input).getFile().getFullPath();
// Propose new file extension
if (!DisplayModel.FILE_EXTENSION.equals(orig_path.getFileExtension()))
orig_path = orig_path.removeFileExtension().addFileExtension(DisplayModel.FILE_EXTENSION);
dlg.setOriginalFile(root.getFile(orig_path));
}
if (dlg.open() != Window.OK)
return null;
// Path to the new resource relative to the workspace
IPath path = dlg.getResult();
if (path == null)
return null;
// Assert correct file extension.
// If not display or class file, make it a display file.
final String ext = path.getFileExtension();
if (!(DisplayModel.FILE_EXTENSION.equals(ext) || WidgetClassSupport.FILE_EXTENSION.equals(ext)))
path = path.removeFileExtension().addFileExtension(DisplayModel.FILE_EXTENSION);
return root.getFile(path);
}
use of org.eclipse.ui.dialogs.SaveAsDialog in project jbosstools-hibernate by jbosstools.
the class DiagramViewer method doSaveAs.
public void doSaveAs() {
SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getWorkbenchWindow().getShell());
saveAsDialog.setOriginalName(getStoreFileName());
saveAsDialog.open();
final IPath pathSave = saveAsDialog.getResult();
if (pathSave == null) {
return;
}
saveProperties();
IPath pathTmp = pathSave;
String ext = pathSave.getFileExtension();
if (ext == null) {
// $NON-NLS-1$
pathTmp = pathTmp.addFileExtension("hibernate");
}
getOrmDiagram().saveInWorkspaceFile(pathTmp, true);
getOrmDiagram().setDirty(false);
}
Aggregations