Search in sources :

Example 1 with FileStoreEditorInput

use of org.eclipse.ui.ide.FileStoreEditorInput in project dbeaver by serge-rider.

the class SQLEditor method afterSaveToFile.

protected void afterSaveToFile(File saveFile) {
    try {
        IFileStore fileStore = EFS.getStore(saveFile.toURI());
        IEditorInput input = new FileStoreEditorInput(fileStore);
        EditorUtils.setInputDataSource(input, getDataSourceContainer(), false);
        init(getEditorSite(), input);
    } catch (CoreException e) {
        UIUtils.showErrorDialog(getSite().getShell(), "File save", "Can't open SQL editor from external file", e);
    }
}
Also used : IFileStore(org.eclipse.core.filesystem.IFileStore) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 2 with FileStoreEditorInput

use of org.eclipse.ui.ide.FileStoreEditorInput in project dbeaver by serge-rider.

the class EditorUtils method openExternalFileEditor.

public static void openExternalFileEditor(File file, IWorkbenchWindow window) {
    try {
        IEditorDescriptor desc = window.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
        IFileStore fileStore = EFS.getStore(file.toURI());
        IEditorInput input = new FileStoreEditorInput(fileStore);
        IDE.openEditor(window.getActivePage(), input, desc.getId());
    } catch (CoreException e) {
        log.error("Can't open editor from file '" + file.getAbsolutePath(), e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IFileStore(org.eclipse.core.filesystem.IFileStore) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 3 with FileStoreEditorInput

use of org.eclipse.ui.ide.FileStoreEditorInput in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method performSaveAs.

/**
	 * 执行另存为
	 * @param progressMonitor
	 *            进度条;
	 */
private void performSaveAs(IProgressMonitor progressMonitor) {
    Shell shell = getSite().getShell();
    final IEditorInput input = getEditorInput();
    // 新的EditorInput
    final IEditorInput newInput;
    // 原始的file
    final File oldFile;
    // if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) { // 外部文件
    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    URI uri = ((IURIEditorInput) input).getURI();
    IPath oldPath = URIUtil.toPath(uri);
    if (oldPath != null) {
        dialog.setFileName(oldPath.lastSegment());
        // 设置所在文件夹
        dialog.setFilterPath(oldPath.removeLastSegments(1).toOSString());
        oldFile = oldPath.toFile();
    } else {
        oldFile = new File(uri);
    }
    // 得到保存路径
    String newPath = dialog.open();
    if (newPath == null) {
        if (progressMonitor != null)
            progressMonitor.setCanceled(true);
        return;
    }
    // 检查文件是否存在,如果存在则确认是否覆盖
    final File localFile = new File(newPath);
    if (localFile.exists()) {
        String msg = MessageFormat.format(Messages.getString("editor.XLIFFEditorImplWithNatTable.msg1"), newPath);
        MessageDialog overwriteDialog = new MessageDialog(shell, Messages.getString("editor.XLIFFEditorImplWithNatTable.overwriteDialog"), null, msg, MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1);
        if (overwriteDialog.open() != MessageDialog.OK) {
            if (progressMonitor != null) {
                progressMonitor.setCanceled(true);
                return;
            }
        }
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    // 得到新文件
    IFile file = root.getFileForLocation(URIUtil.toPath(localFile.toURI()));
    if (file != null) {
        // 是“WorkSpace”内的文件
        newInput = new FileEditorInput(file);
    } else {
        // 不是“WorkSpace”内的文件
        try {
            IFileStore fileStore = EFS.getStore(localFile.toURI());
            newInput = new FileStoreEditorInput(fileStore);
        } catch (CoreException ex) {
            // EditorsPlugin.log(ex.getStatus());
            LOGGER.error("", ex);
            String title = Messages.getString("editor.XLIFFEditorImplWithNatTable.msgTitle1");
            String msg = MessageFormat.format(Messages.getString("editor.XLIFFEditorImplWithNatTable.msg2"), ex.getMessage());
            MessageDialog.openError(shell, title, msg);
            return;
        }
    }
    // } else {
    // SaveAsDialog dialog = new SaveAsDialog(shell);
    // // 源文件
    // IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
    // if (original != null) {
    // dialog.setOriginalFile(original); // 添加源文件信息
    // oldFile = original.getLocation().toFile();
    // if ((!oldFile.exists() || !oldFile.canRead()) && original != null) {
    // String message = MessageFormat.format(
    // "The original file ''{0}'' has been deleted or is not accessible.", original.getName());
    // dialog.setErrorMessage(null);
    // dialog.setMessage(message, IMessageProvider.WARNING);
    // }
    // } else {
    // oldFile = null;
    // }
    // dialog.create();
    //
    // if (dialog.open() == MessageDialog.CANCEL) { // 打开“另存为”对话框,用户点击了“取消”按钮
    // if (progressMonitor != null)
    // progressMonitor.setCanceled(true);
    // return;
    // }
    //
    // IPath filePath = dialog.getResult(); // 获得用户选择的路径
    // if (filePath == null) { // 检查路径
    // if (progressMonitor != null)
    // progressMonitor.setCanceled(true);
    // return;
    // }
    //
    // IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    // IFile file = root.getFile(filePath);
    // newInput = new FileEditorInput(file);
    // }
    saveAs(newInput, oldFile, progressMonitor);
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) URI(java.net.URI) Shell(org.eclipse.swt.widgets.Shell) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IFileStore(org.eclipse.core.filesystem.IFileStore) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 4 with FileStoreEditorInput

use of org.eclipse.ui.ide.FileStoreEditorInput in project translationstudio8 by heartsome.

the class ExportAsHtmlHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    String elementName = event.getParameter("elementName");
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    Shell shell = activeEditor.getEditorSite().getShell();
    if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor;
    if (xliffEditor.isMultiFile()) {
        MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。");
    }
    IEditorInput input = xliffEditor.getEditorInput();
    URI uri = null;
    if (input instanceof FileEditorInput) {
        uri = ((FileEditorInput) input).getURI();
    } else if (input instanceof FileStoreEditorInput) {
        uri = ((FileStoreEditorInput) input).getURI();
    } else {
        return null;
    }
    File xliff = new File(uri);
    FileDialog fd = new FileDialog(shell, SWT.SAVE);
    String[] names = { "HTML Files [*.html]", "All Files [*.*]" };
    //$NON-NLS-1$ //$NON-NLS-2$
    String[] extensions = { "*.html", "*.*" };
    fd.setFilterExtensions(extensions);
    fd.setFilterNames(names);
    //$NON-NLS-1$
    fd.setFileName(xliff.getName() + ".html");
    String out = fd.open();
    if (out == null) {
        return null;
    }
    XLFHandler handler = xliffEditor.getXLFHandler();
    boolean result = handler.saveAsHtml(xliff.getAbsolutePath(), out, elementName);
    if (result) {
        IWorkbenchPage page = xliffEditor.getEditorSite().getPage();
        OpenEditorUtil.OpenFileWithSystemEditor(page, out);
    } else {
        MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。");
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) Shell(org.eclipse.swt.widgets.Shell) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 5 with FileStoreEditorInput

use of org.eclipse.ui.ide.FileStoreEditorInput in project translationstudio8 by heartsome.

the class ExportAsTextHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    String elementName = event.getParameter("elementName");
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    Shell shell = activeEditor.getEditorSite().getShell();
    if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor;
    if (xliffEditor.isMultiFile()) {
        MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。");
    }
    IEditorInput input = xliffEditor.getEditorInput();
    URI uri = null;
    if (input instanceof FileEditorInput) {
        uri = ((FileEditorInput) input).getURI();
    } else if (input instanceof FileStoreEditorInput) {
        uri = ((FileStoreEditorInput) input).getURI();
    } else {
        return null;
    }
    File xliff = new File(uri);
    FileDialog fd = new FileDialog(shell, SWT.SAVE);
    String[] names = { "Plain Text Files [*.txt]", "All Files [*.*]" };
    //$NON-NLS-1$ //$NON-NLS-2$
    String[] extensions = { "*.txt", "*.*" };
    fd.setFilterExtensions(extensions);
    fd.setFilterNames(names);
    //$NON-NLS-1$
    fd.setFileName(xliff.getName() + ".txt");
    String out = fd.open();
    if (out == null) {
        return null;
    }
    XLFHandler handler = xliffEditor.getXLFHandler();
    boolean result = handler.saveAsText(xliff.getAbsolutePath(), out, elementName);
    if (result) {
        IWorkbenchPage page = xliffEditor.getEditorSite().getPage();
        OpenEditorUtil.OpenFileWithSystemEditor(page, out);
    } else {
        MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。");
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) Shell(org.eclipse.swt.widgets.Shell) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)12 FileEditorInput (org.eclipse.ui.part.FileEditorInput)8 IFile (org.eclipse.core.resources.IFile)7 File (java.io.File)6 CoreException (org.eclipse.core.runtime.CoreException)6 IEditorInput (org.eclipse.ui.IEditorInput)4 URI (java.net.URI)3 IFileStore (org.eclipse.core.filesystem.IFileStore)3 FileDialog (org.eclipse.swt.widgets.FileDialog)3 Shell (org.eclipse.swt.widgets.Shell)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)2 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IFileEditorInput (org.eclipse.ui.IFileEditorInput)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1