private void checkContextGroupSource() {
   IContextManager contextManager = getContextManager();
   if (helper == null) {
     return;
   }
   if (contextManager != null) {
     helper.initHelper(contextManager);
     Map<String, Item> items = new HashMap<String, Item>();
     boolean needRefresh = false;
     for (IContextParameter param : contextManager.getDefaultContext().getContextParameterList()) {
       if (!param.isBuiltIn()) {
         String source = param.getSource();
         Item sourceItem = items.get(source);
         if (sourceItem == null) {
           sourceItem = ContextUtils.getRepositoryContextItemById(source);
         }
         if (sourceItem == null) { // source not found
           needRefresh = true;
           param.setSource(IContextParameter.BUILT_IN);
           propagateType(contextManager, param);
         } else {
           items.put(source, sourceItem);
         }
       }
     }
     if (needRefresh) {
       setModifiedFlag(contextManager);
       modelManager.refresh();
     }
   }
 }
  private void initializeContextCombo() {
    IContextManager contextManager = getContextManager();
    if (contextsCombo.getItems().length > 0) {
      contextsCombo.removeAll();
    }
    if (contextManager != null) {
      List<IContext> contexts = contextManager.getListContext();
      for (IContext context : contexts) {
        if (!Arrays.asList(contextsCombo.getItems()).contains(context.getName())) {
          contextsCombo.add(context.getName());
        }
      }

      for (int i = 0; i < contextsCombo.getItemCount(); i++) {
        IContext defaultContext = contextManager.getDefaultContext();
        if (defaultContext.getName().equals(contextsCombo.getItem(i))) {
          contextsCombo.select(i);
          break;
        }
      }
    }

    int visibleItemCount = contextsCombo.getItemCount();
    if (visibleItemCount > 20) {
      visibleItemCount = 20;
    }
    contextsCombo.setVisibleItemCount(visibleItemCount);
  }
 @Override
 public void undo() {
   for (int i = 0; i < contextManager.getListContext().size(); i++) {
     IContext context = contextManager.getListContext().get(i);
     List<IContextParameter> listParams = context.getContextParameterList();
     List<IContextParameter> contextParamList = mapParams.get(context.getName());
     if (contextParamList != null) {
       listParams.addAll(contextParamList);
     }
   }
   contextManager.fireContextsChangedEvent();
   helper.refreshContextView();
 }
 private void updateRelation() {
   // set updated flag.
   if (param != null) {
     IContextManager manager = modelManager.getContextManager();
     if (manager != null && manager instanceof JobContextManager) {
       JobContextManager jobContextManager = (JobContextManager) manager;
       // not added new
       if (!modelManager.isRepositoryContext()
           || modelManager.isRepositoryContext()
               && jobContextManager.isOriginalParameter(param.getName())) {
         jobContextManager.setModified(true);
         manager.fireContextsChangedEvent();
       }
     }
   }
 }
 public IContextParameter getRealParameter(
     IContextManager manager, String property, Object element) {
   IContextParameter para = null;
   IContext context = null;
   if (manager != null) {
     context = manager.getContext(property);
     if (context == null) {
       return null;
     }
     if (element instanceof ContextTableTabParentModel) {
       if (IContextParameter.BUILT_IN.equals(
           ((ContextTableTabParentModel) element).getSourceId())) {
         IContextParameter builtContextParameter =
             ((ContextTableTabParentModel) element).getContextParameter();
         if (builtContextParameter != null) {
           para = context.getContextParameter(builtContextParameter.getName());
         }
       }
     } else if (element instanceof ContextTableTabChildModel) {
       ContextTableTabChildModel child = (ContextTableTabChildModel) element;
       String sourceId = child.getContextParameter().getSource();
       para =
           context.getContextParameter(
               sourceId, ((ContextTableTabChildModel) element).getContextParameter().getName());
     }
   }
   return para;
 }
 /**
  * This method is used to remove the <code>JobContextParameter</code> in <code>JobContext</code>,
  * using the combination of <code>sourceId</code> and <code>name</code> can identify the unique
  * <code>JobContextParameter</code>.
  *
  * @param sourceId
  * @param name
  */
 private void removeParameterFromContext(String sourceId, String name) {
   List<IContext> list = contextManager.getListContext();
   if (list != null && list.size() > 0) {
     for (int i = 0; i < list.size(); i++) {
       IContext context = list.get(i);
       List<IContextParameter> contextParameters = context.getContextParameterList();
       List<IContextParameter> movedList = new ArrayList<IContextParameter>();
       if (contextParameters != null && contextParameters.size() > 0) {
         for (int j = 0; j < contextParameters.size(); j++) {
           IContextParameter contextPara = contextParameters.get(j);
           String tempSourceId = contextPara.getSource();
           String tempParaName = contextPara.getName();
           if (tempSourceId.equals(sourceId) && tempParaName.equals(name)) {
             movedList.add(contextPara);
             contextParameters.remove(j);
             if (mapParams.get(context.getName()) != null) {
               mapParams.get(context.getName()).addAll(movedList);
               mapParams.put(context.getName(), mapParams.get(context.getName()));
             } else {
               mapParams.put(context.getName(), movedList);
             }
             break;
           }
         }
       }
     }
   }
 }
 private void propagateType(IContextManager contextManager, IContextParameter param) {
   for (IContext context : contextManager.getListContext()) {
     IContextParameter paramToModify = context.getContextParameter(param.getName());
     paramToModify.setType(param.getType());
     paramToModify.setComment(param.getComment());
     paramToModify.setSource(param.getSource());
   }
 }
  protected void getInformationsFromContextManager(IContextManager contextManager) {
    List<IContext> internalContextList = new ArrayList<IContext>();
    IContext newSelectedCopiedContext = null;

    // if (!contextComboViewer.getSelection().isEmpty()) {
    // oldSelectedCopiedContext = (IContext) ((StructuredSelection)
    // contextComboViewer.getSelection()).getFirstElement();
    // }

    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());
    }
  }
 private void updateRelation(String _oldName, String _newName) {
   // set updated flag.
   if (param != null) {
     IContextManager manager = modelManager.getContextManager();
     if (manager != null && manager instanceof JobContextManager) {
       JobContextManager jobContextManager = (JobContextManager) manager;
       // not added new
       if (!modelManager.isRepositoryContext()
           || modelManager.isRepositoryContext()
               && jobContextManager.isOriginalParameter(param.getName())) {
         jobContextManager.setModified(true);
         manager.fireContextsChangedEvent();
       }
     }
   }
   // update nodes in the job
   if (modelManager instanceof ContextComposite) {
     ((ContextComposite) modelManager).switchSettingsView(_oldName, _newName);
   }
 }
 /**
  * Changed by Marvin Wang on Mar.6, 2012 for bug TDI-8574, for each JobContext, only has one
  * JobContextParameter with the unique combination of source and name. The original algorithm will
  * cause some JobContextParamters can not be removed.
  */
 @Override
 public void execute() {
   mapParams.clear();
   if (contextParamNames != null && contextParamNames.size() > 0) {
     Iterator<String> it = contextParamNames.iterator();
     while (it.hasNext()) {
       String contextParaName = it.next();
       removeParameterFromContext(paraSourceId, contextParaName);
     }
   }
   contextManager.fireContextsChangedEvent();
   if (needRefresh) {
     helper.refreshContextView();
   }
 }
Esempio n. 11
0
 @SuppressWarnings("unchecked")
 private void initSets() {
   if (source != null) {
     if (source instanceof ContextItem) {
       ContextItem contextItem = (ContextItem) source;
       defalutContext = contextItem.getDefaultContext();
       for (ContextType type : (List<ContextType>) contextItem.getContext()) {
         String name = type.getName();
         if (name.equals(defalutContext)) {
           name = name + DEFAULT_FLAG;
         }
         contextSetsList.add(name);
       }
     } else if (source instanceof IContextManager) {
       IContextManager contextManager = (IContextManager) (source);
       for (IContext context : contextManager.getListContext()) {
         String name = context.getName();
         if (name.equals(defalutContext)) {
           name = name + DEFAULT_FLAG;
         }
         contextSetsList.add(name);
       }
     } else if (source instanceof List<?>) {
       for (Object obj : (List<?>) source) {
         if (obj instanceof ContextType) {
           ContextType context = (ContextType) obj;
           String name = context.getName();
           if (name.equals(defalutContext)) {
             name = name + DEFAULT_FLAG;
           }
           contextSetsList.add(name);
         }
       }
     }
   }
 }
 private void initExistedParametersMap() {
   if (!isValid(manager)) {
     return;
   }
   itemNameToParametersMap.clear();
   for (IContextParameter param : manager.getDefaultContext().getContextParameterList()) {
     if (!param.isBuiltIn()) {
       final String source = param.getSource();
       Set<String> paramSet = itemNameToParametersMap.get(source);
       if (paramSet == null) {
         paramSet = new HashSet<String>();
         itemNameToParametersMap.put(source, paramSet);
       }
       paramSet.add(param.getName());
     }
   }
 }
  /** qzhang Comment method "runPreviewCode". */
  public Process runPreviewCode() {
    getProcess();
    if (jobContextManager == null) {
      // proc.getContextManager().setListContext(component.getProcess().getContextManager().getListContext());
      proc.getContextManager()
          .setDefaultContext(component.getProcess().getContextManager().getDefaultContext());
    } else {
      // proc.getContextManager().setListContext(jobContextManager.getListContext());
      proc.getContextManager().setDefaultContext(jobContextManager.getDefaultContext());
    }
    // IContext context2 = new org.talend.core.model.context.JobContext(PREVIEW);
    // if (UIManager.isJavaProject()) {
    // List<IContextParameter> params = new ArrayList<IContextParameter>();
    // JobContextParameter contextParameter = new JobContextParameter();
    // contextParameter.setContext(context2);
    // contextParameter.setName(PREVIEW);
    // contextParameter.setValue(PREVIEW);
    // contextParameter.setType("String");
    // params.add(contextParameter);
    // context2.setContextParameterList(params);
    // }

    // generate context files.
    IProcessor contextProcessor = ProcessorUtilities.getProcessor(proc, null);
    contextProcessor.setContext(proc.getContextManager().getDefaultContext());
    try {
      contextProcessor.cleanBeforeGenerate(TalendProcessOptionConstants.CLEAN_CONTEXTS);
      contextProcessor.generateContextCode();
    } catch (ProcessorException pe) {
      ExceptionHandler.process(pe);
    }

    IProcessor processor =
        ProcessorUtilities.getProcessor(proc, null, proc.getContextManager().getDefaultContext());
    try {
      return processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
    } catch (Exception e) {
      ExceptionHandler.process(e);
      return null;
    }
  }
 /*
  * get the have existed variables.
  */
 public IContextParameter getExistedContextParameter(String paramName) {
   if (!isValid(paramName) || !isValid(manager)) {
     return null;
   }
   return manager.getDefaultContext().getContextParameter(paramName);
 }