Loop conversions, extURL validation, minor ui cleanup
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@6871 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
1 parent
37b2f9a3ab
commit
beb9f12d23
12 files changed
+138
-122
No files matched your search
+10
-5
@@ -382,8 +382,8 @@ public class PMDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
label.setText(comboLabel);
|
||||
|
||||
final Combo combo = new Combo(panel, SWT.READ_ONLY);
|
||||
combo.setItems(SWTUtil.labelsIn(groupingChoices,1));
|
||||
combo.select(groupingChoices.length - 1);
|
||||
combo.setItems(SWTUtil.labelsIn(groupingChoices, 1));
|
||||
combo.select(groupingChoices.length - 1); // picks last one by default TODO make it a persistent preference
|
||||
|
||||
combo.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
@@ -423,13 +423,14 @@ public class PMDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
*/
|
||||
private RulePropertyManager buildPropertyTab(TabFolder parent, int index, String title) {
|
||||
|
||||
TabItem propertyTab = new TabItem(parent, 0, index);
|
||||
propertyTab.setText(title);
|
||||
TabItem tab = new TabItem(parent, 0, index);
|
||||
tab.setText(title);
|
||||
|
||||
PerRulePropertyPanelManager manager = new PerRulePropertyPanelManager(this);
|
||||
propertyTab.setControl(
|
||||
tab.setControl(
|
||||
manager.setupOn(parent, this)
|
||||
);
|
||||
manager.tab(tab);
|
||||
return manager;
|
||||
}
|
||||
|
||||
@@ -446,6 +447,7 @@ public class PMDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
tab.setControl(
|
||||
manager.setupOn(parent)
|
||||
);
|
||||
manager.tab(tab);
|
||||
return manager;
|
||||
}
|
||||
|
||||
@@ -462,6 +464,7 @@ public class PMDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
tab.setControl(
|
||||
manager.setupOn(parent)
|
||||
);
|
||||
manager.tab(tab);
|
||||
return manager;
|
||||
}
|
||||
|
||||
@@ -469,6 +472,7 @@ public class PMDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
*
|
||||
* @param parent TabFolder
|
||||
* @param index int
|
||||
* @param title String
|
||||
*/
|
||||
private RulePropertyManager buildUsageTab(TabFolder parent, int index, String title) {
|
||||
|
||||
@@ -483,6 +487,7 @@ public class PMDPreferencePage extends PreferencePage implements IWorkbenchPrefe
|
||||
"XPath exclusion expression"
|
||||
)
|
||||
);
|
||||
manager.tab(tab);
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ public class RuleGroup implements Comparable<RuleGroup> {
|
||||
|
||||
Arrays.sort(sortedRules, ruleComparator);
|
||||
rules.clear();
|
||||
for (int i=0;i<sortedRules.length; i++) rules.add((Rule)sortedRules[i]);
|
||||
for (Object rule : sortedRules) rules.add((Rule)rule);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+9
-9
@@ -76,12 +76,12 @@ public class RuleSelection {
|
||||
|
||||
if (ruleItems == null) return;
|
||||
|
||||
for (int i=0; i<ruleItems.length; i++) {
|
||||
if (ruleItems[i] instanceof Rule) {
|
||||
((Rule)ruleItems[i]).setPriority(priority);
|
||||
for (Object ruleItem : ruleItems) {
|
||||
if (ruleItem instanceof Rule) {
|
||||
((Rule)ruleItem).setPriority(priority);
|
||||
}
|
||||
if (ruleItems[i] instanceof RuleGroup) {
|
||||
((RuleGroup)ruleItems[i]).setPriority(priority);
|
||||
if (ruleItem instanceof RuleGroup) {
|
||||
((RuleGroup)ruleItem).setPriority(priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,12 +105,12 @@ public class RuleSelection {
|
||||
return selections;
|
||||
}
|
||||
|
||||
for (int i=0; i<ruleItems.length; i++) {
|
||||
if (ruleItems[i] instanceof Rule) {
|
||||
selections.add((Rule)ruleItems[i]);
|
||||
for (Object ruleItem : ruleItems) {
|
||||
if (ruleItem instanceof Rule) {
|
||||
selections.add((Rule)ruleItem);
|
||||
continue;
|
||||
} else {
|
||||
Rule[] rules = ((RuleGroup)ruleItems[i]).rules();
|
||||
Rule[] rules = ((RuleGroup)ruleItem).rules();
|
||||
for (int r=0; r<rules.length; r++) selections.add(rules[r]);
|
||||
}
|
||||
}
|
||||
|
||||
+33
@@ -3,13 +3,17 @@ package net.sourceforge.pmd.eclipse.ui.preferences.panelmanagers;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.eclipse.ui.preferences.br.RuleSelection;
|
||||
import net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener;
|
||||
import net.sourceforge.pmd.eclipse.util.ColourManager;
|
||||
import net.sourceforge.pmd.lang.rule.properties.StringProperty;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Link;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.TabItem;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
/**
|
||||
@@ -18,23 +22,32 @@ import org.eclipse.swt.widgets.Text;
|
||||
*/
|
||||
public abstract class AbstractRulePanelManager implements RulePropertyManager {
|
||||
|
||||
private TabItem tab;
|
||||
protected RuleSelection rules;
|
||||
final protected ValueChangeListener changeListener;
|
||||
|
||||
protected static Color textColour;
|
||||
protected static Color errorColour;
|
||||
protected static Color disabledColour;
|
||||
|
||||
public AbstractRulePanelManager(ValueChangeListener theListener) {
|
||||
changeListener = theListener;
|
||||
}
|
||||
|
||||
public void tab(TabItem theTab) { tab = theTab; }
|
||||
|
||||
public void manage(RuleSelection theRules) {
|
||||
rules = theRules;
|
||||
|
||||
if (rules.hasMultipleRules() && !canManageMultipleRules()) {
|
||||
setVisible(false);
|
||||
clearControls();
|
||||
// tab.setImage(ResourceManager.imageFor(PMDUiConstants.ICON_FILTER));
|
||||
return;
|
||||
}
|
||||
|
||||
setVisible(true);
|
||||
// tab.setImage(null);
|
||||
adapt();
|
||||
}
|
||||
|
||||
@@ -59,6 +72,16 @@ public abstract class AbstractRulePanelManager implements RulePropertyManager {
|
||||
return rules.soleRule();
|
||||
}
|
||||
|
||||
protected void initializeOn(Composite parent) {
|
||||
|
||||
if (errorColour != null) return;
|
||||
|
||||
ColourManager clrMgr = ColourManager.managerFor(parent.getDisplay());
|
||||
errorColour = clrMgr.colourFor(new int[] { 255, 0, 0 }); // red
|
||||
textColour = clrMgr.colourFor(new int[] { 0, 0, 0 }); // black
|
||||
disabledColour = clrMgr.colourFor(new int[] {128, 128, 128}); // grey
|
||||
}
|
||||
|
||||
/**
|
||||
* @param property StringProperty
|
||||
* @param newValue String
|
||||
@@ -95,4 +118,14 @@ public abstract class AbstractRulePanelManager implements RulePropertyManager {
|
||||
control.setText(value == null ? "" : value);
|
||||
control.setEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method newTextField.
|
||||
* @param parent Composite
|
||||
* @return Text
|
||||
*/
|
||||
protected Text newTextField(Composite parent) {
|
||||
|
||||
return new Text(parent, SWT.BORDER | SWT.WRAP | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
}
|
||||
}
|
||||
+32
-54
@@ -5,6 +5,7 @@ import java.net.URL;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.eclipse.ui.preferences.br.ValueChangeListener;
|
||||
import net.sourceforge.pmd.eclipse.util.ColourManager;
|
||||
import net.sourceforge.pmd.util.StringUtil;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
@@ -12,6 +13,7 @@ import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
@@ -37,7 +39,7 @@ public class DescriptionPanelManager extends AbstractRulePanelManager {
|
||||
private Button browseButton;
|
||||
private Label messageLabel;
|
||||
private Text messageField;
|
||||
|
||||
|
||||
public DescriptionPanelManager(ValueChangeListener theListener) {
|
||||
super(theListener);
|
||||
}
|
||||
@@ -58,21 +60,22 @@ public class DescriptionPanelManager extends AbstractRulePanelManager {
|
||||
messageLabel.setVisible(flag);
|
||||
messageField.setVisible(flag);
|
||||
}
|
||||
|
||||
|
||||
public Control setupOn(Composite parent) {
|
||||
|
||||
initializeOn(parent);
|
||||
|
||||
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
|
||||
Composite panel = new Composite(parent, 0);
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
layout.verticalSpacing = 0;
|
||||
layout.marginBottom = 0;
|
||||
GridLayout layout = new GridLayout(3, false);
|
||||
panel.setLayout(layout);
|
||||
|
||||
descriptionBox = buildDescriptionBox(panel);
|
||||
descriptionBox = newTextField(panel);
|
||||
gridData = new GridData(GridData.FILL_BOTH);
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
gridData.horizontalSpan = 1;
|
||||
gridData.horizontalSpan = 3;
|
||||
descriptionBox.setLayoutData(gridData);
|
||||
|
||||
descriptionBox.addListener(SWT.FocusOut, new Listener() {
|
||||
@@ -90,54 +93,29 @@ public class DescriptionPanelManager extends AbstractRulePanelManager {
|
||||
}
|
||||
});
|
||||
|
||||
Composite urlPanel = buildExternalUrlPanel(panel, "External URL:");
|
||||
gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gridData.horizontalSpan = 2;
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
urlPanel.setLayoutData(gridData);
|
||||
|
||||
Composite messagePanel = buildMessagePanel(panel, "Message:");
|
||||
gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gridData.horizontalSpan = 2;
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
messagePanel.setLayoutData(gridData);
|
||||
buildExternalUrlPanel(panel, "External URL:");
|
||||
buildMessagePanel(panel, "Message:");
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method buildDescriptionBox.
|
||||
* @param parent Composite
|
||||
* @return Text
|
||||
*/
|
||||
private Text buildDescriptionBox(Composite parent) {
|
||||
|
||||
return new Text(parent, SWT.BORDER | SWT.WRAP | SWT.MULTI);
|
||||
}
|
||||
|
||||
private Composite buildExternalUrlPanel(Composite parent, String urlLabel) {
|
||||
|
||||
Composite panel = new Composite(parent, 0);
|
||||
GridLayout layout = new GridLayout(3, false);
|
||||
layout.verticalSpacing = 0;
|
||||
layout.marginBottom = 0;
|
||||
panel.setLayout(layout);
|
||||
|
||||
private void buildExternalUrlPanel(Composite parent, String urlLabel) {
|
||||
|
||||
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
|
||||
|
||||
extURLLabel = new Label(panel, 0);
|
||||
extURLLabel = new Label(parent, 0);
|
||||
extURLLabel.setText(urlLabel);
|
||||
gridData.horizontalSpan = 1;
|
||||
gridData.grabExcessHorizontalSpace = false;
|
||||
extURLLabel.setLayoutData(gridData);
|
||||
|
||||
externalURLField = new Text(panel, SWT.BORDER);
|
||||
externalURLField = new Text(parent, SWT.BORDER);
|
||||
gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gridData.horizontalSpan = 1;
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
externalURLField.setLayoutData(gridData);
|
||||
|
||||
browseButton = buildExternalInfoUrlButton(panel);
|
||||
browseButton = buildExternalInfoUrlButton(parent);
|
||||
gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
|
||||
gridData.horizontalSpan = 1;
|
||||
browseButton.setLayoutData(gridData);
|
||||
@@ -152,25 +130,19 @@ public class DescriptionPanelManager extends AbstractRulePanelManager {
|
||||
adjustBrowseButton();
|
||||
}
|
||||
});
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private Composite buildMessagePanel(Composite parent, String messageLbl) {
|
||||
|
||||
Composite panel = new Composite(parent, 0);
|
||||
GridLayout layout = new GridLayout(3, false);
|
||||
panel.setLayout(layout);
|
||||
|
||||
private void buildMessagePanel(Composite parent, String messageLbl) {
|
||||
|
||||
GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
|
||||
|
||||
messageLabel = new Label(panel, 0);
|
||||
messageLabel = new Label(parent, 0);
|
||||
messageLabel.setText(messageLbl);
|
||||
gridData.horizontalSpan = 1;
|
||||
gridData.grabExcessHorizontalSpace = false;
|
||||
messageLabel.setLayoutData(gridData);
|
||||
|
||||
messageField = new Text(panel, SWT.BORDER);
|
||||
messageField = new Text(parent, SWT.BORDER);
|
||||
gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
gridData.horizontalSpan = 2;
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
@@ -181,8 +153,6 @@ public class DescriptionPanelManager extends AbstractRulePanelManager {
|
||||
handleMessageChange();
|
||||
}
|
||||
});
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void handleExternalURLChange() {
|
||||
@@ -254,16 +224,24 @@ public class DescriptionPanelManager extends AbstractRulePanelManager {
|
||||
if (StringUtil.isEmpty(url)) return false;
|
||||
|
||||
String urlUC = url.toUpperCase();
|
||||
return urlUC.startsWith("HTTP");
|
||||
if (!urlUC.startsWith("HTTP")) return false;
|
||||
|
||||
for (int i=0; i<url.length(); i++) {
|
||||
if (Character.isWhitespace(url.charAt(i))) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void adjustBrowseButton() {
|
||||
|
||||
String url = externalURLField.getText().trim();
|
||||
boolean isValid = isValidURL(url);
|
||||
|
||||
browseButton.setEnabled(
|
||||
isValidURL(url)
|
||||
);
|
||||
browseButton.setEnabled(isValid);
|
||||
externalURLField.setForeground(
|
||||
isValid ? textColour : errorColour
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+12
-24
@@ -23,7 +23,7 @@ import org.eclipse.swt.widgets.Text;
|
||||
*/
|
||||
public class ExamplePanelManager extends AbstractRulePanelManager {
|
||||
|
||||
private Text exampleBox;
|
||||
private Text exampleField;
|
||||
|
||||
public ExamplePanelManager(ValueChangeListener theListener) {
|
||||
super(theListener);
|
||||
@@ -32,12 +32,12 @@ public class ExamplePanelManager extends AbstractRulePanelManager {
|
||||
protected boolean canManageMultipleRules() { return false; }
|
||||
|
||||
protected void clearControls() {
|
||||
exampleBox.setText("");
|
||||
exampleField.setText("");
|
||||
}
|
||||
|
||||
protected void setVisible(boolean flag) {
|
||||
|
||||
exampleBox.setVisible(flag);
|
||||
exampleField.setVisible(flag);
|
||||
}
|
||||
|
||||
public Control setupOn(Composite parent) {
|
||||
@@ -48,18 +48,18 @@ public class ExamplePanelManager extends AbstractRulePanelManager {
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
panel.setLayout(layout);
|
||||
|
||||
exampleBox = buildDescriptionBox(panel);
|
||||
exampleField = newTextField(panel);
|
||||
gridData = new GridData(GridData.FILL_BOTH);
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
gridData.horizontalSpan = 1;
|
||||
exampleBox.setLayoutData(gridData);
|
||||
exampleField.setLayoutData(gridData);
|
||||
|
||||
exampleBox.addListener(SWT.FocusOut, new Listener() {
|
||||
exampleField.addListener(SWT.FocusOut, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
|
||||
Rule soleRule = soleRule();
|
||||
|
||||
String cleanValue = exampleBox.getText().trim();
|
||||
String cleanValue = exampleField.getText().trim();
|
||||
String existingValue = soleRule.getDescription();
|
||||
|
||||
if (StringUtil.areSemanticEquals(existingValue, cleanValue)) return;
|
||||
@@ -71,17 +71,7 @@ public class ExamplePanelManager extends AbstractRulePanelManager {
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method buildDescriptionBox.
|
||||
* @param parent Composite
|
||||
* @return Text
|
||||
*/
|
||||
private Text buildDescriptionBox(Composite parent) {
|
||||
|
||||
return new Text(parent, SWT.BORDER | SWT.WRAP | SWT.MULTI);
|
||||
}
|
||||
|
||||
|
||||
private void formatExampleOn(StringBuilder sb, String example) {
|
||||
// TODO - adjust for common leading whitespace on all lines - see StringUtil facilities
|
||||
// sb.append(example.trim());
|
||||
@@ -95,8 +85,8 @@ public class ExamplePanelManager extends AbstractRulePanelManager {
|
||||
if (trimDepth > 0) {
|
||||
lines = StringUtil.trimStartOn(lines, trimDepth);
|
||||
}
|
||||
for (int i=0; i<lines.length; i++) {
|
||||
sb.append(lines[i]).append(PMD.EOL);
|
||||
for (String line : lines) {
|
||||
sb.append(line).append(PMD.EOL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,11 +111,9 @@ public class ExamplePanelManager extends AbstractRulePanelManager {
|
||||
Rule soleRule = soleRule();
|
||||
|
||||
if (soleRule == null) {
|
||||
shutdown(exampleBox);
|
||||
// shutdown(externalURL);
|
||||
shutdown(exampleField);
|
||||
} else {
|
||||
show(exampleBox, examples(soleRule));
|
||||
// show(externalURL, "<a>"+soleRule.getExternalInfoUrl()+"</a>");
|
||||
show(exampleField, examples(soleRule));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -36,8 +36,7 @@ public class ExclusionPanelManager extends AbstractRulePanelManager {
|
||||
super(listener);
|
||||
}
|
||||
|
||||
protected boolean canManageMultipleRules() { return true; }
|
||||
|
||||
protected boolean canManageMultipleRules() { return true; }
|
||||
|
||||
protected void clearControls() {
|
||||
excludeWidget.setText("");
|
||||
@@ -95,7 +94,7 @@ public class ExclusionPanelManager extends AbstractRulePanelManager {
|
||||
*/
|
||||
public Control setupOn(Composite parent, String regexExclusionLabel, String xpathExclusionLabel) {
|
||||
|
||||
colourManager = new ColourManager(parent.getDisplay());
|
||||
colourManager = ColourManager.managerFor(parent.getDisplay());
|
||||
|
||||
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
|
||||
|
||||
@@ -112,7 +111,7 @@ public class ExclusionPanelManager extends AbstractRulePanelManager {
|
||||
|
||||
excludeColour = newColourPanel(panel, "Color code ");
|
||||
|
||||
excludeWidget = new Text(panel, SWT.BORDER | SWT.WRAP | SWT.MULTI);
|
||||
excludeWidget = newTextField(panel);
|
||||
gridData = new GridData(GridData.FILL_BOTH);
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
gridData.horizontalSpan = 2;
|
||||
@@ -131,7 +130,7 @@ public class ExclusionPanelManager extends AbstractRulePanelManager {
|
||||
gridData = new GridData(GridData.FILL_BOTH);
|
||||
gridData.horizontalSpan = 2;
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
xpathWidget = new Text(panel, SWT.BORDER | SWT.WRAP | SWT.MULTI);
|
||||
xpathWidget = newTextField(panel);
|
||||
xpathWidget.setLayoutData(gridData);
|
||||
|
||||
addListeners(xpathWidget, Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR, xPathColour);
|
||||
|
||||
+7
-7
@@ -49,8 +49,8 @@ public class FormArranger {
|
||||
|
||||
public void clearChildren() {
|
||||
Control[] kids = parent.getChildren();
|
||||
for (int i=0; i<kids.length; i++)
|
||||
kids[i].dispose();
|
||||
for (Control kid : kids)
|
||||
kid.dispose();
|
||||
parent.pack();
|
||||
rule = null;
|
||||
}
|
||||
@@ -76,10 +76,10 @@ public class FormArranger {
|
||||
|
||||
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]);
|
||||
for (PropertyDescriptor<?> desc: orderedDescs) {
|
||||
EditorFactory factory = factoryFor(desc);
|
||||
if (factory == null) {
|
||||
System.out.println("No editor defined for: " + orderedDescs[i]);
|
||||
System.out.println("No editor defined for: " + desc);
|
||||
continue;
|
||||
}
|
||||
int colsReqd = factory.columnsRequired();
|
||||
@@ -96,8 +96,8 @@ public class FormArranger {
|
||||
if (maxColumns < 1) return 0;
|
||||
|
||||
int rowsAdded = 0;
|
||||
for (int i=0; i<orderedDescs.length; i++) {
|
||||
if (addRowWidgets(factoryFor(orderedDescs[i]), rowsAdded, orderedDescs[i])) rowsAdded++;
|
||||
for (PropertyDescriptor<?> desc: orderedDescs) {
|
||||
if (addRowWidgets(factoryFor(desc), rowsAdded, desc)) rowsAdded++;
|
||||
}
|
||||
|
||||
if (rowsAdded > 0) {
|
||||
|
||||
+3
@@ -2,8 +2,11 @@ package net.sourceforge.pmd.eclipse.ui.preferences.panelmanagers;
|
||||
|
||||
import net.sourceforge.pmd.eclipse.ui.preferences.br.RuleSelection;
|
||||
|
||||
import org.eclipse.swt.widgets.TabItem;
|
||||
|
||||
|
||||
public interface RulePropertyManager {
|
||||
|
||||
public void tab(TabItem tab);
|
||||
public void manage(RuleSelection rules);
|
||||
}
|
||||
+6
-6
@@ -205,7 +205,7 @@ public class ReviewAction extends ViolationSelectionAction {
|
||||
System.getProperty("user.name", ""), new Date() });
|
||||
|
||||
// Copy the source code until the violation line not included
|
||||
StringBuffer sb = new StringBuffer(sourceCode.substring(0, offset));
|
||||
StringBuilder sb = new StringBuilder(sourceCode.substring(0, offset));
|
||||
|
||||
// Add the review comment
|
||||
sb.append(computeIndent(sourceCode, offset));
|
||||
@@ -275,21 +275,21 @@ public class ReviewAction extends ViolationSelectionAction {
|
||||
return indent.toString();
|
||||
}
|
||||
|
||||
private String readFile(IFile file) throws IOException, CoreException {
|
||||
public static String readFile(IFile file) throws IOException, CoreException {
|
||||
InputStream contents = file.getContents(true);
|
||||
InputStreamReader reader = new InputStreamReader(contents);
|
||||
|
||||
try {
|
||||
char[] buffer = new char[4096];
|
||||
StringBuilder stringBuffer = new StringBuilder(4096);
|
||||
StringBuilder sb = new StringBuilder(4096);
|
||||
while (reader.ready()) {
|
||||
int readCount = reader.read(buffer);
|
||||
if (readCount != -1) {
|
||||
stringBuffer.append(buffer, 0, readCount);
|
||||
sb.append(buffer, 0, readCount);
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuffer.toString();
|
||||
return sb.toString();
|
||||
|
||||
} finally {
|
||||
reader.close();
|
||||
@@ -297,7 +297,7 @@ public class ReviewAction extends ViolationSelectionAction {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper mehod to retreive an NLS string from its key
|
||||
* Helper method to retrieve an NLS string from its key
|
||||
*/
|
||||
private String getString(String key) {
|
||||
return PMDPlugin.getDefault().getStringTable().getString(key);
|
||||
|
||||
+20
-7
@@ -20,10 +20,28 @@ public class ColourManager {
|
||||
|
||||
private final Map<int[], Color> coloursByRGB = new HashMap<int[], Color>();
|
||||
|
||||
public ColourManager(Display theDisplay) {
|
||||
private static ColourManager instance;
|
||||
|
||||
public static ColourManager managerFor(Display display) {
|
||||
|
||||
if (instance == null) instance = new ColourManager(display);
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ColourManager(Display theDisplay) {
|
||||
display = theDisplay;
|
||||
}
|
||||
|
||||
public Color colourFor(int[] colourFractions) {
|
||||
|
||||
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 Color colourFor(String text) {
|
||||
|
||||
if (StringUtil.isEmpty(text)) return display.getSystemColor(SWT.COLOR_WHITE);
|
||||
@@ -46,12 +64,7 @@ public class ColourManager {
|
||||
(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;
|
||||
return colourFor(colourFractions);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
|
||||
+1
-4
@@ -1,13 +1,10 @@
|
||||
package net.sourceforge.pmd.eclipse.util;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.eclipse.ui.preferences.br.CellPainterBuilder;
|
||||
@@ -128,7 +125,7 @@ public class Util {
|
||||
|
||||
private ColourManager colorManagerFor(Display display) {
|
||||
if (colorManager != null) return colorManager;
|
||||
colorManager = new ColourManager(display);
|
||||
colorManager = ColourManager.managerFor(display);
|
||||
return colorManager;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user