Search in sources :

Example 1 with ConfigProperty

use of net.sf.eclipsecs.core.config.ConfigProperty in project eclipse-cs by checkstyle.

the class MetadataFactory method createGenericMetadata.

/**
 * Creates a set of generic metadata for a module that has no metadata delivered with the plugin.
 *
 * @param module
 *          the module
 * @return the generic metadata built
 */
public static RuleMetadata createGenericMetadata(Module module) {
    String parent = null;
    try {
        Class<?> checkClass = CheckstylePlugin.getDefault().getAddonExtensionClassLoader().loadClass(module.getName());
        Object moduleInstance = checkClass.newInstance();
        if (moduleInstance instanceof AbstractFileSetCheck) {
            parent = XMLTags.CHECKER_MODULE;
        } else {
            parent = XMLTags.TREEWALKER_MODULE;
        }
    } catch (Exception e) {
        // Ok we tried... default to TreeWalker
        parent = XMLTags.TREEWALKER_MODULE;
    }
    RuleGroupMetadata otherGroup = getRuleGroupMetadata(XMLTags.OTHER_GROUP);
    RuleMetadata ruleMeta = new RuleMetadata(module.getName(), module.getName(), parent, MetadataFactory.getDefaultSeverity(), false, true, true, false, otherGroup);
    module.setMetaData(ruleMeta);
    sRuleMetadata.put(ruleMeta.getInternalName(), ruleMeta);
    List<ConfigProperty> properties = module.getProperties();
    int size = properties != null ? properties.size() : 0;
    for (int i = 0; i < size; i++) {
        ConfigProperty property = properties.get(i);
        ConfigPropertyMetadata meta = new ConfigPropertyMetadata(ConfigPropertyType.String, property.getName(), null, null);
        property.setMetaData(meta);
    }
    return ruleMeta;
}
Also used : AbstractFileSetCheck(com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck) ConfigProperty(net.sf.eclipsecs.core.config.ConfigProperty) DocumentException(org.dom4j.DocumentException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException)

Example 2 with ConfigProperty

use of net.sf.eclipsecs.core.config.ConfigProperty in project eclipse-cs by checkstyle.

the class RuleConfigurationEditDialog method okPressed.

/**
 * OK button was selected.
 */
@Override
protected void okPressed() {
    // 
    // Get the selected severity level.
    // 
    Severity severity = mRule.getSeverity();
    try {
        severity = (Severity) ((IStructuredSelection) mSeverityCombo.getSelection()).getFirstElement();
    } catch (IllegalArgumentException e) {
        CheckstyleLog.log(e);
    }
    // Get the comment.
    final String comment = Strings.emptyToNull(mCommentText.getText());
    // Get the id
    final String id = Strings.emptyToNull(mIdText.getText());
    // Get the custom message
    for (Map.Entry<String, Text> entry : mCustomMessages.entrySet()) {
        String msgKey = entry.getKey();
        String standardMessage = MetadataFactory.getStandardMessage(msgKey, mRule.getMetaData().getInternalName());
        if (standardMessage == null) {
            // $NON-NLS-1$
            standardMessage = "";
        }
        String message = Strings.emptyToNull(entry.getValue().getText());
        if (message != null && !message.equals(standardMessage)) {
            mRule.getCustomMessages().put(msgKey, message);
        } else {
            mRule.getCustomMessages().remove(msgKey);
        }
    }
    // 
    if (mConfigPropertyWidgets != null) {
        for (int i = 0; i < mConfigPropertyWidgets.length; i++) {
            IConfigPropertyWidget widget = mConfigPropertyWidgets[i];
            ConfigProperty property = widget.getConfigProperty();
            try {
                widget.validate();
            } catch (CheckstylePluginException e) {
                String message = NLS.bind(Messages.RuleConfigurationEditDialog_msgInvalidPropertyValue, property.getMetaData().getName());
                this.setErrorMessage(message);
                return;
            }
            property.setValue(widget.getValue());
        }
    }
    // 
    // If we made it this far then all of the user input validated and we
    // can
    // update the final rule with the values the user entered.
    // 
    mRule.setSeverity(severity);
    mRule.setComment(comment);
    mRule.setId(id);
    super.okPressed();
}
Also used : ConfigProperty(net.sf.eclipsecs.core.config.ConfigProperty) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) Severity(net.sf.eclipsecs.core.config.Severity) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) HashMap(java.util.HashMap) Map(java.util.Map) IConfigPropertyWidget(net.sf.eclipsecs.ui.config.widgets.IConfigPropertyWidget)

Example 3 with ConfigProperty

use of net.sf.eclipsecs.core.config.ConfigProperty in project eclipse-cs by checkstyle.

the class RuleConfigurationEditDialog method createConfigPropertyEntries.

private void createConfigPropertyEntries(Composite parent) {
    List<ConfigProperty> configItemMetadata = mRule.getProperties();
    if (configItemMetadata.size() <= 0) {
        return;
    }
    mConfigPropertyWidgets = new IConfigPropertyWidget[configItemMetadata.size()];
    Iterator<ConfigProperty> iter = configItemMetadata.iterator();
    for (int i = 0; iter.hasNext(); i++) {
        ConfigProperty prop = iter.next();
        // 
        // Add an input widget for the properties value.
        // 
        mConfigPropertyWidgets[i] = ConfigPropertyWidgetFactory.createWidget(parent, prop, getShell());
        mConfigPropertyWidgets[i].setEnabled(!mReadonly);
    }
}
Also used : ConfigProperty(net.sf.eclipsecs.core.config.ConfigProperty)

Aggregations

ConfigProperty (net.sf.eclipsecs.core.config.ConfigProperty)3 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)2 AbstractFileSetCheck (com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck)1 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MissingResourceException (java.util.MissingResourceException)1 Severity (net.sf.eclipsecs.core.config.Severity)1 IConfigPropertyWidget (net.sf.eclipsecs.ui.config.widgets.IConfigPropertyWidget)1 DocumentException (org.dom4j.DocumentException)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Text (org.eclipse.swt.widgets.Text)1