Package org.eclipse.core.filebuffers

Examples of org.eclipse.core.filebuffers.ITextFileBufferManager


    private boolean isOutOfDate(FileMatch match) {

        if (match.getCreationTimeStamp() != match.getFile().getModificationStamp())
            return true;
        ITextFileBufferManager bm = FileBuffers.getTextFileBufferManager();
        ITextFileBuffer fb = bm.getTextFileBuffer(match.getFile().getFullPath());
        if (fb != null && fb.isDirty())
            return true;
        return false;
    }
View Full Code Here


                        fSkipReadonly = true;
                        skipFile();
                        return;
                }
            }
            ITextFileBufferManager bm = FileBuffers.getTextFileBufferManager();
            try {
                bm.connect(file.getFullPath(), new SubProgressMonitor(pm, 1));
                ITextFileBuffer fb = bm.getTextFileBuffer(file.getFullPath());
                boolean wasDirty = fb.isDirty();
                IDocument doc = fb.getDocument();
                for (int i = 0; i < markers.length; i++) {
                    PositionTracker tracker = InternalSearchUI.getInstance().getPositionTracker();
                    Match match = markers[i];
                    int offset = match.getOffset();
                    int length = match.getLength();
                    Position currentPosition = tracker.getCurrentPosition(match);
                    if (currentPosition != null) {
                        offset = currentPosition.offset;
                        length = currentPosition.length;
                    }
                    String originalText = doc.get(offset, length);
                    String replacementString = computeReplacementString(pattern, originalText, replacementText);
                    doc.replace(offset, length, replacementString);
                    fMarkers.remove(match);
                    fPage.getInput().removeMatch(match);
                }
                if (!wasDirty) {
                    fb.commit(new SubProgressMonitor(pm, 1), true);
                    fSaved = true;
                }
            } finally {
                bm.disconnect(file.getFullPath(), new SubProgressMonitor(pm, 1));
            }
        } finally {
            pm.done();
        }
    }
View Full Code Here

    public static ITextFileBuffer getBufferFromPath(IPath path) {
        try {
            try {

                //eclipse 3.3 has a different interface
                ITextFileBufferManager textFileBufferManager = ITextFileBufferManager.DEFAULT;
                if (textFileBufferManager != null) {//we don't have it in tests
                    ITextFileBuffer textFileBuffer = textFileBufferManager.getTextFileBuffer(path,
                            LocationKind.LOCATION);

                    if (textFileBuffer != null) { //we don't have it when it is not properly refreshed
                        return textFileBuffer;
                    }
                }

            } catch (Throwable e) {//NoSuchMethod/NoClassDef exception
                if (e instanceof ClassNotFoundException || e instanceof LinkageError
                        || e instanceof NoSuchMethodException || e instanceof NoSuchMethodError
                        || e instanceof NoClassDefFoundError) {

                    ITextFileBufferManager textFileBufferManager = FileBuffers.getTextFileBufferManager();

                    if (textFileBufferManager != null) {//we don't have it in tests
                        ITextFileBuffer textFileBuffer = textFileBufferManager.getTextFileBuffer(path);

                        if (textFileBuffer != null) { //we don't have it when it is not properly refreshed
                            return textFileBuffer;
                        }
                    }
View Full Code Here

        }
    }

    private static ITextFileBuffer getBuffer(IFile file) {
        try {
            ITextFileBufferManager manager = ITextFileBufferManager.DEFAULT;
            return manager.getTextFileBuffer(file.getFullPath(), org.eclipse.core.filebuffers.LocationKind.IFILE);
        } catch (Throwable e) {//NoSuchMethod/NoClassDef exception
            if (e instanceof ClassNotFoundException || e instanceof LinkageError || e instanceof NoSuchMethodException
                    || e instanceof NoSuchMethodError || e instanceof NoClassDefFoundError) {
                return null; // that's ok -- not available in Eclipse 3.2
            }
View Full Code Here

    initialize();
  }

  private void initialize() {
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    try {
      manager.connect(fPath, LocationKind.NORMALIZE,
          new NullProgressMonitor());
      fTextFileBuffer = manager.getTextFileBuffer(fPath,
          LocationKind.NORMALIZE);
      fDocument = fTextFileBuffer.getDocument();
    } catch (CoreException x) {
      fStatus = x.getStatus();
      fDocument = manager.createEmptyDocument(fPath,
          LocationKind.NORMALIZE);
      if (fDocument instanceof ISynchronizable)
        ((ISynchronizable) fDocument).setLockObject(new Object());
    }
    fDocument.addPrenotifiedDocumentListener(this);
View Full Code Here

    IDocument d = fDocument;
    fDocument = null;
    d.removePrenotifiedDocumentListener(this);

    if (fTextFileBuffer != null) {
      ITextFileBufferManager manager = FileBuffers
          .getTextFileBufferManager();
      try {
        manager.disconnect(fTextFileBuffer.getLocation(),
            LocationKind.NORMALIZE, new NullProgressMonitor());
      } catch (CoreException x) {
        // ignore
      }
      fTextFileBuffer = null;
View Full Code Here

    File thefile = new File(getFilePath(project, file));
    if(!thefile.exists()){
      return null;
    }

    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    //IPath location = thefile.getFullPath();
    IPath location = new Path(thefile.getAbsolutePath());
    boolean connected = false;
    try {
      ITextFileBuffer buffer =
        manager.getTextFileBuffer(location, LocationKind.LOCATION);
      if (buffer == null) {
        //no existing file buffer..create one
        manager.connect(location, LocationKind.LOCATION, new NullProgressMonitor());
        connected = true;
        buffer = manager.getTextFileBuffer(location, LocationKind.LOCATION);
        if (buffer == null) {
          return null;
        }
      }
      return buffer.getDocument();
    } finally {
      if (connected) {
        try {
          manager.disconnect(
              location, LocationKind.LOCATION, new NullProgressMonitor());
        }catch(Exception e){
        }
      }
    }
View Full Code Here

        TextFileChange change = new PyTextFileChange(Messages.format(
                SearchMessages.ReplaceRefactoring_group_label_change_for_file, file.getName()), file);
        change.setEdit(new MultiTextEdit());

        ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
        manager.connect(file.getFullPath(), LocationKind.IFILE, null);
        try {
            ITextFileBuffer textFileBuffer = manager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
            if (textFileBuffer == null) {
                resultingStatus.addError(Messages.format(SearchMessages.ReplaceRefactoring_error_accessing_file_buffer,
                        file.getName()));
                return null;
            }
            IDocument document = textFileBuffer.getDocument();
            String lineDelimiter = TextUtilities.getDefaultLineDelimiter(document);

            for (Iterator iterator = matches.iterator(); iterator.hasNext();) {
                FileMatch match = (FileMatch) iterator.next();
                int offset = match.getOffset();
                int length = match.getLength();
                Position currentPosition = tracker.getCurrentPosition(match);
                if (currentPosition != null) {
                    offset = currentPosition.offset;
                    if (length != currentPosition.length) {
                        resultingStatus.addError(Messages.format(
                                SearchMessages.ReplaceRefactoring_error_match_content_changed, file.getName()));
                        continue;
                    }
                }

                String originalText = getOriginalText(document, offset, length);
                if (originalText == null) {
                    resultingStatus.addError(Messages.format(
                            SearchMessages.ReplaceRefactoring_error_match_content_changed, file.getName()));
                    continue;
                }

                String replacementString = computeReplacementString(pattern, originalText, fReplaceString,
                        lineDelimiter);
                if (replacementString == null) {
                    resultingStatus.addError(Messages.format(
                            SearchMessages.ReplaceRefactoring_error_match_content_changed, file.getName()));
                    continue;
                }

                ReplaceEdit replaceEdit = new ReplaceEdit(offset, length, replacementString);
                change.addEdit(replaceEdit);
                TextEditChangeGroup textEditChangeGroup = new TextEditChangeGroup(change, new TextEditGroup(
                        SearchMessages.ReplaceRefactoring_group_label_match_replace, replaceEdit));
                change.addTextEditChangeGroup(textEditChangeGroup);
                matchGroups.add(new MatchGroup(textEditChangeGroup, match));
            }
        } finally {
            manager.disconnect(file.getFullPath(), LocationKind.IFILE, null);
        }
        return change;
    }
View Full Code Here

    if (!(element instanceof IAdaptable))
      return null;
    IAdaptable adaptable= (IAdaptable) element;

    IFile file= null;
    ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
    ITextFileBuffer fileBuffer= null;
    LocationKind locationKind= null;

    file= (IFile)adaptable.getAdapter(IFile.class);
    if (file != null) {
      IPath location= file.getFullPath();
      locationKind= LocationKind.IFILE;
      manager.connect(location, locationKind,getProgressMonitor());
      fileBuffer= manager.getTextFileBuffer(location, locationKind);
    } else {
      ILocationProvider provider= (ILocationProvider) adaptable.getAdapter(ILocationProvider.class);
      if (provider instanceof ILocationProviderExtension) {
        URI uri= ((ILocationProviderExtension)provider).getURI(element);
        if (ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri).length == 0) {
          IFileStore fileStore= EFS.getStore(uri);
          manager.connectFileStore(fileStore, getProgressMonitor());
          fileBuffer= manager.getFileStoreTextFileBuffer(fileStore);
        }
      }
      if (fileBuffer == null && provider != null) {
        IPath location= provider.getPath(element);
        if (location == null)
          return null;
        locationKind= LocationKind.NORMALIZE;
        manager.connect(location, locationKind, getProgressMonitor());
        fileBuffer= manager.getTextFileBuffer(location, locationKind);
        file= FileBuffers.getWorkspaceFileAtLocation(location);
      }
    }

    if (fileBuffer != null) {
View Full Code Here

   * @throws CoreException if the creation of the file fails
   */
  protected void createFileFromDocument(IProgressMonitor monitor, IFile file, IDocument document) throws CoreException {
    try {
      monitor.beginTask(EditorMessages.TextFileDocumentProvider_beginTask_saving, 2000);
      ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
      manager.connect(file.getFullPath(), LocationKind.IFILE, monitor);
      ITextFileBuffer buffer= ITextFileBufferManager.DEFAULT.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
      buffer.getDocument().set(document.get());
      buffer.commit(monitor, true);
      manager.disconnect(file.getFullPath(), LocationKind.IFILE, monitor);
    } finally {
      monitor.done();
    }
  }
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.