private void createVerticalRuler(IDocument newInput, Class<SourceViewer> sourceViewerClazz)
      throws SecurityException, NoSuchMethodException, IllegalArgumentException,
          IllegalAccessException, InvocationTargetException, NoSuchFieldException {

    forceCustomAnnotationHover();

    Method declaredMethod2 = sourceViewerClazz.getDeclaredMethod("getVerticalRuler");
    declaredMethod2.setAccessible(true);
    CompositeRuler ruler = (CompositeRuler) declaredMethod2.invoke(sourceViewer);
    boolean hasDecorator = false;

    Iterator<?> iter = (ruler).getDecoratorIterator();
    while (iter.hasNext()) {
      Object obj = iter.next();
      if (obj instanceof AnnotationColumn) {
        hasDecorator = true;
      }
    }

    if (!hasDecorator) {
      AnnotationColumn annotationColumn = new AnnotationColumn();
      annotationColumn.createControl(ruler, ruler.getControl().getParent());
      ruler.addDecorator(0, annotationColumn);
    }
  }
  @Override
  protected CompositeRuler createCompositeRuler() {
    annotationAccess = new AnnotationMarkerAccess();
    IAnnotationModel annotationModel = getDocumentProvider().getAnnotationModel(getEditorInput());
    AnnotationRulerColumn annotationRulerCol =
        new AnnotationRulerColumn(annotationModel, 16, annotationAccess);
    annotationRulerCol.addAnnotationType(AlternativeAnnotation.ALTERNATIVE_TYPE);

    CompositeRuler compositeRuler = new CompositeRuler();
    compositeRuler.setModel(annotationModel);
    compositeRuler.addDecorator(0, annotationRulerCol);

    return compositeRuler;
  }
Exemplo n.º 3
0
  /**
   * @param parent
   * @param ruler
   * @param styles
   */
  public DiffViewer(Composite parent, IVerticalRuler ruler, int styles) {
    super(parent, ruler, styles);
    setDocument(new Document());
    SourceViewerDecorationSupport support =
        new SourceViewerDecorationSupport(this, null, null, EditorsUI.getSharedTextColors());
    support.setCursorLinePainterPreferenceKeys(
        AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE,
        AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR);
    support.install(EditorsUI.getPreferenceStore());
    if (ruler instanceof CompositeRuler) {
      lineNumberRuler = new LineNumberRulerColumn();
      ((CompositeRuler) ruler).addDecorator(0, lineNumberRuler);
    }
    initListeners();
    getControl()
        .addDisposeListener(
            new DisposeListener() {

              public void widgetDisposed(DisposeEvent e) {
                EditorsUI.getPreferenceStore().removePropertyChangeListener(editorPrefListener);
                PlatformUI.getWorkbench()
                    .getThemeManager()
                    .removePropertyChangeListener(themeListener);
                colors.dispose();
              }
            });
    refreshDiffColors();
    styleViewer();
  }
 protected void setLastRulerMouseLocation(ISourceViewer viewer, int line) {
   // set last mouse activity in order to get the correct context menu
   if (fCompositeRuler != null) {
     StyledText st = viewer.getTextWidget();
     if (st != null && !st.isDisposed()) {
       if (viewer instanceof ITextViewerExtension5) {
         int widgetLine = ((ITextViewerExtension5) viewer).modelLine2WidgetLine(line);
         Point loc = st.getLocationAtOffset(st.getOffsetAtLine(widgetLine));
         fCompositeRuler.setLocationOfLastMouseButtonActivity(0, loc.y);
       } else if (viewer instanceof TextViewer) {
         // TODO remove once TextViewer implements the extension
         int widgetLine = ((TextViewer) viewer).modelLine2WidgetLine(line);
         Point loc = st.getLocationAtOffset(st.getOffsetAtLine(widgetLine));
         fCompositeRuler.setLocationOfLastMouseButtonActivity(0, loc.y);
       }
     }
   }
 }
Exemplo n.º 5
0
 @SuppressWarnings("unchecked")
 protected IVerticalRuler createCompositeRuler() {
   CompositeRuler ruler = new CompositeRuler();
   ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH, getAnnotationAccess()));
   for (Iterator iter = ruler.getDecoratorIterator(); iter.hasNext(); ) {
     IVerticalRulerColumn col = (IVerticalRulerColumn) iter.next();
     if (col instanceof AnnotationRulerColumn) {
       AnnotationRulerColumn column = (AnnotationRulerColumn) col;
       for (Iterator iter2 = fAnnotationPreferences.getAnnotationPreferences().iterator();
           iter2.hasNext(); ) {
         AnnotationPreference preference = (AnnotationPreference) iter2.next();
         column.addAnnotationType(preference.getAnnotationType());
       }
       column.addAnnotationType(Annotation.TYPE_UNKNOWN);
       break;
     }
   }
   return ruler;
 }