/**
  * ggu Comment method "getContextItemById".
  *
  * <p>bug 13184
  */
 public ContextItem getContextItemById(String id) {
   if (!isValid(id)) {
     return null;
   }
   Set<ContextItem> itemSet = getContextItems();
   for (ContextItem item : itemSet) {
     if (item.getProperty().getId().equals(id)) {
       return item;
     }
   }
   return null;
 }
 /*
  * get default ContextType from ContextItem
  */
 public static ContextType getDefaultContextType(ContextItem item) {
   if (!isValid(item)) {
     return null;
   }
   for (Object obj : item.getContext()) {
     ContextType type = (ContextType) obj;
     if (type.getName().equals(item.getDefaultContext())) {
       return type;
     }
   }
   return null;
 }
 /**
  * get the ContextItem from the name.
  *
  * @deprecated by 13184
  */
 @Deprecated
 public ContextItem getContextItemByName(String name) {
   if (!isValid(name)) {
     return null;
   }
   Set<ContextItem> itemSet = getContextItems();
   for (ContextItem item : itemSet) {
     if (item.getProperty().getLabel().equals(name)) {
       return item;
     }
   }
   return null;
 }
 /**
  * ggu Comment method "existParameterForJob".
  *
  * <p>check that the obj is existed in job context.
  */
 public boolean existParameterForJob(Object obj, List<ContextItem> allContextItems) {
   if (!isValid(obj)) {
     return false;
   }
   if (allContextItems == null) {
     allContextItems = new ArrayList<ContextItem>(getContextItems());
   }
   if (obj instanceof ContextItem) {
     Set<String> paramSet =
         this.itemNameToParametersMap.get(((ContextItem) obj).getProperty().getId());
     return paramSet != null && !paramSet.isEmpty();
   } else if (obj instanceof ContextParameterType) {
     ContextItem contextItem = (ContextItem) getParentContextItem(obj, allContextItems);
     if (contextItem != null) {
       Set<String> paramSet = this.itemNameToParametersMap.get(contextItem.getProperty().getId());
       return paramSet != null && paramSet.contains(((ContextParameterType) obj).getName());
     }
   }
   return false;
 }
Ejemplo n.º 5
0
  private void createSourceArea(Composite parent) {
    if (source != null && source instanceof ContextItem) {
      ContextItem contextItem = (ContextItem) source;

      Composite inner = new Composite(parent, SWT.NONE);
      GridLayout gridLayout = new GridLayout(2, false);
      gridLayout.marginHeight = 0;
      inner.setLayout(gridLayout);
      inner.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

      Label label = new Label(inner, SWT.NONE);
      label.setText(Messages.getString("ContextSetsSelectionDialog.Source")); // $NON-NLS-1$

      Label source = new Label(inner, SWT.NONE);
      source.setText(
          contextItem.getProperty().getLabel()
              + " "
              + contextItem.getProperty().getVersion()); // $NON-NLS-1$
      source.setForeground(new Color(null, 255, 0, 0));
    }
  }
 /** get parent object of the object */
 public Object getParentContextItem(Object obj, List<ContextItem> allContextItems) {
   if (!isValid(obj)) {
     return null;
   }
   if (obj instanceof ContextItem) {
     return null;
   }
   if (allContextItems == null) {
     allContextItems = new ArrayList<ContextItem>(getContextItems());
   }
   if (allContextItems != null) {
     // for SelectRepositoryContextDialog
     if (obj instanceof ContextParameterType) {
       for (ContextItem contextItem : allContextItems) {
         for (Object objType : contextItem.getContext()) {
           ContextType type = (ContextType) objType;
           if (type.getName().equals(contextItem.getDefaultContext())) {
             List paramList = type.getContextParameter();
             if (paramList != null && paramList.contains(obj)) {
               return contextItem;
             }
           }
         }
       }
     }
     // for SelectRepositoryContextGroupDialog
     if (obj instanceof ContextType) {
       for (ContextItem contextItem : allContextItems) {
         if (contextItem.getContext().contains(obj)) {
           return contextItem;
         }
       }
     }
   }
   return null;
 }
Ejemplo n.º 7
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);
         }
       }
     }
   }
 }
  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;
  }