Examples of ViolationTableModel


Examples of org.sonar.ide.intellij.model.ViolationTableModel

    }

    private SonarToolWindow(final Project project, final ToolWindow toolWindow) {
        this.toolWindow = toolWindow;
        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);
                            }
                        });
                    }
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.