Ejemplo n.º 1
1
  /**
   * Updates the element info to a change of the file content and sends out appropriate
   * notifications.
   *
   * @param fileEditorInput the input of an text editor
   */
  protected void handleElementContentChanged(IEditorInput fileEditorInput) {
    FileInfo info = (FileInfo) getElementInfo(fileEditorInput);
    if (info == null) {
      return;
    }

    IStorage storage = EditorUtils.getStorageFromInput(fileEditorInput);
    if (storage instanceof IFile) {
      IFile file = (IFile) storage;
      IDocument document = createEmptyDocument();
      IStatus status = null;

      try {

        try {
          refreshFile(file);
        } catch (CoreException x) {
          log.error("handleElementContentChanged", x);
        }

        setDocumentContent(document, file);
      } catch (CoreException x) {
        status = x.getStatus();
      }

      String newContent = document.get();

      if (!newContent.equals(info.fDocument.get())) {

        // set the new content and fire content related events
        fireElementContentAboutToBeReplaced(fileEditorInput);

        removeUnchangedElementListeners(fileEditorInput, info);

        info.fDocument.removeDocumentListener(info);
        info.fDocument.set(newContent);
        info.fCanBeSaved = false;
        info.modificationStamp = computeModificationStamp(file);
        info.fStatus = status;

        addUnchangedElementListeners(fileEditorInput, info);

        fireElementContentReplaced(fileEditorInput);

      } else {

        removeUnchangedElementListeners(fileEditorInput, info);

        // fires only the dirty state related event
        info.fCanBeSaved = false;
        info.modificationStamp = computeModificationStamp(file);
        info.fStatus = status;

        addUnchangedElementListeners(fileEditorInput, info);

        fireElementDirtyStateChanged(fileEditorInput, false);
      }
    }
  }