use of org.eclipse.ui.IEditorRegistry in project webtools.sourceediting by eclipse.
the class ReferencedFileErrorUtility method openEditorAndGotoError.
public static void openEditorAndGotoError(String uristring, final int line, final int column) {
if (uristring != null) {
try {
URL uri = new URL(uristring);
if (uri != null) {
if (// $NON-NLS-1$
"file".equals(uri.getProtocol())) {
String pathString = uri.getPath();
IPath path = new Path(pathString);
String device = path.getDevice();
if (// $NON-NLS-1$
(device != null) && device.startsWith("/")) {
path = path.setDevice(device.substring(1));
}
final IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
if ((iFile != null) && iFile.exists()) {
// Open the editor for this file.
final IWorkbench workbench = PlatformUI.getWorkbench();
final IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
IContentType contentType = iFile.getContentDescription().getContentType();
IEditorRegistry editorRegistry = workbench.getEditorRegistry();
String fileName = iFile.getName();
IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(fileName, contentType);
String editorId;
if (descriptor != null) {
editorId = descriptor.getId();
} else {
// $NON-NLS-1$
descriptor = editorRegistry.getDefaultEditor(fileName + ".txt");
editorId = descriptor.getId();
}
if (editorId != null) {
FileEditorInput editorInput = new FileEditorInput(iFile);
IWorkbenchPage activePage = workbenchWindow.getActivePage();
activePage.openEditor(editorInput, editorId);
}
} catch (Exception ex) {
// $NON-NLS-1$ //$NON-NLS-2$
LoggerFactory.getLoggerInstance().logError("Exception encountered when attempting to open file: " + iFile + "\n\n", ex);
}
}
});
Runnable runnable = new Runnable() {
public void run() {
IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
gotoError(editorPart, line, column);
}
};
Display.getCurrent().asyncExec(runnable);
}
}
}
} catch (Exception e) {
// Do nothing.
}
}
}
use of org.eclipse.ui.IEditorRegistry 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;
}
use of org.eclipse.ui.IEditorRegistry in project webtools.sourceediting by eclipse.
the class AbstractOpenOn method getEditorId.
/**
* Determines the editor associated with the given file name
*
* @param filename
* @return editor id of the editor associated with the given file name
*/
private String getEditorId(String filename) {
IWorkbench workbench = PlatformUI.getWorkbench();
IEditorRegistry editorRegistry = workbench.getEditorRegistry();
IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(filename);
if (descriptor != null)
return descriptor.getId();
return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
}
use of org.eclipse.ui.IEditorRegistry in project liferay-ide by liferay.
the class DefaultScriptEditorHelper method getEditorId.
public String getEditorId() {
IContentType contentType = Platform.getContentTypeManager().getContentType("org.eclipse.core.runtime.text");
IWorkbench workBench = PlatformUI.getWorkbench();
IEditorRegistry editRegistry = workBench.getEditorRegistry();
IEditorDescriptor defaultEditorDescriptor = editRegistry.getDefaultEditor("default.txt", contentType);
return defaultEditorDescriptor.getId();
}
use of org.eclipse.ui.IEditorRegistry in project liferay-ide by liferay.
the class OpenPortletResourceAction method findEditor.
/**
* @param file
* @return
*/
protected IEditorDescriptor findEditor(IFile file) {
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
IContentType contentType = IDE.getContentType(file);
IEditorDescriptor editorDescriptor = registry.getDefaultEditor(file.getName(), contentType);
if (editorDescriptor == null) {
// no editor associated...
return null;
}
return editorDescriptor;
}
Aggregations