Search in sources :

Example 21 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project iobserve-analysis by research-iobserve.

the class systemadaptationEditor method doSaveAs.

/**
 * This also changes the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSaveAs() {
    SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getShell());
    saveAsDialog.open();
    IPath path = saveAsDialog.getResult();
    if (path != null) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (file != null) {
            doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(), true), new FileEditorInput(file));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 22 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project iobserve-analysis by research-iobserve.

the class cloudprofileEditor method doSaveAs.

/**
 * This also changes the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSaveAs() {
    SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getShell());
    saveAsDialog.open();
    IPath path = saveAsDialog.getResult();
    if (path != null) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (file != null) {
            doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(), true), new FileEditorInput(file));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 23 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project jbosstools-hibernate by jbosstools.

the class AbstractQueryEditor method performSaveAs.

/**
 * @see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#performSaveAs(IProgressMonitor)
 * the same method except line: "dialog.setOriginalName(getSaveAsFileExtension());"
 */
protected void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().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) {
            dialog.setFileName(oldPath.lastSegment());
            dialog.setFilterPath(oldPath.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, HibernateConsoleMessages.AbstractQueryEditor_save_as, null, MessageFormat.format(HibernateConsoleMessages.AbstractQueryEditor_already_exists_do_you_want_to_replace_it, 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) {
            HibernateConsolePlugin.getDefault().log(ex.getStatus());
            String title = HibernateConsoleMessages.AbstractQueryEditor_problems_during_save_as;
            String msg = MessageFormat.format(HibernateConsoleMessages.AbstractQueryEditor_save_could_not_be_completed, 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(getSaveAsFileExtension());
        }
        dialog.create();
        if (provider.isDeleted(input) && original != null) {
            String message = MessageFormat.format(HibernateConsoleMessages.AbstractQueryEditor_the_original_file_has_been_deleted_or_is_not_accessible, 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 = HibernateConsoleMessages.AbstractQueryEditor_problems_during_save_as;
            String msg = MessageFormat.format(HibernateConsoleMessages.AbstractQueryEditor_save_could_not_be_completed, 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) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) 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 24 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project Malai by arnobl.

the class ActionEditor method doSaveAs.

/**
 * This also changes the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSaveAs() {
    SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getShell());
    saveAsDialog.open();
    IPath path = saveAsDialog.getResult();
    if (path != null) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (file != null) {
            doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(), true), new FileEditorInput(file));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 25 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project Malai by arnobl.

the class EventEditor method doSaveAs.

/**
 * This also changes the editor's input.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void doSaveAs() {
    SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getShell());
    saveAsDialog.open();
    IPath path = saveAsDialog.getResult();
    if (path != null) {
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (file != null) {
            doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(), true), new FileEditorInput(file));
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

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