use of org.eclipse.ui.IEditorDescriptor in project webtools.sourceediting by eclipse.
the class ExternalFileHyperlink method getEditorLabel.
private String getEditorLabel() {
final IFileStore store = EFS.getLocalFileSystem().getStore(fHyperlinkFile.toURI());
final String name = store.fetchInfo().getName();
if (name == null) {
return null;
}
IContentType contentType = null;
try {
InputStream is = null;
try {
is = store.openInputStream(EFS.NONE, null);
contentType = Platform.getContentTypeManager().findContentTypeFor(is, name);
} finally {
if (is != null) {
is.close();
}
}
} catch (CoreException ex) {
// continue without content type
} catch (IOException ex) {
// continue without content type
}
final IEditorDescriptor descriptor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(name, contentType);
return descriptor != null ? descriptor.getLabel() : null;
}
use of org.eclipse.ui.IEditorDescriptor in project webtools.sourceediting by eclipse.
the class URLStorageHyperlink method open.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
*/
public void open() {
if (fURL != null) {
IEditorInput input = new StorageEditorInput(new URLStorage(fURL));
try {
final IEditorDescriptor descriptor = getEditorDescriptor();
if (descriptor != null) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IDE.openEditor(page, input, descriptor.getId(), true);
}
} catch (PartInitException e) {
Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
new URLHyperlink(fRegion, fURL.toString()).open();
}
}
}
use of org.eclipse.ui.IEditorDescriptor in project webtools.sourceediting by eclipse.
the class NewXSDWizard method openEditor.
public void openEditor(final IFile iFile) {
if (iFile != null) {
IWorkbench workbench2;
if (workbench == null) {
workbench2 = XSDEditorPlugin.getPlugin().getWorkbench();
} else {
workbench2 = workbench;
}
final IWorkbenchWindow workbenchWindow = workbench2.getActiveWorkbenchWindow();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
String editorId = null;
IEditorDescriptor editor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(iFile.getLocation().toOSString(), iFile.getContentDescription().getContentType());
if (editor != null) {
editorId = editor.getId();
}
workbenchWindow.getActivePage().openEditor(new FileEditorInput(iFile), editorId);
} catch (PartInitException ex) {
} catch (CoreException ex) {
}
}
});
}
}
use of org.eclipse.ui.IEditorDescriptor in project webtools.sourceediting by eclipse.
the class URLFileRegionHyperlink method open.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
*/
public void open() {
if (fURL != null) {
IEditorInput input = new StorageEditorInput(new URLStorage(fURL));
IEditorDescriptor descriptor;
try {
descriptor = IDE.getEditorDescriptor(input.getName(), true);
if (descriptor != null) {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart openedEditor = IDE.openEditor(page, input, descriptor.getId(), true);
IRegion definitionRegion = findDefinitionRegion(new URLStorage(fURL));
if (definitionRegion != null) {
openedEditor.getSite().getSelectionProvider().setSelection(new TextSelection(definitionRegion.getOffset(), definitionRegion.getLength()));
}
}
} catch (PartInitException e) {
Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
}
}
}
use of org.eclipse.ui.IEditorDescriptor in project webtools.sourceediting by eclipse.
the class ExtendedStorageEditorInputView method getEditorId.
String getEditorId(IEditorInput input) {
IWorkbench workbench = PlatformUI.getWorkbench();
IEditorRegistry editorRegistry = workbench.getEditorRegistry();
IContentType[] types = null;
String editorID = null;
if (input instanceof IStorageEditorInput) {
InputStream inputStream = null;
try {
inputStream = ((IStorageEditorInput) input).getStorage().getContents();
} catch (CoreException e) {
e.printStackTrace();
}
try {
types = Platform.getContentTypeManager().findContentTypesFor(inputStream, input.getName());
} catch (IOException e) {
e.printStackTrace();
}
try {
if (inputStream != null) {
inputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(input.getName(), types[0]);
if (descriptor != null) {
editorID = descriptor.getId();
}
if (editorID == null) {
editorID = EditorsUI.DEFAULT_TEXT_EDITOR_ID;
}
return editorID;
}
Aggregations