Search in sources :

Example 11 with ICodeGeneratorService

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

the class DownloadComponenentsAction method updateUI.

/**
     * Update ui after job finished.
     * 
     * @param action
     * @param event
     */
private void updateUI(final IJobChangeEvent event) {
    // activate aection again after job finished
    if (fExtensionDownloaded > 0) {
        // refresh palette
        ExchangeUtils.reloadComponents();
        // update needed modules.
        CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
        // see feature 0005050: confirmation popup once the component is installed
        confirmInstallation();
        // Start Code Generation Init
        ICodeGeneratorService codeGenService = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
        Job job = codeGenService.refreshTemplates();
        job.addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                ComponentPaletteUtilities.setSkipUpdatePalette(false);
            }
        });
        RefreshComponenentsAction action = new RefreshComponenentsAction();
        action.run(new String[] { RefreshComponenentsAction.REFRESH_INSTALLED }, ContentConstants.UL_DOWNLOADED_EXTENSIONS);
    }
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService)

Example 12 with ICodeGeneratorService

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

the class AbstractRoutineAction method openRoutineEditor.

/**
     * DOC smallet Comment method "openRoutineEditor".
     * 
     * @param routineItem
     * @throws SystemException
     * @throws PartInitException
     */
protected IEditorPart openRoutineEditor(RoutineItem routineItem, boolean readOnly) throws SystemException, PartInitException {
    if (routineItem == null) {
        return null;
    }
    ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
    ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
    ITalendSynchronizer routineSynchronizer;
    switch(lang) {
        case JAVA:
            routineSynchronizer = service.createJavaRoutineSynchronizer();
            break;
        case PERL:
            routineSynchronizer = service.createPerlRoutineSynchronizer();
            break;
        default:
            //$NON-NLS-1$
            throw new UnsupportedOperationException(Messages.getString("AbstractRoutineAction.unknowLanguage") + lang);
    }
    // check if the related editor is open.
    IWorkbenchPage page = getActivePage();
    IEditorReference[] editorParts = page.getEditorReferences();
    //$NON-NLS-1$ //$NON-NLS-2$
    String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor";
    boolean found = false;
    IEditorPart talendEditor = null;
    for (IEditorReference reference : editorParts) {
        IEditorPart editor = reference.getEditor(false);
        if (talendEditorID.equals(editor.getSite().getId())) {
            // TextEditor talendEditor = (TextEditor) editor;
            RepositoryEditorInput editorInput = (RepositoryEditorInput) editor.getEditorInput();
            if (editorInput.getItem().equals(routineItem)) {
                page.bringToTop(editor);
                found = true;
                talendEditor = editor;
                break;
            }
        }
    }
    if (!found) {
        IFile file = null;
        ProjectManager projectManager = ProjectManager.getInstance();
        boolean flag = projectManager.isInCurrentMainProject(routineItem);
        if (!flag) {
            // is ref project
            file = routineSynchronizer.getRoutinesFile(routineItem);
        } else {
            // need open from item file with multiple version
            boolean needForceRefresh = false;
            if (!ProxyRepositoryFactory.getInstance().isLocalConnectionProvider()) {
                // in case only routine.item file modified, better refresh every time, especially for git mode
                needForceRefresh = true;
            }
            routineSynchronizer.syncRoutine(routineItem, true, needForceRefresh);
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            String lastVersion = factory.getLastVersion(routineItem.getProperty().getId()).getVersion();
            String curVersion = routineItem.getProperty().getVersion();
            if (curVersion != null && curVersion.equals(lastVersion)) {
                file = routineSynchronizer.getFile(routineItem);
            } else {
                file = routineSynchronizer.getRoutinesFile(routineItem);
            }
        }
        if (file == null) {
            return null;
        }
        RepositoryEditorInput input = new RoutineEditorInput(file, routineItem);
        input.setReadOnly(readOnly);
        talendEditor = page.openEditor(input, talendEditorID);
    }
    return talendEditor;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ProjectManager(org.talend.repository.ProjectManager) IEditorReference(org.eclipse.ui.IEditorReference) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 13 with ICodeGeneratorService

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

the class AbstractBeanAction method openBeanEditor.

public IEditorPart openBeanEditor(BeanItem beanItem, boolean readOnly) throws SystemException, PartInitException {
    if (beanItem == null) {
        return null;
    }
    ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
    ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
    ITalendSynchronizer routineSynchronizer = service.createRoutineSynchronizer();
    // check if the related editor is open.
    IWorkbenchPage page = getActivePage();
    IEditorReference[] editorParts = page.getEditorReferences();
    //$NON-NLS-1$ //$NON-NLS-2$
    String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor";
    boolean found = false;
    IEditorPart talendEditor = null;
    for (IEditorReference reference : editorParts) {
        IEditorPart editor = reference.getEditor(false);
        if (talendEditorID.equals(editor.getSite().getId())) {
            // TextEditor talendEditor = (TextEditor) editor;
            RepositoryEditorInput editorInput = (RepositoryEditorInput) editor.getEditorInput();
            if (editorInput.getItem().equals(beanItem)) {
                page.bringToTop(editor);
                found = true;
                talendEditor = editor;
                break;
            }
        }
    }
    if (!found) {
        routineSynchronizer.syncRoutine(beanItem, true);
        IFile file = routineSynchronizer.getFile(beanItem);
        if (file == null) {
            return null;
        }
        RepositoryEditorInput input = new BeanEditorInput(file, beanItem);
        input.setReadOnly(readOnly);
        //$NON-NLS-1$            
        talendEditor = page.openEditor(input, talendEditorID);
    }
    return talendEditor;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IEditorReference(org.eclipse.ui.IEditorReference) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IFile(org.eclipse.core.resources.IFile) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 14 with ICodeGeneratorService

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

the class AbstractSqlpatternAction method openSQLPatternEditor.

/**
     * DOC smallet Comment method "openRoutineEditor".
     * 
     * @param item
     * @throws SystemException
     * @throws PartInitException
     */
public IEditorPart openSQLPatternEditor(SQLPatternItem item, boolean readOnly) throws SystemException, PartInitException {
    if (item == null) {
        return null;
    }
    ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
    ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
    ISQLPatternSynchronizer routineSynchronizer = service.getSQLPatternSynchronizer();
    // check if the related editor is open.
    IWorkbenchPage page = getActivePage();
    IEditorReference[] editorParts = page.getEditorReferences();
    //$NON-NLS-1$ //$NON-NLS-2$
    String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor";
    boolean found = false;
    IEditorPart talendEditor = null;
    for (IEditorReference reference : editorParts) {
        IEditorPart editor = reference.getEditor(false);
        if (talendEditorID.equals(editor.getSite().getId())) {
            // TextEditor talendEditor = (TextEditor) editor;
            RepositoryEditorInput editorInput = (RepositoryEditorInput) editor.getEditorInput();
            Item item2 = editorInput.getItem();
            if (item2 != null && item2 instanceof SQLPatternItem && item2.getProperty().getId().equals(item.getProperty().getId())) {
                if (item2.getProperty().getVersion().equals(item.getProperty().getVersion())) {
                    page.bringToTop(editor);
                    found = true;
                    talendEditor = editor;
                    break;
                } else {
                    page.closeEditor(editor, false);
                }
            }
        }
    }
    if (!found) {
        routineSynchronizer.syncSQLPattern(item, true);
        IFile file = routineSynchronizer.getSQLPatternFile(item);
        if (file == null) {
            return null;
        }
        RepositoryEditorInput input = new RepositoryEditorInput(file, item);
        input.setReadOnly(readOnly);
        //$NON-NLS-1$            
        talendEditor = page.openEditor(input, talendEditorID);
    }
    return talendEditor;
}
Also used : RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IFile(org.eclipse.core.resources.IFile) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IEditorPart(org.eclipse.ui.IEditorPart) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) Item(org.talend.core.model.properties.Item) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 15 with ICodeGeneratorService

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

the class ProblemsView method restoreProblem.

/**
     * 
     * ggu Comment method "restoreProblem".
     * 
     * when restore the item, check the problem.
     */
private void restoreProblem(RoutineItem item) {
    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:
    }
    if (routineSynchronizer != null) {
        try {
            routineSynchronizer.syncRoutine(item, true);
            IFile file = routineSynchronizer.getFile(item);
            if (file == null) {
                return;
            }
            file.refreshLocal(IResource.DEPTH_ONE, null);
            Problems.addRoutineFile(file, item.getProperty());
        } catch (SystemException e) {
            ExceptionHandler.process(e);
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                Problems.refreshProblemTreeView();
            }
        });
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) SystemException(org.talend.commons.exception.SystemException) CoreException(org.eclipse.core.runtime.CoreException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService)

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