Search in sources :

Example 1 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project KaiZen-OpenAPI-Editor by RepreZen.

the class JsonEditor method hack_AbstractTextEditor_doSave.

/* Copy of AbstractTextEditor#doSave(IProgressMonitor) which is shadowed by YEdit.
     * Saves the file, but does NOT perform any validation. The validation should be done in a workspace job*/
private void hack_AbstractTextEditor_doSave(IProgressMonitor progressMonitor) {
    IDocumentProvider p = getDocumentProvider();
    if (p == null)
        return;
    if (p.isDeleted(getEditorInput())) {
        if (isSaveAsAllowed()) {
            /*
                 * 1GEUSSR: ITPUI:ALL - User should never loose changes made in the editors. Changed Behavior to make
                 * sure that if called inside a regular save (because of deletion of input element) there is a way to
                 * report back to the caller.
                 */
            performSaveAs(progressMonitor);
        } else {
            Shell shell = getSite().getShell();
            String title = "Cannot Save";
            String msg = "The file has been deleted or is not accessible.";
            MessageDialog.openError(shell, title, msg);
        }
    } else {
        updateState(getEditorInput());
        validateState(getEditorInput());
        performSave(false, progressMonitor);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider)

Example 2 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method turnToJobScriptPage.

protected void turnToJobScriptPage(int newPageIndex) {
    if (jobletEditor != getEditor(newPageIndex)) {
        return;
    }
    ICreateXtextProcessService convertJobtoScriptService = CorePlugin.getDefault().getCreateXtextProcessService();
    try {
        final String scriptValue = convertJobtoScriptService.convertJobtoScript(getProcess().saveXmlFile());
        IFile file = (IFile) jobletEditor.getEditorInput().getAdapter(IResource.class);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(scriptValue.getBytes());
        if (file.exists()) {
            jobletEditor.getDocumentProvider().getDocument(jobletEditor.getEditorInput()).set(scriptValue);
            boolean isProcessReadOnly = ((JobEditorInput) getEditor(0).getEditorInput()).isReadOnly();
            IProxyRepositoryFactory rFactory = ProxyRepositoryFactory.getInstance();
            if (isProcessReadOnly || rFactory.isUserReadOnlyOnCurrentProject()) {
                IDocumentProvider provider = jobletEditor.getDocumentProvider();
                Class p = provider.getClass();
                Class[] type = new Class[1];
                type[0] = Boolean.TYPE;
                Object[] para = new Object[1];
                para[0] = Boolean.TRUE;
                Method method = p.getMethod("setReadOnly", type);
                method.invoke(provider, para);
            }
            //$NON-NLS-1$
            IAction action = jobletEditor.getAction("FoldingRestore");
            action.run();
            jobletEditor.doSave(null);
        } else {
            file.create(byteArrayInputStream, true, null);
        }
        if (propertyListener == null) {
            propertyListener = new IPropertyListener() {

                @Override
                public void propertyChanged(Object source, int propId) {
                    if (source instanceof IEditorPart && ((IEditorPart) source).isDirty()) {
                        getProcess().setProcessModified(true);
                        getProcess().setNeedRegenerateCode(true);
                    }
                }
            };
            jobletEditor.addPropertyListener(propertyListener);
        }
    } catch (PartInitException e) {
        ExceptionHandler.process(e);
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } catch (SecurityException e) {
        ExceptionHandler.process(e);
    } catch (NoSuchMethodException e) {
        ExceptionHandler.process(e);
    } catch (IllegalArgumentException e) {
        ExceptionHandler.process(e);
    } catch (IllegalAccessException e) {
        ExceptionHandler.process(e);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    }
    changeContextsViewStatus(false);
}
Also used : IFile(org.eclipse.core.resources.IFile) ICreateXtextProcessService(org.talend.core.services.ICreateXtextProcessService) IPropertyListener(org.eclipse.ui.IPropertyListener) PartInitException(org.eclipse.ui.PartInitException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IAction(org.eclipse.jface.action.IAction) Method(java.lang.reflect.Method) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) InvocationTargetException(java.lang.reflect.InvocationTargetException) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PlatformObject(org.eclipse.core.runtime.PlatformObject) IResource(org.eclipse.core.resources.IResource)

Example 3 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project tdi-studio-se by Talend.

the class SaveAsSQLPatternAction method run.

@Override
public void run() {
    SaveAsSQLPatternWizard processWizard = new SaveAsSQLPatternWizard(editorPart);
    WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), processWizard);
    if (dlg.open() == Window.OK) {
        try {
            SQLPatternItem sqlpatternItem = processWizard.getSQLPatternItem();
            // get the IFile
            ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
            // only for talend java version
            ISQLPatternSynchronizer sqlPatternSynchronizer = service.getSQLPatternSynchronizer();
            IFile file = sqlPatternSynchronizer.getSQLPatternFile(sqlpatternItem);
            if (file == null) {
                return;
            }
            // Set readonly to false since created job will always be editable.
            RepositoryEditorInput repositoryEditorInput = new RepositoryEditorInput(file, sqlpatternItem);
            IWorkbenchPage page = getActivePage();
            IRepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(repositoryEditorInput.getItem().getProperty().getId(), false);
            repositoryEditorInput.setRepositoryNode(repositoryNode);
            // here really do the normal save as function
            IDocumentProvider provider = ((StandAloneTalendJavaEditor) this.editorPart).getDocumentProvider();
            provider.aboutToChange(repositoryEditorInput);
            provider.saveDocument(null, repositoryEditorInput, provider.getDocument(this.editorPart.getEditorInput()), true);
            provider.changed(repositoryEditorInput);
            // copy back from the *.java file to *.item file.
            // @see:StandAloneTalendJavaEditor.doSave(IProgressMonitor monitor)
            ByteArray byteArray = sqlpatternItem.getContent();
            byteArray.setInnerContentFromFile(repositoryEditorInput.getFile());
            IProxyRepositoryFactory repFactory = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
            repFactory.save(sqlpatternItem);
            // 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
            page.openEditor(repositoryEditorInput, StandAloneTalendJavaEditor.ID, true);
        } catch (Exception e) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", "SQLTemplate could not be saved" + " : " + e.getMessage());
            ExceptionHandler.process(e);
        }
    }
}
Also used : SaveAsSQLPatternWizard(org.talend.designer.core.ui.wizards.SaveAsSQLPatternWizard) IFile(org.eclipse.core.resources.IFile) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) StandAloneTalendJavaEditor(org.talend.designer.core.ui.editor.StandAloneTalendJavaEditor) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ByteArray(org.talend.core.model.properties.ByteArray) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 4 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider 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 5 with IDocumentProvider

use of org.eclipse.ui.texteditor.IDocumentProvider in project tdi-studio-se by Talend.

the class TalendJavaSourceViewer method initializeModel.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.ui.viewer.ReconcilerViewer#initializeModel(IDocument document)
     */
@Override
protected void initializeModel() {
    getSourceViewerDecorationSupport().install(JavaPlugin.getDefault().getCombinedPreferenceStore());
    this.setRangeIndicator(new DefaultRangeIndicator());
    IAnnotationModel model;
    IDocument document;
    if (checkCode) {
        IDocumentProvider provider = JavaPlugin.getDefault().getCompilationUnitDocumentProvider();
        IEditorInput ei = new FileEditorInput(file);
        try {
            provider.connect(ei);
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
        document = provider.getDocument(ei);
        model = provider.getAnnotationModel(ei);
    } else {
        model = new AnnotationModel();
        document = getDocument();
        model.connect(document);
    }
    if (document != null) {
        setDocument(document, model);
        showAnnotations(model != null && checkCode);
    }
    super.initializeModel();
}
Also used : DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)12 IFile (org.eclipse.core.resources.IFile)5 IOException (java.io.IOException)4 IDocumentWrapper (bndtools.editor.model.IDocumentWrapper)3 IResource (org.eclipse.core.resources.IResource)3 CoreException (org.eclipse.core.runtime.CoreException)3 IDocument (org.eclipse.jface.text.IDocument)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 PartInitException (org.eclipse.ui.PartInitException)3 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)3 Workspace (aQute.bnd.build.Workspace)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 IPath (org.eclipse.core.runtime.IPath)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 IEditorInput (org.eclipse.ui.IEditorInput)2 IEditorPart (org.eclipse.ui.IEditorPart)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 ByteArray (org.talend.core.model.properties.ByteArray)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2