Now differentiates btwn one file and several

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1473 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2003-02-24 22:35:46 +00:00
parent c4568d680d
commit e29986621b
3 changed files with 68 additions and 70 deletions

View File

@ -0,0 +1,45 @@
package net.sourceforge.pmd.jdeveloper;
import net.sourceforge.pmd.RuleViolation;
import oracle.ide.Ide;
import oracle.ide.editor.Editor;
import oracle.ide.model.Document;
import oracle.jdeveloper.ceditor.CodeEditor;
import javax.swing.DefaultListModel;
import javax.swing.DefaultListSelectionModel;
import java.util.Iterator;
import java.util.List;
public class JumpingSelectionModel extends DefaultListSelectionModel {
private DefaultListModel model;
public JumpingSelectionModel(DefaultListModel model) {
this.model = model;
}
public JumpingSelectionModel() {
setSelectionMode(SINGLE_SELECTION);
}
public void setSelectionInterval(int index0, int index1) {
int oldIndex = getMinSelectionIndex();
super.setSelectionInterval(index0, index1);
int newIndex = getMinSelectionIndex();
if (oldIndex != newIndex) {
RuleViolation rv = ((RuleViolationWrapper)model.getElementAt(newIndex)).getRV();
List editors = Ide.getEditorManager().getAllEditors();
for (Iterator i = editors.iterator(); i.hasNext();) {
Editor editor = (Editor)i.next();
Document doc = editor.getContext().getDocument();
if (doc.getLongLabel().equals(rv.getFilename()) && editor instanceof CodeEditor) {
Ide.getEditorManager().openDefaultEditorInFrame(editor.getContext());
((CodeEditor)editor).gotoLine(rv.getLine(), 0, false);
break;
}
}
}
}
}

View File

@ -95,24 +95,28 @@ public class Plugin implements Addin, Controller, ContextMenuListener {
public boolean handleEvent(IdeAction ideAction, Context context) {
if (ideAction.getCommandId() == CHECK_CMD_ID) {
try {
PMD pmd = new PMD();
RuleContext ctx = new RuleContext();
ctx.setReport(new Report());
ctx.setSourceCodeFilename(context.getDocument().getLongLabel());
SelectedRules rs = new SelectedRules();
pmd.processFile(context.getDocument().getInputStream(), rs.getSelectedRules(), ctx);
if (rvPage == null) {
rvPage = new RuleViolationPage();
}
if (!rvPage.isVisible()) {
rvPage.show();
}
rvPage.clearAll();
if (ctx.getReport().isEmpty()) {
JOptionPane.showMessageDialog(null, "No problems found", "PMD", JOptionPane.INFORMATION_MESSAGE);
if (resolveType(context.getDocument()) == PROJECT) {
} else {
for (Iterator i = ctx.getReport().iterator(); i.hasNext();) {
rvPage.add((RuleViolation)i.next());
PMD pmd = new PMD();
RuleContext ctx = new RuleContext();
ctx.setReport(new Report());
ctx.setSourceCodeFilename(context.getDocument().getLongLabel());
SelectedRules rs = new SelectedRules();
pmd.processFile(context.getDocument().getInputStream(), rs.getSelectedRules(), ctx);
if (rvPage == null) {
rvPage = new RuleViolationPage();
}
if (!rvPage.isVisible()) {
rvPage.show();
}
rvPage.clearAll();
if (ctx.getReport().isEmpty()) {
JOptionPane.showMessageDialog(null, "No problems found", "PMD", JOptionPane.INFORMATION_MESSAGE);
} else {
for (Iterator i = ctx.getReport().iterator(); i.hasNext();) {
rvPage.add((RuleViolation)i.next());
}
}
}
return true;

View File

@ -2,80 +2,30 @@ package net.sourceforge.pmd.jdeveloper;
import net.sourceforge.pmd.RuleViolation;
import oracle.ide.Ide;
import oracle.ide.editor.Editor;
import oracle.ide.layout.ViewId;
import oracle.ide.log.AbstractLogPage;
import oracle.ide.model.Document;
import oracle.jdeveloper.ceditor.CodeEditor;
import javax.swing.DefaultListModel;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import java.awt.Component;
import java.util.Iterator;
import java.util.List;
public class RuleViolationPage extends AbstractLogPage {
public class SingleSelectionModel extends DefaultListSelectionModel {
public SingleSelectionModel() {
setSelectionMode(SINGLE_SELECTION);
}
public void setSelectionInterval(int index0, int index1) {
int oldIndex = getMinSelectionIndex();
super.setSelectionInterval(index0, index1);
int newIndex = getMinSelectionIndex();
if (oldIndex != newIndex) {
updateSingleSelection(oldIndex, newIndex);
}
}
public void updateSingleSelection(int oldIndex, int newIndex) {
RuleViolation rv = ((RVWrapper)model.getElementAt(newIndex)).getRV();
List editors = Ide.getEditorManager().getAllEditors();
for (Iterator i = editors.iterator(); i.hasNext();) {
Editor editor = (Editor)i.next();
Document doc = editor.getContext().getDocument();
if (doc.getLongLabel().equals(rv.getFilename()) && editor instanceof CodeEditor) {
Ide.getEditorManager().openDefaultEditorInFrame(editor.getContext());
((CodeEditor)editor).gotoLine(rv.getLine(), 0, false);
break;
}
}
}
}
private static class RVWrapper {
private RuleViolation rv;
public RVWrapper(RuleViolation rv) {
this.rv = rv;
}
public RuleViolation getRV() {
return this.rv;
}
public String toString() {
return rv.getFilename() + ":" + rv.getLine() +":"+ rv.getDescription();
}
}
private DefaultListModel model = new DefaultListModel();
private JScrollPane scrollPane;
private JList list;
public RuleViolationPage() {
super(new ViewId("PMDPage", "PMD"), null, false);
list = new JList(model);
list.setSelectionModel(new SingleSelectionModel());
list.setSelectionModel(new JumpingSelectionModel(model));
scrollPane = new JScrollPane(list);
Ide.getLogManager().addPage(this);
}
public void add(RuleViolation ruleViolation) {
model.addElement(new RVWrapper(ruleViolation));
model.addElement(new RuleViolationWrapper(ruleViolation));
}
public Component getGUI() {
@ -86,5 +36,4 @@ public class RuleViolationPage extends AbstractLogPage {
super.clearAll();
model.clear();
}
}