this.project = project;
final ViolationTableModel violationTableModel = new ViolationTableModel();
final JTabbedPane tabbedPane = new JTabbedPane();
final JXTable violationsTable = new JXTable(violationTableModel);
final SonarTreeModel treeModel = new SonarTreeModel(true);
final JXTree violationsTree = new JXTree(treeModel);
violationsTree.setShowsRootHandles(true);
final AnAction displayDescriptionAction = new DisplayDescriptionAction(violationsTree);
TreeSelectionListener mySelectionListener = new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (e.getNewLeadSelectionPath() == null)
return;
Object selection = e.getNewLeadSelectionPath().getLastPathComponent();
if (selection instanceof SonarTreeModel.ViolationLabel) {
final SonarTreeModel.ViolationLabel violationLabel = (SonarTreeModel.ViolationLabel) selection;
if (violationLabel.getLine() != null) {
DataManager.getInstance().getDataContextFromFocus().doWhenDone(new AsyncResult.Handler<DataContext>() {
@Override
public void run(DataContext dataContext) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, violationLabel.getVirtualFile(), violationLabel.getLine() - 1, 0);
descriptor.navigate(false);
}
});
}
}
}
};
downloadRules();
violationsTree.getSelectionModel().addTreeSelectionListener(mySelectionListener);
violationsTree.setEditable(false);
violationsTree.setCellRenderer(cellRenderer);
violationsTree.setRootVisible(false);
if (LastInspectionResult.getInstance().getViolations() != null)
treeModel.setViolations(LastInspectionResult.getInstance().getViolations());
violationsTable.addHighlighter(new ToolTipHighlighter(HighlightPredicate.IS_TEXT_TRUNCATED));
violationsTable.setFillsViewportHeight(true);
violationsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
violationsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
violationsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
ListSelectionModel listSelectionModel = (ListSelectionModel) e.getSource();
if (!listSelectionModel.isSelectionEmpty()) {
Integer selectionIndex = listSelectionModel.getMinSelectionIndex();
final Violation violation = violationTableModel.getViolation(violationsTable.convertRowIndexToModel(selectionIndex));
if (violation.getLine() != null) {
DataManager.getInstance().getDataContextFromFocus().doWhenDone(new AsyncResult.Handler<DataContext>() {
@Override
public void run(DataContext dataContext) {
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, violationTableModel.getCurrentVirtualFile(), violation.getLine() - 1, 0);
descriptor.navigate(false);
}
});
}
}
}
});
SonarTreeModel localTreeModel = new SonarTreeModel(false);
final JXTree localViolationsTree = new JXTree(localTreeModel);
localViolationsTree.setShowsRootHandles(true);
localViolationsTree.getSelectionModel().addTreeSelectionListener(mySelectionListener);
localViolationsTree.setCellRenderer(cellRenderer);
localViolationsTree.setRootVisible(false);