Search in sources :

Example 1 with SaveAsRoutineWizard

use of org.talend.designer.core.ui.wizards.SaveAsRoutineWizard 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)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 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 ByteArray (org.talend.core.model.properties.ByteArray)1 RoutineItem (org.talend.core.model.properties.RoutineItem)1 ICodeGeneratorService (org.talend.designer.codegen.ICodeGeneratorService)1 ITalendSynchronizer (org.talend.designer.codegen.ITalendSynchronizer)1 SaveAsRoutineWizard (org.talend.designer.core.ui.wizards.SaveAsRoutineWizard)1 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)1 IRepositoryNode (org.talend.repository.model.IRepositoryNode)1 RoutineEditorInput (org.talend.repository.ui.actions.routines.RoutineEditorInput)1