Search in sources :

Example 1 with IEditorInput

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

the class FileRefDocumentProvider method createElementInfo.

@Override
protected ElementInfo createElementInfo(Object element) throws CoreException {
    if (element instanceof IEditorInput) {
        IEditorInput input = (IEditorInput) element;
        IStorage storage = EditorUtils.getStorageFromInput(input);
        if (storage instanceof IFile) {
            IFile file = (IFile) storage;
            try {
                refreshFile(file);
            } catch (CoreException x) {
                log.warn("Can't refresh file", x);
            }
            IDocument d;
            IStatus s = null;
            try {
                d = createDocument(element);
            } catch (CoreException x) {
                log.warn("Can't create document", x);
                s = x.getStatus();
                d = createEmptyDocument();
            }
            // Set the initial line delimiter
            String initialLineDelimiter = GeneralUtils.getDefaultLineSeparator();
            if (initialLineDelimiter != null) {
                ((IDocumentExtension4) d).setInitialLineDelimiter(initialLineDelimiter);
            }
            IAnnotationModel m = createAnnotationModel(element);
            FileSynchronizer f = new FileSynchronizer(input);
            f.install();
            FileInfo info = new FileInfo(d, m, f);
            info.modificationStamp = computeModificationStamp(file);
            info.fStatus = s;
            return info;
        }
    }
    return super.createElementInfo(element);
}
Also used : IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with IEditorInput

use of org.eclipse.ui.IEditorInput in project translationstudio8 by heartsome.

the class AbstractSelectProjectFilesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    shell = HandlerUtil.getActiveShell(event);
    isEditor = false;
    // UNDO 如果焦点在其他视图上时,获取的文件错误。
    ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
    if (selection == null || !(selection instanceof StructuredSelection) || selection.isEmpty()) {
        MessageDialog.openInformation(shell, Messages.getString("handlers.AbstractSelectProjectFilesHandler.msgTitle"), Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg1"));
        return null;
    }
    StructuredSelection structuredSelection = (StructuredSelection) selection;
    IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    String partId = HandlerUtil.getActivePartIdChecked(event);
    if (part instanceof IEditorPart) {
        // 当前焦点在编辑器
        IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
        IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
        isEditor = true;
        ArrayList<IFile> list = new ArrayList<IFile>();
        //代替 Arrays.asList(iFile)
        list.add(iFile);
        return execute(event, list);
    } else if ("net.heartsome.cat.common.ui.navigator.view".equals(partId)) {
        // 当前焦点在导航视图
        ArrayList<IFile> list = new ArrayList<IFile>();
        ArrayList<IFile> wrongFiles = new ArrayList<IFile>();
        String projectName = null;
        @SuppressWarnings("unchecked") Iterator<IResource> iterator = structuredSelection.iterator();
        while (iterator.hasNext()) {
            IResource resource = iterator.next();
            if (projectName == null) {
                projectName = resource.getProject().getName();
            } else {
                if (!projectName.equals(resource.getProject().getName())) {
                    MessageDialog.openInformation(shell, Messages.getString("handlers.AbstractSelectProjectFilesHandler.msgTitle"), Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg2"));
                    return null;
                }
            }
            if (resource instanceof IFile) {
                IFile file = (IFile) resource;
                String fileExtension = file.getFileExtension();
                if (getLegalFileExtensions() == null || getLegalFileExtensions().length == 0) {
                    // 未限制后缀名的情况
                    list.add(file);
                } else {
                    // 限制了后缀名的情况
                    if (fileExtension == null) {
                        // 无后缀名的文件
                        fileExtension = "";
                    }
                    if (CommonFunction.containsIgnoreCase(getLegalFileExtensions(), fileExtension)) {
                        list.add(file);
                    } else {
                        wrongFiles.add(file);
                    }
                }
            } else if (resource instanceof IContainer) {
                // IContainer 包含 IFolder、IPorject。
                try {
                    ResourceUtils.getFiles((IContainer) resource, list, getLegalFileExtensions());
                } catch (CoreException e) {
                    LOGGER.error(MessageFormat.format(Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg3"), resource.getFullPath().toOSString()), e);
                    e.printStackTrace();
                }
            }
        }
        if (!wrongFiles.isEmpty()) {
            String msg = Messages.getString("handlers.AbstractSelectProjectFilesHandler.msg4");
            StringBuffer arg = new StringBuffer();
            for (IFile iFile : wrongFiles) {
                arg.append("\n").append(iFile.getFullPath().toOSString());
            }
            if (!MessageDialog.openConfirm(shell, Messages.getString("handlers.AbstractSelectProjectFilesHandler.msgTitle"), MessageFormat.format(msg.toString(), arg.toString()))) {
                return null;
            }
        }
        return execute(event, list);
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IContainer(org.eclipse.core.resources.IContainer) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Example 3 with IEditorInput

use of org.eclipse.ui.IEditorInput in project translationstudio8 by heartsome.

the class LockRepeatedSegmentHandler method lockTU.

/**
	 * 概据内部匹配结果,锁定文本段。
	 * @param xlfHandler
	 * @param rowIdMap
	 */
private void lockTU(final XLFHandler xlfHandler, Map<String, List<String>> rowIdMap) {
    Iterator<Entry<String, List<String>>> it = rowIdMap.entrySet().iterator();
    while (it.hasNext()) {
        isLocked = false;
        final Entry<String, List<String>> rowIdsEntry = it.next();
        final String fileLC = rowIdsEntry.getKey();
        // 查看该文件是否打开,若打开,则获editor的handler,若未打开,则直接使用当前handler
        final IEditorInput input = new FileEditorInput(ResourceUtils.fileToIFile(fileLC));
        final IEditorReference[] editorRefes = window.getActivePage().getEditorReferences();
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                for (int i = 0; i < editorRefes.length; i++) {
                    if (XLIFF_EDITOR_ID.equals(editorRefes[i].getId())) {
                        // 先判断打开单个文件的情况
                        XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) (editorRefes[i].getEditor(true));
                        if (!nattable.isMultiFile()) {
                            if (nattable.getEditorInput().equals(input)) {
                                nattable.getXLFHandler().lockTransUnits(rowIdsEntry.getValue(), true);
                                isLocked = true;
                                nattable.getTable().redraw();
                            }
                        } else {
                            // 这是合并打开的情况
                            if (nattable.getMultiFileList().indexOf(new File(fileLC)) >= 0) {
                                nattable.getXLFHandler().lockTransUnits(rowIdsEntry.getValue(), true);
                                isLocked = true;
                                nattable.getTable().redraw();
                            }
                            ;
                        }
                    }
                }
                // 如果未被锁定(当前文件没有打开),就调用当前XLFHandler去锁定所有文本段
                if (!isLocked) {
                    xlfHandler.lockTransUnits(rowIdsEntry.getValue(), true);
                }
            }
        });
    }
}
Also used : Entry(java.util.Map.Entry) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorReference(org.eclipse.ui.IEditorReference) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ArrayList(java.util.ArrayList) List(java.util.List) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput)

Example 4 with IEditorInput

use of org.eclipse.ui.IEditorInput in project translationstudio8 by heartsome.

the class AbstractExportHandler method initExportConfig.

public boolean initExportConfig(ExecutionEvent event) throws ExecutionException {
    config = new ExportConfig();
    Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
        // 导航视图处于激活状态
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
        StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
        if (selection != null && !selection.isEmpty()) {
            for (Object obj : selection.toList()) {
                if (obj instanceof IFile) {
                    addXLFFile((IFile) obj);
                } else if (obj instanceof IFolder) {
                    traversalFile((IFolder) obj);
                } else if (obj instanceof IProject) {
                    IProject proj = (IProject) obj;
                    traversalFile(proj.getFolder(XLF));
                }
            }
            if (config.getProjects() == null || config.getProjects().size() < 1) {
                MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("xlf2tmx.info.notfoundxlf"));
                return false;
            }
        }
    } else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
        // nattable 处于激活状态
        IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
        IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
        IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        if (xliffEditor.isMultiFile()) {
            MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
            return false;
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            addXLFFile(iFile);
        }
    }
    return true;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ExportConfig(net.heartsome.cat.ts.ui.external.ExportConfig) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with IEditorInput

use of org.eclipse.ui.IEditorInput in project translationstudio8 by heartsome.

the class ExportDocxHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    IFile file = null;
    if (partId.equals("net.heartsome.cat.common.ui.navigator.view")) {
        // 导航视图处于激活状态
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart viewPart = page.findView("net.heartsome.cat.common.ui.navigator.view");
        StructuredSelection selection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
        // ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
            List<?> lstObj = ((IStructuredSelection) selection).toList();
            ArrayList<IFile> lstXliff = new ArrayList<IFile>();
            for (Object obj : lstObj) {
                if (obj instanceof IFile) {
                    IFile tempFile = (IFile) obj;
                    // Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
                    if (tempFile.getFileExtension() != null && CommonFunction.validXlfExtension(tempFile.getFileExtension())) {
                        lstXliff.add(tempFile);
                    }
                }
            }
            if (lstXliff.size() > 1) {
                MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg1"));
                return null;
            }
            if (lstXliff.size() == 1) {
                file = lstXliff.get(0);
            }
        }
    } else if (partId.equals("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor")) {
        // nattable 处于激活状态
        IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
        IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
        IFile iFile = (IFile) editorInput.getAdapter(IFile.class);
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        if (xliffEditor.isMultiFile()) {
            MessageDialog.openInformation(shell, Messages.getString("all.dialog.ok.title"), Messages.getString("ExportDocxHandler.msg2"));
            return null;
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            file = iFile;
        }
    }
    if (file != null) {
        XLFValidator.resetFlag();
        if (!XLFValidator.validateXliffFile(file)) {
            return null;
        }
        XLFValidator.resetFlag();
    }
    ExportDocxDialog dialog = new ExportDocxDialog(shell, file == null ? "" : file.getFullPath().toOSString(), file == null ? "" : ResourceUtils.iFileToOSPath(file));
    dialog.open();
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) ExportDocxDialog(net.heartsome.cat.ts.ui.docx.dialog.ExportDocxDialog) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)71 IFile (org.eclipse.core.resources.IFile)26 PartInitException (org.eclipse.ui.PartInitException)21 IEditorPart (org.eclipse.ui.IEditorPart)19 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)17 IEditorReference (org.eclipse.ui.IEditorReference)14 CoreException (org.eclipse.core.runtime.CoreException)13 ArrayList (java.util.ArrayList)11 IViewPart (org.eclipse.ui.IViewPart)11 FileEditorInput (org.eclipse.ui.part.FileEditorInput)10 Shell (org.eclipse.swt.widgets.Shell)9 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)8 IFileEditorInput (org.eclipse.ui.IFileEditorInput)8 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)8 File (java.io.File)7 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)7 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)7 Item (org.talend.core.model.properties.Item)7 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)6 IProject (org.eclipse.core.resources.IProject)6