diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java new file mode 100644 index 0000000000..34a3426a50 --- /dev/null +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/JumpingSelectionModel.java @@ -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; + } + } + } + } + +} diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java index d38f673dde..feab921d86 100644 --- a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/Plugin.java @@ -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; diff --git a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationPage.java b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationPage.java index a1892661fd..fdf6c6987f 100644 --- a/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationPage.java +++ b/pmd-jdeveloper/src/net/sourceforge/pmd/jdeveloper/RuleViolationPage.java @@ -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(); } - }