Search in sources :

Example 31 with IEditorReference

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

the class NavigatorHandlerObjectDelete method deleteNewObject.

private boolean deleteNewObject(IWorkbenchWindow workbenchWindow, DBNDatabaseNode node) throws DBException {
    for (final IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
        final IEditorPart editor = editorRef.getEditor(false);
        if (editor instanceof IDatabaseEditor) {
            final IDatabaseEditorInput editorInput = ((IDatabaseEditor) editor).getEditorInput();
            if (editorInput.getDatabaseObject() == node.getObject()) {
                ConfirmResult confirmResult = confirmObjectDelete(workbenchWindow, node, false);
                if (confirmResult == ConfirmResult.NO) {
                    return true;
                }
                // Just close editor
                // It should dismiss new object and remove navigator node
                workbenchWindow.getActivePage().closeEditor(editor, false);
                return true;
            }
        }
    }
    return false;
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) IEditorReference(org.eclipse.ui.IEditorReference) IEditorPart(org.eclipse.ui.IEditorPart) IDatabaseEditor(org.jkiss.dbeaver.ui.editors.IDatabaseEditor)

Example 32 with IEditorReference

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

the class ApplicationWorkbenchWindowAdvisor method restorEditorHistory.

/**
	 * 重新恢复产品上次退时出所保存的编辑器,此修复针对 mac 下的 bug 2998 启动:某客户安装的软件只能使用一次.		robert	2013-05-21
	 */
private void restorEditorHistory() {
    // 只针对 mac 下的用户
    if (System.getProperty("os.name").indexOf("Mac") == -1) {
        return;
    }
    final WorkbenchPage page = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask("", 10);
            String tempEditorHistoryLC = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(Constant.TEMP_EDITOR_HISTORY).toOSString();
            File tempEditorHistoryFile = new File(tempEditorHistoryLC);
            if (!tempEditorHistoryFile.exists()) {
                return;
            }
            monitor.worked(1);
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            VTDGen vg = new VTDGen();
            try {
                boolean parseResult = vg.parseFile(tempEditorHistoryLC, true);
                if (!parseResult) {
                    return;
                }
                VTDNav vn = vg.getNav();
                AutoPilot ap = new AutoPilot(vn);
                int storeFileSum = 0;
                ap.selectXPath("count(/editors/editor)");
                storeFileSum = (int) ap.evalXPathToNumber();
                IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                subMonitor.beginTask("", storeFileSum);
                ap.selectXPath("/editors/editor");
                String editorId = null;
                String localFilePath = null;
                boolean activate = false;
                IEditorReference activateEditorRefe = null;
                IEditorReference firstEditor = null;
                IFile curIFile = null;
                int index = -1;
                while (ap.evalXPath() != -1) {
                    activate = false;
                    editorId = null;
                    localFilePath = null;
                    if ((index = vn.getAttrVal("id")) != -1) {
                        editorId = vn.toRawString(index);
                    }
                    if ((index = vn.getAttrVal("path")) != -1) {
                        localFilePath = vn.toRawString(index);
                    }
                    if (editorId == null || editorId.trim().length() <= 0 || localFilePath == null || localFilePath.trim().length() <= 0) {
                        continue;
                    }
                    if ((index = vn.getAttrVal("active")) != -1) {
                        if ("true".equals(vn.toRawString(index))) {
                            activate = true;
                        }
                    }
                    curIFile = root.getFileForLocation(new Path(localFilePath));
                    if (!curIFile.exists()) {
                        subMonitor.worked(1);
                        continue;
                    }
                    if (activate) {
                        activateEditorRefe = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
                    } else {
                        if (firstEditor == null) {
                            firstEditor = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
                        } else {
                            page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
                        }
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
                    }
                    subMonitor.worked(1);
                }
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
                if (activateEditorRefe != null) {
                    if (firstEditor != null) {
                        page.activate(firstEditor.getEditor(true));
                    }
                    page.activate(activateEditorRefe.getEditor(true));
                }
                subMonitor.done();
                monitor.done();
            } catch (Exception e) {
                LOGGER.error("restore editor file error", e);
            }
        }
    };
    try {
        new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
    } catch (Exception e) {
        LOGGER.error("restore editor file error", e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) VTDGen(com.ximpleware.VTDGen) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) WorkbenchPage(org.eclipse.ui.internal.WorkbenchPage) IEditorReference(org.eclipse.ui.IEditorReference) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) AutoPilot(com.ximpleware.AutoPilot) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IFile(org.eclipse.core.resources.IFile) File(java.io.File) VTDNav(com.ximpleware.VTDNav)

Example 33 with IEditorReference

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

the class OpenFileWithValidAction method validIsopened.

/**
	 * 验证是否已经被打开
	 * @param iFile
	 * @return 如果当前要打开的文件未被打开,那么验证通过,返回true,否则返回false。
	 */
private boolean validIsopened(IFile iFile) throws Exception {
    String extention = iFile.getFileExtension();
    if (IDE.getDefaultEditor(iFile, true) != null && XLIFF_EDITOR_ID.equals(IDE.getDefaultEditor(iFile, true).getId()) && CommonFunction.validXlfExtension(extention)) {
        IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
        IEditorPart editor = null;
        IFile openIFile = null;
        String needOpenIfileLc = iFile.getLocation().toOSString();
        for (int i = 0; i < editorRes.length; i++) {
            if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
                // 备注:这里的两行代码已经被注释了,原因是因为 getEditor 方法会让每一个 editor 都初始一次,这并不是本次需求所要的。注意。	2013-01-04
                //editor = editorRes[i].getEditor(true);
                //openIFile = ((IFileEditorInput) editor.getEditorInput()).getFile();
                openIFile = ((IFileEditorInput) editorRes[i].getEditorInput()).getFile();
                // 判断是否是合并打开,后缀名为xlp为合并打开,后缀名为xlf为单一打开
                if ("xlp".equals(openIFile.getFileExtension())) {
                    // 开始解析这个合并打开临时文件,获取合并打开的文件。
                    VTDGen vg = new VTDGen();
                    if (vg.parseFile(openIFile.getLocation().toOSString(), true)) {
                        VTDNav vn = vg.getNav();
                        AutoPilot ap = new AutoPilot(vn);
                        try {
                            ap.selectXPath("/mergerFiles/mergerFile/@filePath");
                            int index = -1;
                            while ((index = ap.evalXPath()) != -1) {
                                String fileLC = vn.toString(index + 1);
                                if (fileLC != null && !"".equals(fileLC)) {
                                    if (fileLC.equals(needOpenIfileLc)) {
                                        editor = editorRes[i].getEditor(true);
                                        page.activate(editor);
                                        return false;
                                    }
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) AutoPilot(com.ximpleware.AutoPilot) VTDGen(com.ximpleware.VTDGen) IEditorPart(org.eclipse.ui.IEditorPart) VTDNav(com.ximpleware.VTDNav) PartInitException(org.eclipse.ui.PartInitException)

Example 34 with IEditorReference

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

the class DeleteResourceAndCloseEditorAction method closeRelatedEditors.

/**
	 * 删除文件时,如果文件在编辑器中已打开,则关闭此文件。 ;
	 */
private void closeRelatedEditors() {
    IWorkbenchPage page = null;
    for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        if (window != null) {
            page = window.getActivePage();
            break;
        }
    }
    if (page == null) {
        return;
    }
    IEditorReference[] editorReferences = page.getEditorReferences();
    final List<IResource> selectionResource = getSelectedResources();
    final List<IEditorReference> lstCloseEditor = new ArrayList<IEditorReference>();
    final VTDGen vg = new VTDGen();
    final AutoPilot ap = new AutoPilot();
    final List<IEditorInput> inputList = new ArrayList<IEditorInput>();
    for (final IEditorReference reference : editorReferences) {
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                IFile file = ((FileEditorInput) reference.getEditor(true).getEditorInput()).getFile();
                if ("xlp".equals(file.getFileExtension())) {
                    if (vg.parseFile(file.getLocation().toOSString(), true)) {
                        VTDNav vn = vg.getNav();
                        ap.bind(vn);
                        try {
                            ap.selectXPath("/mergerFiles/mergerFile/@filePath");
                            int index = -1;
                            merge: while ((index = ap.evalXPath()) != -1) {
                                String fileLC = vn.toString(index + 1);
                                if (fileLC != null && !"".equals(fileLC)) {
                                    for (IResource resource : selectionResource) {
                                        if (resource instanceof IProject || resource instanceof IFolder) {
                                            if (fileLC.startsWith(resource.getLocation().toOSString() + File.separator)) {
                                                lstCloseEditor.add(reference);
                                                inputList.add(reference.getEditorInput());
                                                break merge;
                                            }
                                        } else if (resource instanceof IFile) {
                                            if (resource.getLocation().toOSString().equals(fileLC)) {
                                                lstCloseEditor.add(reference);
                                                inputList.add(reference.getEditorInput());
                                                break merge;
                                            }
                                        }
                                    }
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    try {
                        for (IResource resource : selectionResource) {
                            if (resource instanceof IProject) {
                                if (resource.getLocation().toOSString().equals(file.getProject().getLocation().toOSString())) {
                                    lstCloseEditor.add(reference);
                                    inputList.add(reference.getEditorInput());
                                    break;
                                }
                            } else if (resource instanceof IFolder) {
                                if (file.getLocation().toOSString().startsWith(resource.getLocation().toOSString() + File.separator)) {
                                    lstCloseEditor.add(reference);
                                    inputList.add(reference.getEditorInput());
                                    break;
                                }
                            } else if (resource instanceof IFile) {
                                if (resource.getLocation().toOSString().equals(file.getLocation().toOSString())) {
                                    lstCloseEditor.add(reference);
                                    inputList.add(reference.getEditorInput());
                                    break;
                                }
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }
    final IWorkbenchPage page2 = page;
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            IEditorReference[] arrEditorReference = new IEditorReference[lstCloseEditor.size()];
            page2.closeEditors(lstCloseEditor.toArray(arrEditorReference), false);
            // 删除文件时,刷新访问记录	robert	2012-11-20
            for (IEditorInput input : inputList) {
                System.out.println("input = " + input);
                CommonFunction.refreshHistoryWhenDelete(input);
            }
        }
    });
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) VTDGen(com.ximpleware.VTDGen) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) IEditorReference(org.eclipse.ui.IEditorReference) AutoPilot(com.ximpleware.AutoPilot) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) VTDNav(com.ximpleware.VTDNav) IResource(org.eclipse.core.resources.IResource) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder)

Example 35 with IEditorReference

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

the class MultiFilesOper method getOpenedIfile.

/**
	 * 获取所选择的要合并打开的文件中已经被打开的文件
	 * @return
	 */
public List<IFile> getOpenedIfile() {
    IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    List<IFile> isOpenedXlfList = new ArrayList<IFile>();
    IXliffEditor xlfEditor;
    try {
        for (int i = 0; i < editorRes.length; i++) {
            if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
                IFile iFile = ((FileEditorInput) editorRes[i].getEditorInput()).getFile();
                //合并打开的情况
                if ("xlp".equals(iFile.getFileExtension())) {
                    xlfEditor = (IXliffEditor) editorRes[i].getEditor(true);
                    isOpenedXlfList.addAll(ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList()));
                } else {
                    try {
                        isOpenedXlfList.add(((FileEditorInput) editorRes[i].getEditorInput()).getFile());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return isOpenedXlfList;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ArrayList(java.util.ArrayList) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

IEditorReference (org.eclipse.ui.IEditorReference)174 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)83 IEditorPart (org.eclipse.ui.IEditorPart)78 PartInitException (org.eclipse.ui.PartInitException)59 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)55 IFile (org.eclipse.core.resources.IFile)50 IEditorInput (org.eclipse.ui.IEditorInput)49 ArrayList (java.util.ArrayList)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)28 Item (org.talend.core.model.properties.Item)17 IWorkbench (org.eclipse.ui.IWorkbench)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 IOException (java.io.IOException)12 CoreException (org.eclipse.core.runtime.CoreException)12 ProcessItem (org.talend.core.model.properties.ProcessItem)11 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 Path (org.eclipse.core.runtime.Path)10 IProcess2 (org.talend.core.model.process.IProcess2)10