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();
}
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;
}
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();
}
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();
}
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);
}
}
Aggregations