Search in sources :

Example 1 with IConfigPropertyWidget

use of net.sf.eclipsecs.ui.config.widgets.IConfigPropertyWidget 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)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConfigProperty (net.sf.eclipsecs.core.config.ConfigProperty)1 Severity (net.sf.eclipsecs.core.config.Severity)1 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)1 IConfigPropertyWidget (net.sf.eclipsecs.ui.config.widgets.IConfigPropertyWidget)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Text (org.eclipse.swt.widgets.Text)1