/** yzhang Comment method "updateProblems". */
  private void updateProblems(List<IRepositoryViewObject> routineObjectList, String filePath) {

    IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
    try {
      ITalendProcessJavaProject talendProcessJavaProject =
          runProcessService.getTalendProcessJavaProject();
      if (talendProcessJavaProject == null) {
        return;
      }
      IProject javaProject = talendProcessJavaProject.getProject();
      IFile file = javaProject.getFile(filePath);
      String fileName = file.getName();

      for (IRepositoryViewObject repositoryObject : routineObjectList) {
        Property property = repositoryObject.getProperty();
        ITalendSynchronizer synchronizer =
            CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        Item item = property.getItem();
        if (GlobalServiceRegister.getDefault()
            .isServiceRegistered(ICamelDesignerCoreService.class)) {
          ICamelDesignerCoreService service =
              (ICamelDesignerCoreService)
                  GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
          if (service.isInstanceofCamel(item)) {
            synchronizer =
                CorePlugin.getDefault().getCodeGeneratorService().createCamelBeanSynchronizer();
          }
        }
        IFile currentFile = synchronizer.getFile(item);
        if (currentFile != null && fileName.equals(currentFile.getName()) && currentFile.exists()) {
          Problems.addRoutineFile(currentFile, property);
          break;
        }
      }
    } catch (SystemException e) {
      ExceptionHandler.process(e);
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see org.talend.repository.ui.actions.ITreeContextualAction#init(org.eclipse.jface.viewers.TreeViewer,
   * org.eclipse.jface.viewers.IStructuredSelection)
   */
  @Override
  public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = !selection.isEmpty() && selection.size() == 1;
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (factory.isUserReadOnlyOnCurrentProject()) {
      canWork = false;
    }
    if (canWork) {
      Object o = selection.getFirstElement();
      RepositoryNode node = (RepositoryNode) o;
      Object property = node.getProperties(EProperties.CONTENT_TYPE);
      switch (node.getType()) {
        case REPOSITORY_ELEMENT:
        case STABLE_SYSTEM_FOLDER:
          canWork = false;
          break;
        case SYSTEM_FOLDER:
          if (ERepositoryObjectType.GENERATED.equals(property)
              || ERepositoryObjectType.JOBS.equals(property)
              || ERepositoryObjectType.JOBLETS.equals(property)
              || ERepositoryObjectType.SQLPATTERNS.equals(property)
              || ERepositoryObjectType.REFERENCED_PROJECTS.equals(property)
              || ERepositoryObjectType.SVN_ROOT.equals(property)) {
            canWork = false;
          } else if (property != null
              && GlobalServiceRegister.getDefault()
                  .isServiceRegistered(ICamelDesignerCoreService.class)) {
            ICamelDesignerCoreService camelService =
                (ICamelDesignerCoreService)
                    GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
            if (property.equals(camelService.getRouteDocsType())) {
              canWork = false;
            }
          }
          break;
        case SIMPLE_FOLDER:
          if (ERepositoryObjectType.JOB_DOC.equals(property)
              || ERepositoryObjectType.JOBLET_DOC.equals(property)
              || (ERepositoryObjectType.SQLPATTERNS.equals(property)
                  && !isUnderUserDefined(node))) {
            canWork = false;
          } else if (property != null
              && GlobalServiceRegister.getDefault()
                  .isServiceRegistered(ICamelDesignerCoreService.class)) {
            ICamelDesignerCoreService camelService =
                (ICamelDesignerCoreService)
                    GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
            if (property.equals(camelService.getRouteDocType())) {
              canWork = false;
            }
          }
          if (node.getObject().isDeleted()) {
            canWork = false;
          }
          break;
        default:
          // Nothing to do
      }

      if (canWork && !ProjectManager.getInstance().isInCurrentMainProject(node)) {
        canWork = false;
      }
    }
    setEnabled(canWork);
  }