/**
  * Returns the variable and function names at the current line, or <code>null</code> if none.
  *
  * @param part text editor
  * @param selection text selection
  * @return the variable and function names at the current line, or <code>null</code> if none. The
  *     array has two elements, the first is the variable name, the second is the function name.
  */
 protected String[] getVariableAndFunctionName(IWorkbenchPart part, ISelection selection) {
   ITextEditor editor = getEditor(part);
   if (editor != null && selection instanceof ITextSelection) {
     ITextSelection textSelection = (ITextSelection) selection;
     IDocumentProvider documentProvider = editor.getDocumentProvider();
     try {
       documentProvider.connect(this);
       IDocument document = documentProvider.getDocument(editor.getEditorInput());
       IRegion region = document.getLineInformationOfOffset(textSelection.getOffset());
       String string = document.get(region.getOffset(), region.getLength()).trim();
       if (string.startsWith("var ")) { // $NON-NLS-1$
         String varName = string.substring(4).trim();
         String fcnName =
             getFunctionName(
                 document, varName, document.getLineOfOffset(textSelection.getOffset()));
         return new String[] {varName, fcnName};
       }
     } catch (CoreException e) {
     } catch (BadLocationException e) {
     } finally {
       documentProvider.disconnect(this);
     }
   }
   return null;
 }
	private boolean openFileImpl(IProject project, IPath sourceLoc, int lineNumber) {
		if (sourceLoc == null || "??".equals(sourceLoc.toString())) return false;
		try {
			IEditorInput editorInput = getEditorInput(sourceLoc, project);
			IWorkbenchPage p= CUIPlugin.getActivePage();
			if (p != null) {
				if (editorInput == null) {
					p.openEditor(
							new STCSourceNotFoundEditorInput(project, sourceLoc, lineNumber),
							"org.eclipse.linuxtools.binutils.link2source.STCSourceNotFoundEditor",
							true);
				} else {
					IEditorPart editor = p.openEditor(editorInput, CUIPlugin.EDITOR_ID, true);
					if (lineNumber > 0 && editor instanceof ITextEditor){
						IDocumentProvider provider= ((ITextEditor)editor).getDocumentProvider();
						IDocument document= provider.getDocument(editor.getEditorInput());
						try {
							int start = document.getLineOffset(lineNumber-1);
							((ITextEditor)editor).selectAndReveal(start, 0);
							IWorkbenchPage page= editor.getSite().getPage();
							page.activate(editor);
							return true;
						} catch (BadLocationException x) {
							// ignore
						}
					}
				}
			}
		}
		catch (Exception _) {
		}
		return false;
	}
  @Override
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    clearAnnotations();

    if (oldInput != null) {
      IDocument document = documentProvider.getDocument(oldInput);
      if (document != null) {
        try {
          document.removePositionCategory(SEGMENTS);
        } catch (BadPositionCategoryException e) {
          // Do Nothing
        }
        document.removePositionUpdater(positionUpdater);
      }
    }

    if (newInput != null) {
      IDocument document = documentProvider.getDocument(newInput);
      if (document != null) {
        document.addPositionCategory(SEGMENTS);
        document.addPositionUpdater(positionUpdater);

        tree = parser.parse(document.get());
        addAnnotations(document.get());
      }
    }
  }
  @Override
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    if (oldInput != null) {
      IDocument document = documentProvider.getDocument(oldInput);

      if (document != null) {
        try {
          document.removePositionCategory(CLASS_POSITIONS);
        } catch (BadPositionCategoryException x) {
        }

        document.removePositionUpdater(positionUpdater);
      }
    }

    editorInput = (IEditorInput) newInput;

    if (newInput != null) {
      IDocument document = documentProvider.getDocument(newInput);

      if (document != null) {
        document.addPositionCategory(CLASS_POSITIONS);
        document.addPositionUpdater(positionUpdater);
        editorPageChanged(viewer);
      }
    }

    viewer.refresh();
  }
 public void apply(final IDocument document) {
   IProject p = marker.getResource().getProject();
   IFile f = BuildWrapperPlugin.getCabalFile(p);
   IDocumentProvider prov = new TextFileDocumentProvider();
   try {
     prov.connect(f);
     IDocument doc = prov.getDocument(f);
     PackageDescription pd = PackageDescriptionLoader.load(f);
     int length = pd.getStanzas().size();
     for (int a = 0; a < length; a++) {
       PackageDescriptionStanza pds = pd.getStanzas().get(a);
       CabalSyntax cs = pds.getType();
       if (CabalSyntax.SECTION_EXECUTABLE.equals(cs)
           || CabalSyntax.SECTION_LIBRARY.equals(cs)
           || CabalSyntax.SECTION_TESTSUITE.equals(cs)) {
         RealValuePosition rvp = pds.addToPropertyList(CabalSyntax.FIELD_BUILD_DEPENDS, pkg);
         if (rvp != null) {
           rvp.updateDocument(doc);
           pd = PackageDescriptionLoader.load(doc.get());
         }
       }
     }
     prov.saveDocument(new NullProgressMonitor(), f, doc, true);
   } catch (CoreException ce) {
     HaskellUIPlugin.log(ce);
   }
 }
  /**
   * Attaches a coverage annotation model for the given editor if the editor can be annotated. Does
   * nothing if the model is already attached.
   *
   * @param editor Editor to attach a annotation model to
   */
  public static boolean attach(ITextEditor editor) {
    IDocumentProvider provider = editor.getDocumentProvider();
    IEditorInput input = editor.getEditorInput();

    if (provider != null && input instanceof FileEditorInput) {
      IAnnotationModel model = provider.getAnnotationModel(input);

      if (model instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;

        ColorAnnotationModel colormodel = (ColorAnnotationModel) modelex.getAnnotationModel(KEY);

        if (colormodel == null) {
          IFile file = ((FileEditorInput) input).getFile();
          IFeatureProject project = CorePlugin.getFeatureProject(file);
          if (project != null
              && project.getComposer() != null
              && project.getComposer().needColor()) {
            IDocument document = provider.getDocument(input);
            colormodel = new ColorAnnotationModel(document, file, project, editor);
            modelex.addAnnotationModel(KEY, colormodel);

            return true;
          }
        } else {
          colormodel.updateAnnotations(!editor.isDirty());
        }
      }
    }
    return false;
  }
示例#7
0
  private void updateDocumentProvider(IEditorInput input) {

    IProgressMonitor rememberedProgressMonitor = null;

    IDocumentProvider provider = getDocumentProvider();
    if (provider != null) {
      provider.removeElementStateListener(fElementStateListener);
      if (provider instanceof IDocumentProviderExtension2) {
        IDocumentProviderExtension2 extension = (IDocumentProviderExtension2) provider;
        rememberedProgressMonitor = extension.getProgressMonitor();
        extension.setProgressMonitor(null);
      }
    }

    setDocumentProvider(input);

    provider = getDocumentProvider();
    if (provider != null) {
      provider.addElementStateListener(fElementStateListener);
      if (provider instanceof IDocumentProviderExtension2) {
        IDocumentProviderExtension2 extension = (IDocumentProviderExtension2) provider;
        extension.setProgressMonitor(rememberedProgressMonitor);
      }
    }
  }
示例#8
0
  void removeOccurrenceAnnotations() {
    fMarkOccurrenceModificationStamp = IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
    fMarkOccurrenceTargetRegion = null;

    final IDocumentProvider documentProvider = erlangEditor.getDocumentProvider();
    if (documentProvider == null) {
      return;
    }

    final IAnnotationModel annotationModel =
        documentProvider.getAnnotationModel(erlangEditor.getEditorInput());
    if (annotationModel == null || fOccurrenceAnnotations == null) {
      return;
    }

    synchronized (erlangEditor.getLockObject(annotationModel)) {
      if (annotationModel instanceof IAnnotationModelExtension) {
        ((IAnnotationModelExtension) annotationModel)
            .replaceAnnotations(fOccurrenceAnnotations, null);
      } else {
        for (int i = 0, length = fOccurrenceAnnotations.length; i < length; i++) {
          annotationModel.removeAnnotation(fOccurrenceAnnotations[i]);
        }
      }
      fOccurrenceAnnotations = null;
    }
  }
  @Override
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

    if (oldInput != null) {
      IDocument document = fDocumentProvider.getDocument(oldInput);
      if (document != null) {
        try {
          document.removePositionCategory(JSON_ELEMENTS);
        } catch (BadPositionCategoryException x) {
        }
        document.removePositionUpdater(fPositionUpdater);
      }
    }

    rootObject = null;

    if (newInput != null) {
      IDocument document = fDocumentProvider.getDocument(newInput);
      if (document != null) {
        document.addPositionCategory(JSON_ELEMENTS);
        document.addPositionUpdater(fPositionUpdater);

        parse(document);
      }
    }
  }
  public static IWorkbench getMockWorkbench(String file) {

    IWorkbench workbench = mock(IWorkbench.class);
    IWorkbenchWindow window = mock(IWorkbenchWindow.class);
    IWorkbenchPage page = mock(IWorkbenchPage.class);

    ITextEditor editor = mock(ITextEditor.class);

    IDocumentProvider docProvider = mock(IDocumentProvider.class);
    IDocument doc = mock(IDocument.class);

    IPath ipath = mock(IPath.class);
    File afile = mock(File.class);
    IFile inputFile = mock(IFile.class);

    IFileEditorInput editorInput = mock(IFileEditorInput.class);

    when(workbench.getWorkbenchWindows()).thenReturn(new IWorkbenchWindow[] {window});
    when(window.getActivePage()).thenReturn(page);
    when(page.getActiveEditor()).thenReturn(editor);

    when(editor.getEditorInput()).thenReturn(editorInput);
    when(editor.getDocumentProvider()).thenReturn(docProvider);

    when(editorInput.getFile()).thenReturn(inputFile);
    when(docProvider.getDocument(any())).thenReturn(doc);

    when(inputFile.getLocation()).thenReturn(ipath);
    when(inputFile.getName()).thenReturn(file);

    when(ipath.toFile()).thenReturn(afile);
    when(afile.length()).thenReturn(33l);

    return workbench;
  }
示例#11
0
  private synchronized void checkFile() {
    if (fActiveEditor == null) return;
    IEditorInput input = fActiveEditor.getEditorInput();
    IPath location = null;

    if (input instanceof IFileEditorInput) {
      IFile file = ((IFileEditorInput) input).getFile();
      location = file.getLocation();
    } else if (input instanceof FileStoreEditorInput) {
      location = URIUtil.toPath(((FileStoreEditorInput) input).getURI());
    } else if (input instanceof CommonSourceNotFoundEditorInput) {
      Object artifact = ((CommonSourceNotFoundEditorInput) input).getArtifact();
      if (artifact instanceof CSourceNotFoundElement) {
        location = new Path(((CSourceNotFoundElement) artifact).getFile());
      }
    }

    if (location != null
        && fExpectedFile != null
        && location.lastSegment().equals(fExpectedFile.lastSegment())) {
      fFileFound = true;

      if (fActiveEditor instanceof ITextEditor) {
        IDocumentProvider docProvider = ((ITextEditor) fActiveEditor).getDocumentProvider();
        fAnnotationModel = docProvider.getAnnotationModel(fActiveEditor.getEditorInput());
        fAnnotationModel.addAnnotationModelListener(this);

        checkAnnotations();
      } else if (fActiveEditor instanceof CommonSourceNotFoundEditor) {
        // No annotation will be painted if source not found.
        fAnnotationFound = true;
      }
    }
  }
  /**
   * Provide the initialization of the listeners additions. The Window, Part, and Document Listener
   * are added. Note that sensor shell should be instantiated before this method is called because
   * <code>processActivity()</code> method uses sensor shell instance.
   */
  private void registerListeners() {
    IWorkbench workbench = EclipseSensorPlugin.getInstance().getWorkbench();

    // :RESOLVED: JULY 1, 2003
    // Supports the multiple window for sensor collection.
    IWorkbenchWindow[] activeWindows = workbench.getWorkbenchWindows();

    // Check if window listener is not added yet. Otherwise multi instances are notified.
    if (this.windowListener == null) {
      this.windowListener = new WindowListenerAdapter();
      workbench.addWindowListener(new WindowListenerAdapter());
    }

    for (int i = 0; i < activeWindows.length; i++) {
      IWorkbenchPage activePage = activeWindows[i].getActivePage();
      activePage.addPartListener(new PartListenerAdapter());
      IEditorPart activeEditorPart = activePage.getActiveEditor();

      // Adds this EclipseSensorPlugin instance to IDocumentListener
      // only when activeEditorPart is the instance of ITextEditor
      // so that null case is also ignored.
      if (activeEditorPart instanceof ITextEditor) {
        // Sets activeTextEditor. Otherwise a first activated file would not be recorded.
        this.activeTextEditor = (ITextEditor) activeEditorPart;
        // Gets opened file since the initial opened file is not notified from IPartListener.
        URI fileResource = EclipseSensor.this.getFileResource(this.activeTextEditor);

        Map<String, String> keyValueMap = new HashMap<String, String>();
        keyValueMap.put(EclipseSensorConstants.SUBTYPE, "Open");
        keyValueMap.put(EclipseSensorConstants.UNIT_TYPE, EclipseSensorConstants.FILE);
        keyValueMap.put(
            EclipseSensorConstants.UNIT_NAME, EclipseSensor.this.extractFileName(fileResource));
        this.addDevEvent(
            EclipseSensorConstants.DEVEVENT_EDIT,
            fileResource,
            keyValueMap,
            "Opened " + fileResource.toString());

        IDocumentProvider provider = this.activeTextEditor.getDocumentProvider();
        IDocument document = provider.getDocument(activeEditorPart.getEditorInput());

        // Initially sets active buffer and threshold buffer.
        // Otherwise a first activated buffer would not be recorded.
        this.activeBufferSize = document.getLength();
        this.thresholdBufferSize = document.getLength();
        document.addDocumentListener(new DocumentListenerAdapter());
      }
    }

    // Handles breakpoint set/unset event.
    IBreakpointManager bpManager = DebugPlugin.getDefault().getBreakpointManager();
    bpManager.addBreakpointListener(new BreakPointerSensor(this));

    // Listens to debug event.
    DebugPlugin.getDefault().addDebugEventListener(new DebugSensor(this));

    // Creates instance to handle build error.
    this.buildErrorSensor = new BuildErrorSensor(this);
  }
 /**
  * Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's input.
  *
  * @return the marker annotation model
  */
 protected AbstractMarkerAnnotationModel getAnnotationModel() {
   IDocumentProvider provider = fTextEditor.getDocumentProvider();
   IAnnotationModel model = provider.getAnnotationModel(fTextEditor.getEditorInput());
   if (model instanceof AbstractMarkerAnnotationModel) {
     return (AbstractMarkerAnnotationModel) model;
   }
   return null;
 }
 /**
  * Detaches the coverage annotation model from the given editor. If the editor does not have a
  * model attached, this method does nothing.
  *
  * @param editor Editor to detach the annotation model from
  */
 public static void detach(ITextEditor editor) {
   IDocumentProvider provider = editor.getDocumentProvider();
   // there may be text editors without document providers (SF #1725100)
   if (provider == null) return;
   IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
   if (!(model instanceof IAnnotationModelExtension)) return;
   IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;
   modelex.removeAnnotationModel(KEY);
 }
示例#15
0
  private void setXMLOutlineInput() {
    IDocumentProvider provider = fEditor.getDocumentProvider();

    // force creation of the document & the model.
    IDocument document = provider.getDocument(fEditor.getEditorInput());
    IXMLModelProvider modelProvider = UIPlugin.getDefault().getXMLModelProvider();
    XMLReconciler model = (modelProvider).getModel(document);
    fXMLOutlinePage.setInput(model.getRoot());
  }
 private IAnnotationModel getAnnotationModel() {
   if (fTextEditor == null) {
     return null;
   }
   final IDocumentProvider documentProvider = fTextEditor.getDocumentProvider();
   if (documentProvider == null) {
     return null;
   }
   return documentProvider.getAnnotationModel(fTextEditor.getEditorInput());
 }
    public void uninstall() {
      ISourceViewer sourceViewer = editor.getISourceViewer();
      if (sourceViewer != null) sourceViewer.removeTextInputListener(this);

      IDocumentProvider documentProvider = editor.getDocumentProvider();
      if (documentProvider != null) {
        IDocument document = documentProvider.getDocument(editor.getEditorInput());
        if (document != null) document.removeDocumentListener(this);
      }
    }
示例#18
0
  /**
   * the command has been executed, so extract extract the needed information from the application
   * context.
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    ITextSelection content =
        (ITextSelection)
            window
                .getActivePage()
                .getActiveEditor()
                .getEditorSite()
                .getSelectionProvider()
                .getSelection();
    String texto = content.getText();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Clipboard clipboard = toolkit.getSystemClipboard();

    String sqlFormatado = formatSQL(texto);

    StringSelection textoFormatado = new StringSelection(sqlFormatado);
    clipboard.setContents(textoFormatado, null);

    if (isBlank(texto)) {
      MessageDialog.openInformation(window.getShell(), "SQLCopy", "Você não selecionou nada!");
    } else {
      if (isConvertToJava(
          texto)) { // Realizar a substituição do texto selecionado apenas quando estiver
        // convertendo um SQL para Java.
        IEditorPart part =
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        ITextEditor editor = (ITextEditor) part;
        IDocumentProvider prov = editor.getDocumentProvider();
        IDocument doc = prov.getDocument(editor.getEditorInput());
        ISelection sel = editor.getSelectionProvider().getSelection();

        if (sel instanceof TextSelection) {
          final TextSelection textSel = (TextSelection) sel;
          try {
            //		            	IRegion region = doc.getLineInformationOfOffset(textSel.getOffset());
            //						doc.replace( textSel.getOffset(), textSel.getLength(),
            // identingCode(region.getLength(), sqlFormatado));
            doc.replace(textSel.getOffset(), textSel.getLength(), sqlFormatado);
          } catch (BadLocationException e) {
            e.printStackTrace();
          }
        }
      }
      //			MessageDialog.openInformation(
      //					window.getShell(),
      //					"SQLCopy",
      //					sqlFormatado.toString());
      CustomMessageDialog dialog =
          new CustomMessageDialog(window.getShell(), sqlFormatado.toString());
      dialog.open();
    }

    return null;
  }
 private static IRegion getRegionOfInterest(ITextEditor editor, int invocationLocation)
     throws BadLocationException {
   IDocumentProvider documentProvider = editor.getDocumentProvider();
   if (documentProvider == null) {
     return null;
   }
   IDocument document = documentProvider.getDocument(editor.getEditorInput());
   if (document == null) {
     return null;
   }
   return document.getLineInformationOfOffset(invocationLocation);
 }
示例#20
0
 protected IAnnotationModel getAnnotationModel(XtextEditor editor) {
   if (editor != null) {
     IEditorInput editorInput = editor.getEditorInput();
     if (editorInput != null) {
       IDocumentProvider documentProvider = editor.getDocumentProvider();
       if (documentProvider != null) {
         return documentProvider.getAnnotationModel(editorInput);
       }
     }
   }
   return null;
 }
  /**
   * Detaches the coverage annotation model from the given editor. If the editor does not have a
   * model attached, this method does nothing.
   *
   * @param editor Editor to detach the annotation model from
   */
  public static void detach(ITextEditor editor) {
    IDocumentProvider provider = editor.getDocumentProvider();
    if (provider != null) {
      IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());

      if (model instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;

        modelex.removeAnnotationModel(KEY);
      }
    }
  }
示例#22
0
  public static IDocument getDocument(IEditorReference er) {
    IEditorPart ep = er.getEditor(false);
    if (!(ep instanceof ITextEditor)) return null;
    ITextEditor te = (ITextEditor) ep;

    IDocumentProvider dp = te.getDocumentProvider();
    if (dp == null) return null;

    IEditorInput input = getEditorInput(er);
    if (input == null) return null;

    return dp.getDocument(input);
  }
 private IDocument getDocument(IDocumentProvider provider, IEditorInput input) {
   if (input == null) {
     return null;
   }
   IDocument result = null;
   try {
     provider.connect(input);
     result = provider.getDocument(input);
   } catch (CoreException e) {
   } finally {
     provider.disconnect(input);
   }
   return result;
 }
示例#24
0
  /**
   * Disposes of the connection with the document provider. Subclasses may extend.
   *
   * @since 3.0
   */
  protected void disposeDocumentProvider() {
    IDocumentProvider provider = getDocumentProvider();
    if (provider != null) {

      IEditorInput input = getEditorInput();
      if (input != null) provider.disconnect(input);

      if (fElementStateListener != null) {
        provider.removeElementStateListener(fElementStateListener);
        fElementStateListener = null;
      }
    }
    fImplicitDocumentProvider = null;
  }
示例#25
0
    public void uninstall() {
      final ISourceViewer sourceViewer = erlangEditor.getViewer();
      if (sourceViewer != null) {
        sourceViewer.removeTextInputListener(this);
      }

      final IDocumentProvider documentProvider = erlangEditor.getDocumentProvider();
      if (documentProvider != null) {
        final IDocument document = documentProvider.getDocument(erlangEditor.getEditorInput());
        if (document != null) {
          document.removeDocumentListener(this);
        }
      }
    }
    /**
     * Provides manipulation of browser open status due to implement <code>IWindowListener</code>.
     * This method must not be called by client because it is called by platform. Do nothing for
     * Eclipse sensor so far.
     *
     * @param window An IWorkbenchWindow instance to be triggered when a window is activated.
     */
    public void windowActivated(IWorkbenchWindow window) {
      IEditorPart activeEditorPart = window.getActivePage().getActiveEditor();
      if (activeEditorPart instanceof ITextEditor) {
        EclipseSensor.this.activeTextEditor = (ITextEditor) activeEditorPart;
        ITextEditor editor = EclipseSensor.this.activeTextEditor;
        IDocumentProvider provider = editor.getDocumentProvider();
        IDocument document = provider.getDocument(editor.getEditorInput());
        document.addDocumentListener(new DocumentListenerAdapter());
        int activeBufferSize = provider.getDocument(editor.getEditorInput()).getLength();

        // BuffTrans: Copy the new active file size to the threshold buffer size .
        EclipseSensor.this.thresholdBufferSize = activeBufferSize;
        EclipseSensor.this.activeBufferSize = activeBufferSize;
      }
    }
  /**
   * Attaches a coverage annotation model for the given editor if the editor can be annotated. Does
   * nothing if the model is already attached.
   *
   * @param editor Editor to attach a annotation model to
   */
  public static void attach(ITextEditor editor) {
    IDocumentProvider provider = editor.getDocumentProvider();
    // there may be text editors without document providers (SF #1725100)
    if (provider == null) return;
    IAnnotationModel model = provider.getAnnotationModel(editor.getEditorInput());
    if (!(model instanceof IAnnotationModelExtension)) return;
    IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;

    IDocument document = provider.getDocument(editor.getEditorInput());

    CoverageAnnotationModel coveragemodel =
        (CoverageAnnotationModel) modelex.getAnnotationModel(KEY);
    if (coveragemodel == null) {
      coveragemodel = new CoverageAnnotationModel(editor, document);
      modelex.addAnnotationModel(KEY, coveragemodel);
    }
  }
    /**
     * Provides manipulation of browser deactivation status due to implement <code>IWindowListener
     * </code>. This method must not be called by client because it is called by platform. Do
     * nothing for Eclipse sensor so far.
     *
     * @param window An IWorkbenchWindow instance to be triggered when a window is deactivated.
     */
    public void windowDeactivated(IWorkbenchWindow window) {
      EclipseSensor.this.isActivatedWindow = false;
      IEditorPart activeEditorPart = window.getActivePage().getActiveEditor();
      if (activeEditorPart instanceof ITextEditor) {
        ITextEditor editor = (ITextEditor) activeEditorPart;
        IDocumentProvider provider = editor.getDocumentProvider();

        // provider could be null if the text editor is closed before this method is called.
        EclipseSensor.this.previousTextEditor = editor;
        int fromFileBufferSize = provider.getDocument(editor.getEditorInput()).getLength();

        // Check if a threshold buffer is either dirty or
        // not the same as the current from file buffer size;
        EclipseSensor.this.isModifiedFromFile =
            (editor.isDirty() || (EclipseSensor.this.thresholdBufferSize != fromFileBufferSize));
      }
    }
    /**
     * Provides manipulation of browser part activation status due to implement <code>IPartListener
     * </code>. This method must not be called by client because it is called by platform. Do
     * nothing for Eclipse sensor so far.
     *
     * @param part An IWorkbenchPart instance to be triggered when a part is activated.
     */
    public void partActivated(IWorkbenchPart part) {

      if (part instanceof ITextEditor) {
        // System.out.println("Sensor : " + part);
        EclipseSensor.this.isActivatedWindow = true;
        EclipseSensor.this.activeTextEditor = (ITextEditor) part;
        ITextEditor editor = EclipseSensor.this.activeTextEditor;
        IDocumentProvider provider = editor.getDocumentProvider();
        IDocument document = provider.getDocument(editor.getEditorInput());
        document.addDocumentListener(new DocumentListenerAdapter());
        int activeBufferSize = provider.getDocument(editor.getEditorInput()).getLength();

        // BuffTrans: Copy the new active file size to the threshold buffer size .
        EclipseSensor.this.thresholdBufferSize = activeBufferSize;
        EclipseSensor.this.activeBufferSize = activeBufferSize;
      }
    }
  public void removeAnnotations() {
    final IDocumentProvider docProvider = fEditor.getDocumentProvider();

    if (docProvider == null) {
      return;
    }

    IAnnotationModel model = docProvider.getAnnotationModel(fEditor.getEditorInput());

    if (model == null) return;

    for (Iterator i = model.getAnnotationIterator(); i.hasNext(); ) {
      Annotation a = (Annotation) i.next();

      if (a.getType().equals(fAnnotationType)) model.removeAnnotation(a);
    }
  }