示例#1
0
  @Override
  public void setUp() {

    ServiceProvider provider = ServiceProvider.getInstance();
    IDefineService defService = provider.getDefineService();

    String path = TestProjectFinder.lookupProject("java", "recognition");
    ArrayList<String> paths = new ArrayList<String>();
    paths.add(path);
    ArrayList<ProjectDTO> projects = new ArrayList<ProjectDTO>();
    projects.add(
        new ProjectDTO(
            "TestProject",
            new ArrayList<String>(),
            "java",
            "1.0",
            "test project for unit tests",
            new ArrayList<AnalysedModuleDTO>()));
    defService.createApplication("Java Recognition", projects, "1.0");

    service = provider.getAnalyseService();

    try {
      if (!isAnalysed) {
        service.analyseApplication(projects.get(0));
        isAnalysed = true;
      }

    } catch (Exception e) {
      System.out.println(
          "We're sorry. You need to have a java project 'benchmark_application' with inside the benchmark_application. Or you have the wrong version of the benchmark_application.");
      System.exit(0);
    }
  }
示例#2
0
 @Override
 protected void setColumnHeaders() {
   tablemodel.addColumn(
       ServiceProvider.getInstance().getLocaleService().getTranslatedString("RuleType"));
   tablemodel.addColumn(
       ServiceProvider.getInstance().getLocaleService().getTranslatedString("ToModule"));
   tablemodel.addColumn(
       "# " + ServiceProvider.getInstance().getLocaleService().getTranslatedString("Exceptions"));
 }
示例#3
0
 public void exportDependencies(File file) {
   IAnalyseService analyseService = ServiceProvider.getInstance().getAnalyseService();
   try {
     analyseService.exportDependencies(file.getAbsolutePath());
   } catch (Exception exception) {
     IControlService controlService = ServiceProvider.getInstance().getControlService();
     controlService.showErrorMessage(exception.getMessage());
   }
 }
示例#4
0
 private void setButtonTexts() {
   this.newModuleButton.setText(
       ServiceProvider.getInstance().getLocaleService().getTranslatedString("NewModule"));
   this.moveModuleUpButton.setText(
       ServiceProvider.getInstance().getLocaleService().getTranslatedString("MoveUp"));
   this.removeModuleButton.setText(
       ServiceProvider.getInstance().getLocaleService().getTranslatedString("RemoveModule"));
   this.moveModuleDownButton.setText(
       ServiceProvider.getInstance().getLocaleService().getTranslatedString("MoveDown"));
 }
示例#5
0
 public void exportViolationsReport(File file) {
   Filename filename = new Filename(file, File.separatorChar, '.');
   IValidateService validateService = ServiceProvider.getInstance().getValidateService();
   try {
     validateService.exportViolations(file, filename.getExtension());
   } catch (Exception exception) {
     IControlService controlService = ServiceProvider.getInstance().getControlService();
     controlService.showErrorMessage(exception.getMessage());
   }
 }
 private static void checkConformance() {
   ServiceProvider.getInstance().getControlService().setValidate(true);
   logger.info(
       new Date().toString()
           + " CheckConformanceTask is Starting: IValidateService.checkConformance()");
   ServiceProvider.getInstance().getValidateService().getCategories();
   ServiceProvider.getInstance().getValidateService().checkConformance();
   ServiceProvider.getInstance().getControlService().setValidate(false);
   logger.info(new Date().toString() + " CheckConformanceTask sets state Validating to false");
 }
示例#7
0
 private void removeModule() {
   long moduleId = getSelectedModuleId();
   if (moduleId != -1 && moduleId != 0) {
     boolean confirm =
         UiDialogs.confirmDialog(
             this,
             ServiceProvider.getInstance().getLocaleService().getTranslatedString("RemoveConfirm"),
             ServiceProvider.getInstance()
                 .getLocaleService()
                 .getTranslatedString("RemovePopupTitle"));
     if (confirm) {
       this.moduleTree.clearSelection();
       DefinitionController.getInstance().removeModuleById(moduleId);
     }
   }
 }
 private int getNumberofDependenciesBetweenSoftwareUnits(String fromUnit, String toUnit) {
   analyseService = ServiceProvider.getInstance().getAnalyseService();
   DependencyDTO[] foundDependencies =
       analyseService.getDependenciesFromSoftwareUnitToSoftwareUnit(fromUnit, toUnit);
   int numberOfDependencies = foundDependencies.length;
   return numberOfDependencies;
 }
示例#9
0
 public void changeColumnHeaders() {
   getTableHeader()
       .getColumnModel()
       .getColumn(0)
       .setHeaderValue(
           ServiceProvider.getInstance().getLocaleService().getTranslatedString("RuleType"));
   getTableHeader()
       .getColumnModel()
       .getColumn(1)
       .setHeaderValue(
           ServiceProvider.getInstance().getLocaleService().getTranslatedString("ToModule"));
   getTableHeader()
       .getColumnModel()
       .getColumn(2)
       .setHeaderValue(
           ServiceProvider.getInstance().getLocaleService().getTranslatedString("Exceptions"));
 }
示例#10
0
 public void initGui() {
   DefinitionController.getInstance().addObserver(this);
   BorderLayout modulePanelLayout = new BorderLayout();
   this.setLayout(modulePanelLayout);
   this.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
   this.add(createInnerModulePanel(), BorderLayout.CENTER);
   this.updateModuleTree();
   ServiceProvider.getInstance().getControlService().addServiceListener(this);
 }
  @Override
  public List<Violation> check(
      ConfigurationServiceImpl configuration, RuleDTO rootRule, RuleDTO currentRule) {
    violations.clear();
    fromMappings = getAllClasspathsOfModule(currentRule.moduleFrom, currentRule.violationTypeKeys);
    toMappings = getAllClasspathsOfModule(currentRule.moduleTo, currentRule.violationTypeKeys);

    // Create HashMap with all allowed to-classes (including the from-classes)
    HashMap<String, Mapping> fromMap = new HashMap<String, Mapping>();
    for (Mapping from : fromMappings) {
      fromMap.put(from.getPhysicalPath(), from);
    }
    for (Mapping to : toMappings) {
      fromMap.put(to.getPhysicalPath(), to);
    }

    // Create a HashMap with all allowed from-to combinations, based on the exception rules.
    HashSet<String> allExceptionFromTos = getAllExceptionFromTos(currentRule);

    for (Mapping classPathTo : toMappings) {
      // Get all dependencies with matching dependency.classPathTo
      DependencyDTO[] dependenciesTo =
          analyseService.getDependenciesFromTo("", classPathTo.getPhysicalPath());
      for (DependencyDTO dependency : dependenciesTo) {
        String fromToCombi = dependency.from + "|" + classPathTo.getPhysicalPath();
        if (fromMap.containsKey(dependency.from) || allExceptionFromTos.contains(fromToCombi)) {
          // Do nothing
        } else {
          Mapping classPathFrom = new Mapping(dependency.from, classPathTo.getViolationTypes());
          Violation violation =
              createViolation(rootRule, classPathFrom, classPathTo, dependency, configuration);

          // Get logicalModuleFrom based on dependency.from and add it to the violation
          ModuleDTO moduleFrom =
              ServiceProvider.getInstance()
                  .getDefineService()
                  .getModule_BasedOnSoftwareUnitName(dependency.from);
          if (moduleFrom != null) {
            // Add moduleFrom to violation.logicalModules, so that graphics can include these
            // violations in architecture diagrams
            LogicalModules logicalModulesOld = violation.getLogicalModules();
            LogicalModule logicalModuleTo = logicalModulesOld.getLogicalModuleTo();
            LogicalModule logicalModuleFrom =
                new LogicalModule(moduleFrom.logicalPath, moduleFrom.type);
            LogicalModules logicalModules = new LogicalModules(logicalModuleFrom, logicalModuleTo);
            violation.setLogicalModules(logicalModules);
          }

          violations.add(violation);
        }
      }
    }
    return violations;
  }
示例#12
0
 private boolean checkPathsNames() {
   if (pathsfilter.isEmpty()) {
     return true;
   }
   boolean returnValue = true;
   for (String path : pathsfilter) {
     if (path.isEmpty()) {
       returnValue = false;
     }
   }
   if (!returnValue) {
     ServiceProvider.getInstance()
         .getControlService()
         .showInfoMessage(
             String.format(
                 localeService.getTranslatedString("EmptyField"),
                 ServiceProvider.getInstance().getLocaleService().getTranslatedString("Path")));
   }
   return returnValue;
 }
  @BeforeClass
  public static void beforeClass() {
    try {
      setLog4jConfiguration();
      workspacePath = TestResourceFinder.findHusacctWorkspace("java", workspace);
      logger.info(String.format("Running HUSACCT using workspace: " + workspacePath));

      // Import analysed model
      controlService = (ControlServiceImpl) ServiceProvider.getInstance().getControlService();
      mainController = controlService.getMainController();
      workspaceController = mainController.getWorkspaceController();
      workspaceController.closeWorkspace();
      loadWorkspace(workspacePath);
      analyseStatisticsBeforeReconstruction = getAnalyseStatistics();
      exportFilePath = TestResourceFinder.findHusacctExportFile("java", exportFile);
      importAnalysisModel();
      analyseStatisticsAfterReconstruction = getAnalyseStatistics();

      logger.info(String.format("Start: Architecture Reconstruction"));
      analyseStatisticsBeforeReconstruction = getAnalyseStatistics();
      reconstructArchitecture();
      analyseStatisticsAfterReconstruction = getAnalyseStatistics();
      logger.info(String.format("Finished: Architecture Reconstruction"));

      checkConformance(); // checkConformance() starts a different Thread, and needs some time
      boolean isValidating = true;
      controlService = (ControlServiceImpl) ServiceProvider.getInstance().getControlService();
      mainController = controlService.getMainController();
      while (isValidating) {
        try {
          Thread.sleep((long) 10);
        } catch (InterruptedException e) {
        }
        isValidating = mainController.getStateController().isValidating();
      }

    } catch (Exception e) {
      String errorMessage = "Exception: " + e.getMessage();
      logger.warn(errorMessage);
    }
  }
 private int getNumberofDependenciesBetweenModulesInIntendedArchitecture(
     String fromModule, String toModule) {
   analyseService = ServiceProvider.getInstance().getAnalyseService();
   IDefineService defineService = ServiceProvider.getInstance().getDefineService();
   HashSet<String> physicalFromClassPaths =
       defineService.getModule_AllPhysicalClassPathsOfModule(fromModule);
   HashSet<String> physicalToClassPaths =
       defineService.getModule_AllPhysicalClassPathsOfModule(toModule);
   ArrayList<DependencyDTO> allFoundDependencies = new ArrayList<DependencyDTO>();
   for (String fromPackages : physicalFromClassPaths) {
     for (String toPackages : physicalToClassPaths) {
       for (DependencyDTO dependency :
           analyseService.getDependenciesFromSoftwareUnitToSoftwareUnit(
               fromPackages, toPackages)) {
         allFoundDependencies.add(dependency);
       }
     }
   }
   int numberOfDependencies = allFoundDependencies.size();
   return numberOfDependencies;
 }
示例#15
0
 public FilterViolations(
     TaskServiceImpl taskServiceImpl, FilterViolationsObserver filterViolationsObserver) {
   super(
       ((ControlServiceImpl) ServiceProvider.getInstance().getControlService())
           .getMainController()
           .getMainGui(),
       true);
   this.filterViolationsObserver = filterViolationsObserver;
   this.taskServiceImpl = taskServiceImpl;
   initComponents();
   loadGUIText();
 }
 private static AnalysisStatisticsDTO getAnalyseStatistics() {
   analyseService = ServiceProvider.getInstance().getAnalyseService();
   AnalysisStatisticsDTO statistics = analyseService.getAnalysisStatistics(null);
   logger.info(
       String.format(
           "Statistics - Packages: "
               + statistics.totalNrOfPackages
               + ", Classes: "
               + statistics.totalNrOfClasses
               + ", Dependencies: "
               + statistics.totalNrOfDependencies));
   return statistics;
 }
示例#17
0
 public JPanel createInnerModulePanel() {
   JPanel innerModulePanel = new JPanel();
   BorderLayout innerModulePanelLayout = new BorderLayout();
   innerModulePanel.setLayout(innerModulePanelLayout);
   innerModulePanel.setBorder(
       BorderFactory.createTitledBorder(
           ServiceProvider.getInstance()
               .getLocaleService()
               .getTranslatedString("ModuleHierachy")));
   innerModulePanel.add(this.createModuleTreePanel(), BorderLayout.CENTER);
   innerModulePanel.add(this.addButtonPanel(), BorderLayout.SOUTH);
   return innerModulePanel;
 }
示例#18
0
  public void analyseApplication() {
    IControlService controlService = ServiceProvider.getInstance().getControlService();
    ILocaleService localeService = ServiceProvider.getInstance().getLocaleService();
    ApplicationDTO applicationDTO =
        ServiceProvider.getInstance().getDefineService().getApplicationDetails();

    ThreadWithLoader analyseThread =
        controlService.getThreadWithLoader(
            localeService.getTranslatedString("AnalysingApplication"),
            new AnalyseTask(mainController, applicationDTO));
    currentLoader = analyseThread.getLoader();
    currentThread = analyseThread.getThread();
    currentLoader.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            mainController.getStateController().setAnalysing(false);

            logger.debug("Stopping Thread");
          }
        });
    analyseThread.run();
  }
示例#19
0
  public void exportArchitecture(File file) {
    HashMap<String, Object> resourceData = new HashMap<String, Object>();
    resourceData.put("file", file);
    IResource xmlResource = ResourceFactory.get("xml");
    try {
      Element logicalData =
          ServiceProvider.getInstance().getDefineService().getLogicalArchitectureData();
      Document doc = DocumentHelper.createDocument(logicalData);

      xmlResource.save(doc, resourceData);
    } catch (Exception e) {
      e.printStackTrace();
      logger.debug("Unable to export logical architecture: " + e.getMessage());
    }
  }
public class SeverityPerTypeRepository {
  private HashMap<String, HashMap<String, Severity>> severitiesPerTypePerProgrammingLanguage;
  private HashMap<String, HashMap<String, Severity>> defaultSeveritiesPerTypePerProgrammingLanguage;
  private final RuleTypesFactory ruletypefactory;
  private final IAnalyseService analsyseService = ServiceProvider.getInstance().getAnalyseService();

  public SeverityPerTypeRepository(ConfigurationServiceImpl configuration) {
    this.ruletypefactory = new RuleTypesFactory(configuration);

    severitiesPerTypePerProgrammingLanguage = new HashMap<String, HashMap<String, Severity>>();
    defaultSeveritiesPerTypePerProgrammingLanguage =
        new HashMap<String, HashMap<String, Severity>>();
  }

  public void initializeDefaultSeverities() {
    for (String programmingLanguage : analsyseService.getAvailableLanguages()) {
      severitiesPerTypePerProgrammingLanguage.putAll(
          initializeDefaultSeverityForLanguage(programmingLanguage));
      defaultSeveritiesPerTypePerProgrammingLanguage.putAll(
          initializeDefaultSeverityForLanguage(programmingLanguage));
    }
  }

  private HashMap<String, HashMap<String, Severity>> initializeDefaultSeverityForLanguage(
      String programmingLanguage) {
    HashMap<String, HashMap<String, Severity>> severitiesPerTypePerProgrammingLanguage =
        new HashMap<String, HashMap<String, Severity>>();
    severitiesPerTypePerProgrammingLanguage.put(
        programmingLanguage, new HashMap<String, Severity>());
    for (Entry<String, List<RuleType>> entry :
        ruletypefactory.getRuleTypes(programmingLanguage).entrySet()) {
      HashMap<String, Severity> severityPerType =
          severitiesPerTypePerProgrammingLanguage.get(programmingLanguage);

      for (RuleType ruleType : entry.getValue()) {
        severityPerType.put(ruleType.getKey(), ruleType.getSeverity());

        for (ViolationType violationType : ruleType.getViolationTypes()) {
          severityPerType.put(violationType.getViolationtypeKey(), violationType.getSeverity());
        }
      }
    }

    return severitiesPerTypePerProgrammingLanguage;
  }

  public HashMap<String, HashMap<String, Severity>> getSeveritiesPerTypePerProgrammingLanguage() {
    return severitiesPerTypePerProgrammingLanguage;
  }

  public Severity getSeverity(String language, String key) {
    HashMap<String, Severity> severityPerType =
        severitiesPerTypePerProgrammingLanguage.get(language);
    if (severityPerType == null) {
      throw new SeverityNotFoundException();
    } else {
      Severity severity = severityPerType.get(key);
      if (severity == null) {
        throw new SeverityNotFoundException();
      } else {
        return severity;
      }
    }
  }

  public void restoreDefaultSeverity(String language, String key) {
    HashMap<String, Severity> severitiesPerType =
        severitiesPerTypePerProgrammingLanguage.get(language);

    // if there is no value, autmatically the default severities will be applied
    if (severitiesPerType != null) {
      Severity oldSeverity = severitiesPerType.get(key);
      if (oldSeverity != null) {
        Severity defaultSeverity = getDefaultRuleKey(language, key);
        if (defaultSeverity != null) {
          severitiesPerType.remove(key);
          severitiesPerType.put(key, defaultSeverity);
        }
      }
    }
  }

  private Severity getDefaultRuleKey(String language, String key) {
    HashMap<String, Severity> severityPerType =
        defaultSeveritiesPerTypePerProgrammingLanguage.get(language);
    if (severityPerType == null) {
      throw new SeverityNotFoundException();
    } else {
      Severity severity = severityPerType.get(key);
      if (severity == null) {
        throw new SeverityNotFoundException();
      } else {
        return severity;
      }
    }
  }

  public void restoreAllToDefault(String programmingLanguage) {
    initializeDefaultSeverityForLanguage(programmingLanguage);
  }

  public void setSeverityMap(
      HashMap<String, HashMap<String, Severity>> severitiesPerTypePerProgrammingLanguage) {
    this.severitiesPerTypePerProgrammingLanguage = severitiesPerTypePerProgrammingLanguage;
  }

  public void setSeverityMap(String language, HashMap<String, Severity> severityMap) {
    HashMap<String, Severity> local = severitiesPerTypePerProgrammingLanguage.get(language);

    for (Entry<String, Severity> entry : severityMap.entrySet()) {
      if (local.containsKey(entry.getKey())) {
        local.remove(entry.getKey());
      }
      local.put(entry.getKey(), entry.getValue());
    }
    severitiesPerTypePerProgrammingLanguage.remove(language);
    severitiesPerTypePerProgrammingLanguage.put(language, local);
  }
}
class ActiveViolationTypesRepository {

  private final IAnalyseService analsyseService = ServiceProvider.getInstance().getAnalyseService();
  private final IDefineService defineService = ServiceProvider.getInstance().getDefineService();
  private final RuleTypesFactory ruletypesfactory;
  private final Map<String, List<ActiveRuleType>> startupViolationTypes;
  private Map<String, List<ActiveRuleType>> currentActiveViolationTypes;

  private Logger logger = Logger.getLogger(ActiveViolationTypesRepository.class);

  ActiveViolationTypesRepository(RuleTypesFactory ruletypesfactory) {
    this.ruletypesfactory = ruletypesfactory;
    this.startupViolationTypes = initializeAllActiveViolationTypes();
    this.currentActiveViolationTypes = initializeAllActiveViolationTypes();
  }

  private Map<String, List<ActiveRuleType>> initializeAllActiveViolationTypes() {
    Map<String, List<ActiveRuleType>> activeViolationTypes =
        new HashMap<String, List<ActiveRuleType>>();

    for (String programmingLanguage : analsyseService.getAvailableLanguages()) {
      List<ActiveRuleType> activeRuleTypes = new ArrayList<ActiveRuleType>();
      activeViolationTypes.put(programmingLanguage, activeRuleTypes);

      for (List<RuleType> ruleTypes : ruletypesfactory.getRuleTypes(programmingLanguage).values()) {

        for (RuleType ruleType : ruleTypes) {
          ActiveRuleType activeRuleType = initializeActiveViolationTypes(ruleType);
          activeRuleTypes.add(activeRuleType);

          for (RuleType exceptionRuleType : ruleType.getExceptionrules()) {
            try {
              containsRuleType(activeRuleTypes, exceptionRuleType.getKey());
              activeRuleTypes.add(initializeActiveViolationTypes(exceptionRuleType));
            } catch (RuntimeException e) {

            }
          }
        }
      }
    }
    return activeViolationTypes;
  }

  private ActiveRuleType containsRuleType(
      List<ActiveRuleType> activeRuleTypes, String ruleTypeKey) {
    for (ActiveRuleType activeRuleType : activeRuleTypes) {
      if (activeRuleType.getRuleType().equals(ruleTypeKey)) {
        return activeRuleType;
      }
    }
    throw new RuntimeException();
  }

  private ActiveRuleType initializeActiveViolationTypes(RuleType ruleType) {
    final String ruleTypeKey = ruleType.getKey();
    List<ActiveViolationType> initialActiveViolationTypes = new ArrayList<ActiveViolationType>();

    for (ViolationType violationType : ruleType.getViolationTypes()) {
      final String violationTypeKey = violationType.getViolationtypeKey();
      boolean enabled = violationType.isActive();
      ActiveViolationType activeViolationType = new ActiveViolationType(violationTypeKey, enabled);
      initialActiveViolationTypes.add(activeViolationType);
    }
    ActiveRuleType activeRuleType = new ActiveRuleType(ruleTypeKey);
    activeRuleType.setViolationTypes(initialActiveViolationTypes);
    return activeRuleType;
  }

  boolean isEnabled(String ruleTypeKey, String violationTypeKey) {
    final String currentLanguage = defineService.getApplicationDetails().programmingLanguage;
    return isEnabled(currentLanguage, ruleTypeKey, violationTypeKey);
  }

  boolean isEnabled(String programmingLanguage, String ruleTypeKey, String violationTypeKey) {
    List<ActiveRuleType> activeRuleTypes =
        this.currentActiveViolationTypes.get(programmingLanguage);
    if (activeRuleTypes != null) {
      for (ActiveRuleType activeRuleType : activeRuleTypes) {
        if (activeRuleType.getRuleType().toLowerCase().equals(ruleTypeKey.toLowerCase())) {

          if (activeRuleType.getViolationTypes().isEmpty()) {
            return false;
          }

          for (ActiveViolationType activeViolationType : activeRuleType.getViolationTypes()) {
            if (activeViolationType
                .getType()
                .toLowerCase()
                .equals(violationTypeKey.toLowerCase())) {
              return activeViolationType.isEnabled();
            }
          }
        }
      }
    } else {
      throw new ProgrammingLanguageNotFoundException();
    }
    return false;
  }

  Map<String, List<ActiveRuleType>> getActiveViolationTypes() {
    return currentActiveViolationTypes;
  }

  void setActiveViolationTypes(Map<String, List<ActiveRuleType>> activeViolationTypes) {
    for (Entry<String, List<ActiveRuleType>> activeViolationTypeSet :
        activeViolationTypes.entrySet()) {
      if (programmingLanguageExists(activeViolationTypeSet.getKey())) {
        setActiveViolationTypes(
            activeViolationTypeSet.getKey(),
            activeViolationTypes.get(activeViolationTypeSet.getKey()));
      }
    }
  }

  void setActiveViolationTypes(
      String programmingLanguage, List<ActiveRuleType> newActiveViolationTypes) {
    if (programmingLanguageExists(programmingLanguage)) {
      List<ActiveRuleType> checkedNewActiveViolationTypes =
          checkNewActiveViolationTypes(programmingLanguage, newActiveViolationTypes);

      if (currentActiveViolationTypes.containsKey(programmingLanguage)) {
        currentActiveViolationTypes.remove(programmingLanguage);
        currentActiveViolationTypes.put(programmingLanguage, checkedNewActiveViolationTypes);
      } else {
        currentActiveViolationTypes.put(programmingLanguage, checkedNewActiveViolationTypes);
      }
    } else {
      throw new ProgrammingLanguageNotFoundException(programmingLanguage);
    }
  }

  private boolean programmingLanguageExists(String programmingLanguage) {
    for (String language : startupViolationTypes.keySet()) {
      if (language.toLowerCase().equals(programmingLanguage.toLowerCase())) {
        return true;
      }
    }
    throw new ProgrammingLanguageNotFoundException(programmingLanguage);
  }

  private List<ActiveRuleType> checkNewActiveViolationTypes(
      String programmingLanguage, List<ActiveRuleType> newActiveViolationTypes) {
    List<ActiveRuleType> activeViolationTypesForLanguage = new ArrayList<ActiveRuleType>();

    for (ActiveRuleType newActiveRuleType : newActiveViolationTypes) {
      if (ruleTypeKeyExists(programmingLanguage, newActiveRuleType.getRuleType())) {

        List<ActiveViolationType> activeViolationTypes = new ArrayList<ActiveViolationType>();
        ActiveRuleType activeRuleType = new ActiveRuleType(newActiveRuleType.getRuleType());
        activeRuleType.setViolationTypes(activeViolationTypes);
        boolean foundViolationTypeKey = false;

        for (ActiveViolationType newActiveViolationType : newActiveRuleType.getViolationTypes()) {
          if (violationTypeKeyExists(
              programmingLanguage,
              newActiveRuleType.getRuleType(),
              newActiveViolationType.getType())) {
            foundViolationTypeKey = true;
            activeViolationTypes.add(
                new ActiveViolationType(
                    newActiveViolationType.getType(), newActiveViolationType.isEnabled()));
          } else {
            logger.debug(
                String.format("violationTypeKey %s not exists", newActiveViolationType.getType()));
          }
        }
        if (foundViolationTypeKey) {
          activeViolationTypesForLanguage.add(activeRuleType);
        }
      } else {
        logger.debug(
            String.format(
                "ruleTypeKey %s not exists in programminglanguage %s",
                newActiveRuleType.getRuleType(), programmingLanguage));
      }
    }
    return mergeNewViolationTypes(programmingLanguage, activeViolationTypesForLanguage);
  }

  private List<ActiveRuleType> mergeNewViolationTypes(
      String programmingLanguage, List<ActiveRuleType> newActiveViolationTypes) {
    List<ActiveRuleType> activeViolationTypesForLanguage = new ArrayList<ActiveRuleType>();

    for (ActiveRuleType currentActiveRuleType : startupViolationTypes.get(programmingLanguage)) {
      try {
        ActiveRuleType existingActiveRuleType =
            containsRuleType(newActiveViolationTypes, currentActiveRuleType.getRuleType());
        List<ActiveViolationType> activeViolationTypes = new ArrayList<ActiveViolationType>();

        for (ActiveViolationType currentActiveViolationType :
            containsRuleType(
                    startupViolationTypes.get(programmingLanguage),
                    existingActiveRuleType.getRuleType())
                .getViolationTypes()) {
          boolean found = false;
          for (ActiveViolationType newViolationType : existingActiveRuleType.getViolationTypes()) {
            if (newViolationType.getType().equals(currentActiveViolationType.getType())) {
              activeViolationTypes.add(newViolationType);
              found = true;
            }
          }
          if (!found) {
            activeViolationTypes.add(
                new ActiveViolationType(
                    currentActiveViolationType.getType(), currentActiveViolationType.isEnabled()));
          }
        }
        activeViolationTypesForLanguage.add(
            new ActiveRuleType(existingActiveRuleType.getRuleType(), activeViolationTypes));

      } catch (RuntimeException e) {
        List<ActiveViolationType> activeViolationTypes = new ArrayList<ActiveViolationType>();
        for (ActiveViolationType activeViolationType : currentActiveRuleType.getViolationTypes()) {
          activeViolationTypes.add(
              new ActiveViolationType(
                  activeViolationType.getType(), activeViolationType.isEnabled()));
        }
        ActiveRuleType activeRuleType =
            new ActiveRuleType(currentActiveRuleType.getRuleType(), activeViolationTypes);
        activeViolationTypesForLanguage.add(activeRuleType);
      }
    }
    return activeViolationTypesForLanguage;
  }

  private boolean ruleTypeKeyExists(String programmingLanguage, String ruleTypeKey) {
    if (programmingLanguageExists(programmingLanguage)) {

      for (ActiveRuleType activeRuleType : startupViolationTypes.get(programmingLanguage)) {
        if (activeRuleType.getRuleType().toLowerCase().equals(ruleTypeKey.toLowerCase())) {
          return true;
        }
      }
    } else {
      throw new ProgrammingLanguageNotFoundException(programmingLanguage);
    }
    throw new RuleTypeNotFoundException(ruleTypeKey);
  }

  private boolean violationTypeKeyExists(
      String programmingLanguage, String ruleTypeKey, String violationTypeKey) {
    if (programmingLanguageExists(programmingLanguage)
        && ruleTypeKeyExists(programmingLanguage, ruleTypeKey)) {

      for (ActiveRuleType activeRuleType : startupViolationTypes.get(programmingLanguage)) {

        for (ActiveViolationType activeViolationType : activeRuleType.getViolationTypes()) {
          if (activeViolationType.getType().toLowerCase().equals(violationTypeKey.toLowerCase())) {
            return true;
          }
        }
      }
    }
    throw new ViolationTypeNotFoundException(violationTypeKey);
  }
}
 private static void reconstructArchitecture() {
   analyseService = ServiceProvider.getInstance().getAnalyseService();
   analyseService.reconstructArchitecture();
 }
public class ExportArchitectureDialog extends JDialog {

  private static final long serialVersionUID = 1L;

  private MainController mainController;

  private JLabel pathLabel;
  private JTextField pathText;
  private JButton browseButton, exportButton;

  private File selectedFile;

  private IControlService controlService = ServiceProvider.getInstance().getControlService();

  public ExportArchitectureDialog(MainController mainController) {
    super(mainController.getMainGui(), true);
    this.mainController = mainController;
    setTitle(controlService.getTranslatedString("ExportArchitecture"));
    setup();
    addComponents();
    setListeners();
    this.setVisible(true);
  }

  private void setup() {
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    this.setLayout(new FlowLayout());
    this.setSize(new Dimension(350, 100));
    this.setResizable(false);
    DialogUtils.alignCenter(this);
  }

  private void addComponents() {
    pathLabel = new JLabel(controlService.getTranslatedString("PathLabel"));
    pathText = new JTextField(20);
    browseButton = new JButton(controlService.getTranslatedString("BrowseButton"));
    exportButton = new JButton(controlService.getTranslatedString("ExportButton"));
    exportButton.setEnabled(false);
    pathText.setEnabled(false);

    getRootPane().setDefaultButton(exportButton);

    add(pathLabel);
    add(pathText);
    add(browseButton);
    add(exportButton);
  }

  private void setListeners() {
    browseButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            showFileDialog();
          }
        });
    exportButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            mainController.getExportController().exportArchitecture(selectedFile);
            dispose();
          }
        });
  }

  private void showFileDialog() {
    FileNameExtensionFilter filter = new FileNameExtensionFilter("XML", "xml", "xml");
    FileDialog fileDialog =
        new FileDialog(
            JFileChooser.FILES_ONLY, controlService.getTranslatedString("ExportButton"), filter);
    int returnVal = fileDialog.showDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      setFile(fileDialog.getSelectedFile());
    }
  }

  private void setFile(File file) {
    selectedFile = file;
    pathText.setText(file.getAbsolutePath());
    exportButton.setEnabled(true);
  }
}
 private static void importAnalysisModel() {
   File file = new File(exportFilePath);
   controlService = (ControlServiceImpl) ServiceProvider.getInstance().getControlService();
   mainController = controlService.getMainController();
   mainController.getExportImportController().importAnalysisModel(file);
 }
示例#25
0
@SuppressWarnings("serial")
public class DefineMenu extends JMenu {
  private MainController mainController;
  private JMenuItem defineArchitectureItem;
  private JMenuItem definedArchitectureDiagramItem;
  private JMenuItem exportArchitectureItem;
  private JMenuItem importArchitectureItem;

  private ILocaleService localeService = ServiceProvider.getInstance().getLocaleService();

  public DefineMenu(final MainController mainController) {
    super();
    this.mainController = mainController;
    setText(localeService.getTranslatedString("Define"));
    addComponents();
    setListeners();
  }

  private void addComponents() {
    defineArchitectureItem = new JMenuItem(localeService.getTranslatedString("DefineArchitecture"));
    defineArchitectureItem.setAccelerator(KeyStroke.getKeyStroke('D', KeyEvent.CTRL_DOWN_MASK));
    defineArchitectureItem.setMnemonic(getMnemonicKeycode("DefineArchitectureMnemonic"));

    definedArchitectureDiagramItem =
        new JMenuItem(localeService.getTranslatedString("DefinedArchitectureDiagram"));
    definedArchitectureDiagramItem.setAccelerator(
        KeyStroke.getKeyStroke('L', KeyEvent.CTRL_DOWN_MASK));
    definedArchitectureDiagramItem.setMnemonic(
        getMnemonicKeycode("DefinedArchitectureDiagramMnemonic"));

    importArchitectureItem = new JMenuItem(localeService.getTranslatedString("ImportArchitecture"));
    importArchitectureItem.setMnemonic(getMnemonicKeycode("ImportArchitectureMnemonic"));

    exportArchitectureItem = new JMenuItem(localeService.getTranslatedString("ExportArchitecture"));
    exportArchitectureItem.setMnemonic(getMnemonicKeycode("ExportArchitectureMnemonic"));

    this.add(defineArchitectureItem);
    this.add(definedArchitectureDiagramItem);
    this.add(importArchitectureItem);
    this.add(exportArchitectureItem);
  }

  private void setListeners() {
    defineArchitectureItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mainController.getViewController().showDefineArchitecture();
          }
        });

    definedArchitectureDiagramItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mainController.getViewController().showDefinedArchitectureDiagram();
          }
        });

    importArchitectureItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mainController.getImportController().showImportArchitectureGui();
          }
        });

    exportArchitectureItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mainController.getExportController().showExportArchitectureGui();
          }
        });

    mainController
        .getStateController()
        .addStateChangeListener(
            new IStateChangeListener() {
              public void changeState(List<States> states) {
                defineArchitectureItem.setEnabled(false);
                definedArchitectureDiagramItem.setEnabled(false);
                importArchitectureItem.setEnabled(false);
                exportArchitectureItem.setEnabled(false);

                if (states.contains(States.OPENED)) {
                  defineArchitectureItem.setEnabled(true);
                  importArchitectureItem.setEnabled(true);
                }

                if (states.contains(States.DEFINED) || states.contains(States.MAPPED)) {
                  exportArchitectureItem.setEnabled(true);
                  definedArchitectureDiagramItem.setEnabled(true);
                }
              }
            });

    final DefineMenu defineMenu = this;
    localeService.addServiceListener(
        new IServiceListener() {
          public void update() {
            defineMenu.setText(localeService.getTranslatedString("Define"));
            defineArchitectureItem.setText(localeService.getTranslatedString("DefineArchitecture"));
            definedArchitectureDiagramItem.setText(
                localeService.getTranslatedString("DefinedArchitectureDiagram"));
            exportArchitectureItem.setText(localeService.getTranslatedString("ExportArchitecture"));
            importArchitectureItem.setText(localeService.getTranslatedString("ImportArchitecture"));
            defineArchitectureItem.setMnemonic(getMnemonicKeycode("DefineArchitectureMnemonic"));
            definedArchitectureDiagramItem.setMnemonic(
                getMnemonicKeycode("DefinedArchitectureDiagramMnemonic"));
            importArchitectureItem.setMnemonic(getMnemonicKeycode("ImportArchitectureMnemonic"));
            exportArchitectureItem.setMnemonic(getMnemonicKeycode("ExportArchitectureMnemonic"));
          }
        });
  }

  public JMenuItem getDefineArchitectureItem() {
    return defineArchitectureItem;
  }

  public JMenuItem getDefinedArchitectureDiagramItem() {
    return definedArchitectureDiagramItem;
  }

  public JMenuItem getExportArchitectureItem() {
    return exportArchitectureItem;
  }

  public JMenuItem getIimportArchitectureItem() {
    return importArchitectureItem;
  }

  private int getMnemonicKeycode(String translatedString) {
    String mnemonicString = localeService.getTranslatedString(translatedString);
    int keyCode = KeyStroke.getKeyStroke(mnemonicString).getKeyCode();
    return keyCode;
  }
}
示例#26
0
 public String[] getExportExtensions() {
   IValidateService validateService = ServiceProvider.getInstance().getValidateService();
   return validateService.getExportExtentions();
 }
示例#27
0
public final class FilterViolations extends JDialog {

  private static final long serialVersionUID = -6295611607558238501L;
  private boolean selectedFilterValues = true;
  private TaskServiceImpl taskServiceImpl;
  private DefaultTableModel ruletypeModelFilter, violationtypeModelFilter, pathFilterModel;
  private JTabbedPane tabbedPane;
  private JButton addPath, removePath, save, cancel;
  private JPanel filterViolationPanel, pathFilterPanel;
  private ButtonGroup filtergroup;
  private JRadioButton hideFilteredValues, showFilteredValues;
  private JScrollPane pathFilterScrollPane, ruletypePanel, violationtypePanel;
  private JTable pathFilterTable, ruletypeTable, violationtypeTable;
  private FilterViolationsObserver filterViolationsObserver;
  private ArrayList<String> ruletypesfilter = new ArrayList<String>();
  private ArrayList<String> violationtypesfilter = new ArrayList<String>();
  private ArrayList<String> pathsfilter = new ArrayList<String>();
  private Calendar violationDate = Calendar.getInstance();
  private ILocaleService localeService = ServiceProvider.getInstance().getLocaleService();

  public FilterViolations(
      TaskServiceImpl taskServiceImpl, FilterViolationsObserver filterViolationsObserver) {
    super(
        ((ControlServiceImpl) ServiceProvider.getInstance().getControlService())
            .getMainController()
            .getMainGui(),
        true);
    this.filterViolationsObserver = filterViolationsObserver;
    this.taskServiceImpl = taskServiceImpl;
    initComponents();
    loadGUIText();
  }

  private void initComponents() {
    filtergroup = new ButtonGroup();
    tabbedPane = new JTabbedPane();
    filterViolationPanel = new JPanel();
    ruletypePanel = new JScrollPane();
    ruletypeTable = new JTable();
    violationtypePanel = new JScrollPane();
    violationtypeTable = new JTable();
    pathFilterPanel = new JPanel();
    pathFilterScrollPane = new JScrollPane();
    pathFilterTable = new JTable();
    addPath = new JButton();
    removePath = new JButton();
    save = new JButton();
    cancel = new JButton();
    showFilteredValues = new JRadioButton();
    hideFilteredValues = new JRadioButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setResizable(false);
    setModal(true);
    DialogUtils.alignCenter(this);

    ruletypeTable.setAutoCreateRowSorter(true);
    ruletypeTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
    ruletypeTable.setFillsViewportHeight(true);
    ruletypeTable.getTableHeader().setResizingAllowed(false);
    ruletypeTable.getTableHeader().setReorderingAllowed(false);
    ruletypePanel.setViewportView(ruletypeTable);

    violationtypeTable.setFillsViewportHeight(true);
    violationtypeTable.getTableHeader().setReorderingAllowed(false);
    violationtypePanel.setViewportView(violationtypeTable);

    pathFilterTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN);
    pathFilterTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    pathFilterTable.setFillsViewportHeight(true);
    pathFilterTable.getTableHeader().setResizingAllowed(false);
    pathFilterTable.getTableHeader().setReorderingAllowed(false);
    pathFilterScrollPane.setViewportView(pathFilterTable);

    addPath.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            addPathActionPerformed();
          }
        });

    removePath.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            removePathActionPerformed();
          }
        });

    save.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            saveActionPerformed();
          }
        });

    cancel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            cancelActionPerformed();
          }
        });

    hideFilteredValues.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            setSelectedFilterValues(false);
          }
        });

    showFilteredValues.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            setSelectedFilterValues(true);
          }
        });

    filtergroup.add(showFilteredValues);

    filtergroup.add(hideFilteredValues);
    hideFilteredValues.setSelected(true);

    createFilterViolationPanelLayout();
    createPathFilterPanelLayout();
    createBaseLayout();
    setSize(800, 600);
  }

  private void setSelectedFilterValues(boolean value) {
    this.selectedFilterValues = value;
  }

  private void createFilterViolationPanelLayout() {
    GroupLayout filterViolationPanelLayout = new GroupLayout(filterViolationPanel);

    GroupLayout.SequentialGroup horizontalFilterViolationGroup =
        filterViolationPanelLayout.createSequentialGroup();
    horizontalFilterViolationGroup.addComponent(ruletypePanel);
    horizontalFilterViolationGroup.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
    horizontalFilterViolationGroup.addComponent(violationtypePanel);

    filterViolationPanelLayout.setHorizontalGroup(horizontalFilterViolationGroup);

    GroupLayout.ParallelGroup verticalFilterViolationGroup =
        filterViolationPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
    verticalFilterViolationGroup.addComponent(ruletypePanel);
    verticalFilterViolationGroup.addComponent(violationtypePanel);

    filterViolationPanelLayout.setVerticalGroup(verticalFilterViolationGroup);
    filterViolationPanel.setLayout(filterViolationPanelLayout);
  }

  private void createPathFilterPanelLayout() {
    GroupLayout pathFilterPanelLayout = new GroupLayout(pathFilterPanel);

    GroupLayout.ParallelGroup horizontalButtonPathGroup =
        pathFilterPanelLayout.createParallelGroup(GroupLayout.Alignment.TRAILING, false);
    horizontalButtonPathGroup.addComponent(
        removePath, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
    horizontalButtonPathGroup.addComponent(
        addPath, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);

    GroupLayout.SequentialGroup horizontalPanePathGroup =
        pathFilterPanelLayout.createSequentialGroup();
    horizontalPanePathGroup.addComponent(pathFilterScrollPane);
    horizontalPanePathGroup.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
    horizontalPanePathGroup.addGroup(horizontalButtonPathGroup);
    horizontalPanePathGroup.addContainerGap();

    pathFilterPanelLayout.setHorizontalGroup(horizontalPanePathGroup);

    GroupLayout.SequentialGroup verticalButtonPathGroup =
        pathFilterPanelLayout.createSequentialGroup();
    verticalButtonPathGroup.addComponent(addPath);
    verticalButtonPathGroup.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
    verticalButtonPathGroup.addComponent(removePath);
    verticalButtonPathGroup.addContainerGap();

    GroupLayout.ParallelGroup verticalPanePathGroup =
        pathFilterPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
    verticalPanePathGroup.addComponent(pathFilterScrollPane);
    verticalPanePathGroup.addGroup(verticalButtonPathGroup);

    pathFilterPanelLayout.setVerticalGroup(verticalPanePathGroup);
    pathFilterPanel.setLayout(pathFilterPanelLayout);
  }

  private void createBaseLayout() {
    GroupLayout layout = new GroupLayout(getContentPane());

    GroupLayout.SequentialGroup horizontalButtonGroup = layout.createSequentialGroup();
    horizontalButtonGroup.addComponent(hideFilteredValues);
    horizontalButtonGroup.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
    horizontalButtonGroup.addComponent(showFilteredValues);
    horizontalButtonGroup.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
    horizontalButtonGroup.addComponent(save);
    horizontalButtonGroup.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
    horizontalButtonGroup.addComponent(cancel);
    horizontalButtonGroup.addContainerGap();

    GroupLayout.ParallelGroup horizontalPaneGroup =
        layout.createParallelGroup(GroupLayout.Alignment.LEADING);
    horizontalPaneGroup.addComponent(tabbedPane);
    horizontalPaneGroup.addGroup(horizontalButtonGroup);

    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(horizontalPaneGroup);

    GroupLayout.ParallelGroup verticalRadioButtonGroup =
        layout.createParallelGroup(GroupLayout.Alignment.TRAILING);
    verticalRadioButtonGroup.addComponent(hideFilteredValues);
    verticalRadioButtonGroup.addComponent(showFilteredValues);

    GroupLayout.ParallelGroup verticalButtonGroup =
        layout.createParallelGroup(GroupLayout.Alignment.TRAILING);
    verticalButtonGroup.addComponent(save);
    verticalButtonGroup.addComponent(cancel);
    verticalButtonGroup.addGroup(verticalRadioButtonGroup);

    GroupLayout.SequentialGroup verticalPaneGroup = layout.createSequentialGroup();
    verticalPaneGroup.addComponent(tabbedPane);
    verticalPaneGroup.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED);
    verticalPaneGroup.addGroup(verticalButtonGroup);

    layout.setVerticalGroup(verticalPaneGroup);
  }

  public void setViolationDate(Calendar date) {
    violationDate = date;
  }

  public void loadGUIText() {
    setTitle(localeService.getTranslatedString("TotalViolations"));
    tabbedPane.addTab(localeService.getTranslatedString("FilterViolations"), filterViolationPanel);
    addPath.setText(localeService.getTranslatedString("Add"));
    removePath.setText(localeService.getTranslatedString("Remove"));
    tabbedPane.addTab(localeService.getTranslatedString("FilterPaths"), pathFilterPanel);
    save.setText(localeService.getTranslatedString("Save"));
    cancel.setText(localeService.getTranslatedString("Cancel"));
    showFilteredValues.setText(localeService.getTranslatedString("ShowSelectedValues"));
    hideFilteredValues.setText(localeService.getTranslatedString("HideSelectedValues"));

    loadModels();
  }

  public void loadModels() {
    String[] columnNamesRuletype = {"", localeService.getTranslatedString("Ruletypes")};
    String[] columnNamesViolationtype = {"", localeService.getTranslatedString("Violationtypes")};
    String[] columnNamesPath = {" ", localeService.getTranslatedString("Path")};

    ruletypeModelFilter =
        new DefaultTableModel(columnNamesRuletype, 0) {
          private static final long serialVersionUID = -7173080075671054375L;
          Class<?>[] types = new Class[] {Boolean.class, String.class};
          boolean[] canEdit = new boolean[] {true, false};

          @Override
          public Class<?> getColumnClass(int columnIndex) {
            return types[columnIndex];
          }

          @Override
          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
          }
        };

    violationtypeModelFilter =
        new DefaultTableModel(columnNamesViolationtype, 0) {
          private static final long serialVersionUID = -9191282154177444964L;
          Class<?>[] types = new Class[] {Boolean.class, String.class};
          boolean[] canEdit = new boolean[] {true, false};

          @Override
          public Class<?> getColumnClass(int columnIndex) {
            return types[columnIndex];
          }

          @Override
          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
          }
        };

    pathFilterModel =
        new DefaultTableModel(columnNamesPath, 0) {
          private static final long serialVersionUID = 1832644249597223838L;
          Class<?>[] types = new Class[] {Boolean.class, String.class};
          boolean[] canEdit = new boolean[] {true, true};

          @Override
          public Class<?> getColumnClass(int columnIndex) {
            return types[columnIndex];
          }

          @Override
          public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit[columnIndex];
          }
        };

    ruletypeTable.setModel(ruletypeModelFilter);
    violationtypeTable.setModel(violationtypeModelFilter);
    pathFilterTable.setModel(pathFilterModel);

    loadFilterValues();
  }

  private void cancelActionPerformed() {
    dispose();
  }

  private void saveActionPerformed() {
    ruletypesfilter = getRuletypesFilter();
    violationtypesfilter = getViolationtypesFilter();
    pathsfilter = getPathFilter();
    if (!checkPathsNames()) {
      return;
    }
    PathDTO dto = new PathDTO(ruletypesfilter, violationtypesfilter, pathsfilter);
    taskServiceImpl.setFilterValues(dto, hideFilteredValues.isSelected(), violationDate);
    filterViolationsObserver.updateViolationsTable();
    dispose();
  }

  private void addPathActionPerformed() {
    pathFilterModel.addRow(new Object[] {true, ""});
  }

  private void removePathActionPerformed() {
    if (pathFilterTable.getSelectedRow() > -1) {
      pathFilterModel.removeRow(pathFilterTable.getSelectedRow());
    }
  }

  private ArrayList<String> getRuletypesFilter() {
    ArrayList<String> Ruletypes = new ArrayList<String>();
    for (int i = 0; i < ruletypeModelFilter.getRowCount(); i++) {
      if ((Boolean) ruletypeModelFilter.getValueAt(i, 0)) {
        Ruletypes.add((String) ruletypeModelFilter.getValueAt(i, 1));
      }
    }

    return Ruletypes;
  }

  private ArrayList<String> getViolationtypesFilter() {
    ArrayList<String> violationtypes = new ArrayList<String>();

    for (int i = 0; i < violationtypeModelFilter.getRowCount(); i++) {
      if ((Boolean) violationtypeModelFilter.getValueAt(i, 0)) {
        violationtypes.add((String) violationtypeModelFilter.getValueAt(i, 1));
      }
    }

    return violationtypes;
  }

  private ArrayList<String> getPathFilter() {
    ArrayList<String> paths = new ArrayList<String>();

    for (int i = 0; i < pathFilterModel.getRowCount(); i++) {
      if ((Boolean) pathFilterModel.getValueAt(i, 0)) {
        paths.add((String) pathFilterModel.getValueAt(i, 1));
      }
    }

    return paths;
  }

  public void loadFilterValues() {
    loadRuletypes();
    loadViolationtypes();
  }

  private void loadRuletypes() {
    ArrayList<String> enabledRuleTypes = taskServiceImpl.getEnabledFilterRuleTypes();
    while (ruletypeModelFilter.getRowCount() > 0) {
      ruletypeModelFilter.removeRow(0);
    }
    ArrayList<String> ruletypes = taskServiceImpl.loadRuletypesForFilter(violationDate);
    boolean isEnabled;
    for (String ruletype : ruletypes) {
      isEnabled = false;
      if (enabledRuleTypes.contains(ruletype)) {
        isEnabled = true;
      }
      ruletypeModelFilter.addRow(new Object[] {isEnabled, ruletype});
    }
  }

  private void loadViolationtypes() {
    ArrayList<String> enabledViolations = taskServiceImpl.getEnabledFilterViolations();
    while (violationtypeModelFilter.getRowCount() > 0) {
      violationtypeModelFilter.removeRow(0);
    }
    ArrayList<String> violationtypes = taskServiceImpl.loadViolationtypesForFilter(violationDate);
    boolean isEnabled;
    for (String violationtype : violationtypes) {
      if (!violationtype.isEmpty()) {
        isEnabled = false;
        if (enabledViolations.contains(violationtype)) {
          isEnabled = true;
        }
        violationtypeModelFilter.addRow(new Object[] {isEnabled, violationtype});
      }
    }
  }

  private boolean checkPathsNames() {
    if (pathsfilter.isEmpty()) {
      return true;
    }
    boolean returnValue = true;
    for (String path : pathsfilter) {
      if (path.isEmpty()) {
        returnValue = false;
      }
    }
    if (!returnValue) {
      ServiceProvider.getInstance()
          .getControlService()
          .showInfoMessage(
              String.format(
                  localeService.getTranslatedString("EmptyField"),
                  ServiceProvider.getInstance().getLocaleService().getTranslatedString("Path")));
    }
    return returnValue;
  }
}
示例#28
0
 public void setApplicationData(ApplicationDTO applicationDTO) {
   ServiceProvider.getInstance()
       .getDefineService()
       .createApplication(applicationDTO.name, applicationDTO.projects, applicationDTO.version);
 }