Search in sources :

Example 16 with SaveAsDialog

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);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IWorkspace(org.eclipse.core.resources.IWorkspace) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 17 with SaveAsDialog

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);
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkspace(org.eclipse.core.resources.IWorkspace) IFileStore(org.eclipse.core.filesystem.IFileStore) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 18 with SaveAsDialog

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) Point(org.eclipse.draw2d.geometry.Point)

Example 19 with SaveAsDialog

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);
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 20 with SaveAsDialog

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);
}
Also used : IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog)

Aggregations

IPath (org.eclipse.core.runtime.IPath)42 SaveAsDialog (org.eclipse.ui.dialogs.SaveAsDialog)42 IFile (org.eclipse.core.resources.IFile)39 FileEditorInput (org.eclipse.ui.part.FileEditorInput)35 IWorkspace (org.eclipse.core.resources.IWorkspace)5 CoreException (org.eclipse.core.runtime.CoreException)5 Shell (org.eclipse.swt.widgets.Shell)4 IFileEditorInput (org.eclipse.ui.IFileEditorInput)4 File (java.io.File)3 IEditorInput (org.eclipse.ui.IEditorInput)3 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)3 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 IFigure (org.eclipse.draw2d.IFigure)2 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)2 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2