Search in sources :

Example 6 with FileStoreEditorInput

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

the class XLIFFEditorImplWithNatTable method saveAs.

/**
	 * 另存文件
	 * @param newInput
	 * @param oldFile
	 * @param monitor
	 *            ;
	 */
private void saveAs(IEditorInput newInput, File oldFile, IProgressMonitor monitor) {
    if (newInput == null || oldFile == null) {
        return;
    }
    boolean success = false;
    try {
        if (newInput instanceof FileEditorInput) {
            IFile newFile = (IFile) newInput.getAdapter(IFile.class);
            if (newFile != null) {
                FileInputStream fis = new FileInputStream(oldFile);
                BufferedInputStream bis = new BufferedInputStream(fis);
                if (newFile.exists()) {
                    newFile.setContents(bis, false, true, monitor);
                } else {
                    newFile.create(bis, true, monitor);
                }
                bis.close();
                fis.close();
            }
        } else if (newInput instanceof FileStoreEditorInput) {
            FileStoreEditorInput storeEditorInput = (FileStoreEditorInput) newInput;
            File newFile = new File(storeEditorInput.getURI());
            copyFile(oldFile, newFile);
        }
        success = true;
    } catch (CoreException e) {
        LOGGER.error("", e);
        final IStatus status = e.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            String title = Messages.getString("editor.XLIFFEditorImplWithNatTable.msgTitle1");
            String msg = MessageFormat.format(Messages.getString("editor.XLIFFEditorImplWithNatTable.msg2"), e.getMessage());
            MessageDialog.openError(getSite().getShell(), title, msg);
        }
    } catch (FileNotFoundException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (IOException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } finally {
        if (success) {
            setInput(newInput);
        }
    }
    if (monitor != null) {
        monitor.setCanceled(!success);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) BufferedInputStream(java.io.BufferedInputStream) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 7 with FileStoreEditorInput

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

the class XLIFFEditorImplWithNatTable method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(Messages.getString("editor.XLIFFEditorImplWithNatTable.logger1"));
    }
    setSite(site);
    setInput(input);
    List<File> files = null;
    if (input instanceof FileStoreEditorInput) {
        FileStoreEditorInput editorInput = (FileStoreEditorInput) input;
        files = Arrays.asList(new File(editorInput.getURI()));
        setPartName(input.getName());
    } else if (input instanceof FileEditorInput) {
        FileEditorInput editorInput = (FileEditorInput) input;
        try {
            files = getFilesByFileEditorInput(editorInput);
        } catch (CoreException e) {
            throw new PartInitException(e.getMessage(), e);
        }
        if (files != null) {
            if (files instanceof ArrayList<?>) {
                // “打开项目”的情况,会返回 java.util.ArrayList<?> 对象。
                if (files.size() <= 0) {
                    // 关闭此编辑器。
                    close();
                    return;
                }
                // 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
                StringBuffer nameSB = new StringBuffer();
                for (File file : files) {
                    nameSB.append(file.getName() + "、");
                }
                nameSB.deleteCharAt(nameSB.length() - 1);
                String partName = "";
                if (nameSB.length() > 17) {
                    partName = nameSB.substring(0, 17) + "...";
                } else {
                    partName = nameSB.toString();
                }
                setPartName(partName);
                titleToolTip = nameSB.toString();
                multiFile = true;
                multiFileList = files;
            } else {
                // 打开文件的一般情况
                setPartName(input.getName());
                String name = input.getName().toLowerCase();
                if (!CommonFunction.validXlfExtensionByFileName(name)) {
                    // IFile file = (IFile) input.getAdapter(IFile.class);
                    // 打开正转换对话框
                    // ConverterCommandTrigger.openConversionDialog(site.getWorkbenchWindow(), file);
                    // 关闭此编辑器。
                    close();
                    return;
                }
            }
        }
    }
    // if (files == null || !XLFValidator.validateXlifFiles(files)) {
    // close(); // 关闭此编辑器。
    // return;
    // }
    openFile(files, input);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) PartInitException(org.eclipse.ui.PartInitException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 8 with FileStoreEditorInput

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

the class DataSourceHelper method setDataSource.

/**
	 * 设置数据源
	 * @param editorInput
	 * @param dataSource
	 * @return ;
	 */
public boolean setDataSource(IEditorInput editorInput, T dataSource) {
    if (editorInput instanceof FileEditorInput) {
        FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
        IFile file = fileEditorInput.getFile();
        return setDataSource(file, dataSource);
    } else if (editorInput instanceof FileStoreEditorInput) {
        FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput;
        map.put(generateKey(fileStoreEditorInput), dataSource);
        return true;
    }
    return false;
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 9 with FileStoreEditorInput

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

the class DataSourceHelper method getDataSource.

/**
	 * 获取数据源
	 * @param editorInput
	 * @return ;
	 */
@SuppressWarnings("unchecked")
public T getDataSource(IEditorInput editorInput) {
    if (editorInput instanceof FileEditorInput) {
        if (editorInput instanceof FileEditorInput) {
            FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
            IFile file = fileEditorInput.getFile();
            return this.getDataSource(file);
        }
    } else if (editorInput instanceof FileStoreEditorInput) {
        FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput;
        Object obj = map.get(generateKey(fileStoreEditorInput));
        if (dataSourceClass.isInstance(obj)) {
            return (T) obj;
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 10 with FileStoreEditorInput

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

the class DataSourceHelper method copyDataSource.

/**
	 * 从 oldInput 复制数据源到 newInput
	 * @param oldInput
	 * @param newInput
	 * @return ;
	 */
@SuppressWarnings("unchecked")
public static boolean copyDataSource(IEditorInput oldInput, IEditorInput newInput) {
    if (oldInput instanceof FileEditorInput) {
        FileEditorInput fileEditorInput = (FileEditorInput) oldInput;
        IFile file = fileEditorInput.getFile();
        try {
            Collection<Object> values = file.getSessionProperties().values();
            for (Object value : values) {
                DataSourceHelper helper = new DataSourceHelper(value.getClass());
                helper.setDataSource(newInput, value);
            }
            return true;
        } catch (CoreException e) {
            e.printStackTrace();
            return false;
        }
    } else if (oldInput instanceof FileStoreEditorInput) {
        FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) oldInput;
        for (Entry<String, Object> entry : map.entrySet()) {
            String key = entry.getKey();
            if (key.startsWith(fileStoreEditorInput.getURI().toString() + " ")) {
                Object value = map.get(key);
                DataSourceHelper helper = new DataSourceHelper(value.getClass());
                helper.setDataSource(newInput, value);
            }
        }
        return true;
    }
    return false;
}
Also used : Entry(java.util.Map.Entry) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

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