use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class ViewerTestJSP 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 XSDMultiPageEditorContributor method setActivePage.
/*
* (non-JavaDoc) Method declared in
* AbstractMultiPageEditorActionBarContributor.
*/
public void setActivePage(IEditorPart part) {
if (activeEditorPart == part)
return;
activeEditorPart = part;
IActionBars actionBars = getActionBars();
boolean isSource = false;
if (activeEditorPart != null && activeEditorPart instanceof ITextEditor) {
isSource = true;
zoomInRetargetAction.setEnabled(false);
zoomOutRetargetAction.setEnabled(false);
captureScreenAction.setEnabled(false);
activateSourcePage(activeEditorPart, true);
} else {
activateSourcePage(xsdEditor, false);
if (part instanceof InternalXSDMultiPageEditor) {
xsdEditor = (InternalXSDMultiPageEditor) part;
}
if (xsdEditor != null) {
// cs: here's we ensure the UNDO and REDO actions are available when
// the design view is active
IWorkbenchPartSite site = xsdEditor.getSite();
if (site instanceof IEditorSite) {
ITextEditor textEditor = xsdEditor.getTextEditor();
IActionBars siteActionBars = ((IEditorSite) site).getActionBars();
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.UNDO, getAction(textEditor, ITextEditorActionConstants.UNDO));
siteActionBars.setGlobalActionHandler(ITextEditorActionConstants.REDO, getAction(textEditor, ITextEditorActionConstants.REDO));
siteActionBars.updateActionBars();
}
Object adapter = xsdEditor.getAdapter(ActionRegistry.class);
if (adapter instanceof ActionRegistry) {
ActionRegistry registry = (ActionRegistry) adapter;
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), registry.getAction(DeleteAction.ID));
actionBars.setGlobalActionHandler(GEFActionConstants.ZOOM_IN, registry.getAction(GEFActionConstants.ZOOM_IN));
actionBars.setGlobalActionHandler(GEFActionConstants.ZOOM_OUT, registry.getAction(GEFActionConstants.ZOOM_OUT));
actionBars.setGlobalActionHandler(ActionFactory.PRINT.getId(), registry.getAction(ActionFactory.PRINT.getId()));
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), registry.getAction(ActionFactory.SELECT_ALL.getId()));
zoomInRetargetAction.setEnabled(true);
zoomOutRetargetAction.setEnabled(true);
captureScreenAction.setEnabled(true);
}
}
}
if (actionBars != null) {
// update menu bar and tool bar
actionBars.updateActionBars();
}
if (zoomComboContributionItem != null) {
zoomComboContributionItem.setVisible(!isSource);
zoomComboContributionItem.update();
// Bug 254772 - parent contribution manager should not be null. We added this item already.
// Force the ToolBarManager to update/redraw the items
zoomComboContributionItem.getParent().update(true);
}
}
use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class AbstractCommentActionXMLDelegate method run.
public void run(IAction action) {
if (fEditor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) fEditor;
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
if (document != null) {
// get current text selection
ITextSelection textSelection = getCurrentSelection();
if (textSelection.isEmpty()) {
return;
}
processAction(document, textSelection);
}
}
}
use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class CleanupdocumentHandler 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) {
final ITextEditor finalTextEditor = textEditor;
Dialog cleanupDialog = new CleanupDialogXML(editor.getSite().getShell());
if (cleanupDialog.open() == Window.OK) {
// setup runnable
Runnable runnable = new Runnable() {
public void run() {
IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
if (cleanupProcessor != null) {
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForEdit(finalTextEditor.getDocumentProvider().getDocument(finalTextEditor.getEditorInput()));
if (model != null) {
cleanupProcessor.cleanupModel(model);
}
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
}
};
// TODO: make independent of 'model'.
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForEdit(textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()));
if (model != null) {
// begin recording
ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection();
model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength());
// tell the model that we are about to make a big
// model change
model.aboutToChangeModel();
// run
BusyIndicator.showWhile(textEditor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable);
}
} finally {
if (model != null) {
// tell the model that we are done with the big
// model
// change
model.changedModel();
// end recording
ITextSelection selection = (ITextSelection) textEditor.getSelectionProvider().getSelection();
model.endRecording(this, selection.getOffset(), selection.getLength());
model.releaseFromEdit();
}
}
}
}
return null;
}
use of org.eclipse.ui.texteditor.ITextEditor in project webtools.sourceediting by eclipse.
the class WorkspaceFileHyperlink method open.
public void open() {
if ((fFile != null) && fFile.exists()) {
try {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = IDE.openEditor(page, fFile, true);
// highlight range in editor if possible
if ((fHighlightRange != null) && (editor instanceof ITextEditor)) {
((ITextEditor) editor).setHighlightRange(fHighlightRange.getOffset(), fHighlightRange.getLength(), true);
}
} catch (PartInitException pie) {
Logger.log(Logger.WARNING_DEBUG, pie.getMessage(), pie);
}
}
}
Aggregations