Search in sources :

Example 36 with IEditorDescriptor

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

the class HtmlBrowserEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
    setInput(input);
    setPartName(input.getName());
    Image oldTitleImage = titleImage;
    if (input != null) {
        IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
        IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
        ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
        titleImage = imageDesc != null ? imageDesc.createImage() : null;
    }
    setTitleImage(titleImage);
    if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
        oldTitleImage.dispose();
    }
    FileEditorInput fileInput = (FileEditorInput) input;
    htmlUrl = fileInput.getFile().getLocation().toOSString();
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Example 37 with IEditorDescriptor

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

the class XLFEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("init(IEditorSite site, IEditorInput input)");
    }
    setSite(site);
    setInput(input);
    // 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
    setPartName(input.getName());
    Image oldTitleImage = titleImage;
    if (input != null) {
        IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
        IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
        ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
        titleImage = imageDesc != null ? imageDesc.createImage() : null;
    }
    setTitleImage(titleImage);
    if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
        oldTitleImage.dispose();
    }
    getSite().setSelectionProvider(this);
    cursorIbeam = new Cursor(null, SWT.CURSOR_IBEAM);
    cursorArrow = new Cursor(null, SWT.CURSOR_ARROW);
    hookListener();
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Example 38 with IEditorDescriptor

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

the class XLIFFEditorImplWithNatTable method openFile.

/**
	 * 打开文件
	 * @param files
	 * @param input
	 * @throws PartInitException
	 *             ;
	 */
private void openFile(List<File> files, IEditorInput input) throws PartInitException {
    OpenFile of = new OpenFile(files);
    try {
        /**
			 * 异常信息:<br />
			 * Warning: Detected recursive attempt by part net.heartsome.cat.ts.ui.xliffeditor.nattable.editor to create
			 * itself (this is probably, but not necessarily, a bug)
			 */
        if (!PlatformUI.getWorkbench().isStarting()) {
            new ProgressMonitorDialog(getSite().getShell()).run(false, true, of);
        } else {
            of.run(null);
        }
    // of.run(null);
    } catch (InvocationTargetException e) {
        throw new PartInitException(e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new PartInitException(e.getMessage(), e);
    }
    Map<String, Object> result = of.getOpenFileResult();
    if (result == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) result.get(Constant.RETURNVALUE_RESULT)) {
        openFileSucceed = false;
        Throwable e = (Throwable) result.get(Constant.RETURNVALUE_EXCEPTION);
        if (e != null) {
            throw new PartInitException(e.getMessage(), e);
        }
        String msg = (String) result.get(Constant.RETURNVALUE_MSG);
        if (msg == null || msg.length() == 0) {
            msg = Messages.getString("editor.XLIFFEditorImplWithNatTable.msg4");
        }
        MessageDialog.openError(getSite().getShell(), Messages.getString("editor.XLIFFEditorImplWithNatTable.msgTitle3"), msg);
        // 关闭此编辑器。
        close();
    } else {
        // 成功打开文件时
        openFileSucceed = true;
        // 判断所打开的文件是否为空,如果为空,进行提示,并关闭编辑器, robert 2013-04-01
        int tuSize = handler.countTransUnit();
        if (tuSize <= 0) {
            MessageDialog.openWarning(getSite().getShell(), Messages.getString("dialog.UpdateNoteDialog.msgTitle1"), Messages.getString("editor.XLIFFEditorImplWithNatTable.cantOpenNullFile"));
            close();
        }
        Image oldTitleImage = titleImage;
        if (input != null) {
            IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
            IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
            ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
            titleImage = imageDesc != null ? imageDesc.createImage() : null;
        }
        // 如果是合并打开,设置不一样的标志
        if (multiFile) {
            setTitleImage(net.heartsome.cat.ts.ui.xliffeditor.nattable.Activator.getImageDescriptor("icons/multiFiles.png").createImage());
        } else {
            setTitleImage(titleImage);
        }
        if (oldTitleImage != null && !oldTitleImage.isDisposed()) {
            oldTitleImage.dispose();
        }
        JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
    }
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) Image(org.eclipse.swt.graphics.Image) InvocationTargetException(java.lang.reflect.InvocationTargetException) Point(org.eclipse.swt.graphics.Point) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) PartInitException(org.eclipse.ui.PartInitException) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Example 39 with IEditorDescriptor

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

the class ConversionCompleteAction method run.

@Override
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    Assert.isNotNull(window);
    Shell shell = window.getShell();
    if (status.getSeverity() == IStatus.ERROR) {
        MessageDialog.openError(shell, Messages.getString("action.ConversionCompleteAction.msgTitle1"), status.getMessage());
    } else {
        // 转换完成后直接打开编辑器,不再进行弹框提示。
        // MessageDialog.openInformation(shell, "文件转换完成", status.getMessage());
        final String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
        String xliffFile = conversionResult.get(Converter.ATTR_XLIFF_FILE);
        IWorkbenchPage page = window.getActivePage();
        Assert.isNotNull(page, Messages.getString("action.ConversionCompleteAction.msg1"));
        if (xliffFile != null) {
            IEditorDescriptor editorDescriptor = PlatformUI.getWorkbench().getEditorRegistry().findEditor(XLIFF_EDITOR_ID);
            if (editorDescriptor != null) {
                try {
                    IDE.openEditor(page, new File(xliffFile).toURI(), XLIFF_EDITOR_ID, true);
                } catch (PartInitException e) {
                    MessageDialog.openInformation(shell, Messages.getString("action.ConversionCompleteAction.msgTitle2"), Messages.getString("action.ConversionCompleteAction.msg2") + e.getMessage());
                    e.printStackTrace();
                }
            }
        } else {
            String targetFile = conversionResult.get(Converter.ATTR_TARGET_FILE);
            if (targetFile == null) {
                MessageDialog.openInformation(shell, Messages.getString("action.ConversionCompleteAction.msgTitle2"), Messages.getString("action.ConversionCompleteAction.msg3"));
            } else {
                IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
                IFile input = root.getFileForLocation(new Path(targetFile));
                try {
                    // 使用外部编辑器(系统默认编辑器)打开文件。
                    IDE.openEditor(page, input, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
                } catch (PartInitException e) {
                    MessageDialog.openInformation(shell, Messages.getString("action.ConversionCompleteAction.msgTitle2"), Messages.getString("action.ConversionCompleteAction.msg4") + e.getMessage());
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) File(java.io.File) IFile(org.eclipse.core.resources.IFile)

Example 40 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project eclipse.platform.text by eclipse.

the class EditorOpener method openAndSelect.

public IEditorPart openAndSelect(IWorkbenchPage wbPage, IFile file, int offset, int length, boolean activate) throws PartInitException {
    String editorId = null;
    IEditorDescriptor desc = IDE.getEditorDescriptor(file, true, true);
    if (desc == null || !desc.isInternal()) {
        // $NON-NLS-1$
        editorId = "org.eclipse.ui.DefaultTextEditor";
    } else {
        editorId = desc.getId();
    }
    IEditorPart editor;
    if (NewSearchUI.reuseEditor()) {
        editor = showWithReuse(file, wbPage, editorId, activate);
    } else {
        editor = showWithoutReuse(file, wbPage, editorId, activate);
    }
    if (editor instanceof ITextEditor) {
        ITextEditor textEditor = (ITextEditor) editor;
        textEditor.selectAndReveal(offset, length);
    } else if (editor != null) {
        showWithMarker(editor, file, offset, length);
    }
    return editor;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart)

Aggregations

IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)74 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)34 PartInitException (org.eclipse.ui.PartInitException)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)27 IWorkbench (org.eclipse.ui.IWorkbench)25 IEditorPart (org.eclipse.ui.IEditorPart)21 IFile (org.eclipse.core.resources.IFile)19 IEditorRegistry (org.eclipse.ui.IEditorRegistry)18 CoreException (org.eclipse.core.runtime.CoreException)10 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)10 IEditorInput (org.eclipse.ui.IEditorInput)8 IContentType (org.eclipse.core.runtime.content.IContentType)7 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)7 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)7 Image (org.eclipse.swt.graphics.Image)5 InputStream (java.io.InputStream)4 BadLocationException (org.eclipse.jface.text.BadLocationException)4 Path (org.eclipse.core.runtime.Path)3 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)3 JavaModelException (org.eclipse.jdt.core.JavaModelException)3