private void ensurePositionCategoryInstalled(final IDocument document, LinkedModeModel model) {
    if (!document.containsPositionCategory(getCategory())) {
      document.addPositionCategory(getCategory());
      fUpdater = new InclusivePositionUpdater(getCategory());
      document.addPositionUpdater(fUpdater);

      model.addLinkingListener(
          new ILinkedModeListener() {

            /*
             * @see org.eclipse.jface.text.link.ILinkedModeListener#left(org.eclipse.jface.text.link.LinkedModeModel, int)
             */
            @Override
            public void left(LinkedModeModel environment, int flags) {
              ensurePositionCategoryRemoved(document);
            }

            @Override
            public void suspend(LinkedModeModel environment) {}

            @Override
            public void resume(LinkedModeModel environment, int flags) {}
          });
    }
  }
 private void ensurePositionCategoryRemoved(IDocument document) {
   if (document.containsPositionCategory(getCategory())) {
     try {
       document.removePositionCategory(getCategory());
     } catch (BadPositionCategoryException e) {
       // ignore
     }
     document.removePositionUpdater(fUpdater);
   }
 }