Search in sources :

Example 1 with SaveAsDialog

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

the class InteractionEditor 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 2 with SaveAsDialog

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

the class WidgetEditor 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 3 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project linuxtools by eclipse.

the class STDataViewersExportToCSVDialog method handleBrowseWorkspace.

private void handleBrowseWorkspace() {
    SaveAsDialog dialog = new SaveAsDialog(getShell());
    dialog.setTitle("Output file");
    if (dialog.open() == IDialogConstants.OK_ID) {
        IPath p = dialog.getResult();
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IFile file = workspace.getRoot().getFile(p);
        outputFile.setText(file.getLocation().toOSString());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 4 with SaveAsDialog

use of org.eclipse.ui.dialogs.SaveAsDialog in project liferay-ide by liferay.

the class InputContext method doSaveAs.

/**
 * @param monitor
 */
public void doSaveAs(IProgressMonitor monitor) throws Exception {
    // Get the editor shell
    IDEFormEditor editor = getEditor();
    Shell shell = editor.getSite().getShell();
    // Create the save as dialog
    SaveAsDialog dialog = new SaveAsDialog(shell);
    // Set the initial file name to the original file name
    IFile file = null;
    if (_fEditorInput instanceof IFileEditorInput) {
        file = ((IFileEditorInput) _fEditorInput).getFile();
        dialog.setOriginalFile(file);
    }
    // Create the dialog
    dialog.create();
    if (_fDocumentProvider.isDeleted(_fEditorInput) && (file != null)) {
        String message = NLS.bind("File does not exist: {0}", file.getName());
        dialog.setErrorMessage(null);
        dialog.setMessage(message, IMessageProvider.WARNING);
    }
    if (dialog.open() == Window.OK) {
        // Get the path to where the new file will be stored
        IPath path = dialog.getResult();
        _handleSaveAs(monitor, path);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IDEFormEditor(com.liferay.ide.ui.form.IDEFormEditor)

Example 5 with SaveAsDialog

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

the class ExportImageAction method run.

public void run() {
    boolean createdSaveDialog = false;
    if (saveDialog == null) {
        saveDialog = new SaveAsDialog(getDiagramViewer().getSite().getWorkbenchWindow().getShell());
        createdSaveDialog = true;
    }
    saveDialog.setOriginalName(getDiagramViewer().getStoreFileName());
    saveDialog.open();
    final IPath pathSave = saveDialog.getResult();
    saveDialog = null;
    if (pathSave == null) {
        return;
    }
    final IFigure fig = ((ScalableFreeformRootEditPart) getDiagramViewer().getEditPartViewer().getRootEditPart()).getLayer(LayerConstants.PRINTABLE_LAYERS);
    int imageTypeTmp = SWT.IMAGE_BMP;
    String ext = pathSave.getFileExtension();
    if (ext != null) {
        ext = ext.toLowerCase();
        if (ext.endsWith("jpg")) {
            // $NON-NLS-1$
            imageTypeTmp = SWT.IMAGE_JPEG;
        } else if (ext.endsWith("png")) {
            // $NON-NLS-1$
            imageTypeTmp = SWT.IMAGE_PNG;
        } else if (ext.endsWith("gif")) {
            // $NON-NLS-1$
            imageTypeTmp = SWT.IMAGE_GIF;
        } else if (ext.endsWith("bmp")) {
            // $NON-NLS-1$
            imageTypeTmp = SWT.IMAGE_BMP;
        }
    }
    IPath pathTmp = pathSave;
    if (ext == null) {
        // $NON-NLS-1$
        pathTmp = pathTmp.addFileExtension("bmp");
    }
    final IPath path = pathTmp;
    final int imageType = imageTypeTmp;
    final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

        public void execute(final IProgressMonitor monitor) {
            ByteArrayInputStream inputStream = null;
            try {
                if (file != null) {
                    byte[] imageData = createImage(fig, imageType);
                    if (file.exists()) {
                        file.delete(true, null);
                    }
                    if (!file.exists()) {
                        inputStream = new ByteArrayInputStream(imageData);
                        file.create(inputStream, true, null);
                    }
                }
            } catch (CoreException e) {
                // $NON-NLS-1$
                HibernateConsolePlugin.getDefault().logErrorMessage("ExportImageAction", e);
                if (showErrDialog) {
                    MessageDialog.openInformation(getDiagramViewer().getSite().getShell(), DiagramViewerMessages.ExportImageAction_error, DiagramViewerMessages.ExportImageAction_failed_to_export_image + e.getMessage());
                }
            } finally {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                    // ignore
                    }
                }
            }
        }
    };
    try {
        new ProgressMonitorDialog(createdSaveDialog ? getDiagramViewer().getSite().getWorkbenchWindow().getShell() : null).run(false, true, op);
    } catch (InvocationTargetException e) {
    } catch (InterruptedException e) {
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) ByteArrayInputStream(java.io.ByteArrayInputStream) IFigure(org.eclipse.draw2d.IFigure)

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