Search in sources :

Example 36 with IContext

use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.

the class ProcessContextComposite method getInformationsFromContextManager.

protected void getInformationsFromContextManager(IContextManager contextManager) {
    List<IContext> internalContextList = new ArrayList<IContext>();
    IContext newSelectedCopiedContext = null;
    if (process != null && process.getLastRunContext() != null) {
        for (IContext context : contextManager.getListContext()) {
            IContext copiedContext = context.clone();
            internalContextList.add(copiedContext);
            if (process.getLastRunContext().getName().equals(context.getName())) {
                newSelectedCopiedContext = copiedContext;
            }
        }
    } else {
        for (IContext context : contextManager.getListContext()) {
            IContext copiedContext = context.clone();
            internalContextList.add(copiedContext);
            if (contextManager.getDefaultContext().equals(context)) {
                newSelectedCopiedContext = copiedContext;
            }
        }
    }
    Collections.sort(internalContextList, new ContextCompare());
    contextComboViewer.setInput(internalContextList);
    ProcessManager processManager = ProcessManager.getInstance();
    if (newSelectedCopiedContext != null) {
        setContextComboSelection(new StructuredSelection(newSelectedCopiedContext));
        processManager.setSelectContext(newSelectedCopiedContext);
        contextTableViewer.setInput(newSelectedCopiedContext.getContextParameterList());
    } else {
        IContext element = internalContextList.get(0);
        processManager.setSelectContext(element);
        setContextComboSelection(new StructuredSelection(element));
        contextTableViewer.setInput(element.getContextParameterList());
    }
}
Also used : IContext(org.talend.core.model.process.IContext) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 37 with IContext

use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.

the class ProcessDebugDialog method okPressed.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
     */
@Override
protected void okPressed() {
    if (contextComposite.promptConfirmLauch()) {
        final IContext context = contextComposite.getSelectedContext();
        super.okPressed();
        IRunnableWithProgress worker = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) {
                IProcessor processor = ProcessorUtilities.getProcessor(process, process.getProperty(), context);
                //$NON-NLS-1$
                monitor.beginTask("Launching debugger", IProgressMonitor.UNKNOWN);
                try {
                    // use this function to generate childrens also.
                    ProcessorUtilities.generateCode(process, context, false, false, true, monitor);
                    ILaunchConfiguration config = ((IEclipseProcessor) processor).debug();
                    if (config != null) {
                        // PlatformUI.getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new
                        // DebugInNewWindowListener());
                        DebugUITools.launch(config, ILaunchManager.DEBUG_MODE);
                    } else {
                        MessageDialog.openInformation(getShell(), Messages.getString("ProcessDebugDialog.debugBtn"), //$NON-NLS-1$
                        Messages.getString(//$NON-NLS-1$ //$NON-NLS-2$
                        "ProcessDebugDialog.errortext"));
                    }
                } catch (ProcessorException e) {
                    IStatus status = new Status(IStatus.ERROR, RunProcessPlugin.PLUGIN_ID, IStatus.OK, "Debug launch failed.", //$NON-NLS-1$
                    e);
                    RunProcessPlugin.getDefault().getLog().log(status);
                    //$NON-NLS-1$
                    MessageDialog.openError(//$NON-NLS-1$
                    getShell(), //$NON-NLS-1$
                    Messages.getString("ProcessDebugDialog.debugBtn"), //$NON-NLS-1$
                    "");
                } finally {
                    monitor.done();
                }
            }
        };
        IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
        try {
            progressService.runInUI(PlatformUI.getWorkbench().getProgressService(), worker, ResourcesPlugin.getWorkspace().getRoot());
        } catch (InvocationTargetException e) {
            // e.printStackTrace();
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IStatus(org.eclipse.core.runtime.IStatus) IContext(org.talend.core.model.process.IContext) ProcessorException(org.talend.designer.runprocess.ProcessorException) IProgressService(org.eclipse.ui.progress.IProgressService) IProcessor(org.talend.designer.runprocess.IProcessor) IEclipseProcessor(org.talend.core.model.runprocess.IEclipseProcessor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 38 with IContext

use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.

the class ComponentChooseDialog method createContext.

private void createContext(List<Object> sourceList) {
    if (sourceList.size() == 0) {
        return;
    }
    boolean created = false;
    for (Object source : sourceList) {
        if (source instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) source;
            Item item = sourceNode.getObject().getProperty().getItem();
            if (item instanceof ContextItem) {
                ContextItem contextItem = (ContextItem) item;
                EList context = contextItem.getContext();
                Set<String> contextSet = new HashSet<String>();
                Iterator iterator = context.iterator();
                while (iterator.hasNext()) {
                    Object obj = iterator.next();
                    if (obj instanceof ContextTypeImpl) {
                        EList contextParameters = ((ContextTypeImpl) obj).getContextParameter();
                        Iterator contextParas = contextParameters.iterator();
                        while (contextParas.hasNext()) {
                            ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
                            String name = contextParameterType.getName();
                            contextSet.add(name);
                        }
                    }
                }
                IEditorInput editorInput = editor.getEditorInput();
                if (editorInput instanceof JobEditorInput) {
                    JobEditorInput jobInput = (JobEditorInput) editorInput;
                    IProcess2 process = jobInput.getLoadedProcess();
                    IContextManager contextManager = process.getContextManager();
                    List<IContext> listContext = contextManager.getListContext();
                    // context group will reflect absolutely if no context variable in contextViewer
                    // if (!ConnectionContextHelper.containsVariable(contextManager)) {
                    // for bug 15608
                    // ConnectionContextHelper.addContextVarForJob(process, contextItem, contextManager);
                    // ConnectionContextHelper.checkAndAddContextsVarDND(contextItem, contextManager);
                    Set<String> addedVars = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, process.getContextManager(), false);
                    if (addedVars != null && !addedVars.isEmpty() && !ConnectionContextHelper.isAddContextVar(contextItem, contextManager, contextSet)) {
                        // show
                        Map<String, Set<String>> addedVarsMap = new HashMap<String, Set<String>>();
                        addedVarsMap.put(item.getProperty().getLabel(), contextSet);
                        if (ConnectionContextHelper.showContextdialog(process, contextItem, process.getContextManager(), addedVarsMap, contextSet)) {
                            created = true;
                        }
                    }
                // } else {
                // Set<String> addedContext = ConnectionContextHelper.checkAndAddContextVariables(contextItem,
                // contextSet, contextManager, false);
                // if (addedContext != null && addedContext.size() > 0) {
                // ConnectionContextHelper.addContextVarForJob(process, contextItem, contextSet);
                // created = true;
                // }
                // }
                }
            }
        }
    }
    if (created) {
        RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurContextsView();
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) IContext(org.talend.core.model.process.IContext) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ContextParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) RulesItem(org.talend.core.model.properties.RulesItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) FileItem(org.talend.core.model.properties.FileItem) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) IProcess2(org.talend.core.model.process.IProcess2) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) ContextTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextTypeImpl) IContextManager(org.talend.core.model.process.IContextManager) IEditorInput(org.eclipse.ui.IEditorInput) HashSet(java.util.HashSet)

Example 39 with IContext

use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.

the class TableByRowController method updateContextList.

private void updateContextList(IElementParameter param) {
    List<String> contextParameterNamesList = new ArrayList<String>();
    IElementParameter processTypeParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
    if (processTypeParam == null) {
        processTypeParam = elem.getElementParameterFromField(EParameterFieldType.ROUTE_INPUT_PROCESS_TYPE);
        if (processTypeParam == null) {
            return;
        }
    }
    boolean haveContextParamList = false;
    for (Object valueParam : param.getListItemsValue()) {
        if (valueParam instanceof IElementParameter) {
            IElementParameter vParam = (IElementParameter) valueParam;
            if (vParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
                haveContextParamList = true;
                break;
            }
        }
    }
    if (!haveContextParamList) {
        return;
    }
    IElementParameter jobElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
    IElementParameter jobVersionParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_VERSION.getName());
    IElementParameter contextElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_CONTEXT.getName());
    // get context list
    String processId = (String) jobElemParam.getValue();
    String contextName = (String) contextElemParam.getValue();
    if (contextName == null) {
        contextName = new String();
    }
    if (processId == null || contextName == null) {
        revertToolBarButtonState(false);
        return;
    }
    ProcessItem processItem = ItemCacheManager.getProcessItem(processId, (String) jobVersionParam.getValue());
    Process process = null;
    String[] contextParameterNames = null;
    if (processItem != null) {
        // achen modify to fix bug 0006107
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        process = (Process) service.getProcessFromItem(processItem);
        // process = new Process(processItem.getProperty());
        // process.loadXmlFile();
        IContext context = process.getContextManager().getContext(contextName);
        for (IContextParameter contextParam : context.getContextParameterList()) {
            contextParameterNamesList.add(contextParam.getName());
        }
        contextParameterNames = contextParameterNamesList.toArray(new String[0]);
    } else {
        contextParameterNames = new String[0];
    }
    // update table values
    TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
    Object[] itemsValue = param.getListItemsValue();
    if (tableViewerCreator != null) {
        List colList = tableViewerCreator.getColumns();
        for (int j = 0; j < itemsValue.length; j++) {
            if ((j + 1) >= colList.size()) {
                break;
            }
            if (itemsValue[j] instanceof IElementParameter) {
                IElementParameter tmpParam = (IElementParameter) itemsValue[j];
                if (tmpParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
                    tmpParam.setListItemsDisplayCodeName(contextParameterNames);
                    tmpParam.setListItemsDisplayName(contextParameterNames);
                    tmpParam.setListItemsValue(contextParameterNames);
                    if (contextParameterNames.length > 0) {
                        tmpParam.setDefaultClosedListValue(contextParameterNames[0]);
                    } else {
                        //$NON-NLS-1$
                        tmpParam.setDefaultClosedListValue("");
                    }
                    // j + 1 because first column is masked
                    TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
                    CCombo combo = (CCombo) column.getCellEditor().getControl();
                    String[] oldItems = combo.getItems();
                    combo.setItems(contextParameterNames);
                    List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
                    String[] items = param.getListItemsDisplayCodeName();
                    for (int currentIndex = 0; currentIndex < paramValues.size(); currentIndex++) {
                        Map<String, Object> currentLine = paramValues.get(currentIndex);
                        Object o = currentLine.get(items[j]);
                        if (o instanceof Integer) {
                            Integer nb = (Integer) o;
                            if ((nb >= oldItems.length) || (nb == -1)) {
                                currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
                            } else {
                                currentLine.put(items[j], oldItems[nb]);
                            }
                        } else {
                            if (o instanceof String) {
                                Integer nb = new Integer(tmpParam.getIndexOfItemFromList((String) o));
                                if (nb == -1) {
                                    currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // (bug 3740)
    boolean checked = contextParameterNames != null && contextParameterNames.length > 0;
    if (!checked) {
        Object value = param.getValue();
        if (value != null && value instanceof List) {
            if (!((List) value).isEmpty()) {
                ((List) value).clear();
                if (part != null && part.getTalendEditor() != null) {
                    part.getTalendEditor().setDirty(true);
                }
            }
        }
    }
    revertToolBarButtonState(checked);
}
Also used : IContext(org.talend.core.model.process.IContext) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) TableViewerCreatorColumnNotModifiable(org.talend.commons.ui.runtime.swt.tableviewer.TableViewerCreatorColumnNotModifiable) ArrayList(java.util.ArrayList) Process(org.talend.designer.core.ui.editor.process.Process) IContextParameter(org.talend.core.model.process.IContextParameter) Point(org.eclipse.swt.graphics.Point) CCombo(org.eclipse.swt.custom.CCombo) ProcessItem(org.talend.core.model.properties.ProcessItem) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) Map(java.util.Map) HashMap(java.util.HashMap)

Example 40 with IContext

use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.

the class ConfigureConnParamDialog method resetValues.

/**
     * qzhang Comment method "resetValues".
     * 
     * @param host
     */
private void resetValues(final Text key, final Text value) {
    final IContext context = contextManager.getContext(contextCombo.getItem(contextCombo.getSelectionIndex()));
    value.setText(ContextParameterUtils.parseScriptContextCode(key.getText(), context));
}
Also used : IContext(org.talend.core.model.process.IContext)

Aggregations

IContext (org.talend.core.model.process.IContext)46 IContextParameter (org.talend.core.model.process.IContextParameter)14 ArrayList (java.util.ArrayList)13 List (java.util.List)11 IProcess (org.talend.core.model.process.IProcess)10 ProcessorException (org.talend.designer.runprocess.ProcessorException)10 HashMap (java.util.HashMap)9 ProcessItem (org.talend.core.model.properties.ProcessItem)8 IOException (java.io.IOException)7 IElementParameter (org.talend.core.model.process.IElementParameter)7 IProcessor (org.talend.designer.runprocess.IProcessor)7 File (java.io.File)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IContextManager (org.talend.core.model.process.IContextManager)6 HashSet (java.util.HashSet)5 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)5 IProcess2 (org.talend.core.model.process.IProcess2)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 Map (java.util.Map)4