Beispiel #1
0
  public JComponent createComponent(Category category, Lookup context) {
    Project p = context.lookup(Project.class);
    CheckstyleSettingsProvider checkstyleSettingsProvider =
        p.getLookup().lookup(CheckstyleSettingsProvider.class);
    if (checkstyleSettingsProvider == null) {
      return new JLabel("<not available>");
    }
    final CheckstyleSettings checkstyleSettings =
        checkstyleSettingsProvider.getCheckstyleSettings();

    final CheckstyleConfiguration checkstyleConfiguration = new CheckstyleConfiguration();
    FileObject checkstyleConfigurationFile = checkstyleSettings.getCheckstyleConfigurationFile();
    if (checkstyleConfigurationFile != null) {
      String cleanAbsoluteFile = FileUtil.toFile(checkstyleConfigurationFile).getAbsolutePath();
      checkstyleConfiguration.setConfigFilePath(cleanAbsoluteFile);
    } else {
      checkstyleConfiguration.setConfigFilePath("");
    }
    FileObject checkstylePropertiesFile = checkstyleSettings.getPropertiesFile();
    if (null != checkstylePropertiesFile) {
      String propertiesFilePath = FileUtil.toFile(checkstylePropertiesFile).getAbsolutePath();
      checkstyleConfiguration.setPropertiesFilePath(propertiesFilePath);
    } else {
      checkstyleConfiguration.setPropertiesFilePath("");
    }
    checkstyleConfiguration.setProperties(checkstyleSettings.getPropertiesAsString());

    category.setOkButtonListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            if (checkstyleSettings instanceof CheckstyleSettingsProviderImpl.Settings) {
              CheckstyleSettingsProviderImpl.Settings checkstyleSettingsImpl =
                  (CheckstyleSettingsProviderImpl.Settings) checkstyleSettings;
              checkstyleSettingsImpl.setCheckstyleConfigurationPath(
                  checkstyleConfiguration.getConfigFilePath());
              checkstyleSettingsImpl.setPropertiesPath(
                  checkstyleConfiguration.getPropertiesFilePath());
              checkstyleSettingsImpl.setProperties(checkstyleConfiguration.getProperties());
            }
          }
        });

    return checkstyleConfiguration;
  }