Code cleanup, deprecations, some adaptations for new properties. Some classes that currently have errors will soon be removed.
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@6677 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
1 parent
3a29f39522
commit
7fa24a8af0
42 files changed
+3401
-47
No files matched your search
+1
-1
@@ -96,7 +96,7 @@ public class CPDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
* @see org.eclipse.jface.preference.IPreferencePage#performOk()
|
||||
*/
|
||||
public boolean performOk() {
|
||||
this.preferences.setMinTileSize(new Integer(this.minTileText.getText()).intValue());
|
||||
this.preferences.setMinTileSize(Integer.valueOf(this.minTileText.getText()).intValue());
|
||||
this.preferences.sync();
|
||||
|
||||
return super.performOk();
|
||||
|
||||
+25
-26
@@ -6,7 +6,6 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
@@ -79,7 +78,7 @@ public class PMDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
protected Button addRuleButton;
|
||||
protected Button removeRuleButton;
|
||||
protected Button editRuleButton;
|
||||
protected Button addPropertyButton;
|
||||
// protected Button addPropertyButton;
|
||||
protected Button addExcludePatternButton;
|
||||
protected Button addIncludePatternButton;
|
||||
protected RuleSet ruleSet;
|
||||
@@ -290,7 +289,7 @@ public class PMDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
rowLayout.pack = false;
|
||||
composite.setLayout(rowLayout);
|
||||
|
||||
addPropertyButton = buildAddPropertyButton(composite);
|
||||
// addPropertyButton = buildAddPropertyButton(composite);
|
||||
|
||||
return composite;
|
||||
}
|
||||
@@ -360,7 +359,7 @@ public class PMDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
rulePropertiesTableViewer.setInput(selectedRule);
|
||||
removeRuleButton.setEnabled(selectedRule != null);
|
||||
editRuleButton.setEnabled(selectedRule != null);
|
||||
addPropertyButton.setEnabled(selectedRule != null);
|
||||
// addPropertyButton.setEnabled(selectedRule != null);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -640,28 +639,28 @@ public class PMDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
/**
|
||||
* Build the add property button
|
||||
*/
|
||||
private Button buildAddPropertyButton(Composite parent) {
|
||||
Button button = new Button(parent, SWT.PUSH | SWT.LEFT);
|
||||
button.setText(getMessage(StringKeys.MSGKEY_PREF_RULESET_BUTTON_ADDPROPERTY));
|
||||
button.setEnabled(false);
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
InputDialog input = new InputDialog(getShell(),
|
||||
getMessage(StringKeys.MSGKEY_PREF_RULESET_DIALOG_TITLE),
|
||||
getMessage(StringKeys.MSGKEY_PREF_RULESET_DIALOG_PROPERTY_NAME), "", null);
|
||||
int result = input.open();
|
||||
if (result == InputDialog.OK) {
|
||||
IStructuredSelection selection = (IStructuredSelection)ruleTableViewer.getSelection();
|
||||
Rule selectedRule = (Rule)selection.getFirstElement();
|
||||
selectedRule.addProperty(input.getValue(), "");
|
||||
setModified(true);
|
||||
rulePropertiesTableViewer.refresh();
|
||||
}
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
// private Button buildAddPropertyButton(Composite parent) {
|
||||
// Button button = new Button(parent, SWT.PUSH | SWT.LEFT);
|
||||
// button.setText(getMessage(StringKeys.MSGKEY_PREF_RULESET_BUTTON_ADDPROPERTY));
|
||||
// button.setEnabled(false);
|
||||
// button.addSelectionListener(new SelectionAdapter() {
|
||||
// @Override
|
||||
// public void widgetSelected(SelectionEvent event) {
|
||||
// InputDialog input = new InputDialog(getShell(),
|
||||
// getMessage(StringKeys.MSGKEY_PREF_RULESET_DIALOG_TITLE),
|
||||
// getMessage(StringKeys.MSGKEY_PREF_RULESET_DIALOG_PROPERTY_NAME), "", null);
|
||||
// int result = input.open();
|
||||
// if (result == InputDialog.OK) {
|
||||
// IStructuredSelection selection = (IStructuredSelection)ruleTableViewer.getSelection();
|
||||
// Rule selectedRule = (Rule)selection.getFirstElement();
|
||||
//// selectedRule.addProperty(input.getValue(), "");
|
||||
// setModified(true);
|
||||
// rulePropertiesTableViewer.refresh();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// return button;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Build the exclude pattern table viewer
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class RuleCellModifier implements ICellModifier {
|
||||
} else if (property.equalsIgnoreCase(PMDPreferencePage.PROPERTY_RULE_NAME)) {
|
||||
result = rule.getName();
|
||||
} else if (property.equalsIgnoreCase(PMDPreferencePage.PROPERTY_PRIORITY)) {
|
||||
result = new Integer(rule.getPriority().getPriority() - 1);
|
||||
result = Integer.valueOf(rule.getPriority().getPriority() - 1);
|
||||
} else if (property.equalsIgnoreCase(PMDPreferencePage.PROPERTY_DESCRIPTION)) {
|
||||
result = rule.getDescription();
|
||||
}
|
||||
|
||||
+3
-2
@@ -8,6 +8,7 @@ import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RulePriority;
|
||||
import net.sourceforge.pmd.lang.rule.RuleReference;
|
||||
import net.sourceforge.pmd.lang.rule.XPathRule;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
|
||||
import net.sourceforge.pmd.eclipse.ui.nls.StringKeys;
|
||||
|
||||
@@ -707,7 +708,7 @@ public class RuleDialog extends Dialog {
|
||||
boolean flValid = true;
|
||||
|
||||
String name = nameText.getText();
|
||||
if (name.trim().length() == 0) {
|
||||
if (StringUtil.isEmpty(name)) {
|
||||
MessageDialog.openWarning(getShell(), getMessage(StringKeys.MSGKEY_WARNING_TITLE),
|
||||
getMessage(StringKeys.MSGKEY_WARNING_NAME_MANDATORY));
|
||||
nameText.setFocus();
|
||||
@@ -740,7 +741,7 @@ public class RuleDialog extends Dialog {
|
||||
boolean flValid = true;
|
||||
|
||||
String message = messageText.getText();
|
||||
if (message.trim().length() == 0) {
|
||||
if (StringUtil.isEmpty(message)) {
|
||||
MessageDialog.openWarning(getShell(), getMessage(StringKeys.MSGKEY_WARNING_TITLE),
|
||||
getMessage(StringKeys.MSGKEY_WARNING_MESSAGE_MANDATORY));
|
||||
messageText.setFocus();
|
||||
|
||||
+5
-5
@@ -5,13 +5,14 @@ import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.eclipse.ui.preferences.br.Util;
|
||||
|
||||
/**
|
||||
* This class implements a content provider for the rule properties table of
|
||||
* the PMD Preference page
|
||||
*
|
||||
* @author Philippe Herlin
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public class RulePropertiesContentProvider extends AbstractStructuredContentProvider {
|
||||
|
||||
@@ -19,8 +20,7 @@ public class RulePropertiesContentProvider extends AbstractStructuredContentProv
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
|
||||
*/
|
||||
public Object[] getElements(Object inputElement) {
|
||||
Object[] result = new Object[0];
|
||||
|
||||
|
||||
if (inputElement instanceof Rule) {
|
||||
Rule rule = (Rule) inputElement;
|
||||
Enumeration<String> keys = rule.getProperties().keys();
|
||||
@@ -28,9 +28,9 @@ public class RulePropertiesContentProvider extends AbstractStructuredContentProv
|
||||
while (keys.hasMoreElements()) {
|
||||
propertyList.add(new RuleProperty(rule, keys.nextElement()));
|
||||
}
|
||||
result = propertyList.toArray();
|
||||
return propertyList.toArray();
|
||||
}
|
||||
|
||||
return result;
|
||||
return Util.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -6,7 +6,7 @@ import net.sourceforge.pmd.Rule;
|
||||
* Helper class to display rule properties in a table
|
||||
*
|
||||
* @author Philippe Herlin
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public class RuleProperty {
|
||||
private Rule rule;
|
||||
|
||||
+3
-3
@@ -1,6 +1,7 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences;
|
||||
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.eclipse.ui.preferences.br.Util;
|
||||
|
||||
/**
|
||||
* This class implements a content provider for the rule table of
|
||||
@@ -15,13 +16,12 @@ public class RuleSetContentProvider extends AbstractStructuredContentProvider {
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
|
||||
*/
|
||||
public Object[] getElements(Object inputElement) {
|
||||
Object[] elements = new Object[0];
|
||||
|
||||
if (inputElement instanceof RuleSet) {
|
||||
RuleSet ruleSet = (RuleSet) inputElement;
|
||||
elements = ruleSet.getRules().toArray();
|
||||
return ruleSet.getRules().toArray();
|
||||
}
|
||||
|
||||
return elements;
|
||||
return Util.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
+9
-8
@@ -1,6 +1,5 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
@@ -14,6 +13,9 @@ public class RuleSetExcludeIncludePatternContentProvider extends AbstractStructu
|
||||
|
||||
private final boolean exclude;
|
||||
|
||||
private static final RuleSetExcludeIncludePattern[] emptyRuleSetPattern = new RuleSetExcludeIncludePattern[0];
|
||||
|
||||
|
||||
public RuleSetExcludeIncludePatternContentProvider(boolean exclude) {
|
||||
this.exclude = exclude;
|
||||
}
|
||||
@@ -22,18 +24,17 @@ public class RuleSetExcludeIncludePatternContentProvider extends AbstractStructu
|
||||
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
|
||||
*/
|
||||
public RuleSetExcludeIncludePattern[] getElements(Object inputElement) {
|
||||
RuleSetExcludeIncludePattern[] result = new RuleSetExcludeIncludePattern[0];
|
||||
|
||||
|
||||
if (inputElement instanceof RuleSet) {
|
||||
RuleSet ruleSet = (RuleSet)inputElement;
|
||||
List<String> patterns = exclude ? ruleSet.getExcludePatterns() : ruleSet.getIncludePatterns();
|
||||
List<RuleSetExcludeIncludePattern> patternList = new ArrayList<RuleSetExcludeIncludePattern>();
|
||||
for (int i = 0; i < patterns.size(); i++) {
|
||||
patternList.add(new RuleSetExcludeIncludePattern(ruleSet, exclude, i));
|
||||
RuleSetExcludeIncludePattern[] patternList = new RuleSetExcludeIncludePattern[patterns.size()];
|
||||
for (int i = 0; i < patternList.length; i++) {
|
||||
patternList[i] = new RuleSetExcludeIncludePattern(ruleSet, exclude, i);
|
||||
}
|
||||
result = patternList.toArray(result);
|
||||
return patternList;
|
||||
}
|
||||
|
||||
return result;
|
||||
return emptyRuleSetPattern;
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public abstract class AbstractEditorFactory implements EditorFactory {
|
||||
|
||||
protected AbstractEditorFactory() { }
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @see net.sourceforge.pmd.ui.preferences.br.EditorFactory#columnsRequired()
|
||||
*/
|
||||
public int columnsRequired() { return 2; };
|
||||
|
||||
/**
|
||||
* Method addLabel.
|
||||
* @param parent Composite
|
||||
* @param desc PropertyDescriptor
|
||||
* @return Label
|
||||
*/
|
||||
protected Label addLabel(Composite parent, PropertyDescriptor<?> desc) {
|
||||
|
||||
Label label = new Label(parent, SWT.NONE);
|
||||
label.setText(desc.description());
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value as a string that can be easily recognized and parsed
|
||||
* when we see it again.
|
||||
*
|
||||
* @param value Object
|
||||
* @return String
|
||||
*/
|
||||
protected String asString(Object value) {
|
||||
return value == null ? "" : value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the specified values as a single string using the delimiter.
|
||||
* @param values Object
|
||||
* @param delimiter char
|
||||
* @return String
|
||||
* @see net.sourceforge.pmd.PropertyDescriptor#asDelimitedString(Object)
|
||||
*/
|
||||
public String asDelimitedString(Object values, char delimiter) {
|
||||
|
||||
if (values == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (values instanceof Object[]) {
|
||||
Object[] valueSet = (Object[])values;
|
||||
if (valueSet.length == 0) {
|
||||
return "";
|
||||
}
|
||||
if (valueSet.length == 1) {
|
||||
return asString(valueSet[0]);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(asString(valueSet[0]));
|
||||
for (int i=1; i<valueSet.length; i++) {
|
||||
sb.append(delimiter).append(asString(valueSet[i]));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return asString(values);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public abstract class AbstractMultiValueEditorFactory extends AbstractEditorFactory {
|
||||
|
||||
protected static final String delimiter = ",";
|
||||
|
||||
protected AbstractMultiValueEditorFactory() {
|
||||
}
|
||||
|
||||
protected abstract void configure(Text text, PropertyDescriptor<?> desc, Rule rule, ValueChangeListener listener);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parent Composite
|
||||
* @param columnIndex int
|
||||
* @param desc PropertyDescriptor
|
||||
* @param rule Rule
|
||||
* @param listener ValueChangeListener
|
||||
* @return Control
|
||||
* @see net.sourceforge.pmd.ui.preferences.br.EditorFactory#newEditorOn(Composite, int, PropertyDescriptor, Rule)
|
||||
*/
|
||||
public Control newEditorOn(Composite parent, int columnIndex, final PropertyDescriptor<?> desc, final Rule rule, final ValueChangeListener listener) {
|
||||
|
||||
if (columnIndex == 0) return addLabel(parent, desc);
|
||||
|
||||
if (columnIndex == 1) {
|
||||
|
||||
Composite panel = new Composite(parent, SWT.NONE);
|
||||
panel.setLayout(new GridLayout(2, false));
|
||||
|
||||
Text textWidget = new Text(panel, SWT.SINGLE | SWT.BORDER);
|
||||
// final Button butt = new Button(panel, SWT.BORDER);
|
||||
// butt.setText("...");
|
||||
|
||||
textWidget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
fillWidget(textWidget, desc, rule);
|
||||
configure(textWidget, desc, rule, listener);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void fillWidget(Text textWidget, PropertyDescriptor<?> desc, Rule rule) {
|
||||
|
||||
Object[] values = (Object[])rule.getProperty(desc);
|
||||
textWidget.setText(values == null ? "" : StringUtil.asString(values, delimiter + ' '));
|
||||
}
|
||||
|
||||
protected String[] textWidgetValues(Text textWidget) {
|
||||
|
||||
String values = textWidget.getText().trim();
|
||||
|
||||
if (StringUtil.isEmpty(values)) return StringUtil.EMPTY_STRINGS;
|
||||
|
||||
String[] valueSet = values.split(delimiter);
|
||||
List<String> valueList = new ArrayList<String>(valueSet.length);
|
||||
|
||||
for (int i=0; i<valueSet.length; i++) {
|
||||
String str = valueSet[i].trim();
|
||||
if (str.length() > 0) valueList.add(str);
|
||||
}
|
||||
|
||||
return (String[])valueList.toArray(new String[valueList.size()]);
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.StringProperty;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public abstract class AbstractRulePanelManager implements RulePropertyManager {
|
||||
|
||||
protected Rule currentRule;
|
||||
final protected ValueChangeListener changeListener;
|
||||
|
||||
public AbstractRulePanelManager(ValueChangeListener theListener) {
|
||||
changeListener = theListener;
|
||||
}
|
||||
|
||||
protected void addTextListeners(final Text control, final StringProperty desc) {
|
||||
|
||||
control.addListener(SWT.FocusOut, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
changed(desc, control.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param property StringProperty
|
||||
* @param newValue String
|
||||
*/
|
||||
protected void changed(StringProperty property, String newValue) {
|
||||
|
||||
if (currentRule == null) return;
|
||||
|
||||
String cleanValue = newValue.trim();
|
||||
String existingValue = currentRule.getProperty(property);
|
||||
|
||||
if (StringUtil.areSemanticEquals(existingValue, cleanValue)) return;
|
||||
|
||||
currentRule.setProperty(property, cleanValue);
|
||||
changeListener.changed(property, cleanValue);
|
||||
}
|
||||
|
||||
protected void shutdown(Text control) {
|
||||
control.setText("");
|
||||
control.setEnabled(false);
|
||||
}
|
||||
|
||||
protected void show(Text control, String value) {
|
||||
control.setText(value == null ? "" : value);
|
||||
control.setEnabled(true);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class BasicRuleFieldAccessor implements RuleFieldAccessor {
|
||||
|
||||
public BasicRuleFieldAccessor() {
|
||||
}
|
||||
|
||||
public String labelFor(Rule rule) {
|
||||
Comparable value = valueFor(rule);
|
||||
return value == null ? "" : value.toString();
|
||||
}
|
||||
|
||||
public Comparable valueFor(Rule rule) {
|
||||
throw new RuntimeException("unimplemented method");
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.BooleanProperty;
|
||||
import net.sourceforge.pmd.lang.rule.properties.PropertyDescriptorWrapper;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
/**
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class BooleanEditorFactory extends AbstractEditorFactory {
|
||||
|
||||
public static final BooleanEditorFactory instance = new BooleanEditorFactory();
|
||||
|
||||
|
||||
private BooleanEditorFactory() { }
|
||||
|
||||
/**
|
||||
* Method newEditorOn.
|
||||
* @param parent Composite
|
||||
* @param columnIndex int
|
||||
* @param desc PropertyDescriptor
|
||||
* @param rule Rule
|
||||
* @return Control
|
||||
* @see net.sourceforge.pmd.ui.preferences.br.EditorFactory#newEditorOn(Composite, int, PropertyDescriptor, Rule)
|
||||
*/
|
||||
public Control newEditorOn(Composite parent, int columnIndex, final PropertyDescriptor<?> desc, final Rule rule, final ValueChangeListener listener) {
|
||||
|
||||
if (columnIndex == 0) return addLabel(parent, desc);
|
||||
|
||||
if (columnIndex == 1) {
|
||||
|
||||
final Button butt = new Button(parent, SWT.CHECK);
|
||||
butt.setText("");
|
||||
|
||||
if (desc instanceof PropertyDescriptorWrapper) {
|
||||
|
||||
// TODO
|
||||
return butt;
|
||||
}
|
||||
|
||||
final BooleanProperty bp = (BooleanProperty)desc; // TODO - do I really have to do this?
|
||||
|
||||
boolean set = ((Boolean)rule.getProperty(desc)).booleanValue();
|
||||
butt.setSelection(set);
|
||||
|
||||
butt.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
boolean selected = butt.getSelection();
|
||||
if (selected == rule.getProperty(bp)) return;
|
||||
|
||||
rule.setProperty(bp, Boolean.valueOf(selected));
|
||||
listener.changed(desc, Boolean.valueOf(selected));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return butt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
|
||||
public interface CellPainterBuilder {
|
||||
|
||||
void addPainterFor(Tree tree, int columnIndex, RuleFieldAccessor getter);
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.CharacterProperty;
|
||||
import net.sourceforge.pmd.lang.rule.properties.PropertyDescriptorWrapper;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class CharacterEditorFactory extends AbstractEditorFactory {
|
||||
|
||||
public static final CharacterEditorFactory instance = new CharacterEditorFactory();
|
||||
|
||||
private CharacterEditorFactory() { }
|
||||
|
||||
/**
|
||||
* Method fillWidget.
|
||||
* @param textWidget Text
|
||||
* @param desc PropertyDescriptor<?>
|
||||
* @param rule Rule
|
||||
*/
|
||||
protected void fillWidget(Text textWidget, PropertyDescriptor<?> desc, Rule rule) {
|
||||
Character val = (Character)rule.getProperty(desc);
|
||||
textWidget.setText(val == null ? "" : val.toString());
|
||||
}
|
||||
|
||||
private static Character charValueIn(Text textControl) {
|
||||
String newValue = textControl.getText().trim();
|
||||
if (newValue.length() == 0) return null;
|
||||
return Character.valueOf(newValue.charAt(0));
|
||||
}
|
||||
|
||||
public Control newEditorOn(Composite parent, int columnIndex, PropertyDescriptor<?> desc, final Rule rule, final ValueChangeListener listener) {
|
||||
|
||||
if (columnIndex == 0) return addLabel(parent, desc);
|
||||
|
||||
if (columnIndex == 1) {
|
||||
|
||||
final Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
|
||||
|
||||
fillWidget(text, desc, rule);
|
||||
|
||||
if (desc instanceof PropertyDescriptorWrapper) {
|
||||
|
||||
final PropertyDescriptorWrapper descWrapper = (PropertyDescriptorWrapper)desc;
|
||||
|
||||
text.addListener(SWT.FocusOut, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
Character newValue = charValueIn(text);
|
||||
Character existingValue = (Character)rule.getProperty(descWrapper);
|
||||
if (existingValue.equals(newValue)) return;
|
||||
|
||||
rule.setProperty(descWrapper, newValue);
|
||||
listener.changed(descWrapper, newValue);
|
||||
}
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
final CharacterProperty cp = (CharacterProperty)desc; // TODO - really necessary?
|
||||
|
||||
text.addListener(SWT.FocusOut, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
Character newValue = charValueIn(text);
|
||||
Character existingValue = rule.getProperty(cp);
|
||||
if (existingValue.equals(newValue)) return;
|
||||
|
||||
rule.setProperty(cp, newValue);
|
||||
listener.changed(cp, newValue);
|
||||
}
|
||||
});
|
||||
|
||||
return text;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class ColourManager {
|
||||
|
||||
private final Display display;
|
||||
|
||||
private final Map<int[], Color> coloursByRGB = new HashMap<int[], Color>();
|
||||
|
||||
public ColourManager(Display theDisplay) {
|
||||
display = theDisplay;
|
||||
}
|
||||
|
||||
public Color colourFor(String text) {
|
||||
|
||||
if (StringUtil.isEmpty(text)) return display.getSystemColor(SWT.COLOR_WHITE);
|
||||
|
||||
text = text.trim();
|
||||
int length = text.length();
|
||||
|
||||
if (length < 3) return display.getSystemColor(SWT.COLOR_WHITE);
|
||||
|
||||
int posA = length / 3;
|
||||
int posB = posA * 2;
|
||||
|
||||
int rHash = text.subSequence(0, posA).hashCode();
|
||||
int gHash = text.subSequence(posA, posB).hashCode();
|
||||
int bHash = text.subSequence(posB, length).hashCode();
|
||||
|
||||
int colourFractions[] = new int[] {
|
||||
(int)(Math.log10(rHash) % 1 * 255),
|
||||
(int)(Math.log10(gHash) % 1 * 255),
|
||||
(int)(Math.log10(bHash) % 1 * 255)
|
||||
};
|
||||
|
||||
Color colour = coloursByRGB.get(colourFractions);
|
||||
if (colour != null) return colour;
|
||||
|
||||
colour = new Color(display, colourFractions[0], colourFractions[1], colourFractions[2]);
|
||||
coloursByRGB.put(colourFractions, colour);
|
||||
return colour;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
||||
Iterator<Color> iter = coloursByRGB.values().iterator();
|
||||
while (iter.hasNext()) iter.next().dispose();
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class DescriptionPanelManager extends AbstractRulePanelManager {
|
||||
|
||||
private Text descriptionBox;
|
||||
|
||||
public DescriptionPanelManager(ValueChangeListener theListener) {
|
||||
super(theListener);
|
||||
}
|
||||
|
||||
public Control setupOn(Composite parent) {
|
||||
|
||||
descriptionBox = buildDescriptionBox(parent);
|
||||
|
||||
descriptionBox.addListener(SWT.FocusOut, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
|
||||
if (currentRule == null) return;
|
||||
|
||||
String cleanValue = descriptionBox.getText().trim();
|
||||
String existingValue = currentRule.getDescription();
|
||||
|
||||
if (StringUtil.areSemanticEquals(existingValue, cleanValue)) return;
|
||||
|
||||
currentRule.setDescription(cleanValue);
|
||||
changeListener.changed(null, cleanValue);
|
||||
}
|
||||
});
|
||||
|
||||
return descriptionBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method buildDescriptionBox.
|
||||
* @param parent Composite
|
||||
* @return Text
|
||||
*/
|
||||
private Text buildDescriptionBox(Composite parent) {
|
||||
|
||||
return new Text(parent, SWT.BORDER | SWT.WRAP | SWT.MULTI);
|
||||
}
|
||||
|
||||
public void showRule(Rule rule) {
|
||||
|
||||
currentRule = rule;
|
||||
|
||||
if (rule == null) {
|
||||
shutdown(descriptionBox);
|
||||
} else {
|
||||
show(descriptionBox, rule.getDescription().trim());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
/**
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public interface EditorFactory {
|
||||
|
||||
/**
|
||||
* Return the total number of columns required to position all the widgets
|
||||
* for the editor in a row.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int columnsRequired();
|
||||
|
||||
/**
|
||||
* Creates and parks a new editor widget(s) on the parent for the specified descriptor
|
||||
* and rule. It does not perform any layout operations or set form attachments.
|
||||
*
|
||||
* @param parent Composite
|
||||
* @param columnIndex int
|
||||
* @param desc PropertyDescriptor
|
||||
* @param rule Rule
|
||||
* @param listener ValueChangeListener
|
||||
* @return Control
|
||||
*/
|
||||
Control newEditorOn(Composite parent, int columnIndex, PropertyDescriptor<?> desc, Rule rule, ValueChangeListener listener);
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.EnumeratedProperty;
|
||||
import net.sourceforge.pmd.lang.rule.properties.PropertyDescriptorWrapper;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class EnumerationEditorFactory extends AbstractEditorFactory {
|
||||
|
||||
public static final EnumerationEditorFactory instance = new EnumerationEditorFactory();
|
||||
|
||||
private EnumerationEditorFactory() { }
|
||||
|
||||
private static String[] labelsIn(Object[][] items) {
|
||||
|
||||
String[] labels = new String[items.length];
|
||||
for (int i=0; i<labels.length; i++) labels[i] = items[i][0].toString();
|
||||
return labels;
|
||||
}
|
||||
|
||||
public Control newEditorOn(Composite parent, int columnIndex, PropertyDescriptor<?> desc, Rule rule, ValueChangeListener listener) {
|
||||
|
||||
if (columnIndex == 0) return addLabel(parent, desc);
|
||||
|
||||
if (columnIndex == 1) {
|
||||
final Combo combo = new Combo(parent, SWT.READ_ONLY);
|
||||
|
||||
if (desc instanceof PropertyDescriptorWrapper) {
|
||||
|
||||
// TODO
|
||||
return combo;
|
||||
}
|
||||
|
||||
final EnumeratedProperty ep = (EnumeratedProperty)desc;
|
||||
|
||||
combo.setItems(labelsIn(ep.choices()));
|
||||
|
||||
combo.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return combo;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.StringProperty;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
* Manages the UI form for rule exclusion fields for a designated property rule.
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class ExclusionPanelManager extends AbstractRulePanelManager {
|
||||
|
||||
private Text excludeWidget;
|
||||
private Text xpathWidget;
|
||||
private Composite excludeColour;
|
||||
private Composite xPathColour;
|
||||
private ColourManager colourManager;
|
||||
|
||||
/**
|
||||
* Constructor for ExclusionPanelManager.
|
||||
* @param listener ValueChangeListener
|
||||
*/
|
||||
public ExclusionPanelManager(ValueChangeListener listener) {
|
||||
super(listener);
|
||||
}
|
||||
|
||||
private void addListeners(final Text control, final StringProperty desc, final Control colourWindow) {
|
||||
|
||||
addTextListeners(control, desc);
|
||||
|
||||
control.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
colourWindow.setBackground(
|
||||
colourManager.colourFor(control.getText())
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parent Composite
|
||||
* @param regexExclusionLabel String
|
||||
* @param xpathExclusionLabel String
|
||||
* @return Control
|
||||
*/
|
||||
public Control setupOn(Composite parent, String regexExclusionLabel, String xpathExclusionLabel) {
|
||||
|
||||
colourManager = new ColourManager(parent.getDisplay());
|
||||
|
||||
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
|
||||
Composite panel = new Composite(parent, 0);
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
panel.setLayout(layout);
|
||||
|
||||
Label labelA = new Label(panel, 0);
|
||||
labelA.setText(regexExclusionLabel);
|
||||
gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gridData.horizontalSpan = 2;
|
||||
labelA.setLayoutData(gridData);
|
||||
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
excludeWidget = new Text(panel, SWT.BORDER | SWT.WRAP | SWT.MULTI);
|
||||
gridData = new GridData(GridData.FILL_BOTH);
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
gridData.horizontalSpan = 1;
|
||||
excludeWidget.setLayoutData(gridData);
|
||||
|
||||
excludeColour = new Composite(panel, SWT.BORDER);
|
||||
addListeners(excludeWidget, Rule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR, excludeColour);
|
||||
|
||||
Label labelB = new Label(panel, 0);
|
||||
labelB.setText(xpathExclusionLabel);
|
||||
gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gridData.horizontalSpan = 2;
|
||||
labelB.setLayoutData(gridData);
|
||||
|
||||
gridData = new GridData(GridData.FILL_BOTH);
|
||||
gridData.horizontalSpan = 1;
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
xpathWidget = new Text(panel, SWT.BORDER | SWT.WRAP | SWT.MULTI);
|
||||
xpathWidget.setLayoutData(gridData);
|
||||
|
||||
xPathColour = new Composite(panel, SWT.BORDER);
|
||||
xPathColour.setSize(1,1);
|
||||
addListeners(xpathWidget, Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR, xPathColour);
|
||||
|
||||
panel.pack();
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method showRule.
|
||||
* @param rule Rule
|
||||
*/
|
||||
public void showRule(Rule rule) {
|
||||
|
||||
currentRule = rule;
|
||||
|
||||
if (rule == null) {
|
||||
shutdown(excludeWidget);
|
||||
shutdown(xpathWidget);
|
||||
return;
|
||||
}
|
||||
|
||||
show(excludeWidget, rule.getProperty(Rule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR));
|
||||
show(xpathWidget, rule.getProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR));
|
||||
}
|
||||
}
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class FormArranger {
|
||||
|
||||
private final Composite parent;
|
||||
private final Map<Class, EditorFactory> editorFactoriesByValueType;
|
||||
private final ValueChangeListener changeListener;
|
||||
private Rule rule;
|
||||
|
||||
private Control[][] widgets;
|
||||
|
||||
/**
|
||||
* Constructor for FormArranger.
|
||||
* @param theParent Composite
|
||||
* @param factories Map<Class,EditorFactory>
|
||||
*/
|
||||
public FormArranger(Composite theParent, Map<Class, EditorFactory> factories, ValueChangeListener listener) {
|
||||
parent = theParent;
|
||||
editorFactoriesByValueType = factories;
|
||||
changeListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method factoryFor.
|
||||
* @param desc PropertyDescriptor
|
||||
* @return EditorFactory
|
||||
*/
|
||||
private EditorFactory factoryFor(PropertyDescriptor<?> desc) {
|
||||
return editorFactoriesByValueType.get(desc.type());
|
||||
}
|
||||
|
||||
private void clearChildren() {
|
||||
Control[] kids = parent.getChildren();
|
||||
for (int i=0; i<kids.length; i++) kids[i].dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method arrangeFor.
|
||||
* @param theRule Rule
|
||||
*/
|
||||
public void arrangeFor(Rule theRule) {
|
||||
|
||||
if (rule == theRule) return;
|
||||
|
||||
clearChildren();
|
||||
rule = theRule;
|
||||
|
||||
if (rule == null) return;
|
||||
|
||||
Map<PropertyDescriptor<?>, Object> valuesByDescriptor = PMDPreferencePage.filteredPropertiesOf(rule);
|
||||
if (valuesByDescriptor.isEmpty()) return;
|
||||
|
||||
PropertyDescriptor<?>[] orderedDescs = (PropertyDescriptor[])valuesByDescriptor.keySet().toArray(new PropertyDescriptor[valuesByDescriptor.size()]);
|
||||
|
||||
int maxColumns = 2;
|
||||
int rowCount = 0; // count up the actual rows with widgets needed, not all have editors yet
|
||||
for (int i=0; i<orderedDescs.length; i++) {
|
||||
EditorFactory factory = factoryFor(orderedDescs[i]);
|
||||
if (factory == null) {
|
||||
System.out.println("No editor defined for: " + orderedDescs[i]);
|
||||
continue;
|
||||
}
|
||||
int colsReqd = factory.columnsRequired();
|
||||
maxColumns = Math.max(maxColumns, colsReqd);
|
||||
rowCount++;
|
||||
}
|
||||
|
||||
GridLayout layout = new GridLayout(maxColumns, false);
|
||||
parent.setLayout(layout);
|
||||
|
||||
widgets = new Control[rowCount][maxColumns];
|
||||
if (maxColumns < 1) return;
|
||||
|
||||
int rowsAdded = 0;
|
||||
for (int i=0; i<orderedDescs.length; i++) {
|
||||
if (addRowWidgets(factoryFor(orderedDescs[i]), rowsAdded, orderedDescs[i])) rowsAdded++;
|
||||
}
|
||||
|
||||
if (rowsAdded > 0) {
|
||||
parent.pack();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param factory EditorFactory
|
||||
* @param rowIndex int
|
||||
* @param desc PropertyDescriptor
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean addRowWidgets(EditorFactory factory, int rowIndex, PropertyDescriptor<?> desc) {
|
||||
|
||||
if (factory == null) return false;
|
||||
|
||||
int columns = factory.columnsRequired();
|
||||
for (int i=0; i<columns; i++) { // add all the labels & controls necessary on each row
|
||||
widgets[rowIndex][i] = factory.newEditorOn(parent, i, desc, rule, changeListener);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.IntegerProperty;
|
||||
import net.sourceforge.pmd.lang.rule.properties.PropertyDescriptorWrapper;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Spinner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class IntegerEditorFactory extends AbstractEditorFactory {
|
||||
|
||||
public static final IntegerEditorFactory instance = new IntegerEditorFactory();
|
||||
|
||||
private IntegerEditorFactory() { }
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parent Composite
|
||||
* @param columnIndex int
|
||||
* @param desc PropertyDescriptor
|
||||
* @param rule Rule
|
||||
* @return Control
|
||||
* @see net.sourceforge.pmd.ui.preferences.br.EditorFactory#newEditorOn(Composite, int, PropertyDescriptor, Rule)
|
||||
*/
|
||||
public Control newEditorOn(Composite parent, int columnIndex, final PropertyDescriptor<?> desc, final Rule rule, final ValueChangeListener listener) {
|
||||
|
||||
if (columnIndex == 0) return addLabel(parent, desc);
|
||||
|
||||
if (columnIndex == 1) {
|
||||
|
||||
final Spinner spinner = new Spinner(parent, SWT.SINGLE | SWT.BORDER);
|
||||
|
||||
if (desc instanceof PropertyDescriptorWrapper) {
|
||||
|
||||
// TODO
|
||||
return spinner;
|
||||
}
|
||||
|
||||
|
||||
final IntegerProperty ip = (IntegerProperty)desc; // TODO - do I really have to do this?
|
||||
|
||||
int val = ((Number)rule.getProperty(desc)).intValue();
|
||||
|
||||
spinner.setMinimum(ip.lowerLimit().intValue());
|
||||
spinner.setMaximum(ip.upperLimit().intValue());
|
||||
spinner.setSelection(val);
|
||||
|
||||
spinner.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent event) {
|
||||
int newValue = spinner.getSelection();
|
||||
if (newValue == rule.getProperty(ip)) return;
|
||||
|
||||
rule.setProperty(ip, Integer.valueOf(newValue));
|
||||
listener.changed(desc, Integer.valueOf(newValue));
|
||||
}
|
||||
});
|
||||
|
||||
return spinner;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.IntegerMultiProperty;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
public class MultiIntegerEditorFactory extends AbstractMultiValueEditorFactory {
|
||||
|
||||
public static final MultiIntegerEditorFactory instance = new MultiIntegerEditorFactory();
|
||||
|
||||
private static final Integer[] emptyIntSet = new Integer[0];
|
||||
|
||||
private MultiIntegerEditorFactory() { }
|
||||
|
||||
private Integer[] currentIntegers(Text textWidget) {
|
||||
|
||||
String[] numberStrings = textWidgetValues(textWidget);
|
||||
if (numberStrings.length == 0) return emptyIntSet;
|
||||
|
||||
List<Integer> ints = new ArrayList<Integer>(numberStrings.length);
|
||||
|
||||
Integer intrg = null;
|
||||
|
||||
for (int i=0; i<numberStrings.length; i++) {
|
||||
try {
|
||||
intrg = Integer.parseInt(numberStrings[i]);
|
||||
} catch (Exception e) {
|
||||
// just eat it for now
|
||||
}
|
||||
if (intrg != null) ints.add(intrg);
|
||||
}
|
||||
return (Integer[]) ints.toArray(new Integer[ints.size()]);
|
||||
}
|
||||
|
||||
protected void configure(final Text textWidget, final PropertyDescriptor<?> desc, final Rule rule, final ValueChangeListener listener) {
|
||||
|
||||
final IntegerMultiProperty tmp = (IntegerMultiProperty)desc; // TODO - really necessary?
|
||||
|
||||
textWidget.addListener(SWT.FocusOut, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
Integer[] newValue = currentIntegers(textWidget);
|
||||
Integer[] existingValue = rule.getProperty(tmp);
|
||||
if (Util.areSemanticEquals(existingValue, newValue)) return;
|
||||
|
||||
rule.setProperty(tmp, newValue);
|
||||
fillWidget(textWidget, desc, rule); // display the accepted values
|
||||
listener.changed(desc, newValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class MultiStringEditorFactory extends AbstractMultiValueEditorFactory {
|
||||
|
||||
public static final MultiStringEditorFactory instance = new MultiStringEditorFactory();
|
||||
|
||||
private MultiStringEditorFactory() { }
|
||||
|
||||
protected void configure(final Text textWidget, final PropertyDescriptor<?> desc, final Rule rule, final ValueChangeListener listener) {
|
||||
|
||||
final StringMultiProperty smp = (StringMultiProperty)desc; // TODO - really necessary?
|
||||
|
||||
textWidget.addListener(SWT.FocusOut, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
String[] newValues = textWidgetValues(textWidget);
|
||||
String[] existingValues = rule.getProperty(smp);
|
||||
if (Util.areSemanticEquals(existingValues, newValues)) return;
|
||||
|
||||
rule.setProperty(smp, newValues);
|
||||
fillWidget(textWidget, desc, rule); // reload with latest scrubbed values
|
||||
listener.changed(desc, newValues);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.TypeMultiProperty;
|
||||
import net.sourceforge.pmd.util.ClassUtil;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class MultiTypeEditorFactory extends AbstractMultiValueEditorFactory {
|
||||
|
||||
public static final MultiTypeEditorFactory instance = new MultiTypeEditorFactory();
|
||||
|
||||
private MultiTypeEditorFactory() { }
|
||||
|
||||
public static String[] shortNamesFor(Class[] types) {
|
||||
String[] typeNames = new String[types.length];
|
||||
for (int i=0; i<typeNames.length; i++) {
|
||||
typeNames[i] = ClassUtil.asShortestName(types[i]);
|
||||
}
|
||||
return typeNames;
|
||||
}
|
||||
|
||||
protected void fillWidget(Text textWidget, PropertyDescriptor<?> desc, Rule rule) {
|
||||
|
||||
Class[] values = (Class[])rule.getProperty(desc);
|
||||
if (values == null) {
|
||||
textWidget.setText("");
|
||||
return;
|
||||
}
|
||||
|
||||
String[] typeNames = shortNamesFor(values);
|
||||
|
||||
textWidget.setText(values == null ? "" : StringUtil.asString(typeNames, delimiter + ' '));
|
||||
}
|
||||
|
||||
private Class[] currentTypes(Text textWidget) {
|
||||
|
||||
String[] typeNames = textWidgetValues(textWidget);
|
||||
if (typeNames.length == 0) return ClassUtil.EMPTY_CLASS_ARRAY;
|
||||
|
||||
List<Class> types = new ArrayList<Class>(typeNames.length);
|
||||
|
||||
for (int i=0; i<typeNames.length; i++) {
|
||||
Class newType = TypeEditorFactory.typeFor(typeNames[i]);
|
||||
if (newType != null) types.add(newType);
|
||||
}
|
||||
return (Class[]) types.toArray(new Class[types.size()]);
|
||||
}
|
||||
|
||||
protected void configure(final Text textWidget, final PropertyDescriptor<?> desc, final Rule rule, final ValueChangeListener listener) {
|
||||
|
||||
final TypeMultiProperty tmp = (TypeMultiProperty)desc; // TODO - really necessary?
|
||||
|
||||
textWidget.addListener(SWT.FocusOut, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
Class[] newValue = currentTypes(textWidget);
|
||||
Class[] existingValue = rule.getProperty(tmp);
|
||||
if (Util.areSemanticEquals(existingValue, newValue)) return;
|
||||
|
||||
rule.setProperty(tmp, newValue);
|
||||
fillWidget(textWidget, desc, rule); // display the accepted values
|
||||
listener.changed(desc, newValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+1022
File diff suppressed because it is too large.
Load diff
+60
@@ -0,0 +1,60 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.TabFolder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class PerRulePropertyPanelManager extends AbstractRulePanelManager {
|
||||
|
||||
private Composite composite;
|
||||
private FormArranger formArranger;
|
||||
|
||||
private static final Map<Class, EditorFactory> editorFactoriesByPropertyType;
|
||||
|
||||
static {
|
||||
editorFactoriesByPropertyType = new HashMap<Class, EditorFactory>();
|
||||
|
||||
editorFactoriesByPropertyType.put(Boolean.class, BooleanEditorFactory.instance);
|
||||
editorFactoriesByPropertyType.put(String.class, StringEditorFactory.instance);
|
||||
editorFactoriesByPropertyType.put(Integer.class, IntegerEditorFactory.instance);
|
||||
editorFactoriesByPropertyType.put(Float.class, RealNumberEditorFactory.instance);
|
||||
editorFactoriesByPropertyType.put(Double.class, RealNumberEditorFactory.instance);
|
||||
editorFactoriesByPropertyType.put(Object.class, EnumerationEditorFactory.instance);
|
||||
editorFactoriesByPropertyType.put(Character.class, CharacterEditorFactory.instance);
|
||||
|
||||
editorFactoriesByPropertyType.put(Class.class, TypeEditorFactory.instance);
|
||||
editorFactoriesByPropertyType.put(Class[].class, MultiTypeEditorFactory.instance);
|
||||
editorFactoriesByPropertyType.put(String[].class, MultiStringEditorFactory.instance);
|
||||
editorFactoriesByPropertyType.put(Integer[].class, MultiIntegerEditorFactory.instance);
|
||||
}
|
||||
|
||||
public PerRulePropertyPanelManager(ValueChangeListener theListener) {
|
||||
super(theListener);
|
||||
}
|
||||
|
||||
public Control setupOn(TabFolder parent, ValueChangeListener changeListener) {
|
||||
|
||||
composite = new Composite(parent, SWT.NONE);
|
||||
|
||||
formArranger = new FormArranger(composite, editorFactoriesByPropertyType, changeListener);
|
||||
|
||||
return composite;
|
||||
}
|
||||
|
||||
public void showRule(Rule rule) {
|
||||
|
||||
currentRule = rule;
|
||||
|
||||
formArranger.arrangeFor(rule);
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public interface PropertyChangeListener {
|
||||
|
||||
void changed(PropertyDescriptor<?> descriptor, Object newValue);
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import net.sourceforge.pmd.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.rule.properties.FloatProperty;
|
||||
import net.sourceforge.pmd.lang.rule.properties.PropertyDescriptorWrapper;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class RealNumberEditorFactory extends AbstractEditorFactory {
|
||||
|
||||
public static final RealNumberEditorFactory instance = new RealNumberEditorFactory();
|
||||
|
||||
|
||||
private RealNumberEditorFactory() { }
|
||||
|
||||
public Control newEditorOn(Composite parent, int columnIndex, final PropertyDescriptor<?> desc, final Rule rule, final ValueChangeListener listener) {
|
||||
|
||||
if (columnIndex == 0) return addLabel(parent, desc);
|
||||
|
||||
if (columnIndex == 1) {
|
||||
|
||||
final Text text = new Text(parent, SWT.SINGLE); // TODO use a number-only widget
|
||||
|
||||
if (desc instanceof PropertyDescriptorWrapper) {
|
||||
|
||||
// TODO
|
||||
return text;
|
||||
}
|
||||
|
||||
Number val = (Number)rule.getProperty(desc);
|
||||
text.setText(val == null ? "" : val.toString());
|
||||
|
||||
final FloatProperty fp = (FloatProperty)desc;
|
||||
|
||||
text.addListener(SWT.FocusOut, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
String newValue = text.getText();
|
||||
|
||||
rule.setProperty(fp, Float.valueOf(newValue));
|
||||
listener.changed(fp, Float.valueOf(newValue));
|
||||
}
|
||||
});
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package net.sourceforge.pmd.eclipse.ui.preferences.br;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
import org.eclipse.swt.widgets.TreeColumn;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Brian Remedios
|
||||
*/
|
||||
public class RuleColumnDescriptor {
|
||||
|
||||
private String label;
|
||||
private int alignment;
|
||||
private int width;
|
||||
private RuleFieldAccessor accessor;
|
||||
private boolean isResizeable;
|
||||
private CellPainterBuilder painterBuilder;
|
||||
|
||||
public static final RuleColumnDescriptor name = new RuleColumnDescriptor("Name", SWT.LEFT, 210, RuleFieldAccessor.name, true);
|
||||
public static final RuleColumnDescriptor ruleSetName = new RuleColumnDescriptor("Rule set", SWT.LEFT, 160, RuleFieldAccessor.ruleSetName, true);
|
||||
public static final RuleColumnDescriptor priority = new RuleColumnDescriptor("Priority", SWT.RIGHT, 53, RuleFieldAccessor.priority, false);
|
||||
public static final RuleColumnDescriptor priorityName = new RuleColumnDescriptor("Priority Name", SWT.LEFT, 80, RuleFieldAccessor.priorityName, true);
|
||||
public static final RuleColumnDescriptor since = new RuleColumnDescriptor("Since", SWT.RIGHT, 46, RuleFieldAccessor.since, false);
|
||||
public static final RuleColumnDescriptor usesDFA = new RuleColumnDescriptor("DFA", SWT.LEFT, 60, RuleFieldAccessor.usesDFA, false);
|
||||
public static final RuleColumnDescriptor externalURL = new RuleColumnDescriptor("URL", SWT.LEFT, 100, RuleFieldAccessor.url, true);
|
||||
public static final RuleColumnDescriptor properties = new RuleColumnDescriptor("Properties", SWT.LEFT, 100, RuleFieldAccessor.properties, true);
|
||||
public static final RuleColumnDescriptor minLangVers = new RuleColumnDescriptor("Min Ver", SWT.LEFT, 30, RuleFieldAccessor.minLanguageVersion, false);
|
||||
|
||||
public static final RuleColumnDescriptor exampleCount = new RuleColumnDescriptor("Examples", SWT.RIGHT, 20, RuleFieldAccessor.exampleCount, false);
|
||||
public static final RuleColumnDescriptor ruleType = new RuleColumnDescriptor("Type", SWT.LEFT, 20, RuleFieldAccessor.ruleType, false);
|
||||
public static final RuleColumnDescriptor filterExpression = new RuleColumnDescriptor("V.Regex", SWT.RIGHT, 20, RuleFieldAccessor.violationRegex, true);
|
||||
public static final RuleColumnDescriptor violateXPath = new RuleColumnDescriptor("Filter", SWT.RIGHT, 20, RuleFieldAccessor.violationXPath, true);
|
||||
|
||||
/**
|
||||
* @param theLabel String
|
||||
* @param theAlignment int
|
||||
* @param theWidth int
|
||||
* @param theAccessor RuleFieldAccessor
|
||||
* @param resizableFlag boolean
|
||||
*/
|
||||
public RuleColumnDescriptor(String theLabel, int theAlignment, int theWidth, RuleFieldAccessor theAccessor, boolean resizableFlag) {
|
||||
this(theLabel,theAlignment,theWidth,theAccessor,resizableFlag, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param theLabel String
|
||||
* @param theAlignment int
|
||||
* @param theWidth int
|
||||
* @param theAccessor RuleFieldAccessor
|
||||
* @param resizableFlag boolean
|
||||
* @param thePainterBuilder CellPainterBuilder
|
||||
*/
|
||||
public RuleColumnDescriptor(String theLabel, int theAlignment, int theWidth, RuleFieldAccessor theAccessor, boolean resizableFlag, CellPainterBuilder thePainterBuilder) {
|
||||
label = theLabel;
|
||||
alignment = theAlignment;
|
||||
width = theWidth;
|
||||
accessor = theAccessor;
|
||||
isResizeable = resizableFlag;
|
||||
painterBuilder = thePainterBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parent Tree
|
||||
* @return TreeColumn
|
||||
*/
|
||||
public TreeColumn newTreeColumnFor(Tree parent, int columnIndex, final RuleSortListener sortListener) {
|
||||
TreeColumn tc = new TreeColumn(parent, alignment);
|
||||
tc.setText(label);
|
||||
tc.setWidth(width);
|
||||
tc.setResizable(isResizeable);
|
||||
|
||||
tc.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
sortListener.sortBy(accessor);
|
||||
}
|
||||
});
|
||||
|
||||
if (painterBuilder != null) {
|
||||
painterBuilder.addPainterFor(tc.getParent(), columnIndex, accessor);
|
||||
}
|
||||
|
||||
return tc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
public String label() { return label; }
|
||||
|
||||
/**
|
||||
* @return RuleFieldAccessor
|
||||
*/
|
||||
public RuleFieldAccessor accessor() { return accessor; }
|
||||
}
|
||||
Loaded 30 of 42 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user