use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class ViewerTestDTD method getActiveEditor.
/**
* Returns the current active text editor if possible
*
* @return ITextEditor
*/
private ITextEditor getActiveEditor() {
ITextEditor editor = null;
IEditorPart editorPart = getSite().getWorkbenchWindow().getActivePage().getActiveEditor();
if (editorPart instanceof ITextEditor)
editor = (ITextEditor) editorPart;
if (editor == null && editorPart != null)
editor = (ITextEditor) editorPart.getAdapter(ITextEditor.class);
return editor;
}
use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class ViewerTestXML method getActiveEditor.
/**
* Returns the current active text editor if possible
*
* @return ITextEditor
*/
private ITextEditor getActiveEditor() {
ITextEditor editor = null;
IEditorPart editorPart = getSite().getWorkbenchWindow().getActivePage().getActiveEditor();
if (editorPart instanceof ITextEditor)
editor = (ITextEditor) editorPart;
if (editor == null && editorPart != null)
editor = editorPart.getAdapter(ITextEditor.class);
return editor;
}
use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class ViewerTestXML method followSelection.
/**
* Hooks up the viewer to follow the selection made in the active editor
*/
private void followSelection() {
ITextEditor editor = getActiveEditor();
if (editor != null) {
setupViewerForEditor(editor);
if (fHighlightRangeListener == null)
fHighlightRangeListener = new NodeRangeSelectionListener();
fContentOutlinePage = (editor.getAdapter(IContentOutlinePage.class));
if (fContentOutlinePage != null) {
fContentOutlinePage.addSelectionChangedListener(fHighlightRangeListener);
if (!fContentOutlinePage.getSelection().isEmpty() && fContentOutlinePage.getSelection() instanceof IStructuredSelection) {
fSourceViewer.resetVisibleRegion();
Object[] nodes = ((IStructuredSelection) fContentOutlinePage.getSelection()).toArray();
IndexedRegion startNode = (IndexedRegion) nodes[0];
IndexedRegion endNode = (IndexedRegion) nodes[nodes.length - 1];
if (startNode instanceof Attr)
startNode = (IndexedRegion) ((Attr) startNode).getOwnerElement();
if (endNode instanceof Attr)
endNode = (IndexedRegion) ((Attr) endNode).getOwnerElement();
int start = startNode.getStartOffset();
int end = endNode.getEndOffset();
fSourceViewer.setVisibleRegion(start, end - start);
fSourceViewer.setSelectedRange(start, 0);
}
}
}
}
use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class NewXSLFileWizard method openEditor.
private void openEditor(final IFile file, final int cursorOffset) {
// Open editor on new file.
String editorId = null;
try {
IEditorDescriptor editor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getFullPath().toString(), file.getContentDescription().getContentType());
if (editor != null) {
editorId = editor.getId();
}
} catch (CoreException e1) {
// editor id could not be retrieved, so we can not open editor
return;
}
final String finalEditorId = editorId;
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
try {
if (dw != null) {
IWorkbenchPage page = dw.getActivePage();
if (page != null) {
IEditorPart editor = page.openEditor(new FileEditorInput(file), finalEditorId, true);
ITextEditor textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
if (textEditor != null)
textEditor.selectAndReveal(cursorOffset, 0);
editor.setFocus();
}
}
} catch (PartInitException e) {
// editor can not open for some reason
XSLUIPlugin.log(e);
}
}
});
}
use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class ToggleEditModeHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
ITextEditor textEditor = null;
if (editor instanceof ITextEditor)
textEditor = (ITextEditor) editor;
else {
Object o = editor.getAdapter(ITextEditor.class);
if (o != null)
textEditor = (ITextEditor) o;
}
if (textEditor != null) {
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model != null) {
ModelQuery modelQuery;
try {
modelQuery = ModelQueryUtil.getModelQuery(model);
} finally {
model.releaseFromRead();
}
if (modelQuery != null) {
int newState = getNextState(modelQuery.getEditMode());
modelQuery.setEditMode(newState);
// Force a Refresh on this command so that the image can
// be
// updated.
ICommandService commandService = HandlerUtil.getActiveWorkbenchWindow(event).getService(ICommandService.class);
Map<String, IWorkbenchWindow> filter = new HashMap<>();
filter.put(IServiceScopes.WINDOW_SCOPE, HandlerUtil.getActiveWorkbenchWindow(event));
commandService.refreshElements(event.getCommand().getId(), filter);
}
}
}
return null;
}
Aggregations