use of org.eclipse.ui.texteditor.AbstractTextEditor in project tdi-studio-se by Talend.
the class SaveAsRoutineAction method run.
@Override
public void run() {
SaveAsRoutineWizard processWizard = new SaveAsRoutineWizard(editorPart);
WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), processWizard);
if (dlg.open() == Window.OK) {
try {
RoutineItem routineItem = processWizard.getRoutineItem();
// get the IFile
ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
ITalendSynchronizer routineSynchronizer = null;
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
routineSynchronizer = service.createJavaRoutineSynchronizer();
break;
case PERL:
routineSynchronizer = service.createPerlRoutineSynchronizer();
break;
default:
}
IFile file = routineSynchronizer.getFile(routineItem);
if (file == null) {
return;
}
// Set readonly to false since created job will always be editable.
RoutineEditorInput routineEditorInput = new RoutineEditorInput(file, routineItem);
IWorkbenchPage page = getActivePage();
IRepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(routineEditorInput.getItem().getProperty().getId(), false);
routineEditorInput.setRepositoryNode(repositoryNode);
// here really do the normal save as function
IDocumentProvider provider = ((AbstractTextEditor) this.editorPart).getDocumentProvider();
provider.aboutToChange(routineEditorInput);
provider.saveDocument(null, routineEditorInput, provider.getDocument(this.editorPart.getEditorInput()), true);
provider.changed(routineEditorInput);
// copy back from the *.java file to *.item file.
// @see:StandAloneTalendJavaEditor.doSave(IProgressMonitor monitor)
ByteArray byteArray = routineItem.getContent();
byteArray.setInnerContentFromFile(routineEditorInput.getFile());
IProxyRepositoryFactory repFactory = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
repFactory.save(routineItem);
// close the old editor
page.closeEditor(this.editorPart, false);
// open the new editor, because at the same time, there will update the jobSetting/componentSetting view
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
page.openEditor(routineEditorInput, StandAloneTalendJavaEditor.ID, true);
break;
default:
}
} catch (Exception e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", "Routine could not be saved" + " : " + e.getMessage());
ExceptionHandler.process(e);
}
}
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project dbeaver by serge-rider.
the class UIUtils method enableHostEditorKeyBindings.
/**
* Eclipse hack. Disables/enabled all key bindings in specified site's part. Works only if host editor is extender of
* AbstractTextEditor Uses reflection because setActionActivation is private method
* TODO: find better way to disable key bindings or prioritize event handling to widgets
*
* @param partSite workbench part site
* @param enable enable or disable
*/
@Deprecated
public static void enableHostEditorKeyBindings(IWorkbenchPartSite partSite, boolean enable) {
IWorkbenchPart part = partSite.getPart();
if (part instanceof AbstractTextEditor) {
AbstractTextEditor hostEditor = (AbstractTextEditor) part;
if (hostEditor instanceof BaseTextEditor) {
StyledText textWidget = ((BaseTextEditor) hostEditor).getTextViewer().getTextWidget();
if (textWidget == null || textWidget.isDisposed()) {
return;
}
}
try {
Method activatorMethod = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", Boolean.TYPE);
activatorMethod.setAccessible(true);
activatorMethod.invoke(hostEditor, enable);
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
log.warn("Can't disable text editor action activations", e);
}
//hostEditor.getEditorSite().getActionBarContributor().setActiveEditor(hostEditor);
}
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project linuxtools by eclipse.
the class GNUFormat method getDocument.
public IDocument getDocument(IEditorPart currentEditor) {
AbstractTextEditor castEditor = (AbstractTextEditor) currentEditor;
IDocumentProvider provider = castEditor.getDocumentProvider();
return provider.getDocument(castEditor.getEditorInput());
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project linuxtools by eclipse.
the class CParser method parseCurrentFunction.
@Override
public String parseCurrentFunction(IEditorPart editor) throws CoreException {
// Check for correct editor type
if (!(editor instanceof AbstractTextEditor))
return "";
// Get the editor, test selection and input.
AbstractTextEditor a_editor = (AbstractTextEditor) editor;
ITextSelection selection = (ITextSelection) (a_editor).getSelectionProvider().getSelection();
IEditorInput input = a_editor.getEditorInput();
// Parse it and return the function.
return parseCurrentFunction(input, selection.getOffset());
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project linuxtools by eclipse.
the class GNUFormatTest method tearDown.
@After
public void tearDown() throws Exception {
// content to the empty string).
if (changelogEditorPart != null) {
// testFormatDateLine does not use it
AbstractTextEditor castEditor = (AbstractTextEditor) changelogEditorPart;
IDocumentProvider iDocProvider = castEditor.getDocumentProvider();
IDocument changelogContentDoc = iDocProvider.getDocument(castEditor.getEditorInput());
// empty content
changelogContentDoc.set("");
changelogEditorPart.doSave(null);
// Also close open editor in order for default content to work.
// I.e. avoid spill over from previous test runs
closeEditor(changelogEditorPart);
}
// dispose
project.getTestProject().delete(true, true, null);
}
Aggregations