use of org.eclipse.ui.IEditorDescriptor in project linuxtools by eclipse.
the class SpecfileElementHyperlink method open.
@Override
public void open() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
HashMap<String, Object> map = new HashMap<>();
// TODO don't increment the line number once the SpecfileSource reports
// correct line
map.put(IMarker.LINE_NUMBER, Integer.valueOf(getSource().getLineNumber() + 1));
map.put(IDE.EDITOR_ID_ATTR, desc.getId());
try {
IMarker marker = file.createMarker(IMarker.TEXT);
marker.setAttributes(map);
IDE.openEditor(page, marker);
marker.delete();
} catch (CoreException e) {
SpecfileLog.logError(e);
}
}
use of org.eclipse.ui.IEditorDescriptor in project yamcs-studio by yamcs.
the class OpenWithMenu method createOtherMenuItem.
/**
* Creates the Other... menu item
*
* @param menu
* the menu to add the item to
*/
private void createOtherMenuItem(final Menu menu) {
IFile fileResource = getFileResource();
if (fileResource == null) {
return;
}
new MenuItem(menu, SWT.SEPARATOR);
MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
menuItem.setText("Other...");
menuItem.addListener(SWT.Selection, evt -> {
EditorSelectionDialog dialog = new EditorSelectionDialog(menu.getShell());
dialog.setMessage("Choose the editor for opening " + fileResource.getName());
if (dialog.open() == Window.OK) {
IEditorDescriptor editor = dialog.getSelectedEditor();
if (editor != null) {
openEditor(editor, editor.isOpenExternal());
}
}
});
}
use of org.eclipse.ui.IEditorDescriptor in project yamcs-studio by yamcs.
the class OpenWithMenu method fill.
/* (non-Javadoc)
* Fills the menu with perspective items.
*/
@Override
public void fill(Menu menu, int index) {
IFile file = getFileResource();
if (file == null) {
return;
}
// may be null
IEditorDescriptor defaultEditor = registry.findEditor(IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID);
// may be null
IEditorDescriptor preferredEditor = IDE.getDefaultEditor(file);
IEditorDescriptor[] editors = registry.getEditors(file.getName(), IDE.getContentType(file));
Collections.sort(Arrays.asList(editors), comparer);
boolean defaultFound = false;
// Check that we don't add it twice. This is possible
// if the same editor goes to two mappings.
ArrayList<IEditorDescriptor> alreadyMapped = new ArrayList<>();
for (int i = 0; i < editors.length; i++) {
IEditorDescriptor editor = editors[i];
if (!alreadyMapped.contains(editor)) {
createMenuItem(menu, editor, preferredEditor);
if (defaultEditor != null && editor.getId().equals(defaultEditor.getId())) {
defaultFound = true;
}
alreadyMapped.add(editor);
}
}
// Only add a separator if there is something to separate
if (editors.length > 0) {
new MenuItem(menu, SWT.SEPARATOR);
}
// Add default editor. Check it if it is saved as the preference.
if (!defaultFound && defaultEditor != null) {
createMenuItem(menu, defaultEditor, preferredEditor);
}
// add Other... menu item
createOtherMenuItem(menu);
}
use of org.eclipse.ui.IEditorDescriptor in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class JumpToRTSHandler method jump.
private void jump() {
if (className != null) {
IType cls = null;
try {
cls = project.findType(className);
} catch (JavaModelException e) {
return;
}
try {
IFile file = project.getProject().getFile(getTestFileName(cls));
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
FileEditorInput input = new FileEditorInput(file);
IDocumentProvider provider = new TextFileDocumentProvider();
provider.connect(input);
IDocument document = provider.getDocument(input);
TestFile testFile = new TestFile(input, provider);
testFile.parse();
IEditorDescriptor defaultEditor = workbench.getEditorRegistry().getDefaultEditor(file.getName());
String editorId = defaultEditor.getId();
if (!className.equals(testName)) {
for (Test test : testFile.getTests()) {
if (test.toString().equals(testName)) {
int line = document.getLineOfOffset(test.getPosition().getOffset());
IMarker lineMarker = file.createMarker(IMarker.TEXT);
lineMarker.setAttribute(IMarker.LINE_NUMBER, line + 1);
lineMarker.setAttribute(IDE.EDITOR_ID_ATTR, editorId);
IDE.openEditor(page, lineMarker);
lineMarker.delete();
return;
}
}
} else {
IDE.openEditor(page, file);
}
} catch (CoreException | BadLocationException | NullPointerException e) {
e.printStackTrace();
MessageDialog.openError(shell, "Jump to RTS", "Failed to find associated RTS file.");
}
}
}
use of org.eclipse.ui.IEditorDescriptor 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.
}
}
}
Aggregations