use of org.eclipse.ui.IEditorDescriptor in project liferay-ide by liferay.
the class OpenPortletResourceAction method openEditor.
protected IEditorPart openEditor(IFile file) {
IEditorDescriptor editorDescriptor = findEditor(file);
IEditorPart editorPart = null;
if (editorDescriptor != null) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
editorPart = page.findEditor(new FileEditorInput(file));
if (editorPart == null) {
editorPart = page.openEditor(new FileEditorInput(file), editorDescriptor.getId());
}
} catch (Exception e) {
MessageDialog.openError(page.getWorkbenchWindow().getShell(), Msgs.errorOpeningFile, e.getMessage());
}
}
return editorPart;
}
use of org.eclipse.ui.IEditorDescriptor in project liferay-ide by liferay.
the class OpenPortletResourceAction method openPortletJavaClass.
/**
* @param file
*/
protected void openPortletJavaClass(IFile file) {
Element modelElement = ((PortletNode) selectedNode).getModel();
if (modelElement instanceof Portlet) {
Portlet portlet = (Portlet) modelElement;
JavaTypeName portletClassFile = portlet.getPortletClass().content();
Runnable run = new Runnable() {
public void run() {
IJavaProject project = JavaCore.create(file.getProject());
String fullyQualifiedName = portletClassFile.qualified();
try {
IType type = project.findType(fullyQualifiedName);
if ((type != null) && type.exists()) {
IResource resource = type.getResource();
if (resource instanceof IFile) {
IFile javaFile = (IFile) resource;
IEditorDescriptor editorDescriptor = findEditor(javaFile);
IEditorPart editorPart = null;
if (editorDescriptor != null) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
editorPart = page.findEditor(new FileEditorInput(javaFile));
if (editorPart == null) {
editorPart = page.openEditor(new FileEditorInput(javaFile), editorDescriptor.getId());
}
} catch (Exception e) {
MessageDialog.openError(page.getWorkbenchWindow().getShell(), Msgs.errorOpeningFile, e.getMessage());
}
}
}
}
} catch (JavaModelException jme) {
PortletUIPlugin.logError(jme);
}
}
};
Display.getDefault().asyncExec(run);
}
}
use of org.eclipse.ui.IEditorDescriptor in project xtext-eclipse by eclipse.
the class StorageBasedTextEditorOpener method open.
@Override
public void open(IWorkbenchPage page) {
try {
IEditorInput input = EditorUtils.createEditorInput(storage);
IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor(storage.getName());
IEditorPart opened = IDE.openEditor(page, input, editorDescriptor.getId());
if (region != null && opened instanceof ITextEditor) {
ITextEditor openedTextEditor = (ITextEditor) opened;
openedTextEditor.selectAndReveal(region.getOffset(), region.getLength());
}
} catch (PartInitException e) {
LOG.error(e.getMessage(), e);
}
}
use of org.eclipse.ui.IEditorDescriptor in project egit by eclipse.
the class EgitUiEditorUtils method getEditorId.
private static String getEditorId(String fileName, IContentType type) {
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
IEditorDescriptor descriptor = registry.getDefaultEditor(fileName, type);
String id;
if (descriptor == null || descriptor.isOpenExternal()) {
id = EditorsUI.DEFAULT_TEXT_EDITOR_ID;
} else {
id = descriptor.getId();
}
return id;
}
use of org.eclipse.ui.IEditorDescriptor in project egit by eclipse.
the class OpenWorkingFileAction method openExternalFile.
/**
* Opens external file, the editor that is used is based on best guess from
* file name.
*
* @param file
* the external file
*/
protected void openExternalFile(File file) {
try {
boolean activate = OpenStrategy.activateOnOpen();
IEditorDescriptor desc = IDE.getEditorDescriptor(file.getName());
IDE.openEditor(getWorkbenchPage(), file.toURI(), desc.getId(), activate);
} catch (PartInitException e) {
ErrorDialog.openError(getWorkbenchPage().getWorkbenchWindow().getShell(), UIText.OpenWorkingFileAction_openWorkingFileShellTitle, e.getMessage(), e.getStatus());
}
}
Aggregations