コード例 #1
0
 @Override
 protected boolean isEnabledForSelection(
     CGObject focusedObject, Vector<CGObject> globalSelection) {
   GenerationRepository repository = getRepository(focusedObject, globalSelection);
   if (repository == null) {
     return false;
   }
   return repository.getManageHistory();
 }
コード例 #2
0
  /*    private class GenerateSourceCodeForFile extends GenerateSourceCode.CGFileRunnable {

  public GenerateSourceCodeForFile(AbstractCGFile file) {
  super(file);
  }

  public void run() {
  logger.info(FlexoLocalization.localizedForKey("generate") +  " " + file.getFileName());
  file.getGenerator().refreshConcernedResources(getRepository());
  try {
  	file.getGenerator().generate(false);
  } catch (GenerationException e) {
  	notifyActionFailed(e, e.getMessage());
  }
  }

  @Override
  public String getLocalizedName() {
  return FlexoLocalization.localizedForKey("generating")+" "+file.getFileName();
  }

  }
   */
  @Override
  protected void doAction(Object context) throws FlexoException {
    logger.info("Generate source code for " + getFocusedObject());

    AbstractProjectGenerator<? extends GenerationRepository> pg = getProjectGenerator();
    pg.setAction(this);

    GenerationRepository repository = getRepository();
    if (getSaveBeforeGenerating()) {
      repository.getProject().save();
    }

    // Rebuild and refresh resources, performed here to get also newly created resource on
    // getSelectedCGFilesOnWhyCurrentActionShouldApply
    pg.refreshConcernedResources(null);

    Vector<AbstractCGFile> selectedFiles = getSelectedCGFilesOnWhyCurrentActionShouldApply();
    long start, end;
    boolean hasProgress = getFlexoProgress() != null;
    makeFlexoProgress(
        FlexoLocalization.localizedForKey("generate")
            + " "
            + selectedFiles.size()
            + " "
            + FlexoLocalization.localizedForKey("files")
            + " "
            + FlexoLocalization.localizedForKey("into")
            + " "
            + getRepository().getDirectory().getAbsolutePath(),
        selectedFiles.size() + 1);
    start = System.currentTimeMillis();
    Vector<
            CGRepositoryFileResource<
                ? extends GeneratedResourceData, IFlexoResourceGenerator, CGFile>>
        resources =
            new Vector<
                CGRepositoryFileResource<
                    ? extends GeneratedResourceData, IFlexoResourceGenerator, CGFile>>();
    for (AbstractCGFile file : selectedFiles) {
      resources.add(file.getResource());
    }
    generationSucceeded = true;
    getProjectGenerator().sortResourcesForGeneration(resources);
    HashSet<IFlexoResourceGenerator> generators = new HashSet<IFlexoResourceGenerator>();
    for (CGRepositoryFileResource<? extends GeneratedResourceData, IFlexoResourceGenerator, CGFile>
        r : resources) {
      AbstractCGFile file = (AbstractCGFile) r.getCGFile();
      if (file == null) {
        if (logger.isLoggable(Level.WARNING)) {
          logger.warning(
              "Found a file referencing a resource but the resource does not know the file!: " + r);
        }
        continue;
      }
      setProgress(FlexoLocalization.localizedForKey("generate") + " " + file.getFileName());
      if (file.needsMemoryGeneration()) {
        if (file.getGenerator() != null && !generators.contains(file.getGenerator())) {
          generators.add(file.getGenerator());
          // addJob(new GenerateSourceCodeForFile(file));
          file.getGenerator().generate(false);
          generationSucceeded &= file.getGenerator().getGenerationException() == null;
        }
      }
    }
    // waitForAllJobsToComplete();
    end = System.currentTimeMillis();
    if (repository instanceof CGRepository) {
      ((CGRepository) repository).clearAllJavaParsingData();
    }
    if (!hasProgress) {
      hideFlexoProgress();
    }
    if (logger.isLoggable(Level.INFO)) {
      logger.info("Generation took: " + (end - start) + " ms");
    }
  }