Search in sources :

Example 1 with AbstractTextEditor

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);
        }
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RoutineItem(org.talend.core.model.properties.RoutineItem) RoutineEditorInput(org.talend.repository.ui.actions.routines.RoutineEditorInput) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ByteArray(org.talend.core.model.properties.ByteArray) WizardDialog(org.eclipse.jface.wizard.WizardDialog) SaveAsRoutineWizard(org.talend.designer.core.ui.wizards.SaveAsRoutineWizard) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 2 with AbstractTextEditor

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);
    }
}
Also used : AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) Method(java.lang.reflect.Method) BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with AbstractTextEditor

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());
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor)

Example 4 with AbstractTextEditor

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());
}
Also used : AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) ITextSelection(org.eclipse.jface.text.ITextSelection) IEditorInput(org.eclipse.ui.IEditorInput)

Example 5 with AbstractTextEditor

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);
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IDocument(org.eclipse.jface.text.IDocument) After(org.junit.After)

Aggregations

AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)33 IFile (org.eclipse.core.resources.IFile)14 IEditorPart (org.eclipse.ui.IEditorPart)9 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)9 PartInitException (org.eclipse.ui.PartInitException)8 FileEditorInput (org.eclipse.ui.part.FileEditorInput)8 IDocument (org.eclipse.jface.text.IDocument)7 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 Path (org.eclipse.core.runtime.Path)6 TextSelection (org.eclipse.jface.text.TextSelection)6 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)6 Test (org.junit.Test)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Method (java.lang.reflect.Method)4 After (org.junit.After)3 FocusEvent (org.eclipse.swt.events.FocusEvent)2 FocusListener (org.eclipse.swt.events.FocusListener)2 Control (org.eclipse.swt.widgets.Control)2