aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/viewer/ScannerReportViewerApp.java
blob: 3515263df7cdf533ffb45e6e878678f73b02d5ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/*
 * SonarQube
 * Copyright (C) 2009-2025 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.scanner.protocol.viewer;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import javax.annotation.CheckForNull;
import javax.swing.JEditorPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.sonar.core.util.CloseableIterator;
import org.sonar.scanner.protocol.output.FileStructure;
import org.sonar.scanner.protocol.output.FileStructure.Domain;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Changesets;
import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Changeset;
import org.sonar.scanner.protocol.output.ScannerReport.Component;
import org.sonar.scanner.protocol.output.ScannerReport.Issue;
import org.sonar.scanner.protocol.output.ScannerReport.Metadata;
import org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin;
import org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile;
import org.sonar.scanner.protocol.output.ScannerReportReader;

public class ScannerReportViewerApp {

  private JFrame frame;
  private ScannerReportReader reader;
  private Metadata metadata;
  private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
  private JTree componentTree;
  private JSplitPane splitPane;
  private JTabbedPane tabbedPane;
  private JScrollPane treeScrollPane;
  private JScrollPane componentDetailsTab;
  private JScrollPane highlightingTab;
  private JScrollPane symbolTab;
  private JEditorPane componentEditor;
  private JEditorPane highlightingEditor;
  private JEditorPane symbolEditor;
  private JScrollPane sourceTab;
  private JEditorPane sourceEditor;
  private JScrollPane coverageTab;
  private JEditorPane coverageEditor;
  private JScrollPane testsTab;
  private JEditorPane testsEditor;
  private TextLineNumber textLineNumber;
  private JScrollPane duplicationTab;
  private JEditorPane duplicationEditor;
  private JScrollPane issuesTab;
  private JEditorPane issuesEditor;
  private JScrollPane externalIssuesTab;
  private JEditorPane externalIssuesEditor;
  private JScrollPane measuresTab;
  private JEditorPane measuresEditor;
  private JScrollPane scmTab;
  private JEditorPane scmEditor;
  private JScrollPane activeRuleTab;
  private JEditorPane activeRuleEditor;
  private JScrollPane adHocRuleTab;
  private JEditorPane adHocRuleEditor;
  private JScrollPane qualityProfileTab;
  private JEditorPane qualityProfileEditor;
  private JScrollPane pluginTab;
  private JEditorPane pluginEditor;
  private JScrollPane cpdTextBlocksTab;
  private JEditorPane cpdTextBlocksEditor;
  private JScrollPane significantCodeTab;
  private JEditorPane significantCodeEditor;
  private JScrollPane metadataTab;
  private JEditorPane metadataEditor;

  /**
   * Create the application.
   */
  public ScannerReportViewerApp() {
    initialize();
  }

  /**
   * Launch the application.
   */
  public static void main(String[] args) {
    EventQueue.invokeLater(() -> {
      try {
        ScannerReportViewerApp window = new ScannerReportViewerApp();
        window.frame.setVisible(true);

        window.loadReport();
      } catch (Exception e) {
        e.printStackTrace();
      }
    });
  }

  private void loadReport() {
    final JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Choose scanner report directory");
    File lastReport = getLastUsedReport();
    if (lastReport != null) {
      fc.setCurrentDirectory(lastReport);
    }
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fc.setFileHidingEnabled(false);
    fc.setApproveButtonText("Open scanner report");
    int returnVal = fc.showOpenDialog(frame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fc.getSelectedFile();
      try {
        setLastUsedReport(file);
        loadReport(file);
      } catch (Exception e) {
        JOptionPane.showMessageDialog(frame, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        exit();
      }
    } else {
      exit();
    }

  }

  @CheckForNull
  private File getLastUsedReport() {
    File f = new File(System.getProperty("java.io.tmpdir"), ".last_batch_report_dir");
    if (f.exists()) {
      String path;
      try {
        path = FileUtils.readFileToString(f, StandardCharsets.UTF_8);
      } catch (IOException e) {
        return null;
      }
      File lastReport = new File(path);
      if (lastReport.exists() && lastReport.isDirectory()) {
        return lastReport;
      }
    }
    return null;
  }

  private void setLastUsedReport(File lastReport) throws IOException {

    File f = new File(System.getProperty("java.io.tmpdir"), ".last_batch_report_dir");
    String fullPath = lastReport.getAbsolutePath();
    FileUtils.write(f, fullPath, StandardCharsets.UTF_8);
  }

  private void exit() {
    frame.setVisible(false);
    frame.dispose();
  }

  private void loadReport(File file) {
    FileStructure fileStructure = new FileStructure(file);
    reader = new ScannerReportReader(fileStructure);
    metadata = reader.readMetadata();
    updateTitle();
    loadComponents();
    updateActiveRules();
    updateAdHocRules();
    updateQualityProfiles();
    updatePlugins();
    updateMetadata();
  }

  private void loadComponents() {
    int rootComponentRef = metadata.getRootComponentRef();
    Component component = reader.readComponent(rootComponentRef);
    DefaultMutableTreeNode project = createNode(component);
    loadChildren(component, project);
    getComponentTree().setModel(new DefaultTreeModel(project));
  }

  private static DefaultMutableTreeNode createNode(Component component) {
    return new DefaultMutableTreeNode(component) {
      @Override
      public String toString() {
        return getNodeName((Component) getUserObject());
      }
    };
  }

  private static String getNodeName(Component component) {
    switch (component.getType()) {
      case PROJECT:
      case MODULE:
        return component.getName();
      case DIRECTORY:
      case FILE:
        return component.getProjectRelativePath();
      default:
        throw new IllegalArgumentException("Unknow component type: " + component.getType());
    }
  }

  private void loadChildren(Component parentComponent, DefaultMutableTreeNode parentNode) {
    for (int ref : parentComponent.getChildRefList()) {
      Component child = reader.readComponent(ref);
      DefaultMutableTreeNode childNode = createNode(child);
      parentNode.add(childNode);
      loadChildren(child, childNode);
    }

  }

  private void updateTitle() {
    frame.setTitle(metadata.getProjectKey() + (StringUtils.isNotEmpty(metadata.getBranchName()) ? (" (" + metadata.getBranchName() + ")") : "") + " "
      + sdf.format(new Date(metadata.getAnalysisDate())));
  }

  private void updateDetails(Component component) {
    componentEditor.setText(component.toString());
    updateHighlighting(component);
    updateSymbols(component);
    updateSource(component);
    updateCoverage(component);
    updateDuplications(component);
    updateIssues(component);
    updateExternalIssues(component);
    updateMeasures(component);
    updateScm(component);
    updateCpdTextBlocks(component);
    updateSignificantCode(component);
  }

  private void updateCpdTextBlocks(Component component) {
    cpdTextBlocksEditor.setText("");
    if (reader.hasCoverage(component.getRef())) {
      try (CloseableIterator<ScannerReport.CpdTextBlock> it = reader.readCpdTextBlocks(component.getRef())) {
        while (it.hasNext()) {
          ScannerReport.CpdTextBlock textBlock = it.next();
          cpdTextBlocksEditor.getDocument().insertString(cpdTextBlocksEditor.getDocument().getLength(), textBlock + "\n", null);
        }
      } catch (Exception e) {
        throw new IllegalStateException("Can't read CPD text blocks for " + getNodeName(component), e);
      }
    }
  }

  private void updateSignificantCode(Component component) {
    significantCodeEditor.setText("");
    if (reader.hasCoverage(component.getRef())) {
      try (CloseableIterator<ScannerReport.LineSgnificantCode> it = reader.readComponentSignificantCode(component.getRef())) {
        if (it != null) {
          while (it.hasNext()) {
            ScannerReport.LineSgnificantCode textBlock = it.next();
            significantCodeEditor.getDocument().insertString(significantCodeEditor.getDocument().getLength(), textBlock + "\n", null);
          }
        }
      } catch (Exception e) {
        throw new IllegalStateException("Can't read significant code for " + getNodeName(component), e);
      }
    }
  }

  private void updateDuplications(Component component) {
    duplicationEditor.setText("");
    if (reader.hasCoverage(component.getRef())) {
      try (CloseableIterator<ScannerReport.Duplication> it = reader.readComponentDuplications(component.getRef())) {
        while (it.hasNext()) {
          ScannerReport.Duplication dup = it.next();
          duplicationEditor.getDocument().insertString(duplicationEditor.getDocument().getLength(), dup + "\n", null);
        }
      } catch (Exception e) {
        throw new IllegalStateException("Can't read duplications for " + getNodeName(component), e);
      }
    }
  }

  private void updateIssues(Component component) {
    issuesEditor.setText("");
    try (CloseableIterator<Issue> it = reader.readComponentIssues(component.getRef())) {
      while (it.hasNext()) {
        Issue issue = it.next();
        int offset = issuesEditor.getDocument().getLength();
        issuesEditor.getDocument().insertString(offset, issue.toString(), null);
      }
    } catch (Exception e) {
      throw new IllegalStateException("Can't read issues for " + getNodeName(component), e);
    }
  }

  private void updateExternalIssues(Component component) {
    externalIssuesEditor.setText("");
    try (CloseableIterator<ScannerReport.ExternalIssue> it = reader.readComponentExternalIssues(component.getRef())) {
      while (it.hasNext()) {
        ScannerReport.ExternalIssue issue = it.next();
        int offset = externalIssuesEditor.getDocument().getLength();
        externalIssuesEditor.getDocument().insertString(offset, issue.toString(), null);
      }
    } catch (Exception e) {
      throw new IllegalStateException("Can't read external issues for " + getNodeName(component), e);
    }
  }

  private void updateCoverage(Component component) {
    coverageEditor.setText("");
    try (CloseableIterator<ScannerReport.LineCoverage> it = reader.readComponentCoverage(component.getRef())) {
      while (it.hasNext()) {
        ScannerReport.LineCoverage coverage = it.next();
        coverageEditor.getDocument().insertString(coverageEditor.getDocument().getLength(), coverage + "\n", null);
      }
    } catch (Exception e) {
      throw new IllegalStateException("Can't read code coverage for " + getNodeName(component), e);
    }
  }

  private void updateSource(Component component) {
    File sourceFile = reader.getFileStructure().fileFor(Domain.SOURCE, component.getRef());
    sourceEditor.setText("");

    if (sourceFile.exists()) {
      try (Scanner s = new Scanner(sourceFile, StandardCharsets.UTF_8.name()).useDelimiter("\\Z")) {
        if (s.hasNext()) {
          sourceEditor.setText(s.next());
        }
      } catch (IOException ex) {
        StringWriter errors = new StringWriter();
        ex.printStackTrace(new PrintWriter(errors));
        sourceEditor.setText(errors.toString());
      }
    }
  }

  private void updateMetadata() {
    metadataEditor.setText("");

    StringBuilder builder = new StringBuilder();
    Metadata data = reader.readMetadata();
    builder.append("Project key: ").append(data.getProjectKey()).append("\n");
    builder.append("Project version: ").append(data.getProjectVersion()).append("\n");
    builder.append("Scm revision ID: ").append(data.getScmRevisionId()).append("\n");
    if (data.getNotAnalyzedFilesByLanguageCount() > 0) {
      builder.append("Not analyzed files in project:").append("\n");
      data.getNotAnalyzedFilesByLanguageMap().forEach((key, value) -> builder.append("   ").append(key).append(": ").append(value).append("\n"));
    }
    metadataEditor.setText(builder.toString());
  }

  private void updateActiveRules() {
    activeRuleEditor.setText("");

    StringBuilder builder = new StringBuilder();
    try (CloseableIterator<ScannerReport.ActiveRule> activeRuleCloseableIterator = reader.readActiveRules()) {
      while (activeRuleCloseableIterator.hasNext()) {
        builder.append(activeRuleCloseableIterator.next().toString()).append("\n");
      }
      activeRuleEditor.setText(builder.toString());
    }
  }

  private void updateAdHocRules() {
    adHocRuleEditor.setText("");

    StringBuilder builder = new StringBuilder();
    try (CloseableIterator<ScannerReport.AdHocRule> adHocRuleCloseableIterator = reader.readAdHocRules()) {
      while (adHocRuleCloseableIterator.hasNext()) {
        builder.append(adHocRuleCloseableIterator.next().toString()).append("\n");
      }
      adHocRuleEditor.setText(builder.toString());
    }
  }

  private void updateQualityProfiles() {
    qualityProfileEditor.setText("");

    StringBuilder builder = new StringBuilder();
    for (Map.Entry<String, QProfile> qp : metadata.getQprofilesPerLanguage().entrySet()) {
      builder.append(qp.getKey()).append(":\n").append(qp.getValue()).append("\n\n");

    }
    qualityProfileEditor.setText(builder.toString());
  }

  private void updatePlugins() {
    pluginEditor.setText("");

    StringBuilder builder = new StringBuilder();
    for (Map.Entry<String, Plugin> p : metadata.getPluginsByKey().entrySet()) {
      builder.append(p.getKey()).append(":\n").append(p.getValue()).append("\n\n");

    }
    pluginEditor.setText(builder.toString());
  }

  private void updateHighlighting(Component component) {
    highlightingEditor.setText("");
    try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(component.getRef())) {
      while (it.hasNext()) {
        ScannerReport.SyntaxHighlightingRule rule = it.next();
        int offset = highlightingEditor.getDocument().getLength();
        highlightingEditor.getDocument().insertString(offset, rule + "\n", null);
      }
    } catch (Exception e) {
      throw new IllegalStateException("Can't read syntax highlighting for " + getNodeName(component), e);
    }
  }

  private void updateMeasures(Component component) {
    measuresEditor.setText("");
    try (CloseableIterator<ScannerReport.Measure> it = reader.readComponentMeasures(component.getRef())) {
      while (it.hasNext()) {
        ScannerReport.Measure measure = it.next();
        measuresEditor.getDocument().insertString(measuresEditor.getDocument().getLength(), measure + "\n", null);
      }
    } catch (Exception e) {
      throw new IllegalStateException("Can't read measures for " + getNodeName(component), e);
    }
  }

  private void updateScm(Component component) {
    scmEditor.setText("");
    Changesets changesets = reader.readChangesets(component.getRef());
    if (changesets == null) {
      return;
    }
    List<Integer> changesetIndexByLine = changesets.getChangesetIndexByLineList();
    try {
      int index = 0;
      for (Changeset changeset : changesets.getChangesetList()) {
        scmEditor.getDocument().insertString(scmEditor.getDocument().getLength(), index + "\n", null);
        scmEditor.getDocument().insertString(scmEditor.getDocument().getLength(), changeset + "\n", null);
        index++;
      }

      scmEditor.getDocument().insertString(scmEditor.getDocument().getLength(), "\n", null);
      int line = 1;
      for (Integer idx : changesetIndexByLine) {
        scmEditor.getDocument().insertString(scmEditor.getDocument().getLength(), line + ": " + idx + "\n", null);
        line++;
      }

    } catch (Exception e) {
      throw new IllegalStateException("Can't read SCM for " + getNodeName(component), e);
    }
  }

  private void updateSymbols(Component component) {
    symbolEditor.setText("");
    try (CloseableIterator<ScannerReport.Symbol> it = reader.readComponentSymbols(component.getRef())) {
      while (it.hasNext()) {
        ScannerReport.Symbol symbol = it.next();
        symbolEditor.getDocument().insertString(symbolEditor.getDocument().getLength(), symbol + "\n", null);
      }
    } catch (Exception e) {
      throw new IllegalStateException("Can't read symbol references for " + getNodeName(component), e);
    }
  }

  /**
   * Initialize the contents of the frame.
   */
  private void initialize() {
    try {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (Exception e) {
      // If Nimbus is not available, you can set the GUI to another look and feel.
    }
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    splitPane = new JSplitPane();
    frame.getContentPane().add(splitPane, BorderLayout.CENTER);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.setPreferredSize(new Dimension(500, 7));
    splitPane.setRightComponent(tabbedPane);

    componentDetailsTab = new JScrollPane();
    tabbedPane.addTab("Component details", null, componentDetailsTab, null);

    componentEditor = new JEditorPane();
    componentDetailsTab.setViewportView(componentEditor);

    sourceTab = new JScrollPane();
    tabbedPane.addTab("Source", null, sourceTab, null);

    sourceEditor = createSourceEditor();
    sourceEditor.setEditable(false);
    sourceTab.setViewportView(sourceEditor);

    textLineNumber = createTextLineNumber();
    sourceTab.setRowHeaderView(textLineNumber);

    highlightingTab = new JScrollPane();
    tabbedPane.addTab("Highlighting", null, highlightingTab, null);

    highlightingEditor = new JEditorPane();
    highlightingTab.setViewportView(highlightingEditor);

    symbolTab = new JScrollPane();
    tabbedPane.addTab("Symbol references", null, symbolTab, null);

    symbolEditor = new JEditorPane();
    symbolTab.setViewportView(symbolEditor);

    coverageTab = new JScrollPane();
    tabbedPane.addTab("Coverage", null, coverageTab, null);

    coverageEditor = new JEditorPane();
    coverageTab.setViewportView(coverageEditor);

    duplicationTab = new JScrollPane();
    tabbedPane.addTab("Duplications", null, duplicationTab, null);

    duplicationEditor = new JEditorPane();
    duplicationTab.setViewportView(duplicationEditor);

    testsTab = new JScrollPane();
    tabbedPane.addTab("Tests", null, testsTab, null);

    testsEditor = new JEditorPane();
    testsTab.setViewportView(testsEditor);

    issuesTab = new JScrollPane();
    tabbedPane.addTab("Issues", null, issuesTab, null);

    issuesEditor = new JEditorPane();
    issuesTab.setViewportView(issuesEditor);

    externalIssuesTab = new JScrollPane();
    tabbedPane.addTab("External Issues", null, externalIssuesTab, null);

    externalIssuesEditor = new JEditorPane();
    externalIssuesTab.setViewportView(externalIssuesEditor);

    measuresTab = new JScrollPane();
    tabbedPane.addTab("Measures", null, measuresTab, null);

    measuresEditor = new JEditorPane();
    measuresTab.setViewportView(measuresEditor);

    scmTab = new JScrollPane();
    tabbedPane.addTab("SCM", null, scmTab, null);

    scmEditor = new JEditorPane();
    scmTab.setViewportView(scmEditor);

    activeRuleTab = new JScrollPane();
    tabbedPane.addTab("Active Rules", null, activeRuleTab, null);

    activeRuleEditor = new JEditorPane();
    activeRuleTab.setViewportView(activeRuleEditor);

    adHocRuleTab = new JScrollPane();
    tabbedPane.addTab("Add Hoc Rules", null, adHocRuleTab, null);

    adHocRuleEditor = new JEditorPane();
    adHocRuleTab.setViewportView(adHocRuleEditor);

    qualityProfileTab = new JScrollPane();
    tabbedPane.addTab("Quality Profiles", null, qualityProfileTab, null);

    qualityProfileEditor = new JEditorPane();
    qualityProfileTab.setViewportView(qualityProfileEditor);

    pluginTab = new JScrollPane();
    tabbedPane.addTab("Plugins", null, pluginTab, null);

    pluginEditor = new JEditorPane();
    pluginTab.setViewportView(pluginEditor);

    cpdTextBlocksTab = new JScrollPane();
    tabbedPane.addTab("CPD Text Blocks", null, cpdTextBlocksTab, null);

    cpdTextBlocksEditor = new JEditorPane();
    cpdTextBlocksTab.setViewportView(cpdTextBlocksEditor);

    significantCodeTab = new JScrollPane();
    tabbedPane.addTab("Significant Code Ranges", null, significantCodeTab, null);

    significantCodeEditor = new JEditorPane();
    significantCodeTab.setViewportView(significantCodeEditor);

    metadataTab = new JScrollPane();
    tabbedPane.addTab("Metadata", null, metadataTab, null);

    metadataEditor = new JEditorPane();
    metadataTab.setViewportView(metadataEditor);

    treeScrollPane = new JScrollPane();
    treeScrollPane.setPreferredSize(new Dimension(200, 400));
    splitPane.setLeftComponent(treeScrollPane);

    componentTree = new JTree();
    componentTree.setModel(new DefaultTreeModel(
      new DefaultMutableTreeNode("empty") {
        {
        }
      }));
    treeScrollPane.setViewportView(componentTree);
    componentTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    componentTree.addTreeSelectionListener(new TreeSelectionListener() {
      @Override
      public void valueChanged(TreeSelectionEvent e) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) componentTree.getLastSelectedPathComponent();

        if (node == null) {
          // Nothing is selected.
          return;
        }

        frame.setCursor(new Cursor(Cursor.WAIT_CURSOR));
        updateDetails((Component) node.getUserObject());
        frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

      }

    });
    frame.pack();
  }

  public JTree getComponentTree() {
    return componentTree;
  }

  protected JEditorPane getComponentEditor() {
    return componentEditor;
  }

  /**
   * @wbp.factory
   */
  public static JEditorPane createSourceEditor() {
    return new JEditorPane();
  }

  /**
   * @wbp.factory
   */
  public TextLineNumber createTextLineNumber() {
    return new TextLineNumber(sourceEditor);
  }
}