Package org.eclipse.core.filebuffers

Examples of org.eclipse.core.filebuffers.ITextFileBufferManager


  /*
   * @see org.eclipse.ui.internal.editors.text.FileBufferOperationAction#isAcceptableLocation(org.eclipse.core.runtime.IPath)
   */
  protected boolean isAcceptableLocation(IPath location) {
    ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
    return location != null && manager.isTextFileLocation(location, true);
  }
View Full Code Here


     */
    protected static ITextFileBuffer getTextFileBuffer(IResource resource) {

        IPath fullPath = resource.getFullPath();

        ITextFileBufferManager tfbm = FileBuffers.getTextFileBufferManager();

        ITextFileBuffer fileBuff = tfbm.getTextFileBuffer(fullPath,
            LocationKind.IFILE);
        if (fileBuff != null)
            return fileBuff;
        else {
            try {
                /*
                 * FIXME This call to connect never has a matching call to
                 * disconnect
                 */
                tfbm.connect(fullPath, LocationKind.IFILE,
                    new NullProgressMonitor());
            } catch (CoreException e) {
                EditorManager.log
                    .error("Could not connect to file " + fullPath);
                return null;
            }
            return tfbm.getTextFileBuffer(fullPath, LocationKind.IFILE);
        }
    }
View Full Code Here

        boolean wasReadOnly = FileUtils.setReadOnly(file, false);

        // Now run the conversion operation
        IPath[] paths = new IPath[] { file.getFullPath() };

        ITextFileBufferManager buffManager = FileBuffers
            .getTextFileBufferManager();

        // convert operation to change line delimiters
        TextFileBufferOperation convertOperation = new ConvertLineDelimitersOperation(
            "\n");
View Full Code Here

      // BUG 178598 - If the resource is shared, and it's possible to
      // get the workbench Display, the UI thread is asked to execute the
      // format of the file when it can
      monitor.beginTask("", 20); //$NON-NLS-1$
      try {
        ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
        ITextFileBuffer buffer = null;
       
        try {
          if(manager != null) {
            manager.connect(file.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
            buffer = manager.getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
          }
         
          if(buffer != null && buffer.isShared()) {
            Display display = getDisplay();
            if (display != null) {
              display.syncExec(new Runnable() {
                public void run() {
                  format(new SubProgressMonitor(monitor, 18), file);
                }
              });
            }
          }
          else
            format(new SubProgressMonitor(monitor, 18), file);
        }
        finally {
          if(manager != null)
            manager.disconnect(file.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
        }
        monitor.done();
      }
      catch(CoreException e) {
        String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[]{file.getFullPath().toString()});
View Full Code Here

     
      // BUG 178598 - If the resource is shared, and it's possible to
      // get the workbench Display, the UI thread is asked to execute the
      // format of the file when it can
      try {
        ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
        ITextFileBuffer buffer = null;
       
        try {
          if(manager != null) {
            manager.connect(file.getFullPath(), LocationKind.IFILE, monitor);
            buffer = manager.getTextFileBuffer(resource.getFullPath(), LocationKind.IFILE);
          }
         
          if(buffer != null && buffer.isShared()) {
            Display display = getDisplay();
            display.syncExec(new Runnable() {
              public void run() {
                format(monitor, file);
              }
            });
          }
          else
            format(monitor, file);
        }
        finally {
          if(manager != null)
            manager.disconnect(file.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
        }
      }
      catch(CoreException e) {
        String message = NLS.bind(SSEUIMessages.FormatActionDelegate_4, new String[]{file.getFullPath().toString()});
        fErrorStatus.add(new Status(IStatus.ERROR, SSEUIPlugin.ID, IStatus.ERROR, message, e));
View Full Code Here

    Iterator<CompilationUnit> iterator = cache.values().iterator();
    while (iterator.hasNext()) {
      try {
        CompilationUnit cu = iterator.next();
        ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
        IPath path = cu.getJavaElement().getPath();
        bufferManager.connect(path, null);

        ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path);
        IDocument document = textFileBuffer.getDocument();

        TextEdit edit = cu.rewrite(document, javaProject.getOptions(true));
        TextFileChange dc = new TextFileChange(path.toString(), (IFile) cu.getJavaElement().getResource());
        dc.setTextType("java"); //$NON-NLS-1$
View Full Code Here

   * @throws CoreException
   *             thrown if file paths cannot be connected or disconnected
   */
  public static void save(CompilationUnit unit,
      TextEditProvider textEditProvider) throws CoreException {
    ITextFileBufferManager bufferManager = FileBuffers
        .getTextFileBufferManager();
    IPath path = unit.getJavaElement().getPath();
    try {
      // connect the path
      bufferManager.connect(path, null);

      ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path);
      // retrieve the buffer
      IDocument document = textFileBuffer
          .getDocument();

      // ask the textEditProvider for the change information
      TextEdit edit = textEditProvider.getTextEdit(document);

      // apply the changes to the document
      edit.apply(document);

      // write the changes from the buffer to the file
      textFileBuffer
          .commit(null /* ProgressMonitor */, false /* Overwrite */);

    } catch (MalformedTreeException e) {
      e.printStackTrace();
    } catch (BadLocationException e) {
      e.printStackTrace();
    } finally {
      // disconnect the path
      bufferManager.disconnect(path, null);
    }
  }
View Full Code Here

   * @throws CoreException
   *             thrown if file paths cannot be connected or disconnected
   */
  public static void save(CompilationUnit unit,
      TextEditProvider textEditProvider) throws CoreException {
    ITextFileBufferManager bufferManager = FileBuffers
        .getTextFileBufferManager();
    IPath path = unit.getJavaElement().getPath();
    try {
      // connect the path
      bufferManager.connect(path, null);

      // retrieve the buffer
      IDocument document = bufferManager.getTextFileBuffer(path)
          .getDocument();

      // ask the textEditProvider for the change information
      TextEdit edit = textEditProvider.getTextEdit(document);

      // apply the changes to the document
      edit.apply(document);

    } catch (MalformedTreeException e) {
      e.printStackTrace();
    } catch (BadLocationException e) {
      e.printStackTrace();
    } finally {
      // disconnect the path
      bufferManager.disconnect(path, null);
    }
  }
View Full Code Here

  public IDocument getCurrentDocument(IProgressMonitor pm) throws CoreException {
    if (pm == null)
      pm = new NullProgressMonitor();
    IDocument result = null;
    pm.beginTask("", 2); //$NON-NLS-1$
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    try {
      IPath path = fCurrentFile.getFullPath();
      manager.connect(path, LocationKind.NORMALIZE, pm);
      ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.NORMALIZE);
      result = buffer.getDocument();
    } finally {
      if (result != null)
        manager.disconnect(fCurrentFile.getFullPath(), LocationKind.NORMALIZE, pm);
    }
    pm.done();
    return result;
  }
View Full Code Here

        try {
            monitor.beginTask("Calculating changed lines", 20);
            IFileStore fileStore = buffer.getFileStore();

            ITextFileBufferManager fileBufferManager = FileBuffers.createTextFileBufferManager();
            fileBufferManager.connectFileStore(fileStore, getSubProgressMonitor(monitor, 15));
            try {
                IDocument currentDocument = buffer.getDocument();
                IDocument oldDocument = ((ITextFileBuffer) fileBufferManager.getFileStoreFileBuffer(fileStore))
                        .getDocument();

                result = getChangedLines(oldDocument, currentDocument);
            } finally {
                fileBufferManager.disconnectFileStore(fileStore, getSubProgressMonitor(monitor, 5));
                monitor.done();
            }
        } catch (Exception e) {
            Log.log(e);
            return null;
View Full Code Here

TOP

Related Classes of org.eclipse.core.filebuffers.ITextFileBufferManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.