@Override
  public String getColumnText(Object element, XViewerColumn xCol, int columnIndex)
      throws OseeCoreException {
    ICoverage coverage = (ICoverage) element;
    if (xCol.equals(CoverageXViewerFactory.Name)) {
      return coverage.getName();
    }
    if (element instanceof MessageCoverageItem) {
      return "";
    }
    if (xCol.equals(CoverageXViewerFactory.Assignees_Col)) {
      if (element instanceof CoverageUnit) {
        return Artifacts.toString(
            "; ", OseeCoverageUnitStore.getAssignees((CoverageUnit) coverage));
      }
      return "";
    }
    if (xCol.equals(CoverageXViewerFactory.Notes_Col)) {
      return coverage.getNotes();
    }
    if (xCol.equals(CoverageXViewerFactory.Coverage_Percent)) {
      return coverage.getCoveragePercentStr();
    }
    if (xCol.equals(CoverageXViewerFactory.Location)) {
      return coverage.getLocation();
    }
    if (xCol.equals(CoverageXViewerFactory.Full_Path)) {
      return CoverageUtil.getFullPath(coverage);
    }
    if (xCol.equals(CoverageXViewerFactory.Namespace)) {
      return coverage.getNamespace();
    }
    if (xCol.equals(CoverageXViewerFactory.Work_Product_Task)) {
      return coverage.getWorkProductTaskStr();
    }
    if (xCol.equals(CoverageXViewerFactory.Guid)) {
      return coverage.getGuid();
    }
    if (xCol.equals(CoverageXViewerFactory.Unit)) {
      String unit = "";
      if (element instanceof CoverageUnit) {
        unit = coverage.getName();
      } else {
        unit = coverage.getParent().getName();
      }

      return unit;
    }
    if (xCol.equals(CoverageXViewerFactory.Lines_Covered)) {
      if (element instanceof CoverageUnit) {
        return String.valueOf(((CoverageUnit) coverage).getCoverageItemsCoveredCount(true));
      }
    }
    if (xCol.equals(CoverageXViewerFactory.Total_Lines)) {
      if (element instanceof CoverageUnit) {
        return String.valueOf(((CoverageUnit) coverage).getCoverageItems(true).size());
      }
    }

    if (coverage instanceof CoverageItem
        || (coverage instanceof MergeItem
            && ((MergeItem) coverage).getImportItem() instanceof CoverageItem)) {
      CoverageItem coverageItem = null;
      if (coverage instanceof CoverageItem) {
        coverageItem = (CoverageItem) coverage;
      } else {
        coverageItem = (CoverageItem) ((MergeItem) coverage).getImportItem();
      }
      if (xCol.equals(CoverageXViewerFactory.Coverage_Rationale)) {
        return coverageItem.getRationale();
      }
      if (xCol.equals(CoverageXViewerFactory.Method_Number)) {
        return coverageItem.getParent().getOrderNumber();
      }
      if (xCol.equals(CoverageXViewerFactory.Execution_Number)) {
        return coverageItem.getOrderNumber();
      }
      if (xCol.equals(CoverageXViewerFactory.Line_Number)) {
        return coverageItem.getLineNumber();
      }
      if (xCol.equals(CoverageXViewerFactory.Coverage_Method)) {
        return coverageItem.getCoverageMethod().getName();
      }
      if (xCol.equals(CoverageXViewerFactory.Parent_Coverage_Unit)) {
        return coverageItem.getCoverageUnit().getName();
      }
      if (xCol.equals(CoverageXViewerFactory.Coverage_Test_Units)) {
        Collection<String> testUnits = coverageItem.getTestUnits();
        if (testUnits == null) {
          return "";
        }
        return Collections.toString(", ", testUnits);
      }
      return "";
    }
    if (coverage instanceof CoverageUnit
        || (coverage instanceof MergeItem
            && ((MergeItem) coverage).getImportItem() instanceof CoverageUnit)) {
      CoverageUnit coverageUnit = null;
      if (coverage instanceof CoverageUnit) {
        coverageUnit = (CoverageUnit) coverage;
      } else if (coverage instanceof MergeItem) {
        coverageUnit = (CoverageUnit) ((MergeItem) coverage).getImportItem();
      }
      if (xCol.equals(CoverageXViewerFactory.Parent_Coverage_Unit)) {
        return coverageUnit.getParentCoverageUnit() == null
            ? ""
            : coverageUnit.getParentCoverageUnit().getName();
      }
      if (xCol.equals(CoverageXViewerFactory.Method_Number)) {
        return coverageUnit.getOrderNumber();
      }
    }
    if (coverage instanceof CoverageItem) {
      CoverageItem coverageItem = (CoverageItem) coverage;
      if (xCol.equals(CoverageXViewerFactory.Parent_Coverage_Unit)) {
        return coverageItem.getParent() == null ? "" : coverageItem.getParent().getName();
      }
      if (xCol.equals(CoverageXViewerFactory.Method_Number)) {
        return coverageItem.getParent() == null ? "" : coverageItem.getParent().getOrderNumber();
      }
      if (xCol.equals(CoverageXViewerFactory.Execution_Number)) {
        return coverageItem.getOrderNumber();
      }
      if (xCol.equals(CoverageXViewerFactory.Coverage_Method)) {
        return coverageItem.getCoverageMethod().getName();
      }
    }
    if (coverage instanceof MergeItem
        && (((MergeItem) coverage).getImportItem() instanceof CoverageItem
            || ((MergeItem) coverage).getPackageItem() instanceof CoverageItem)) {
      MergeItem mergeItem = (MergeItem) coverage;
      ICoverage importItem = mergeItem.getImportItem();
      ICoverage packageItem = mergeItem.getPackageItem();
      if (xCol.equals(CoverageXViewerFactory.Parent_Coverage_Unit)) {
        if (importItem != null && importItem.getParent() != null) {
          return importItem.getParent().getName();
        } else if (packageItem != null && packageItem.getParent() != null) {
          return packageItem.getParent().getName();
        }
        return "";
      }
      if (xCol.equals(CoverageXViewerFactory.Method_Number)) {
        if (importItem != null && importItem.getParent() != null) {
          return importItem.getParent().getOrderNumber();
        } else if (packageItem != null && packageItem.getParent() != null) {
          return packageItem.getParent().getOrderNumber();
        }
        return "";
      }
      if (xCol.equals(CoverageXViewerFactory.Execution_Number)) {
        if (importItem != null) {
          return importItem.getOrderNumber();
        } else if (packageItem != null) {
          return packageItem.getOrderNumber();
        }
        return "";
      }
      if (xCol.equals(CoverageXViewerFactory.Coverage_Method)) {
        if (importItem != null) {
          return ((CoverageItem) importItem).getCoverageMethod().getName();
        } else if (packageItem != null) {
          return ((CoverageItem) packageItem).getCoverageMethod().getName();
        }
        return "";
      }
    }
    return "";
  }
Example #2
0
  @Override
  public void run() {
    if (selectedCoverageEditorItem.getSelectedCoverageEditorItems().isEmpty()) {
      AWorkbench.popup("Select Coverage Item");
      return;
    }
    if (selectedCoverageEditorItem.getSelectedCoverageEditorItems().size() > 0) {
      ICoverage item =
          selectedCoverageEditorItem.getSelectedCoverageEditorItems().iterator().next();
      String highlightLine = null;

      try {
        if (item instanceof CoverageItem) {
          if (Strings.isValid(item.getName())) {
            highlightLine = item.getName();
          }
          item = item.getParent();
        }
        // If order number then parent has full file contents
        // attempt to find line in file that matches
        if (Strings.isValid(item.getOrderNumber())) {
          if (item.getParent() != null) {
            String itemLineText = item.getName();
            String parentFileContents = item.getParent().getFileContents();
            if (!Strings.isValid(parentFileContents)) {
              AWorkbench.popup("No File Contents Available");
              return;
            }
            String html = parentFileContents;
            // mark text for method
            if (Strings.isValid(itemLineText)) {
              html = html.replaceAll(itemLineText, "HEREBEGIN" + itemLineText + "HEREEND");
            }
            // mark text for executable line
            if (Strings.isValid(highlightLine)) {
              html = html.replaceAll(highlightLine, "HEREBEGIN" + highlightLine + "HEREEND");
            }
            html = AHTML.textToHtml(html);
            html = html.replaceAll(" ", "&nbsp;");
            html = html.replaceAll("HEREBEGIN", "<FONT style=\"BACKGROUND-COLOR: yellow\">");
            html = html.replaceAll("HEREEND", "</FONT>");
            ResultsEditor.open(
                "source",
                CoverageUtil.getFullPathWithName(item.getParent(), true)
                    + "["
                    + item.getName()
                    + "]",
                html);
          } else {
            AWorkbench.popup("No File Contents Available");
            return;
          }
        }
        // If no order number, just open full text
        else {
          String text = item.getFileContents();
          if (!Strings.isValid(text)) {
            AWorkbench.popup("No File Contents Available");
            return;
          }
          String html = AHTML.textToHtml(text);
          html = html.replaceAll(" ", "&nbsp;");
          ResultsEditor.open("source", CoverageUtil.getFullPathWithName(item, true), html);
        }

      } catch (OseeCoreException ex) {
        OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
      }
    }
  }