public static ContextTableTabParentModel lookupContextParentForNonBuiltinNode(
     String sourceId, List<ContextTableTabParentModel> output) {
   ContextTableTabParentModel firstLevelNode = null;
   if (output != null && output.size() > 0) {
     for (ContextTableTabParentModel parent : output) {
       String tempSourceId = parent.getSourceId();
       if (tempSourceId != null && sourceId.equals(tempSourceId)) {
         firstLevelNode = parent;
         break;
       }
     }
   }
   return firstLevelNode;
 }
 private void removeParentModelInGroupBySource(ContextTableTabParentModel parentModel) {
   Set<String> paraNames = new HashSet<String>();
   String sourceId = parentModel.getSourceId();
   if (IContextParameter.BUILT_IN.equals(sourceId)) {
     String paraName = parentModel.getContextParameter().getName();
     paraNames.add(paraName);
   } else {
     List<ContextTabChildModel> children = parentModel.getChildren();
     if (children != null && children.size() > 0) {
       for (ContextTabChildModel child : children) {
         IContextParameter contextPara = child.getContextParameter();
         String paraName = contextPara.getName();
         paraNames.add(paraName);
       }
     }
   }
   modelManager.onContextRemoveParameter(getContextManager(), paraNames, sourceId);
 }
  private void setPropertyValue(
      IContextModelManager manager,
      Object dataElement,
      String contextParaName,
      int columnIndex,
      Object newValue) {
    String currentColumnName = getColumnProperty(columnIndex);
    if (this.groupModel.isPartOfAGroup(columnIndex)) {
      String columnGroupName = this.groupModel.getColumnGroupByIndex(columnIndex).getName();
      IContextManager contextManger = manager.getContextManager();
      if (contextManger != null) {
        // change the property of context such as prompt,promptyNeeded,value etc.
        List<Object> list = new ArrayList<Object>();
        list.add(dataElement);

        IContextParameter para = null;
        para = getRealParameter(contextManger, columnGroupName, dataElement);
        if (para == null) {
          return;
        }
        Command cmd =
            new SetContextGroupParameterCommand(manager, para, currentColumnName, newValue);
        runCommand(cmd, manager);
        if (currentColumnName.equals(ContextTableConstants.COLUMN_CHECK_PROPERTY)) {
          manager.refresh();
        }
      }
    } else {
      if (currentColumnName.equals(ContextTableConstants.COLUMN_TYPE_PROPERTY)) {
        ContextTableTabParentModel parent = (ContextTableTabParentModel) dataElement;
        IContextParameter contextPara = parent.getContextParameter();
        if (contextPara.getType() == ((String) newValue)) {
          return;
        }
        String newType = getRealType((String) newValue);
        contextPara.setType(newType);

        Command cmd = new SetContextTypeCommand(manager, contextPara, newType);
        runCommand(cmd, manager);
      } else if (currentColumnName.equals(ContextTableConstants.COLUMN_NAME_PROPERTY)) {
        ContextTableTabParentModel parent = (ContextTableTabParentModel) dataElement;
        IContextParameter contextPara = parent.getContextParameter();
        String sourceId = contextPara.getSource();
        String newParaName = (String) newValue;

        if (manager.getContextManager() instanceof JobContextManager) {
          // in case joblet rename will propagate to the job,just record it
          JobContextManager contextManager = (JobContextManager) manager.getContextManager();
          contextManager.addNewName(newParaName, contextPara.getName());
          contextManager.setModified(true);
        }
        Command cmd = new SetContextNameCommand(manager, contextPara, newParaName, sourceId);
        runCommand(cmd, manager);
      } else if (currentColumnName.equals(ContextTableConstants.COLUMN_COMMENT_PROPERTY)) {
        ContextTableTabParentModel parent = (ContextTableTabParentModel) dataElement;
        IContextParameter contextPara = parent.getContextParameter();
        if (contextPara.getComment() == ((String) newValue)) {
          return;
        }
        Command cmd = new setContextCommentCommand(manager, contextPara, (String) newValue);
        runCommand(cmd, manager);
      }
    }
  }
  public static List<ContextTableTabParentModel> constructContextDatas(
      List<IContextParameter> contextDatas) {
    List<ContextTableTabParentModel> output = new ArrayList<ContextTableTabParentModel>();
    if (!contextDatas.isEmpty()) {
      int i = 0;
      for (IContextParameter para : contextDatas) {
        String sourceId = para.getSource();
        if (IContextParameter.BUILT_IN.equals(sourceId)) {
          sourceId = para.getSource();
          ContextTableTabParentModel firstLevelNode = new ContextTableTabParentModel();
          String sourceLabel = sourceId;
          ContextItem contextItem = ContextUtils.getContextItemById2(sourceId);
          if (contextItem != null) {
            sourceLabel = contextItem.getProperty().getLabel();
            final ProjectManager pm = ProjectManager.getInstance();
            if (!pm.isInCurrentMainProject(contextItem)) {
              final Project project = pm.getProject(contextItem);
              if (project != null) {
                firstLevelNode.setProjectLabel(project.getLabel());
              }
            }
          }
          firstLevelNode.setOrder(i);
          firstLevelNode.setSourceName(sourceLabel);
          firstLevelNode.setSourceId(sourceId);
          firstLevelNode.setContextParameter(para);
          output.add(firstLevelNode);
        } else {
          ContextTableTabParentModel firstLevelNode = null;
          if (sourceId != null) {
            firstLevelNode = lookupContextParentForNonBuiltinNode(sourceId, output);
            if (firstLevelNode == null) {
              firstLevelNode = new ContextTableTabParentModel();
              output.add(firstLevelNode);
              String sourceLabel = sourceId;
              // the item maybe a joblet item now
              Item contextItem = ContextUtils.getRepositoryContextItemById(sourceId);
              if (contextItem != null) {
                sourceLabel = contextItem.getProperty().getLabel();
                final ProjectManager pm = ProjectManager.getInstance();
                if (!pm.isInCurrentMainProject(contextItem)) {
                  final Project project = pm.getProject(contextItem);
                  if (project != null) {
                    firstLevelNode.setProjectLabel(project.getLabel());
                  }
                }
              }
              firstLevelNode.setSourceName(sourceLabel);
              firstLevelNode.setOrder(i);
              firstLevelNode.setSourceId(sourceId);
            }

            ContextTableTabChildModel child = new ContextTableTabChildModel();
            child.setSourceId(sourceId);
            child.setContextParameter(para);
            child.setParent(firstLevelNode);
            firstLevelNode.addChild(child);
          }
        }
        i++;
      }
    }
    return output;
  }