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