Search in sources :

Example 6 with IEditorRegistry

use of org.eclipse.ui.IEditorRegistry in project xtext-eclipse by eclipse.

the class XtextEditor method getDefaultImage.

@Override
public Image getDefaultImage() {
    IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
    IEditorDescriptor editorDesc = editorRegistry.findEditor(getSite().getId());
    ImageDescriptor imageDesc = editorDesc != null ? editorDesc.getImageDescriptor() : null;
    return imageDesc != null ? imageHelper.getImage(imageDesc) : super.getDefaultImage();
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Example 7 with IEditorRegistry

use of org.eclipse.ui.IEditorRegistry in project egit by eclipse.

the class UIUtils method getEditorImage.

/**
 * Get editor image for path
 *
 * @param path
 * @return image descriptor
 */
public static ImageDescriptor getEditorImage(final String path) {
    if (path == null || path.length() <= 0) {
        return DEFAULT_FILE_IMG;
    }
    final String fileName = new Path(path).lastSegment();
    if (fileName == null) {
        return DEFAULT_FILE_IMG;
    }
    IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
    IEditorDescriptor defaultEditor = registry.getDefaultEditor(fileName);
    if (defaultEditor != null) {
        return defaultEditor.getImageDescriptor();
    }
    // now we know there is no Eclipse editor for the file, and Eclipse will
    // check Program.findProgram() and this will be slow, see bug 464891
    int extensionIndex = fileName.lastIndexOf('.');
    if (extensionIndex < 0) {
        // Program.findProgram() uses extensions only
        return DEFAULT_FILE_IMG;
    }
    String key = fileName.substring(extensionIndex);
    SoftReference<ImageDescriptor> cached = extensionToDescriptor.get(key);
    if (cached != null) {
        ImageDescriptor descriptor = cached.get();
        if (descriptor != null) {
            return descriptor;
        }
    }
    // In worst case this calls Program.findProgram() and blocks UI
    ImageDescriptor descriptor = registry.getImageDescriptor(fileName);
    extensionToDescriptor.put(key, new SoftReference<>(descriptor));
    return descriptor;
}
Also used : Path(org.eclipse.core.runtime.Path) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IEditorRegistry(org.eclipse.ui.IEditorRegistry) Point(org.eclipse.swt.graphics.Point)

Example 8 with IEditorRegistry

use of org.eclipse.ui.IEditorRegistry 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 9 with IEditorRegistry

use of org.eclipse.ui.IEditorRegistry 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 10 with IEditorRegistry

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

Aggregations

IEditorRegistry (org.eclipse.ui.IEditorRegistry)19 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)18 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)7 IWorkbench (org.eclipse.ui.IWorkbench)7 IContentType (org.eclipse.core.runtime.content.IContentType)5 Image (org.eclipse.swt.graphics.Image)5 InputStream (java.io.InputStream)2 Path (org.eclipse.core.runtime.Path)2 Point (org.eclipse.swt.graphics.Point)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1