public String getStringRepresentation() {
   if (type == ContentSourceType.HistoryVersion) {
     return FlexoLocalization.localizedForKey(type.getUnlocalizedStringRepresentation())
         + " "
         + (version != null ? version.versionAsString() : "???");
   }
   return FlexoLocalization.localizedForKey(type.getUnlocalizedStringRepresentation());
 }
 private String subTitleForFile() {
   if (isEdited) {
     return FlexoLocalization.localizedForKey("edition_of_file_on_disk");
   }
   if (_cgFile instanceof CGJavaFile) {
     if (_cgFile.getGenerationStatus().isDiskModified()
         || _cgFile.getGenerationStatus().isGenerationModified()
         || _cgFile.getGenerationStatus().isConflicting()
         || _cgFile.getGenerationStatus() == GenerationStatus.UpToDate) {
       return FlexoLocalization.localizedForKey("file_on_disk");
     }
   }
   return FlexoLocalization.localizedForKey("perspective_not_available");
 }
    private void rebuildView() {
      removeAll();

      isEdited = _cgFile.isEdited();

      _header = new ViewHeader();

      add(_header, BorderLayout.NORTH);

      generationStatus = _cgFile.getGenerationStatus();
      _codeDisplayer = null;

      if (_cgFile.getGenerationStatus() == GenerationStatus.CodeGenerationNotAvailable) {
        add(
            new JLabel(
                FlexoLocalization.localizedForKey(
                    "sorry_code_generator_not_available_int_this_version"),
                SwingConstants.CENTER),
            BorderLayout.CENTER);
        return;
      }

      GenerationAvailableFileResource resource =
          (GenerationAvailableFileResource) _cgFile.getResource();

      _codeDisplayer = new CodeDisplayer(resource, _contentSource, _controller);
      add(_codeDisplayer.getComponent());
    }
  public CGFileVersionPopup(CGFile file, ContentSource contentSource, SGController controller) {
    super(controller.getFlexoFrame(), getTitle(file, contentSource), false);
    _cgFile = file;
    _contentSource = contentSource;
    _controller = controller;

    view = new CGFileVersionPanel();

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(view, BorderLayout.CENTER);
    JPanel controlPanel = new JPanel(new FlowLayout());
    JButton button = new JButton();
    button.setText(FlexoLocalization.localizedForKey("close", button));
    button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            view.delete();
            dispose();
          }
        });
    controlPanel.add(button);
    getContentPane().add(controlPanel, BorderLayout.SOUTH);
    validate();
    pack();
  }
 @Override
 public String getName() {
   if (getMessageDefinition() != null) {
     return getMessageDefinition().getName();
   }
   return FlexoLocalization.localizedForKey("unbound");
 }
 public String getStringRepresentation(Object object) {
   if (object instanceof String) {
     return (String) object;
   } else if ((object instanceof KeyValueCoding) && (hasFormatter())) {
     return getFormattedObject((KeyValueCoding) object);
   } else if (object instanceof StringConvertable) {
     return ((StringConvertable) object).getConverter().convertToString(object);
   } else if (object instanceof Number) {
     return object.toString();
   } else if (object instanceof Boolean) {
     return object.toString();
   } else if (object instanceof File) {
     return object.toString();
   } else if (object instanceof StringRepresentable) {
     return object.toString();
   } else if (object instanceof Enum) {
     return FlexoLocalization.localizedForKey(((Enum) object).name().toLowerCase());
   } else {
     if (object == null) {
       return "";
     }
     if (logger.isLoggable(Level.WARNING)) {
       logger.warning(
           "There is an error in some configuration file :\n the property named '"
               + name
               + "' has no string representation formatter ! Object is a "
               + (object != null ? object.getClass().getName() : "null"));
     }
     return object.toString();
   }
 }
 @Override
 public String getName() {
   if (getRoleList().isImportedRoleList()) {
     return "[PPM]" + FlexoLocalization.localizedForKey("imported_role_library");
   } else {
     return super.getName();
   }
 }
 @Override
 public String getPreciseType() {
   if (primitiveType == null) {
     return null;
   }
   switch (primitiveType) {
     case String:
       return FlexoLocalization.localizedForKey("string");
     case LocalizedString:
       return FlexoLocalization.localizedForKey("localized_string");
     case Boolean:
       return FlexoLocalization.localizedForKey("boolean");
     case Integer:
       return FlexoLocalization.localizedForKey("integer");
     case Float:
       return FlexoLocalization.localizedForKey("float");
     default:
       return null;
   }
 }
 private <F extends SelfExecutableNode, P extends FlexoNode> P _selectEndNode(
     final F selfExec, CreateEdge action) {
   FlexoPetriGraph pg = selfExec.getExecutionPetriGraph();
   String CHOOSE_EXISTING_END_NODE = FlexoLocalization.localizedForKey("choose_existing_end_node");
   String CREATE_NEW_END_NODE = FlexoLocalization.localizedForKey("create_new_end_node");
   String DEFINE_AS_GENERIC_OUTPUT = FlexoLocalization.localizedForKey("define_as_generic_output");
   Vector<String> availableChoices = new Vector<String>();
   availableChoices.add(CHOOSE_EXISTING_END_NODE);
   availableChoices.add(CREATE_NEW_END_NODE);
   availableChoices.add(DEFINE_AS_GENERIC_OUTPUT);
   String[] choices = availableChoices.toArray(new String[availableChoices.size()]);
   RadioButtonListParameter<String> choiceParam =
       new RadioButtonListParameter<String>(
           "choice", "choose_an_option", CHOOSE_EXISTING_END_NODE, choices);
   TextFieldParameter newEndNodeNameParam =
       new TextFieldParameter(
           "newEndNodeName",
           "new_end_node_name",
           pg.getProcess()
               .findNextInitialName(
                   FlexoLocalization.localizedForKey("end_node"), action.getFocusedObject()));
   newEndNodeNameParam.setDepends("choice");
   newEndNodeNameParam.setConditional("choice=" + '"' + CREATE_NEW_END_NODE + '"');
   NodeParameter existingNodeParameter =
       new NodeParameter("existingNode", "existing_end_node", pg.getAllEndNodes().firstElement());
   existingNodeParameter.setRootObject(action.getFocusedObject());
   existingNodeParameter.setNodeSelectingConditional(
       new NodeSelectingConditional() {
         @Override
         public boolean isSelectable(AbstractNode node) {
           return node instanceof FlexoNode
               && ((FlexoNode) node).isEndNode()
               && ((FlexoNode) node).getParentPetriGraph().getContainer() == selfExec;
         }
       });
   existingNodeParameter.setDepends("choice");
   existingNodeParameter.setConditional("choice=" + '"' + CHOOSE_EXISTING_END_NODE + '"');
   AskParametersDialog dialog =
       AskParametersDialog.createAskParametersDialog(
           getProject(),
           null,
           FlexoLocalization.localizedForKey("multiple_outputs_are_defined_for_this_node"),
           FlexoLocalization.localizedForKey("what_would_you_like_to_do"),
           choiceParam,
           newEndNodeNameParam,
           existingNodeParameter);
   if (dialog.getStatus() == AskParametersDialog.VALIDATE) {
     if (choiceParam.getValue().equals(CHOOSE_EXISTING_END_NODE)) {
       return (P) existingNodeParameter.getValue();
     } else if (choiceParam.getValue().equals(CREATE_NEW_END_NODE)) {
       // TODO: use FlexoAction here !!!
       return (P) pg.createNewEndNode(newEndNodeNameParam.getValue());
     } else {
       action.setIsGenericOutput(true);
       return null;
     }
   } else {
     return null;
   }
 }
 @Override
 protected void doAction(Object context) {
   makeFlexoProgress(FlexoLocalization.localizedForKey("updating_repository"), 3);
   setProgress(FlexoLocalization.localizedForKey("updating_classes"));
   resetSecondaryProgress(getUpdatedEntities().size());
   for (LoadableDMEntity next : getUpdatedEntities()) {
     ClassReference classReference = _updatedSet.getClassReference(next.getJavaType());
     setSecondaryProgress(
         FlexoLocalization.localizedForKey("updating") + " " + classReference.getName());
     if (classReference.isSelected()) {
       if (logger.isLoggable(Level.FINE)) {
         logger.fine("Update " + next + " according to " + classReference);
       }
       next.update(classReference);
     } else {
       if (logger.isLoggable(Level.FINE)) {
         logger.fine("Ignore update " + next);
       }
     }
   }
   setProgress(FlexoLocalization.localizedForKey("updating_classes_done"));
   hideFlexoProgress();
 }
 @Override
 public void generate(boolean forceRegenerate) {
   if (!forceRegenerate && !needsGeneration()) {
     return;
   }
   try {
     refreshSecondaryProgressWindow(
         FlexoLocalization.localizedForKey("generating") + " " + getIdentifier(), false);
     startGeneration();
     String generated = merge(TEMPLATE_NAME, defaultContext());
     generatedCode = new GeneratedTextResource(FILE_NAME, generated);
     stopGeneration();
   } catch (GenerationException e) {
     setGenerationException(e);
   } catch (Exception e) {
     setGenerationException(new UnexpectedExceptionOccuredException(e, getProjectGenerator()));
   }
 }
Beispiel #12
0
 public String getStringRepresentation() {
   return FlexoLocalization.localizedForKey(getUnlocalizedStringRepresentation());
 }
    protected ViewHeader() {
      super(new BorderLayout());
      icon = new JLabel(FilesIconLibrary.mediumIconForFileFormat(_cgFile.getFileFormat()));
      icon.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
      add(icon, BorderLayout.WEST);
      title = new JLabel(_cgFile.getFileName(), SwingConstants.LEFT);
      // title.setVerticalAlignment(JLabel.BOTTOM);
      title.setFont(GeneratorCst.HEADER_FONT);
      title.setForeground(Color.BLACK);
      title.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));
      subTitle = new JLabel(subTitleForFile(), SwingConstants.LEFT);
      // title.setVerticalAlignment(JLabel.BOTTOM);
      subTitle.setFont(GeneratorCst.SUB_TITLE_FONT);
      subTitle.setForeground(Color.GRAY);
      subTitle.setBorder(BorderFactory.createEmptyBorder(0, 10, 5, 10));

      JPanel labelsPanel = new JPanel(new GridLayout(2, 1));
      labelsPanel.add(title);
      labelsPanel.add(subTitle);
      add(labelsPanel, BorderLayout.CENTER);

      controlPanel = new JPanel(new FlowLayout());

      if (isEdited) {
        FlexoActionButton saveAction =
            new FlexoActionButton(
                SaveGeneratedFile.actionType, "save", ParsedCGFileModuleView.this, _controller);
        FlexoActionButton revertToSavedAction =
            new FlexoActionButton(
                RevertToSavedGeneratedFile.actionType,
                "revert_to_saved",
                ParsedCGFileModuleView.this,
                _controller);
        actionButtons.add(saveAction);
        actionButtons.add(revertToSavedAction);
        controlPanel.add(saveAction);
        controlPanel.add(revertToSavedAction);
      } else if (_cgFile.getGenerationStatus().isDiskModified()
          || _cgFile.getGenerationStatus().isGenerationModified()
          || _cgFile.getGenerationStatus().isConflicting()
          || _cgFile.getGenerationStatus() == GenerationStatus.UpToDate) {
        FlexoActionButton editFileAction =
            new FlexoActionButton(
                EditGeneratedFile.actionType, "edit", ParsedCGFileModuleView.this, _controller);
        actionButtons.add(editFileAction);
        controlPanel.add(editFileAction);
        FlexoActionButton reinjectInModelAction =
            new FlexoActionButton(
                ReinjectInModel.actionType,
                "reinject_in_model",
                ParsedCGFileModuleView.this,
                _controller);
        actionButtons.add(reinjectInModelAction);
        controlPanel.add(reinjectInModelAction);
        FlexoActionButton updateModelAction =
            new FlexoActionButton(
                UpdateModel.actionType, "update_model", ParsedCGFileModuleView.this, _controller);
        actionButtons.add(updateModelAction);
        controlPanel.add(updateModelAction);
      }

      controlPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));
      add(controlPanel, BorderLayout.EAST);

      if (!(_cgFile instanceof CGJavaFile)) {
        addInfoPanel(
            IconLibrary.UNFIXABLE_WARNING_ICON,
            FlexoLocalization.localizedForKey("model_reinjection_not_implemented"),
            FlexoLocalization.localizedForKey("model_reinjection_not_implemented_description"));
      }

      if (_cgFile instanceof CGJavaFile) {
        boolean hasJavaParsingError = ((CGJavaFile) _cgFile).getParseException() != null;
        if (hasJavaParsingError) {
          addInfoPanel(
              IconLibrary.UNFIXABLE_ERROR_ICON,
              FlexoLocalization.localizedForKey("parse_exception"),
              FlexoLocalization.localizedForKey("parse_exception_description")
                  + "\n"
                  + FlexoLocalization.localizedForKey("message")
                  + " : "
                  + ((CGJavaFile) _cgFile).getParseException().getMessage());
        }
      }

      if (_cgFile.getGenerationStatus().isGenerationModified()) {
        FlexoActionButton generateAction =
            new FlexoActionButton(
                GenerateSourceCode.actionType,
                "regenerate",
                ParsedCGFileModuleView.this,
                _controller);
        actionButtons.add(generateAction);
        FlexoActionButton writeFileAction =
            new FlexoActionButton(
                WriteModifiedGeneratedFiles.actionType,
                "write_file",
                ParsedCGFileModuleView.this,
                _controller);
        actionButtons.add(writeFileAction);
        JButton switchPerspectiveButton =
            new JButton(
                FlexoLocalization.localizedForKey("switch_to_cg_perspective"), CG_PERSPECTIVE_ICON);
        switchPerspectiveButton.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                getController().switchToPerspective(getController().CODE_GENERATOR_PERSPECTIVE);
              }
            });
        if (_cgFile.hasVersionOnDisk()) {
          addInfoPanel(
              IconLibrary.UNFIXABLE_WARNING_ICON,
              FlexoLocalization.localizedForKey("is_generation_modified_warning"),
              FlexoLocalization.localizedForKey("is_generation_modified_warning_description"),
              switchPerspectiveButton,
              generateAction,
              writeFileAction);
        } else {
          addInfoPanel(
              IconLibrary.UNFIXABLE_WARNING_ICON,
              FlexoLocalization.localizedForKey("is_new_generation_warning"),
              FlexoLocalization.localizedForKey("is_new_generation_warning_description"),
              switchPerspectiveButton,
              generateAction,
              writeFileAction);
        }
      } else if (_cgFile.getGenerationStatus().isDiskModified()) {
        FlexoActionButton acceptDiskVersionAction =
            new FlexoActionButton(
                AcceptDiskUpdate.actionType,
                "accept_disk_version",
                ParsedCGFileModuleView.this,
                _controller);
        actionButtons.add(acceptDiskVersionAction);
        FlexoActionButton acceptAndReinjectAction =
            new FlexoActionButton(
                AcceptDiskUpdateAndReinjectInModel.actionType,
                "accept_and_reinject",
                ParsedCGFileModuleView.this,
                _controller);
        actionButtons.add(acceptAndReinjectAction);
        JButton switchPerspectiveButton =
            new JButton(
                FlexoLocalization.localizedForKey("switch_to_cg_perspective"), CG_PERSPECTIVE_ICON);
        switchPerspectiveButton.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                getController().switchToPerspective(getController().CODE_GENERATOR_PERSPECTIVE);
              }
            });
        addInfoPanel(
            IconLibrary.UNFIXABLE_WARNING_ICON,
            FlexoLocalization.localizedForKey("is_disk_modified_warning"),
            FlexoLocalization.localizedForKey("is_disk_modified_warning_description"),
            switchPerspectiveButton,
            acceptDiskVersionAction,
            acceptAndReinjectAction);
      } else if (_cgFile.getGenerationStatus().isConflicting()) {
        JButton switchPerspectiveButton =
            new JButton(
                FlexoLocalization.localizedForKey("switch_to_cg_perspective"), CG_PERSPECTIVE_ICON);
        switchPerspectiveButton.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                getController().switchToPerspective(getController().CODE_GENERATOR_PERSPECTIVE);
              }
            });
        addInfoPanel(
            IconLibrary.UNFIXABLE_WARNING_ICON,
            FlexoLocalization.localizedForKey("is_conflicting_warning"),
            FlexoLocalization.localizedForKey("is_conflicting_warning_description"),
            switchPerspectiveButton);
      }

      update();
      validate();
    }
 @Override
 public String getName() {
   return FlexoLocalization.localizedForKey("pending...");
 }
Beispiel #15
0
 public static String localizedFontStyle(Font aFont) {
   if (aFont == null) {
     return "null";
   }
   return FlexoLocalization.localizedForKey(fontStyle(aFont));
 }
  /*    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");
    }
  }