Search in sources :

Example 1 with IConfigurationType

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

the class CheckConfigurationPropertiesDialog method createDialogArea.

/**
 * Creates the dialogs main contents.
 *
 * @param parent
 *          the parent composite
 */
@Override
protected Control createDialogArea(Composite parent) {
    // set the logo
    this.setTitleImage(CheckstyleUIPluginImages.getImage(CheckstyleUIPluginImages.PLUGIN_LOGO));
    Composite composite = (Composite) super.createDialogArea(parent);
    Composite contents = new Composite(composite, SWT.NULL);
    contents.setLayout(new GridLayout(2, false));
    GridData fd = new GridData(GridData.FILL_BOTH);
    contents.setLayoutData(fd);
    Label lblConfigType = new Label(contents, SWT.NULL);
    lblConfigType.setText(Messages.CheckConfigurationPropertiesDialog_lblConfigType);
    fd = new GridData();
    // this is a weird hack to find the longest label
    // this is done to have a nice ordered appearance of the this label
    // and the labels below
    // this is very difficult to do, because they belong to different
    // layouts
    GC gc = new GC(lblConfigType);
    int nameSize = gc.textExtent(Messages.CheckConfigurationPropertiesDialog_lblName).x;
    int locationsSize = gc.textExtent(Messages.CheckConfigurationPropertiesDialog_lblLocation).x;
    int max = Math.max(nameSize, locationsSize);
    gc.dispose();
    fd.widthHint = max;
    lblConfigType.setLayoutData(fd);
    mConfigType = new ComboViewer(contents);
    fd = new GridData();
    mConfigType.getCombo().setLayoutData(fd);
    mConfigType.setContentProvider(new ArrayContentProvider());
    mConfigType.setLabelProvider(new LabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            return ((IConfigurationType) element).getName();
        }

        /**
         * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
         */
        @Override
        public Image getImage(Object element) {
            return ConfigurationTypesUI.getConfigurationTypeImage((IConfigurationType) element);
        }
    });
    mConfigType.addSelectionChangedListener(new ISelectionChangedListener() {

        /**
         * @see ISelectionChangedListener#selectionChanged(
         *      org.eclipse.jface.viewers.SelectionChangedEvent)
         */
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof IStructuredSelection) {
                IConfigurationType type = (IConfigurationType) ((IStructuredSelection) event.getSelection()).getFirstElement();
                if (mConfigType.getCombo().isEnabled()) {
                    String oldName = mCheckConfig.getName();
                    String oldDescr = mCheckConfig.getDescription();
                    mCheckConfig = mWorkingSet.newWorkingCopy(type);
                    try {
                        mCheckConfig.setName(oldName);
                    } catch (CheckstylePluginException e) {
                    // NOOP
                    }
                    mCheckConfig.setDescription(oldDescr);
                }
                createConfigurationEditor(mCheckConfig);
            }
        }
    });
    mEditorPlaceHolder = new Composite(contents, SWT.NULL);
    GridLayout layout = new GridLayout(1, true);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    mEditorPlaceHolder.setLayout(layout);
    fd = new GridData(GridData.FILL_HORIZONTAL);
    fd.horizontalSpan = 2;
    mEditorPlaceHolder.setLayoutData(fd);
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) IConfigurationType(net.sf.eclipsecs.core.config.configtypes.IConfigurationType) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) GC(org.eclipse.swt.graphics.GC) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 2 with IConfigurationType

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

the class CheckConfigurationPropertiesDialog method initialize.

/**
 * Initialize the dialogs controls with the data.
 */
private void initialize() {
    if (mCheckConfig == null) {
        IConfigurationType[] types = mTemplate != null ? ConfigurationTypes.getConfigurableConfigTypes() : ConfigurationTypes.getCreatableConfigTypes();
        mCheckConfig = mWorkingSet.newWorkingCopy(types[0]);
        if (mTemplate != null) {
            this.setTitle(NLS.bind(Messages.CheckConfigurationPropertiesDialog_titleCopyConfiguration, mTemplate.getName()));
            this.setMessage(Messages.CheckConfigurationPropertiesDialog_msgCopyConfiguration);
            String nameProposal = NLS.bind(Messages.CheckConfigurationPropertiesDialog_CopyOfAddition, mTemplate.getName());
            setUniqueName(mCheckConfig, nameProposal);
            mCheckConfig.setDescription(mTemplate.getDescription());
            mCheckConfig.getResolvableProperties().addAll(mTemplate.getResolvableProperties());
        } else {
            this.setTitle(Messages.CheckConfigurationPropertiesDialog_titleCheckConfig);
            this.setMessage(Messages.CheckConfigurationPropertiesDialog_msgCreateNewCheckConfig);
        }
        mConfigType.setInput(types);
        mConfigType.setSelection(new StructuredSelection(types[0]), true);
        createConfigurationEditor(mCheckConfig);
    } else {
        this.setTitle(Messages.CheckConfigurationPropertiesDialog_titleCheckConfig);
        this.setMessage(Messages.CheckConfigurationPropertiesDialog_msgEditCheckConfig);
        mConfigType.getCombo().setEnabled(false);
        mConfigType.setInput(new IConfigurationType[] { mCheckConfig.getType() });
        // type of existing configs cannot be changed
        mConfigType.setSelection(new StructuredSelection(mCheckConfig.getType()), true);
        createConfigurationEditor(mCheckConfig);
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IConfigurationType(net.sf.eclipsecs.core.config.configtypes.IConfigurationType)

Example 3 with IConfigurationType

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

the class CheckConfigurationFactory method getGlobalCheckConfigurations.

/**
 * Gets the check configurations from the configuration file document.
 *
 * @param root
 *          the root element of the plugins central configuration file
 * @return the global check configurations configured therein
 */
@SuppressWarnings("unchecked")
private static List<ICheckConfiguration> getGlobalCheckConfigurations(Element root) {
    List<ICheckConfiguration> configs = new ArrayList<>();
    List<Element> configElements = root.elements(XMLTags.CHECK_CONFIG_TAG);
    for (Element configEl : configElements) {
        String name = configEl.attributeValue(XMLTags.NAME_TAG);
        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);
        // 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, true, props, additionalData);
        configs.add(checkConfig);
    }
    return configs;
}
Also used : HashMap(java.util.HashMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) IConfigurationType(net.sf.eclipsecs.core.config.configtypes.IConfigurationType)

Example 4 with IConfigurationType

use of net.sf.eclipsecs.core.config.configtypes.IConfigurationType 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 IConfigurationType

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

the class CheckConfigurationFactory method loadBuiltinConfigurations.

/**
 * Loads the built-in check configurations defined in plugin.xml or custom fragments.
 */
private static void loadBuiltinConfigurations() {
    IExtensionRegistry pluginRegistry = Platform.getExtensionRegistry();
    IConfigurationElement[] elements = pluginRegistry.getConfigurationElementsFor(CONFIGS_EXTENSION_POINT);
    int currentMaxDefaultWeight = -1;
    ICheckConfiguration defaultBuiltInCheckConfig = null;
    for (int i = 0; i < elements.length; i++) {
        String name = elements[i].getAttribute(XMLTags.NAME_TAG);
        String description = elements[i].getAttribute(XMLTags.DESCRIPTION_TAG);
        String location = elements[i].getAttribute(XMLTags.LOCATION_TAG);
        String defaultWeightAsString = elements[i].getAttribute(XMLTags.DEFAULT_WEIGHT);
        final int defaultWeight = defaultWeightAsString != null ? Integer.parseInt(defaultWeightAsString) : 0;
        IConfigurationType configType = ConfigurationTypes.getByInternalName("builtin");
        Map<String, String> additionalData = new HashMap<>();
        additionalData.put(BuiltInConfigurationType.CONTRIBUTOR_KEY, elements[i].getContributor().getName());
        List<ResolvableProperty> props = new ArrayList<>();
        IConfigurationElement[] propEls = elements[i].getChildren(XMLTags.PROPERTY_TAG);
        for (IConfigurationElement propEl : propEls) {
            props.add(new ResolvableProperty(propEl.getAttribute(XMLTags.NAME_TAG), propEl.getAttribute(XMLTags.VALUE_TAG)));
        }
        ICheckConfiguration checkConfig = new CheckConfiguration(name, location, description, configType, true, props, additionalData);
        sConfigurations.add(checkConfig);
        if (defaultWeight > currentMaxDefaultWeight) {
            currentMaxDefaultWeight = defaultWeight;
            defaultBuiltInCheckConfig = checkConfig;
        }
    }
    sDefaultBuiltInConfig = defaultBuiltInCheckConfig;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IConfigurationType(net.sf.eclipsecs.core.config.configtypes.IConfigurationType) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

IConfigurationType (net.sf.eclipsecs.core.config.configtypes.IConfigurationType)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Element (org.dom4j.Element)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 CheckConfiguration (net.sf.eclipsecs.core.config.CheckConfiguration)1 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)1 ResolvableProperty (net.sf.eclipsecs.core.config.ResolvableProperty)1 ProjectConfigurationType (net.sf.eclipsecs.core.config.configtypes.ProjectConfigurationType)1 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 GC (org.eclipse.swt.graphics.GC)1