Search in sources :

Example 1 with RoutineEditorInput

use of org.talend.repository.ui.actions.routines.RoutineEditorInput 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 RoutineEditorInput

use of org.talend.repository.ui.actions.routines.RoutineEditorInput in project tdi-studio-se by Talend.

the class OpenExistVersionProcessWizard method getEditorInput.

protected RepositoryEditorInput getEditorInput(final Item item, final boolean readonly, final IWorkbenchPage page) throws SystemException {
    if (item instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) item;
        return new ProcessEditorInput(processItem, true, false, readonly);
    } else if (item instanceof BusinessProcessItem) {
        BusinessProcessItem businessProcessItem = (BusinessProcessItem) item;
        IFile file = CorePlugin.getDefault().getDiagramModelService().getDiagramFileAndUpdateResource(page, businessProcessItem);
        return new RepositoryEditorInput(file, businessProcessItem);
    } else if (item instanceof RoutineItem) {
        final RoutineItem routineItem = (RoutineItem) item;
        final ICodeGeneratorService codeGenService = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
        ITalendSynchronizer routineSynchronizer = codeGenService.createRoutineSynchronizer();
        ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        String lastVersion = factory.getLastVersion(routineItem.getProperty().getId()).getVersion();
        String curVersion = routineItem.getProperty().getVersion();
        routineSynchronizer.syncRoutine(routineItem, true, true);
        final IFile file;
        if (curVersion != null && curVersion.equals(lastVersion)) {
            file = routineSynchronizer.getFile(routineItem);
        } else {
            file = routineSynchronizer.getRoutinesFile(routineItem);
        }
        if (file != null) {
            return new RoutineEditorInput(file, routineItem);
        }
    } else if (item instanceof SQLPatternItem) {
        SQLPatternItem patternItem = (SQLPatternItem) item;
        final ICodeGeneratorService codeGenService = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
        ISQLPatternSynchronizer SQLPatternSynchronizer = codeGenService.getSQLPatternSynchronizer();
        SQLPatternSynchronizer.syncSQLPattern(patternItem, true);
        IFile file = SQLPatternSynchronizer.getSQLPatternFile(patternItem);
        if (file != null) {
            return new RepositoryEditorInput(file, patternItem);
        }
    }
    return null;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) RoutineEditorInput(org.talend.repository.ui.actions.routines.RoutineEditorInput) ProcessEditorInput(org.talend.designer.core.ui.editor.ProcessEditorInput) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem)

Aggregations

IFile (org.eclipse.core.resources.IFile)2 RoutineItem (org.talend.core.model.properties.RoutineItem)2 ICodeGeneratorService (org.talend.designer.codegen.ICodeGeneratorService)2 ITalendSynchronizer (org.talend.designer.codegen.ITalendSynchronizer)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2 RoutineEditorInput (org.talend.repository.ui.actions.routines.RoutineEditorInput)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)1 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)1 BusinessProcessItem (org.talend.core.model.properties.BusinessProcessItem)1 ByteArray (org.talend.core.model.properties.ByteArray)1 ProcessItem (org.talend.core.model.properties.ProcessItem)1 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)1 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)1 RepositoryEditorInput (org.talend.core.repository.ui.editor.RepositoryEditorInput)1 ISQLPatternSynchronizer (org.talend.designer.codegen.ISQLPatternSynchronizer)1 ProcessEditorInput (org.talend.designer.core.ui.editor.ProcessEditorInput)1 SaveAsRoutineWizard (org.talend.designer.core.ui.wizards.SaveAsRoutineWizard)1 IRepositoryNode (org.talend.repository.model.IRepositoryNode)1