Exemplo n.º 1
0
  @Override
  public void update(ViewerCell cell) {
    super.update(cell);

    SourceFilesViewer.TranslationUnitInfo tuInfo = null;
    Object element = cell.getElement();
    if (element instanceof ITranslationUnit) {
      tuInfo = SourceFilesViewer.fetchTranslationUnitInfo((Executable) viewer.getInput(), element);
    }

    int orgColumnIndex = cell.getColumnIndex();

    if (orgColumnIndex == 0) {
      if (element instanceof String) {
        cell.setText((String) element);
        Font italicFont =
            resourceManager.createFont(
                FontDescriptor.createFrom(viewer.getTree().getFont()).setStyle(SWT.ITALIC));
        cell.setFont(italicFont);
      } else {
        cell.setFont(viewer.getTree().getFont());
      }
    } else if (orgColumnIndex == 1) {
      cell.setText(null);
      if (tuInfo != null) {
        if (tuInfo.location != null) {
          cell.setText(tuInfo.location.toOSString());
          if (tuInfo.exists)
            cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
          else cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
        }
      }
      cell.setImage(null);
    } else if (orgColumnIndex == 2) {
      cell.setText(null);
      if (tuInfo != null && tuInfo.originalLocation != null) {
        cell.setText(tuInfo.originalLocation.toOSString());
        if (tuInfo.originalExists)
          cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
        else cell.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
      }
      cell.setImage(null);
    } else if (orgColumnIndex == 3) {
      cell.setText(null);
      if (tuInfo != null) {
        if (tuInfo.exists) {
          cell.setText(Long.toString(tuInfo.fileLength));
        }
      }
      cell.setImage(null);
    } else if (orgColumnIndex == 4) {
      cell.setText(null);
      if (tuInfo != null) {
        if (tuInfo.exists) {
          String dateTimeString =
              DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
                  .format(new Date(tuInfo.lastModified));
          cell.setText(dateTimeString);
        }
      }
      cell.setImage(null);
    } else if (orgColumnIndex == 5) {
      cell.setText(null);
      if (tuInfo != null) {
        if (tuInfo.location != null) {
          String fileExtension = tuInfo.location.getFileExtension();
          if (fileExtension != null) cell.setText(fileExtension.toLowerCase());
        }
      }
      cell.setImage(null);
    }
  }