Search in sources :

Example 16 with ICodeGeneratorService

use of org.talend.designer.codegen.ICodeGeneratorService in project tdi-studio-se by Talend.

the class CodeView method refresh.

public void refresh() {
    ICodeGeneratorService service = DesignerPlugin.getDefault().getCodeGeneratorService();
    if (service.isInitializingJet()) {
        return;
    }
    if (isGenerating()) {
        return;
    }
    setGenerating(true);
    final List<? extends INode> generatingNodes = selectedNode.getProcess().getGeneratingNodes();
    Job job = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    Messages.getString("CodeView.initMessage")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            if (selectedNode != null) {
                //$NON-NLS-1$
                generatedCode = "";
                try {
                    // joblet or joblet node
                    boolean isJoblet = AbstractProcessProvider.isExtensionProcessForJoblet(selectedNode.getProcess());
                    if (!isJoblet && PluginChecker.isJobLetPluginLoaded()) {
                        IJobletProviderService jobletSservice = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                        if (jobletSservice != null && jobletSservice.isJobletComponent(selectedNode)) {
                            isJoblet = true;
                        }
                    }
                    if (isJoblet) {
                        return org.eclipse.core.runtime.Status.OK_STATUS;
                    }
                    generatingNode = null;
                    for (INode node : generatingNodes) {
                        if (node.getUniqueName().equals(selectedNode.getUniqueName())) {
                            generatingNode = node;
                        }
                    }
                    if (generatingNode == null) {
                        //$NON-NLS-1$
                        generatedCode = Messages.getString("CodeView.MultipleComponentError");
                        return org.eclipse.core.runtime.Status.OK_STATUS;
                    }
                    ICodeGeneratorService service = DesignerPlugin.getDefault().getCodeGeneratorService();
                    // have to do this dirty change to avoid the side effect for BD component.
                    codeGenerator = service.createCodeGenerator(selectedNode.getProcess(), false, false);
                    viewStartAction.setChecked(false);
                    viewMainAction.setChecked(false);
                    viewEndAction.setChecked(false);
                    viewAllAction.setChecked(false);
                    switch(codeView) {
                        case CODE_START:
                            viewStartAction.setChecked(true);
                            generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.BEGIN);
                            break;
                        case CODE_MAIN:
                            viewMainAction.setChecked(true);
                            generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.MAIN);
                            break;
                        case CODE_END:
                            viewEndAction.setChecked(true);
                            generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.END);
                            break;
                        case CODE_ALL:
                            viewAllAction.setChecked(true);
                            generatedCode = codeGenerator.generateComponentCode(generatingNode, ECodePart.BEGIN);
                            generatedCode += codeGenerator.generateComponentCode(generatingNode, ECodePart.MAIN);
                            generatedCode += codeGenerator.generateComponentCode(generatingNode, ECodePart.END);
                            break;
                        default:
                    }
                } catch (SystemException e) {
                    //$NON-NLS-1$
                    generatedCode = Messages.getString("CodeView.Error");
                    ExceptionHandler.process(e);
                } catch (Exception e) {
                    // Some exceptions can appear in case we close some jobs while generating
                    // Just ignore them, and set blank directly to the code view
                    //$NON-NLS-1$
                    generatedCode = "";
                }
            }
            return org.eclipse.core.runtime.Status.OK_STATUS;
        }
    };
    job.setPriority(Job.INTERACTIVE);
    job.schedule();
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            new UIJob("") {

                @Override
                public IStatus runInUIThread(IProgressMonitor monitor) {
                    document.set(generatedCode);
                    setGenerating(false);
                    return org.eclipse.core.runtime.Status.OK_STATUS;
                }
            }.schedule();
        }
    });
}
Also used : INode(org.talend.core.model.process.INode) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SystemException(org.talend.commons.exception.SystemException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) IJobletProviderService(org.talend.core.ui.IJobletProviderService) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SystemException(org.talend.commons.exception.SystemException) UIJob(org.eclipse.ui.progress.UIJob) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob)

Example 17 with ICodeGeneratorService

use of org.talend.designer.codegen.ICodeGeneratorService in project tdi-studio-se by Talend.

the class ComponentsPreferencePage method performOk.

@Override
public boolean performOk() {
    boolean flag = super.performOk();
    String newPath = CodeGeneratorActivator.getDefault().getPreferenceStore().getString(IComponentPreferenceConstant.USER_COMPONENTS_FOLDER);
    if ("".equals(oldPath)) {
        //$NON-NLS-1$
        oldPath = null;
    }
    if ("".equals(newPath)) {
        //$NON-NLS-1$
        newPath = null;
    }
    DesignerPlugin.getDefault().getPreferenceStore().setValue(TalendDesignerPrefConstants.COMPONENT_ASSIST, enableComponentAssistCheckBoxField.getBooleanValue());
    TalendEditorComponentCreationUtil.updateAssistListener();
    if (this.oldPath != newPath) {
        final IRunnableWithProgress runnable = new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                //$NON-NLS-1$
                monitor.beginTask("Loading user component ......", 100);
                Display display = Display.getCurrent();
                if (display == null) {
                    display = Display.getDefault();
                }
                if (display != null) {
                    display.syncExec(new Runnable() {

                        @Override
                        public void run() {
                            // install the new components via P2
                            ComponentsInstallComponent component = LocalComponentInstallHelper.getComponent();
                            if (component != null) {
                                String newPath = CodeGeneratorActivator.getDefault().getPreferenceStore().getString(IComponentPreferenceConstant.USER_COMPONENTS_FOLDER);
                                if (newPath != null && StringUtils.isNotEmpty(newPath.trim())) {
                                    File componentFolder = new File(newPath.trim());
                                    if (componentFolder.exists()) {
                                        try {
                                            component.setComponentFolder(componentFolder);
                                            if (component.install()) {
                                                String installedMessages = component.getInstalledMessages();
                                                //$NON-NLS-1$
                                                String title = Messages.getString("ComponentsPreferencePage_SuccessTitle");
                                                if (component.needRelaunch()) {
                                                    String warningMessage = Messages.getString(//$NON-NLS-1$
                                                    "ComponentsPreferencePage_SuccessMessage1") + //$NON-NLS-1$
                                                    Messages.getString("ComponentsPreferencePage_SuccessMessage2");
                                                    boolean confirm = MessageDialog.openConfirm(getShell(), title, installedMessages + '\n' + '\n' + warningMessage);
                                                    if (confirm) {
                                                        PlatformUI.getWorkbench().restart();
                                                    }
                                                } else {
                                                    MessageDialog.openInformation(getShell(), title, installedMessages);
                                                }
                                            }
                                        } finally {
                                            // after install, clear the setting for service.
                                            component.setComponentFolder(null);
                                        }
                                    }
                                }
                            }
                            // components will be reloaded when refreshTemplates;
                            // IComponentsFactory components = ComponentsFactoryProvider.getInstance();
                            // components.loadUserComponentsFromComponentsProviderExtension();
                            CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
                            monitor.worked(50);
                            // ComponentUtilities.updatePalette();
                            ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
                            service.refreshTemplates();
                        }
                    });
                }
            }
        };
        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
        try {
            dialog.run(true, true, runnable);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
            ExceptionHandler.process(e);
        }
        this.oldPath = newPath;
    }
    return flag;
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ComponentsInstallComponent(org.talend.commons.runtime.service.ComponentsInstallComponent) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Aggregations

ICodeGeneratorService (org.talend.designer.codegen.ICodeGeneratorService)17 IFile (org.eclipse.core.resources.IFile)8 ITalendSynchronizer (org.talend.designer.codegen.ITalendSynchronizer)7 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)5 SystemException (org.talend.commons.exception.SystemException)5 RepositoryEditorInput (org.talend.core.repository.ui.editor.RepositoryEditorInput)5 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)4 ISQLPatternSynchronizer (org.talend.designer.codegen.ISQLPatternSynchronizer)4 CoreException (org.eclipse.core.runtime.CoreException)3 IEditorPart (org.eclipse.ui.IEditorPart)3 IEditorReference (org.eclipse.ui.IEditorReference)3 ECodeLanguage (org.talend.core.language.ECodeLanguage)3 RoutineItem (org.talend.core.model.properties.RoutineItem)3 ICodeGenerator (org.talend.designer.codegen.ICodeGenerator)3 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 Job (org.eclipse.core.runtime.jobs.Job)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2