Search in sources :

Example 11 with SystemException

use of org.talend.commons.exception.SystemException 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 12 with SystemException

use of org.talend.commons.exception.SystemException in project tdi-studio-se by Talend.

the class JavaSQLPatternSynchronizer method syncSQLPattern.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.codegen.ISQLPatternSynchronizer#syncSQLPattern(org.talend.core.model.properties.SQLPatternItem
     * , boolean)
     */
@Override
public void syncSQLPattern(SQLPatternItem routineItem, boolean copyToTemp) throws SystemException {
    FileOutputStream fos = null;
    try {
        IFile file = getSQLPatternFile(routineItem);
        if (file == null) {
            return;
        }
        if (copyToTemp) {
            String routineContent = new String(routineItem.getContent().getInnerContent());
            File f = file.getLocation().toFile();
            fos = new FileOutputStream(f);
            fos.write(routineContent.getBytes());
            fos.close();
        }
        file.refreshLocal(1, null);
    } catch (CoreException e) {
        throw new SystemException(e);
    } catch (IOException e) {
        throw new SystemException(e);
    } finally {
        try {
            fos.close();
        } catch (Exception e) {
        // ignore me even if i'm null
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException)

Example 13 with SystemException

use of org.talend.commons.exception.SystemException in project tdi-studio-se by Talend.

the class JavaRoutineSynchronizer method syncRoutineItems.

private void syncRoutineItems(Collection<RoutineItem> routineObjects, boolean forceUpdate) throws SystemException {
    for (RoutineItem routineItem : routineObjects) {
        syncRoutine(routineItem, true, forceUpdate);
    }
    try {
        ILibrariesService jms = CorePlugin.getDefault().getLibrariesService();
        List<URL> urls = jms.getTalendRoutinesFolder();
        for (URL systemModuleURL : urls) {
            if (systemModuleURL != null) {
                String fileName = systemModuleURL.getPath();
                if (fileName.startsWith("/")) {
                    //$NON-NLS-1$
                    fileName = fileName.substring(1);
                }
                File f = new File(systemModuleURL.getPath());
                if (f.isDirectory()) {
                    syncModule(f.listFiles());
                }
            }
        }
    } catch (IOException e) {
        throw new SystemException(e);
    }
}
Also used : ILibrariesService(org.talend.core.model.general.ILibrariesService) SystemException(org.talend.commons.exception.SystemException) RoutineItem(org.talend.core.model.properties.RoutineItem) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URL(java.net.URL)

Example 14 with SystemException

use of org.talend.commons.exception.SystemException in project tdi-studio-se by Talend.

the class GenerateGrammarController method addReferenceJavaFile.

/**
     * Store file to file system. Actually, it locates src/routines/xx DOC ytao Comment method "addReferenceJavaFile".
     * 
     * @param routineItem
     * @param copyToTemp
     * @return
     * @throws SystemException
     */
private IFile addReferenceJavaFile(RoutineItem routineItem, boolean copyToTemp) throws SystemException {
    FileOutputStream fos = null;
    try {
        IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
        ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return null;
        }
        String label = routineItem.getProperty().getLabel();
        IFile file = talendProcessJavaProject.getSrcFolder().getFile(JavaUtils.JAVA_ROUTINES_DIRECTORY + '/' + label + JavaUtils.JAVA_EXTENSION);
        if (copyToTemp) {
            String routineContent = new String(routineItem.getContent().getInnerContent());
            if (!label.equals(ITalendSynchronizer.TEMPLATE)) {
                routineContent = routineContent.replaceAll(ITalendSynchronizer.TEMPLATE, label);
                File f = file.getLocation().toFile();
                fos = new FileOutputStream(f);
                fos.write(routineContent.getBytes());
                fos.close();
            }
        }
        if (!file.exists()) {
            file.refreshLocal(1, null);
        }
        return file;
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        try {
            fos.close();
        } catch (Exception e) {
            // ignore me even if i'm null
            ExceptionHandler.process(e);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) SystemException(org.talend.commons.exception.SystemException) FileOutputStream(java.io.FileOutputStream) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException)

Example 15 with SystemException

use of org.talend.commons.exception.SystemException in project tdi-studio-se by Talend.

the class OpenExistVersionProcessWizard method openAnotherVersion.

protected void openAnotherVersion(final RepositoryNode node, final boolean readonly) {
    try {
        if (node.getObject() != null) {
            final Item item = node.getObject().getProperty().getItem();
            final IWorkbenchPage page = getActivePage();
            final RepositoryEditorInput fileEditorInput = getEditorInput(item, readonly, page);
            if (fileEditorInput != null) {
                IEditorPart editorPart = page.findEditor(fileEditorInput);
                if (editorPart == null) {
                    fileEditorInput.setRepositoryNode(node);
                    if (item instanceof ProcessItem) {
                        page.openEditor(fileEditorInput, MultiPageTalendEditor.ID, readonly);
                    } else if (item instanceof BusinessProcessItem) {
                        CorePlugin.getDefault().getDiagramModelService().openBusinessDiagramEditor(page, fileEditorInput);
                    } else {
                        ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
                        //$NON-NLS-1$ //$NON-NLS-2$
                        String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor";
                        page.openEditor(fileEditorInput, talendEditorID);
                    }
                } else {
                    page.activate(editorPart);
                }
            } else {
                // TDI-19014:open another version of jobScript
                if (item instanceof JobScriptItem) {
                    IProject fsProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
                    openXtextEditor(node, fsProject, readonly);
                }
            }
        }
    } catch (PartInitException e) {
        MessageBoxExceptionHandler.process(e);
    } catch (SystemException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) JobScriptItem(org.talend.core.model.properties.JobScriptItem) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) Item(org.talend.core.model.properties.Item) JobScriptItem(org.talend.core.model.properties.JobScriptItem) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) SystemException(org.talend.commons.exception.SystemException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

SystemException (org.talend.commons.exception.SystemException)24 IFile (org.eclipse.core.resources.IFile)10 PartInitException (org.eclipse.ui.PartInitException)9 CoreException (org.eclipse.core.runtime.CoreException)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 IOException (java.io.IOException)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 Property (org.talend.core.model.properties.Property)5 ICodeGeneratorService (org.talend.designer.codegen.ICodeGeneratorService)5 RepositoryNode (org.talend.repository.model.RepositoryNode)5 File (java.io.File)4 RoutineItem (org.talend.core.model.properties.RoutineItem)4 FileOutputStream (java.io.FileOutputStream)3 IPath (org.eclipse.core.runtime.IPath)3 ISelection (org.eclipse.jface.viewers.ISelection)3 WizardDialog (org.eclipse.jface.wizard.WizardDialog)3 Project (org.talend.core.model.general.Project)3 Item (org.talend.core.model.properties.Item)3 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)3 BufferedInputStream (java.io.BufferedInputStream)2