Search in sources :

Example 16 with PropertyDescriptor

use of net.sourceforge.pmd.properties.PropertyDescriptor in project pmd-eclipse-plugin by pmd.

the class ReportManager method loadReportProperties.

/**
 * Load the properties for all renderers from the specified filename. Return whether we succeeded or not.
 *
 * @param propertyFilename
 *            String
 * @return boolean
 */
private static boolean loadReportProperties(String propertyFilename) {
    Properties props = new Properties();
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(propertyFilename);
        props.loadFromXML(fis);
    } catch (Exception e) {
        return false;
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
        } catch (Exception e) {
        // ignored
        }
    }
    for (Renderer renderer : ReportManager.INSTANCE.allRenderers()) {
        for (PropertyDescriptor pDesc : renderer.getPropertyDescriptors()) {
            String key = keyOf(renderer, pDesc);
            if (props.containsKey(key)) {
                Object value = pDesc.valueFrom((String) props.get(key));
                renderer.setProperty(pDesc, value);
            }
        }
    }
    return true;
}
Also used : PropertyDescriptor(net.sourceforge.pmd.properties.PropertyDescriptor) Renderer(net.sourceforge.pmd.renderers.Renderer) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 17 with PropertyDescriptor

use of net.sourceforge.pmd.properties.PropertyDescriptor in project pmd-eclipse-plugin by pmd.

the class FormArranger method addAddButton.

private void addAddButton() {
    Button button = new Button(parent, SWT.PUSH);
    button.setText("Add new...");
    button.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            NewPropertyDialog dialog = new NewPropertyDialog(parent.getShell(), editorFactoriesByValueType, propertySource, changeListener);
            if (dialog.open() == Window.OK) {
                PropertyDescriptor<?> desc = dialog.descriptor();
                propertySource.definePropertyDescriptor(desc);
                rearrangeFor(propertySource);
            }
        }
    });
}
Also used : PropertyDescriptor(net.sourceforge.pmd.properties.PropertyDescriptor) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NewPropertyDialog(net.sourceforge.pmd.eclipse.ui.dialogs.NewPropertyDialog) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 18 with PropertyDescriptor

use of net.sourceforge.pmd.properties.PropertyDescriptor in project pmd-eclipse-plugin by pmd.

the class FormArranger method rearrangeFor.

private int rearrangeFor(PropertySource theSource) {
    clearChildren();
    propertySource = theSource;
    if (propertySource == null) {
        return -1;
    }
    Map<PropertyDescriptor<?>, Object> valuesByDescriptor = Configuration.filteredPropertiesOf(propertySource);
    if (valuesByDescriptor.isEmpty()) {
        if (RuleUtil.isXPathRule(propertySource)) {
            addAddButton();
            parent.pack();
            return 1;
        }
        return 0;
    }
    PropertyDescriptor<?>[] orderedDescs = valuesByDescriptor.keySet().toArray(new PropertyDescriptor[valuesByDescriptor.size()]);
    Arrays.sort(orderedDescs);
    // count up the actual rows with widgets needed, not all have editors yet
    int rowCount = 0;
    for (PropertyDescriptor<?> desc : orderedDescs) {
        EditorFactory<?> factory = factoryFor(desc);
        if (factory == null) {
            System.out.println("No editor defined for: " + desc.getClass().getSimpleName());
            continue;
        }
        rowCount++;
    }
    boolean isXPathRule = RuleUtil.isXPathRule(propertySource);
    // xpath descriptors have a column of delete buttons
    int columnCount = isXPathRule ? 3 : 2;
    GridLayout layout = new GridLayout(columnCount, false);
    layout.verticalSpacing = 2;
    layout.marginTop = 1;
    parent.setLayout(layout);
    widgets = new Control[rowCount][columnCount];
    int rowsAdded = 0;
    for (PropertyDescriptor<?> desc : orderedDescs) {
        if (addRowWidgets(factoryFor(desc), rowsAdded, desc, isXPathRule)) {
            rowsAdded++;
        }
    }
    if (RuleUtil.isXPathRule(propertySource)) {
        addAddButton();
        rowsAdded++;
    }
    if (rowsAdded > 0) {
        parent.pack();
    }
    adjustEnabledStates();
    return rowsAdded;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) PropertyDescriptor(net.sourceforge.pmd.properties.PropertyDescriptor)

Aggregations

PropertyDescriptor (net.sourceforge.pmd.properties.PropertyDescriptor)18 Test (org.junit.Test)6 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 JavaUtilLoggingRule (net.sourceforge.pmd.junit.JavaUtilLoggingRule)4 MockRule (net.sourceforge.pmd.lang.rule.MockRule)4 Rule (net.sourceforge.pmd.Rule)3 LanguageVersion (net.sourceforge.pmd.lang.LanguageVersion)3 RuleReference (net.sourceforge.pmd.lang.rule.RuleReference)3 StringReader (java.io.StringReader)2 Properties (java.util.Properties)2 RuleContext (net.sourceforge.pmd.RuleContext)2 Language (net.sourceforge.pmd.lang.Language)2 Parser (net.sourceforge.pmd.lang.Parser)2 ParserOptions (net.sourceforge.pmd.lang.ParserOptions)2 Node (net.sourceforge.pmd.lang.ast.Node)2 ASTCompilationUnit (net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit)2 XPathRule (net.sourceforge.pmd.lang.rule.XPathRule)2 JaxenXPathRuleQuery (net.sourceforge.pmd.lang.rule.xpath.JaxenXPathRuleQuery)2