Search in sources :

Example 1 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.

the class JobDesignImportHandler method afterApplyMigrationTasks.

@Override
protected void afterApplyMigrationTasks(ImportItem importItem) throws Exception {
    Item tmpItem = importItem.getItem();
    if (tmpItem instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) tmpItem;
        ParametersType paType = processItem.getProcess().getParameters();
        boolean statsPSettingRemoved = false;
        // for commanline import project setting
        if (importItem.isRemoveProjectStatslog()) {
            if (paType != null) {
                //$NON-NLS-1$
                String paramName = "STATANDLOG_USE_PROJECT_SETTINGS";
                EList listParamType = paType.getElementParameter();
                for (int j = 0; j < listParamType.size(); j++) {
                    ElementParameterType pType = (ElementParameterType) listParamType.get(j);
                    if (pType != null && paramName.equals(pType.getName())) {
                        pType.setValue(Boolean.FALSE.toString());
                        statsPSettingRemoved = true;
                        break;
                    }
                }
            }
        }
        // 14446: item apply project setting param if use project setting
        String statslogUsePSetting = null;
        String implicitUsePSetting = null;
        if (paType != null) {
            EList listParamType = paType.getElementParameter();
            for (int j = 0; j < listParamType.size(); j++) {
                ElementParameterType pType = (ElementParameterType) listParamType.get(j);
                if (pType != null) {
                    if (!statsPSettingRemoved && "STATANDLOG_USE_PROJECT_SETTINGS".equals(pType.getName())) {
                        //$NON-NLS-1$
                        statslogUsePSetting = pType.getValue();
                    }
                    if ("IMPLICITCONTEXT_USE_PROJECT_SETTINGS".equals(pType.getName())) {
                        //$NON-NLS-1$
                        implicitUsePSetting = pType.getValue();
                    }
                    if (statsPSettingRemoved && implicitUsePSetting != null || !statsPSettingRemoved && implicitUsePSetting != null && statslogUsePSetting != null) {
                        break;
                    }
                }
            }
        }
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
            IDesignerCoreService designerCoreService = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
            if (statslogUsePSetting != null && Boolean.parseBoolean(statslogUsePSetting)) {
                //$NON-NLS-1$
                designerCoreService.reloadParamFromProjectSettings(paType, "STATANDLOG_USE_PROJECT_SETTINGS");
            }
            if (implicitUsePSetting != null && Boolean.parseBoolean(implicitUsePSetting)) {
                //$NON-NLS-1$
                designerCoreService.reloadParamFromProjectSettings(paType, "IMPLICITCONTEXT_USE_PROJECT_SETTINGS");
            }
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) EList(org.eclipse.emf.common.util.EList) ProcessItem(org.talend.core.model.properties.ProcessItem) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService)

Example 2 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.

the class ComponentSearcher method search.

/**
     * DOC hcw Comment method "search".
     * 
     * @param monitor
     * @param nodeName
     * @param found
     */
protected void search(IProgressMonitor monitor, String nodeName, List<IRepositoryViewObject> found) {
    IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
    IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
    try {
        List<IRepositoryViewObject> repositoryObjectList = factory.getAll(ERepositoryObjectType.PROCESS, false);
        repositoryObjectList.addAll(factory.getAll(ERepositoryObjectType.PROCESS_MR, false));
        repositoryObjectList.addAll(factory.getAll(ERepositoryObjectType.valueOf("PROCESS_STORM"), false));
        if (ProjectManager.getInstance().getReferencedProjects(ProjectManager.getInstance().getCurrentProject()).size() > 0) {
            for (Project refProject : ProjectManager.getInstance().getReferencedProjects(ProjectManager.getInstance().getCurrentProject())) {
                repositoryObjectList.addAll(factory.getAll(refProject, ERepositoryObjectType.PROCESS, false));
                repositoryObjectList.addAll(factory.getAll(refProject, ERepositoryObjectType.PROCESS_MR, false));
                repositoryObjectList.addAll(factory.getAll(refProject, ERepositoryObjectType.valueOf("PROCESS_STORM"), false));
            }
        }
        //$NON-NLS-1$
        monitor.beginTask("Searching Component in Jobs ", repositoryObjectList.size());
        for (IRepositoryViewObject rObject : repositoryObjectList) {
            if (monitor.isCanceled()) {
                break;
            }
            //$NON-NLS-1$
            monitor.setTaskName("Search " + rObject.getLabel());
            monitor.worked(1);
            Item item = rObject.getProperty().getItem();
            if (item instanceof ProcessItem) {
                ProcessItem processItem = (ProcessItem) item;
                IProcess process = designerCoreService.getProcessFromProcessItem(processItem);
                List<INode> nodes = (List<INode>) process.getGraphicalNodes();
                for (INode node : nodes) {
                    if (node.getComponent().getName().equals(nodeName)) {
                        found.add(rObject);
                        break;
                    }
                }
            }
        }
        monitor.done();
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
// JobletEditorInput fileEditorInput = new JobletEditorInput(processItem, true);
// IEditorPart editorPart = page.findEditor(fileEditorInput);
}
Also used : Project(org.talend.core.model.general.Project) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) INode(org.talend.core.model.process.INode) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ArrayList(java.util.ArrayList) List(java.util.List) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 3 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.

the class TalendCompletionProposalComputer method computeCompletionProposals.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#computeCompletionProposals(org.eclipse.jdt.ui.text
     * .java.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
     */
public List computeCompletionProposals(ITextViewer textViewer, String prefix, int offset, IProgressMonitor monitor) {
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
    IProcess process = service.getCurrentProcess();
    if (process == null) {
        return Collections.EMPTY_LIST;
    }
    // Compute the length of replacement for proposal. See bug 0004266: Replace value with context value using
    // CTRL+Space.
    int replacementLength = textViewer.getSelectedRange().y;
    if (replacementLength == 0) {
        replacementLength = prefix.length();
    }
    // Proposals based on process context
    List<IContextParameter> ctxParams = process.getContextManager().getDefaultContext().getContextParameterList();
    for (IContextParameter ctxParam : ctxParams) {
        String display = CONTEXT_PREFIX + ctxParam.getName();
        String code = getContextContent(ctxParam);
        String description = getContextDescription(ctxParam, display);
        String ctxName = ctxParam.getName();
        if (prefix.equals("") || display.startsWith(prefix)) {
            //$NON-NLS-1$
            TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
            proposal.setType(TalendCompletionProposal.CONTEXT);
            proposals.add(proposal);
        } else if (prefix.equals("") || ctxName.startsWith(prefix)) {
            //$NON-NLS-1$
            if (code.startsWith(CONTEXT_PREFIX)) {
                code = code.replaceFirst(CONTEXT_PREFIX, "");
            }
            TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
            proposal.setType(TalendCompletionProposal.CONTEXT);
            proposals.add(proposal);
        }
    }
    // Proposals based on global variables
    List<? extends INode> nodes = process.getGraphicalNodes();
    for (INode node : nodes) {
        List<? extends INodeReturn> nodeReturns = node.getReturns();
        for (INodeReturn nodeReturn : nodeReturns) {
            //$NON-NLS-1$
            String display = node.getLabel() + "." + nodeReturn.getName();
            if (prefix.equals("") || display.startsWith(prefix)) {
                //$NON-NLS-1$
                String code = getNodeReturnContent(nodeReturn, node);
                String description = getNodeReturnDescription(nodeReturn, node, display);
                TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), CoreImageProvider.getComponentIcon(node.getComponent(), ICON_SIZE.ICON_16), display, null, description);
                proposal.setType(TalendCompletionProposal.NODE_RETURN);
                proposals.add(proposal);
            }
        }
    }
    // Proposals based on global variables(only perl ).
    // add proposals on global variables in java (bugtracker 2554)
    // add variables in java
    IContentProposal[] javavars = JavaGlobalUtils.getProposals();
    for (IContentProposal javavar : javavars) {
        String display = javavar.getLabel();
        if (prefix.equals("") || display.startsWith(prefix)) {
            //$NON-NLS-1$
            String code = javavar.getContent();
            String description = getGlobalVarDescription(javavar, display);
            TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.PROCESS_ICON), display, null, description);
            proposal.setType(TalendCompletionProposal.VARIABLE);
            proposals.add(proposal);
        }
    }
    FunctionManager functionManager = new FunctionManager();
    List<TalendType> talendTypes = functionManager.getTalendTypes();
    for (TalendType type : talendTypes) {
        for (Object objectFunction : type.getFunctions()) {
            Function function = (Function) objectFunction;
            //$NON-NLS-1$
            String display = function.getCategory() + "." + function.getName();
            if (prefix.equals("") || display.startsWith(prefix)) {
                //$NON-NLS-1$
                String code = FunctionManager.getFunctionMethod(function);
                String description = getFunctionDescription(function, display, code);
                TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.ROUTINE_ICON), display, null, description);
                proposal.setType(TalendCompletionProposal.ROUTINE);
                proposals.add(proposal);
            }
        }
    }
    for (IExternalProposals externalProposals : ProposalFactory.getInstances()) {
        proposals.addAll(externalProposals.getAdvancedProposals(offset, prefix));
    }
    return proposals;
}
Also used : IExternalProposals(org.talend.core.ui.proposal.IExternalProposals) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) IContextParameter(org.talend.core.model.process.IContextParameter) TalendType(org.talend.designer.rowgenerator.data.TalendType) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) Function(org.talend.designer.rowgenerator.data.Function) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) INodeReturn(org.talend.core.model.process.INodeReturn) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) FunctionManager(org.talend.designer.rowgenerator.data.FunctionManager)

Example 4 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.

the class TalendCompletionProposalComputer method computeCompletionProposals.

@Override
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    //$NON-NLS-1$
    String prefix = "";
    try {
        if (context != null) {
            prefix = context.computeIdentifierPrefix().toString();
            //$NON-NLS-1$
            String tmpPrefix = "";
            IDocument doc = context.getDocument();
            if ((!prefix.equals("")) || (doc.get().length() == 0)) {
                //$NON-NLS-1$
                tmpPrefix = prefix;
            } else {
                int offset = context.getInvocationOffset();
                if (doc.getChar(offset - 1) == '.') {
                    // set by default to avoid other completions
                    //$NON-NLS-1$
                    tmpPrefix = ".";
                    if (offset >= CONTEXT_PREFIX.length() && doc.get(offset - CONTEXT_PREFIX.length(), CONTEXT_PREFIX.length()).equals(CONTEXT_PREFIX)) {
                        tmpPrefix = CONTEXT_PREFIX;
                    } else if (offset >= PERL_GLOBAL_PREFIX.length() & doc.get(offset - PERL_GLOBAL_PREFIX.length(), PERL_GLOBAL_PREFIX.length()).equals(PERL_GLOBAL_PREFIX)) {
                        switch(LanguageManager.getCurrentLanguage()) {
                            case JAVA:
                                // do nothing
                                break;
                            case PERL:
                            default:
                                tmpPrefix = PERL_GLOBAL_PREFIX;
                        }
                    } else {
                        // test each component label.
                        IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
                        IProcess process = service.getCurrentProcess();
                        if (process == null) {
                            return Collections.EMPTY_LIST;
                        }
                        List<? extends INode> nodes = process.getGraphicalNodes();
                        for (INode node : nodes) {
                            //$NON-NLS-1$
                            String toTest = node.getLabel() + ".";
                            if (offset >= toTest.length() && doc.get(offset - toTest.length(), toTest.length()).equals(toTest)) {
                                tmpPrefix = toTest;
                                break;
                            }
                        }
                    }
                }
            }
            prefix = tmpPrefix;
            if (".".equals(prefix) && LanguageManager.getCurrentLanguage().equals(ECodeLanguage.PERL)) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                prefix = "";
            }
        }
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
    return computeCompletionProposals(context.getViewer(), prefix, context.getInvocationOffset(), monitor);
}
Also used : INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) List(java.util.List) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 5 with IDesignerCoreService

use of org.talend.designer.core.IDesignerCoreService in project tdi-studio-se by Talend.

the class HTMLDocGenerator method generateSourceCodeInfo.

/**
     * DOC qwei Comment method "generateSourceCodeInfo".
     */
private void generateSourceCodeInfo(ProcessItem item, Element element) {
    if (CorePlugin.getDefault().getPreferenceStore().getBoolean(ITalendCorePrefConstants.DOC_GENERATESOURCECODE)) {
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        IProcess process = service.getProcessFromProcessItem(item);
        IProcessor processor = ProcessorUtilities.getProcessor(process, null, process.getContextManager().getDefaultContext());
        // hidePasswordInSourceCode4Doc(process);
        try {
            processor.cleanBeforeGenerate(TalendProcessOptionConstants.CLEAN_JAVA_CODES | TalendProcessOptionConstants.CLEAN_CONTEXTS | TalendProcessOptionConstants.CLEAN_DATA_SETS);
            processor.generateCode(false, true, false);
        } catch (ProcessorException e) {
            ExceptionHandler.process(e);
        }
        //$NON-NLS-1$
        Element sourceCodeInfoElement = DocumentHelper.createElement("sourcecodes");
        ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        // StringBuffer componentsCode = new StringBuffer();
        try {
            IFile codeFile = synchronizer.getFile(item);
            if (codeFile == null) {
                return;
            }
            //$NON-NLS-1$
            String tempStr = "";
            InputStream in = codeFile.getContents();
            BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
            while ((tempStr = buffer.readLine()) != null) {
                //$NON-NLS-1$
                Element codeElement = DocumentHelper.createElement("code");
                // componentsCode.append(tempStr).append("\n");
                //$NON-NLS-1$
                codeElement.addAttribute("content", tempStr);
                sourceCodeInfoElement.add(codeElement);
            }
            buffer.close();
            in.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
        element.add(sourceCodeInfoElement);
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) ProcessorException(org.talend.designer.runprocess.ProcessorException) IFile(org.eclipse.core.resources.IFile) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.dom4j.Element) BufferedReader(java.io.BufferedReader) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcessor(org.talend.designer.runprocess.IProcessor) IProcess(org.talend.core.model.process.IProcess) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)42 IProcess (org.talend.core.model.process.IProcess)27 ProcessItem (org.talend.core.model.properties.ProcessItem)22 ArrayList (java.util.ArrayList)13 Item (org.talend.core.model.properties.Item)13 INode (org.talend.core.model.process.INode)12 PersistenceException (org.talend.commons.exception.PersistenceException)10 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 IOException (java.io.IOException)8 List (java.util.List)8 IProcess2 (org.talend.core.model.process.IProcess2)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 HashSet (java.util.HashSet)6 IFile (org.eclipse.core.resources.IFile)6 IElementParameter (org.talend.core.model.process.IElementParameter)6 Process (org.talend.designer.core.ui.editor.process.Process)6 IProcessor (org.talend.designer.runprocess.IProcessor)6 HashMap (java.util.HashMap)5 IEditorReference (org.eclipse.ui.IEditorReference)5 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)5