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;
}
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();
}
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);
}
}
Aggregations