Search in sources :

Example 76 with IEditorInput

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

the class XLIFFEditorImplWithNatTable method dispose.

/**
	 * 释放编辑器,同时释放其他相关资源。
	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
	 */
public void dispose() {
    // 当该编辑器被释放资源时,检查该编辑器是否被保存,并且是否是同时打开多个文件,若成立,则删除合并打开所产生的临时文件--robert 2012-03-30
    if (!isStore && isMultiFile()) {
        try {
            IEditorInput input = getEditorInput();
            IProject multiProject = ResourceUtil.getResource(input).getProject();
            ResourceUtil.getResource(input).delete(true, null);
            multiProject.refreshLocal(IResource.DEPTH_INFINITE, null);
            CommonFunction.refreshHistoryWhenDelete(input);
        } catch (CoreException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        }
    }
    if (titleImage != null && !titleImage.isDisposed()) {
        titleImage.dispose();
        titleImage = null;
    }
    if (table != null && !table.isDisposed()) {
        table.dispose();
        table = null;
    }
    if (statusLineImage != null && !statusLineImage.isDisposed()) {
        statusLineImage.dispose();
        statusLineImage = null;
    }
    handler = null;
    JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener);
    NattableUtil.getInstance(this).releaseResource();
    super.dispose();
    System.gc();
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) IProject(org.eclipse.core.resources.IProject)

Example 77 with IEditorInput

use of org.eclipse.ui.IEditorInput 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)

Example 78 with IEditorInput

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

the class WordsFA method lockRepeatTU.

/**
	 * 执行锁定重复文本段
	 */
private void lockRepeatTU(Map<String, WordsFAResult> wordsFAResultMap) {
    final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
    // 首先,判断当前所处理的文件是否合并打开
    if (model.isMultiFile()) {
        if (needLockRowIdList.size() <= 0) {
            return;
        }
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                IEditorInput input = new FileEditorInput(model.getMultiTempIFile());
                IEditorReference[] reference = window.getActivePage().findEditors(input, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                nattble = (XLIFFEditorImplWithNatTable) reference[0].getEditor(true);
                XLFHandler thisHandler = nattble.getXLFHandler();
                thisHandler.lockFaTU(needLockRowIdList);
                nattble.redraw();
            }
        });
    } else {
        //针对已经打开的文件进行锁定
        if (needLockRowIdList.size() <= 0) {
            return;
        }
        final Map<String, List<String>> rowIdMap = RowIdUtil.groupRowIdByFileName(needLockRowIdList);
        for (final IFile iFile : model.getAnalysisIFileList()) {
            isOpened = false;
            final String filePath = iFile.getLocation().toOSString();
            if (rowIdMap.get(filePath) == null || rowIdMap.get(filePath).size() <= 0) {
                continue;
            }
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                    IEditorInput input = new FileEditorInput(iFile);
                    IEditorReference[] reference = window.getActivePage().findEditors(input, XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                    if (reference.length > 0) {
                        isOpened = true;
                        nattble = (XLIFFEditorImplWithNatTable) reference[0].getEditor(true);
                        XLFHandler thisHandler = nattble.getXLFHandler();
                        thisHandler.lockFaTU(rowIdMap.get(filePath));
                        nattble.redraw();
                    }
                }
            });
            if (!isOpened) {
                for (String rowId : rowIdMap.get(filePath)) {
                    handler.lockedTU(rowId);
                }
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IEditorInput(org.eclipse.ui.IEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 79 with IEditorInput

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

the class UpdateTMHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = HandlerUtil.getActiveShell(event);
    String partId = HandlerUtil.getActivePartId(event);
    ArrayList<IFile> lstXliff = new ArrayList<IFile>();
    //		boolean isShowCurrentLangBtn = true;
    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();
            for (Object obj : lstObj) {
                if (obj instanceof IFile) {
                    IFile file = (IFile) obj;
                    // Linux 下的文本文件无扩展名,因此要先判断扩展名是否为空
                    if (file.getFileExtension() != null && CommonFunction.validXlfExtension(file.getFileExtension())) {
                        lstXliff.add(file);
                    }
                } else if (obj instanceof IFolder) {
                    try {
                        ResourceUtils.getXliffs((IFolder) obj, lstXliff);
                    } catch (CoreException e) {
                        LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger1"), e);
                        MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg1"));
                    }
                } else if (obj instanceof IProject) {
                    try {
                        ResourceUtils.getXliffs((IProject) obj, lstXliff);
                    } catch (CoreException e) {
                        LOGGER.error(Messages.getString("handler.UpdateTMHandler.logger2"), e);
                        MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg2"));
                    }
                }
            }
            CommonFunction.removeRepeateSelect(lstXliff);
            if (lstXliff.size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
                return null;
            }
            Iterator<IFile> iterator = lstXliff.iterator();
            while (iterator.hasNext()) {
                IFile file = iterator.next();
                FileEditorInput editorInput = new FileEditorInput(file);
                IEditorPart editorPart = page.findEditor(editorInput);
                if (editorPart == null || (editorPart != null && !(editorPart instanceof IXliffEditor))) {
                    //						isShowCurrentLangBtn = false;
                    break;
                }
            }
        } else {
            MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg3"));
            return null;
        }
    } 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()) {
            List<String> lstFile = new XLFHandler().getMultiFiles(iFile);
            if (lstFile.size() > 0) {
                for (String filePath : lstFile) {
                    lstXliff.add(ResourceUtils.fileToIFile(filePath));
                }
            }
        } else if (iFile.getFileExtension() != null && CommonFunction.validXlfExtension(iFile.getFileExtension())) {
            lstXliff.add(iFile);
        }
    }
    if (lstXliff.size() > 0) {
        if (lstXliff.size() > 1) {
            String projectPath = lstXliff.get(0).getProject().getFullPath().toOSString();
            for (int i = 1; i < lstXliff.size(); i++) {
                String projectPath2 = lstXliff.get(i).getProject().getFullPath().toOSString();
                if (!projectPath.equals(projectPath2)) {
                    MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg4"));
                    return null;
                }
            }
        }
        ArrayList<IFile> lstFiles = new ArrayList<IFile>();
        XLFValidator.resetFlag();
        for (IFile iFile : lstXliff) {
            if (!XLFValidator.validateXliffFile(iFile)) {
                lstFiles.add(iFile);
            }
        }
        XLFValidator.resetFlag();
        lstXliff.removeAll(lstFiles);
        if (lstXliff.size() == 0) {
            return null;
        }
        ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(lstXliff.get(0).getProject());
        if (projectConfig.getDefaultTMDb() == null) {
            MessageDialog.openInformation(shell, Messages.getString("handler.UpdateTMHandler.msgTitle"), Messages.getString("handler.UpdateTMHandler.msg5"));
            return null;
        }
        UpdateTMWizard wizard = new UpdateTMWizard(lstXliff);
        TSWizardDialog dialog = new UpdateTMWizardDialog(shell, wizard);
        //			UpdateTMDialog dialog = new UpdateTMDialog(shell, isShowCurrentLangBtn, lstXliff);
        dialog.open();
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) UpdateTMWizard(net.heartsome.cat.database.ui.tm.wizard.UpdateTMWizard) Shell(org.eclipse.swt.widgets.Shell) UpdateTMWizardDialog(net.heartsome.cat.database.ui.tm.wizard.UpdateTMWizardDialog) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) ArrayList(java.util.ArrayList) List(java.util.List) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) TSWizardDialog(net.heartsome.cat.common.ui.wizard.TSWizardDialog) IEditorInput(org.eclipse.ui.IEditorInput) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) IFolder(org.eclipse.core.resources.IFolder)

Example 80 with IEditorInput

use of org.eclipse.ui.IEditorInput in project cubrid-manager by CUBRID.

the class QueryEditorPart method changeQueryEditorPartNameWithShard.

public void changeQueryEditorPartNameWithShard() {
    IEditorInput input = getEditorInput();
    if (!(input instanceof QueryUnit)) {
        return;
    }
    // [TOOLS-2425]Support shard broker
    boolean isShard = false;
    QueryUnit queryUnit = (QueryUnit) input;
    if (CubridDatabase.hasValidDatabaseInfo(queryUnit.getDatabase())) {
        DatabaseInfo dbInfo = queryUnit.getDatabase().getDatabaseInfo();
        isShard = dbInfo.isShard();
    }
    if (isShard) {
        String text = null;
        if (shardQueryType == DatabaseInfo.SHARD_QUERY_TYPE_ID) {
            text = editorTabNameOriginal + "(SHARD_ID:" + shardId + ")";
        } else {
            text = editorTabNameOriginal + "(SHARD_VAL:" + shardVal + ")";
        }
        queryUnit.setToolTip(text);
        setPartName(text);
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)135 IFile (org.eclipse.core.resources.IFile)38 IEditorPart (org.eclipse.ui.IEditorPart)37 PartInitException (org.eclipse.ui.PartInitException)31 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)28 CoreException (org.eclipse.core.runtime.CoreException)25 IFileEditorInput (org.eclipse.ui.IFileEditorInput)22 IDocument (org.eclipse.jface.text.IDocument)17 IEditorReference (org.eclipse.ui.IEditorReference)17 FileEditorInput (org.eclipse.ui.part.FileEditorInput)16 File (java.io.File)14 ArrayList (java.util.ArrayList)14 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)14 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)14 IResource (org.eclipse.core.resources.IResource)13 Shell (org.eclipse.swt.widgets.Shell)13 IViewPart (org.eclipse.ui.IViewPart)13 IPath (org.eclipse.core.runtime.IPath)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)11