Search in sources :

Example 6 with FileEditorInput

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

the class ScriptsHandlerImpl method openResource.

@Override
public void openResource(@NotNull IResource resource) throws CoreException, DBException {
    if (resource instanceof IFile) {
        FileEditorInput sqlInput = new FileEditorInput((IFile) resource);
        DBeaverUI.getActiveWorkbenchWindow().getActivePage().openEditor(sqlInput, SQLEditor.class.getName());
    } else {
        super.openResource(resource);
    }
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 7 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput 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 8 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class ResourceLinkHelper method activateEditor.

/* (non-Javadoc)
	 * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
	 */
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    if (aSelection == null || aSelection.isEmpty())
        return;
    if (aSelection.getFirstElement() instanceof IFile) {
        IEditorInput fileInput = new FileEditorInput((IFile) aSelection.getFirstElement());
        IEditorPart editor = null;
        if ((editor = aPage.findEditor(fileInput)) != null)
            aPage.bringToTop(editor);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) IEditorInput(org.eclipse.ui.IEditorInput)

Example 9 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class ConcordanceSearchHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    if (!isEnabled()) {
        return null;
    }
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof IXliffEditor) {
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
        IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
            // IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
            IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
            ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
            List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
            if (lstDatabase.size() == 0) {
                MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.ConcordanceSearchHandler.msgTitle"), Messages.getString("handler.ConcordanceSearchHandler.msg"));
                return null;
            }
            String selectText = xliffEditor.getSelectPureText();
            if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
                selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
            } else if (selectText == null) {
                selectText = "";
            }
            String srcLang = xliffEditor.getSrcColumnName();
            String tgtLang = xliffEditor.getTgtColumnName();
            ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file, srcLang, tgtLang, selectText.trim());
            Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
            Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
            dialog.open();
            if (srcLangL.isBidi() || tgtLangL.isBidi()) {
                dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
            }
            if (selectText != null && !selectText.trim().equals("")) {
                dialog.initGroupIdAndSearch();
                IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
                ICommandService commandService = (ICommandService) site.getService(ICommandService.class);
                Command command = commandService.getCommand(ActionFactory.COPY.getCommandId());
                IEvaluationService evalService = (IEvaluationService) site.getService(IEvaluationService.class);
                IEvaluationContext currentState = evalService.getCurrentState();
                ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
                try {
                    command.executeWithChecks(executionEvent);
                } catch (Exception e1) {
                }
            }
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ConcordanceSearchDialog(net.heartsome.cat.database.ui.tm.dialog.ConcordanceSearchDialog) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) ICommandService(org.eclipse.ui.commands.ICommandService) ExecutionException(org.eclipse.core.commands.ExecutionException) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Language(net.heartsome.cat.common.locale.Language) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEvaluationService(org.eclipse.ui.services.IEvaluationService)

Example 10 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class UpdateTMWizard method performFinish.

public boolean performFinish() {
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final boolean isDraft = page.isDraft();
    final boolean isApproved = page.isApproved();
    final boolean isSignedOff = page.isSignedOff();
    final boolean isTranslated = page.isTranslated();
    final boolean isLocked = page.isLocked();
    if (!isDraft && !isApproved && !isSignedOff && !isTranslated && !isLocked) {
        MessageDialog.openInformation(getShell(), Messages.getString("wizard.UpdateTMWizard.msgTitle"), Messages.getString("wizard.UpdateTMWizard.msg"));
        return false;
    }
    IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
    final int contextSize = ps.getInt(TMPreferenceConstants.CONTEXT_MATCH);
    final int tmxImportStrategy = ps.getInt(TMPreferenceConstants.TM_UPDATE);
    IRunnableWithProgress progress = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) {
            monitor.setTaskName(Messages.getString("dialog.UpdateTMDialog.jobTask1"));
            monitor.beginTask(Messages.getString("dialog.UpdateTMDialog.jobTask1"), lstXLIFF.size() * 2);
            for (final IFile xliffFile : lstXLIFF) {
                ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(xliffFile.getProject());
                DatabaseModelBean modelBean = projectConfig.getDefaultTMDb();
                FileEditorInput editorInput = new FileEditorInput(xliffFile);
                IEditorPart editorPart = activePage.findEditor(editorInput);
                // 选择所有语言
                XLFHandler handler = null;
                if (editorPart != null && editorPart instanceof IXliffEditor) {
                    // xliff 文件已用 XLIFF 编辑器打开
                    IXliffEditor xliffEditor = (IXliffEditor) editorPart;
                    handler = xliffEditor.getXLFHandler();
                } else {
                    // xliff 文件未打开
                    handler = new XLFHandler();
                }
                monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask2"));
                // 修改获取系统用户方式/*System.getProperty("user.name");*/
                String systemUser = PlatformUI.getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
                String[] arrTempTMX = handler.generateTMXToUpdateTM(xliffFile, isApproved, isSignedOff, isTranslated, isDraft, isLocked, contextSize, systemUser);
                monitor.worked(1);
                if (arrTempTMX != null) {
                    monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask3"));
                    // }
                    try {
                        DatabaseService.importTmxWithString(modelBean.toDbMetaData(), arrTempTMX[1], new SubProgressMonitor(monitor, 1), tmxImportStrategy, false, arrTempTMX[0]);
                    } catch (ImportException e) {
                        final String msg = e.getMessage();
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateTMDialog.job.msgTitle"), msg);
                            }
                        });
                        canFinish = false;
                        return;
                    }
                }
            }
            monitor.done();
            // 刷新项目
            ResourceUtils.refreshCurentSelectProject();
            canFinish = true;
        }
    };
    try {
        getContainer().run(true, true, progress);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return canFinish;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ImportException(net.heartsome.cat.common.core.exception.ImportException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

FileEditorInput (org.eclipse.ui.part.FileEditorInput)262 IFile (org.eclipse.core.resources.IFile)187 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)99 PartInitException (org.eclipse.ui.PartInitException)96 IEditorPart (org.eclipse.ui.IEditorPart)64 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)58 IPath (org.eclipse.core.runtime.IPath)57 IEditorInput (org.eclipse.ui.IEditorInput)55 CoreException (org.eclipse.core.runtime.CoreException)51 IResource (org.eclipse.core.resources.IResource)39 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)38 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)37 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)35 SaveAsDialog (org.eclipse.ui.dialogs.SaveAsDialog)35 EObject (org.eclipse.emf.ecore.EObject)33 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)33 HashMap (java.util.HashMap)32 Resource (org.eclipse.emf.ecore.resource.Resource)32 ISelection (org.eclipse.jface.viewers.ISelection)32 URI (org.eclipse.emf.common.util.URI)31