示例#1
0
 /**
  * Method "setPropNewName". Try first the new name with "[PROPERTY_NAME]_Copy", then, if it
  * already exists, try again with "[PROPERTY_NAME]_CopyN" where N is number between 1 and
  * Integer.MAX.
  *
  * @param copiedProperty
  * @throws PersistenceException
  * @throws BusinessException
  */
 private void setPropNewName(Property copiedProperty)
     throws PersistenceException, BusinessException {
   String originalLabel = copiedProperty.getDisplayName();
   String copy = "_Copy"; // $NON-NLS-1$
   String initialTry = originalLabel + copy;
   copiedProperty.setLabel(initialTry);
   // changed by hqzhang for TDI-19965
   copiedProperty.setDisplayName(initialTry);
   if (isNameAvailable(getRepositoryContext().getProject(), copiedProperty.getItem(), null)) {
     return;
   } else {
     long index = 1;
     while (!isNameAvailable(
         getRepositoryContext().getProject(), copiedProperty.getItem(), null)) {
       if (index < 0) {
         throw new BusinessException(
             Messages.getString("AbstractEMFRepositoryFactory.cannotGenerateItem")); // $NON-NLS-1$
       }
       String nextTry = originalLabel + copy + (index++);
       copiedProperty.setLabel(nextTry);
       // changed by hqzhang for TDI-19965
       copiedProperty.setDisplayName(nextTry);
     }
   }
 }
 /** ldong Comment method "resetJobProblemList". */
 public static void resetJobProblemList(IRepositoryViewObject obj, String oldLabel) {
   if (obj == null) {
     return;
   }
   Property property = obj.getProperty();
   if (property == null || !(property.getItem() instanceof ProcessItem)) {
     return;
   }
   String newLabel = property.getLabel();
   if (!newLabel.equals(oldLabel)) {
     for (Iterator<Problem> iter = Problems.getProblemList().getProblemList().iterator();
         iter.hasNext(); ) {
       Problem problem = iter.next();
       if (problem instanceof TalendProblem) {
         TalendProblem routineProblem = (TalendProblem) problem;
         if (routineProblem.getJavaUnitName() != null
             && (routineProblem.getJavaUnitName().equals(oldLabel))) {
           // TDI-24683:if rename the jobItem,need clear the problem view to avoid use the old
           // problem list
           iter.remove();
         }
       }
     }
   }
 }
 /**
  * DOC talend Comment method "setConnection".
  *
  * @param object
  */
 private void getConnectionFromViewObject() {
   IRepositoryViewObject object =
       this.getObject() == null ? this.getParent().getObject() : this.getObject();
   if (object != null && object instanceof ISubRepositoryObject) {
     Property property = ((ISubRepositoryObject) object).getProperty();
     if (property == null) {
       return;
     }
     Item theItem = property.getItem();
     if (theItem != null && theItem instanceof ConnectionItem) {
       connection = ((ConnectionItem) theItem).getConnection();
     }
   }
 }
示例#4
0
  private void getAllVersions(
      Project project, Property property, List<IRepositoryViewObject> allVersion)
      throws PersistenceException {
    ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(property.getItem());
    Object fullFolder = getFullFolder(project, itemType, property.getItem().getState().getPath());
    if (fullFolder != null) {
      allVersion.addAll(
          getSerializableFromFolder(
              project, fullFolder, property.getId(), itemType, true, false, false, true));
      if (allVersion.size() == 0) {
        // if no item found in current directory, look for all directory
        allVersion.addAll(getAllVersion(project, property.getId(), false));
      }
    } else {
      allVersion.addAll(getAllVersion(project, property.getId(), false));
    }
    if (allVersion.size() == 0 && project.getEmfProject().getReferencedProjects().size() > 0) {
      String parentBranch = ProjectManager.getInstance().getMainProjectBranch(project);

      for (ProjectReference refProject :
          (List<ProjectReference>) project.getEmfProject().getReferencedProjects()) {
        if (refProject.getBranch() != null && !parentBranch.equals(refProject.getBranch())) {
          continue;
        }
        org.talend.core.model.properties.Project emfProject = refProject.getReferencedProject();
        getAllVersions(new Project(emfProject), property, allVersion);
        if (allVersion.size() > 0) {
          break;
        }
      }
    }
    // MOD mzhao Temporary return original object. In this case, the object hasn't been updated from
    // svn server.
    if (allVersion.size() == 0) {
      allVersion.add(new RepositoryViewObject(property));
    }
  }
  /** cli Comment method "removeJobLaunch". */
  public static void removeJobLaunch(IRepositoryViewObject objToDelete) {
    if (objToDelete == null) {
      return;
    }
    Property property = objToDelete.getProperty();
    if (property == null || !(property.getItem() instanceof ProcessItem)) {
      return;
    }
    Project project = ProjectManager.getInstance().getProject(property);
    if (project == null) {
      return;
    }
    final String objProjectName = project.getLabel();
    final String objId = property.getId();
    // final String objName = property.getLabel();
    final String objVersion = property.getVersion();

    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    if (launchManager == null) {
      return;
    }
    try {
      ILaunchConfiguration configuration = null;
      for (ILaunchConfiguration config : launchManager.getLaunchConfigurations()) {
        String jobId = config.getAttribute(TalendDebugUIConstants.JOB_ID, (String) null);
        // String jobName = configuration.getAttribute(TalendDebugUIConstants.JOB_NAME, (String)
        // null);
        String jobVersion = config.getAttribute(TalendDebugUIConstants.JOB_VERSION, (String) null);
        String projectName =
            config.getAttribute(TalendDebugUIConstants.CURRENT_PROJECT_NAME, (String) null);
        ILaunchConfigurationType type = config.getType();
        if (type != null
            && TalendDebugUIConstants.JOB_DEBUG_LAUNCH_CONFIGURATION_TYPE.equals(
                type.getIdentifier())
            && objProjectName.equals(projectName)
            && objId.equals(jobId)
            && objVersion.equals(jobVersion)) {
          configuration = config;
          break;
        }
      }
      if (configuration == null) {
        return;
      }
      configuration.delete();
    } catch (CoreException e) {
      // nothing to do
    }
  }
 public String getLabel(boolean checkVersion) {
   if (label == null && property != null) {
     if (checkVersion) {
       IBrandingService brandingService =
           (IBrandingService)
               GlobalServiceRegister.getDefault().getService(IBrandingService.class);
       boolean allowVerchange = brandingService.getBrandingConfiguration().isAllowChengeVersion();
       if (allowVerchange && property.getItem().isNeedVersion()) {
         label = property.getLabel() + " " + property.getVersion(); // $NON-NLS-1$
         return label;
       }
     }
     label = property.getLabel();
   }
   return label;
 }
  public String getItemName() {
    if (itemName == null) {
      IBrandingService brandingService =
          (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
      boolean allowVerchange = brandingService.getBrandingConfiguration().isAllowChengeVersion();
      ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(property.getItem());

      StringBuffer sb = new StringBuffer();
      if (itemType != null) {
        sb.append(itemType.toString());
        sb.append(' ');
      }
      sb.append(property.getLabel());

      if (allowVerchange) {
        sb.append(' ');
        sb.append(property.getVersion());
      }
      itemName = sb.toString();
    }
    return itemName;
  }
  /** 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);
    }
  }
 public Item getItem() {
   if (property != null) {
     return property.getItem();
   }
   return null;
 }
 public ERepositoryObjectType getRepositoryType() {
   if (repositoryType == null) {
     repositoryType = ERepositoryObjectType.getItemType(property.getItem());
   }
   return repositoryType;
 }
  /** cli Comment method "renameJobLaunch". */
  public static void renameJobLaunch(IRepositoryViewObject obj, String oldLabel) {
    if (obj == null) {
      return;
    }
    Property property = obj.getProperty();
    if (property == null || !(property.getItem() instanceof ProcessItem)) {
      return;
    }
    String newLabel = property.getLabel();
    if (!newLabel.equals(oldLabel)) {
      Project project = ProjectManager.getInstance().getProject(property);
      if (project == null) {
        return;
      }

      final String objProjectName = project.getLabel();
      final String id = property.getId();
      final String version = property.getVersion();

      ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
      if (launchManager == null) {
        return;
      }
      try {
        for (ILaunchConfiguration configuration : launchManager.getLaunchConfigurations()) {

          String jobId = configuration.getAttribute(TalendDebugUIConstants.JOB_ID, (String) null);
          String jobVersion =
              configuration.getAttribute(TalendDebugUIConstants.JOB_VERSION, (String) null);
          String projectName =
              configuration.getAttribute(
                  TalendDebugUIConstants.CURRENT_PROJECT_NAME, (String) null);

          // ILaunchConfigurationType type = launchManager
          // .getLaunchConfigurationType(TalendDebugUIConstants.JOB_DEBUG_LAUNCH_CONFIGURATION_TYPE);
          ILaunchConfigurationType type = configuration.getType();
          if (type != null
              && TalendDebugUIConstants.JOB_DEBUG_LAUNCH_CONFIGURATION_TYPE.equals(
                  type.getIdentifier())
              && objProjectName.equals(projectName)
              && id.equals(jobId)
              && version.equals(jobVersion)
              && type != null) {
            String displayName = newLabel + " " + jobVersion; // $NON-NLS-1$
            ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
            workingCopy.setAttribute(TalendDebugUIConstants.JOB_NAME, newLabel);
            // workingCopy.setAttribute(TalendDebugUIConstants.JOB_ID, jobId);
            // update to new version
            workingCopy.setAttribute(TalendDebugUIConstants.JOB_VERSION, jobVersion);
            // workingCopy.setAttribute(TalendDebugUIConstants.CURRENT_PROJECT_NAME, projectName);
            workingCopy.rename(displayName);
            workingCopy.doSave();
            break;
          }
        }
        clearUnusedLaunchs();
      } catch (CoreException e) {
        // nothing to do
      }
    }
  }