Search in sources :

Example 1 with ResolvableProperty

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

the class CheckConfigurationPropertiesDialog method okPressed.

/**
 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
 */
@Override
protected void okPressed() {
    try {
        // Check if the configuration is valid
        mCheckConfig = mConfigurationEditor.getEditedWorkingCopy();
        CheckConfigurationTester tester = new CheckConfigurationTester(mCheckConfig);
        List<ResolvableProperty> unresolvedProps = tester.getUnresolvedProperties();
        if (!unresolvedProps.isEmpty()) {
            MessageDialog dialog = new MessageDialog(getShell(), Messages.CheckConfigurationPropertiesDialog_titleUnresolvedProps, null, NLS.bind(Messages.CheckConfigurationPropertiesDialog_msgUnresolvedProps, // $NON-NLS-1$
            "" + unresolvedProps.size()), MessageDialog.WARNING, new String[] { Messages.CheckConfigurationPropertiesDialog_btnEditProps, Messages.CheckConfigurationPropertiesDialog_btnContinue, Messages.CheckConfigurationPropertiesDialog_btnCancel }, 0);
            int result = dialog.open();
            if (0 == result) {
                ResolvablePropertiesDialog propsDialog = new ResolvablePropertiesDialog(getShell(), mCheckConfig);
                propsDialog.open();
                return;
            } else if (1 == result) {
                super.okPressed();
            } else if (2 == result) {
                return;
            }
        } else {
            super.okPressed();
        }
    } catch (CheckstylePluginException e) {
        CheckstyleLog.log(e);
        this.setErrorMessage(e.getLocalizedMessage());
    }
}
Also used : ResolvableProperty(net.sf.eclipsecs.core.config.ResolvableProperty) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) CheckConfigurationTester(net.sf.eclipsecs.core.config.CheckConfigurationTester) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Point(org.eclipse.swt.graphics.Point)

Example 2 with ResolvableProperty

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

the class ResolvablePropertiesDialog method okPressed.

/**
 * {@inheritDoc}
 */
@Override
protected void okPressed() {
    // OK'ing
    for (ResolvableProperty prop : mResolvableProperties) {
        if (Strings.emptyToNull(prop.getValue()) == null) {
            this.setErrorMessage(NLS.bind(Messages.ResolvablePropertiesDialog_msgMissingPropertyValue, prop.getPropertyName()));
            return;
        }
    }
    mCheckConfig.getResolvableProperties().clear();
    mCheckConfig.getResolvableProperties().addAll(mResolvableProperties);
    super.okPressed();
}
Also used : ResolvableProperty(net.sf.eclipsecs.core.config.ResolvableProperty)

Example 3 with ResolvableProperty

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

the class ResolvablePropertiesDialog method initialize.

/**
 * Initialize the dialogs controls with the data.
 */
private void initialize() {
    // clone the properties so that changes don't directly reflect back into
    // the configuration
    mResolvableProperties = new ArrayList<>();
    for (ResolvableProperty prop : mCheckConfig.getResolvableProperties()) {
        mResolvableProperties.add(prop.clone());
    }
    mTableViewer.setInput(mResolvableProperties);
}
Also used : ResolvableProperty(net.sf.eclipsecs.core.config.ResolvableProperty)

Example 4 with ResolvableProperty

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

the class ProjectConfigurationFactory method getLocalCheckConfigs.

@SuppressWarnings("unchecked")
private static List<ICheckConfiguration> getLocalCheckConfigs(Element root, IProject project) {
    List<ICheckConfiguration> configurations = new ArrayList<>();
    List<Element> configElements = root.elements(XMLTags.CHECK_CONFIG_TAG);
    for (Element configEl : configElements) {
        final String name = configEl.attributeValue(XMLTags.NAME_TAG);
        final String description = configEl.attributeValue(XMLTags.DESCRIPTION_TAG);
        String location = configEl.attributeValue(XMLTags.LOCATION_TAG);
        String type = configEl.attributeValue(XMLTags.TYPE_TAG);
        IConfigurationType configType = ConfigurationTypes.getByInternalName(type);
        if (configType instanceof ProjectConfigurationType) {
            // RFE 1420212
            // treat config files relative to *THIS* project
            IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
            // test if the location contains the project name
            if (workspaceRoot.findMember(location) == null) {
                location = project.getFullPath().append(location).toString();
            }
        }
        // get resolvable properties
        List<ResolvableProperty> props = new ArrayList<>();
        List<Element> propertiesElements = configEl.elements(XMLTags.PROPERTY_TAG);
        for (Element propsEl : propertiesElements) {
            ResolvableProperty prop = new ResolvableProperty(propsEl.attributeValue(XMLTags.NAME_TAG), propsEl.attributeValue(XMLTags.VALUE_TAG));
            props.add(prop);
        }
        // get additional data
        Map<String, String> additionalData = new HashMap<>();
        List<Element> dataElements = configEl.elements(XMLTags.ADDITIONAL_DATA_TAG);
        for (Element dataEl : dataElements) {
            additionalData.put(dataEl.attributeValue(XMLTags.NAME_TAG), dataEl.attributeValue(XMLTags.VALUE_TAG));
        }
        ICheckConfiguration checkConfig = new CheckConfiguration(name, location, description, configType, false, props, additionalData);
        configurations.add(checkConfig);
    }
    return configurations;
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) HashMap(java.util.HashMap) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) IConfigurationType(net.sf.eclipsecs.core.config.configtypes.IConfigurationType) CheckConfiguration(net.sf.eclipsecs.core.config.CheckConfiguration) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) ResolvableProperty(net.sf.eclipsecs.core.config.ResolvableProperty) ProjectConfigurationType(net.sf.eclipsecs.core.config.configtypes.ProjectConfigurationType)

Example 5 with ResolvableProperty

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

the class ResolvablePropertyResolver method resolve.

@Override
public String resolve(String aName) {
    String value = null;
    List<ResolvableProperty> resolvableProperties = mCheckConfiguration.getResolvableProperties();
    for (ResolvableProperty prop : resolvableProperties) {
        if (aName.equals(prop.getPropertyName())) {
            value = prop.getValue();
            break;
        }
    }
    return value;
}
Also used : ResolvableProperty(net.sf.eclipsecs.core.config.ResolvableProperty)

Aggregations

ResolvableProperty (net.sf.eclipsecs.core.config.ResolvableProperty)6 ProjectConfigurationType (net.sf.eclipsecs.core.config.configtypes.ProjectConfigurationType)2 Element (org.dom4j.Element)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CheckConfiguration (net.sf.eclipsecs.core.config.CheckConfiguration)1 CheckConfigurationTester (net.sf.eclipsecs.core.config.CheckConfigurationTester)1 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)1 BuiltInConfigurationType (net.sf.eclipsecs.core.config.configtypes.BuiltInConfigurationType)1 IConfigurationType (net.sf.eclipsecs.core.config.configtypes.IConfigurationType)1 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 Path (org.eclipse.core.runtime.Path)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 Point (org.eclipse.swt.graphics.Point)1