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