Package org.eclipse.core.filebuffers

Examples of org.eclipse.core.filebuffers.ITextFileBuffer


    ITextFileBufferManager bufferManager = FileBuffers
        .getTextFileBufferManager();
    IPath path = fSourceModule.getPath();
    bufferManager.connect(path, LocationKind.IFILE, null);
    ITextFileBuffer textFileBuffer = bufferManager.getTextFileBuffer(path,
        LocationKind.IFILE);
   
    IDocument document = textFileBuffer.getDocument();
   
    DocumentChange anotherChange = new DocumentChange(RefactoringMessages.ExtractMethodPreviewPage_TextChangeName, document);
   
    MultiTextEdit rootEdit = new MultiTextEdit();
   
View Full Code Here


      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) {
      fileBuffer.requestSynchronizationContext();

      FileInfo info= createEmptyFileInfo();
      info.fTextFileBuffer= fileBuffer;
      info.fTextFileBufferLocationKind= locationKind;
      info.fCachedReadOnlyState= isSystemFileReadOnly(info);
View Full Code Here

  protected void createFileFromDocument(IProgressMonitor monitor, IFile file, IDocument document) throws CoreException {
    try {
      monitor.beginTask(TextEditorMessages.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

  private void createFileStoreFromDocument(IProgressMonitor monitor, URI uri, IDocument document) throws CoreException {
    try {
      monitor.beginTask(TextEditorMessages.TextFileDocumentProvider_beginTask_saving, 2000);
      IFileStore fileStore= EFS.getStore(uri);
      FileBuffers.getTextFileBufferManager().connectFileStore(fileStore, monitor);
      ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getFileStoreTextFileBuffer(fileStore);
      buffer.getDocument().set(document.get());
      buffer.commit(monitor, true);
      FileBuffers.getTextFileBufferManager().disconnectFileStore(fileStore, monitor);
    } finally {
      monitor.done();
    }
  }
View Full Code Here

      throw new FileNotFoundException();
    }
    file.refreshLocal(1, new NullProgressMonitor());
    IPath fullPath = file.getFullPath();
    boolean dispose = false;
    ITextFileBuffer fileBuffer = (ITextFileBuffer) FileBuffers
        .getTextFileBufferManager().getTextFileBuffer(fullPath,
            LocationKind.IFILE);
    if (fileBuffer == null) {
      FileBuffers.getTextFileBufferManager().connect(fullPath,
          LocationKind.IFILE, monitor);
      fileBuffer = (ITextFileBuffer) FileBuffers
          .getTextFileBufferManager().getTextFileBuffer(fullPath,
              LocationKind.IFILE);
      dispose = true;
    }
    IDocument document = fileBuffer.getDocument();
    try {
      DocumentBuilderFactory newInstance = getBuilder();

      DocumentBuilder newDocumentBuilder = newInstance
          .newDocumentBuilder();
      newDocumentBuilder.setEntityResolver(new EntityResolver() {

        public InputSource resolveEntity(String publicId,
            String systemId) throws SAXException, IOException {
          return new InputSource(new StringReader(""));
        }
      });
      Document parse = newDocumentBuilder.parse(conf.openStream());
      Document myWebXML = newDocumentBuilder.parse(new InputSource(
          new StringReader(document.get())));
      NodeList childNodes = parse.getDocumentElement().getChildNodes();
      ArrayList<Element> toAppend = new ArrayList<Element>();
      for (int a = 0; a < childNodes.getLength(); a++) {
        Node n = childNodes.item(a);
        if (n instanceof Element) {
          Element k = (Element) n;
          Element el = find(myWebXML, k);
          if (el == null) {
            toAppend.add(k);
          }

        }
      }
      if (!toAppend.isEmpty()) {
        NodeList childNodes2 = myWebXML.getDocumentElement()
            .getChildNodes();
        boolean inserted = false;
        for (int a = 0; a < childNodes2.getLength(); a++) {
          Node item = childNodes2.item(a);
          if (item instanceof Comment) {
            Comment mn = (Comment) item;
            if (mn.getTextContent().contains(
                ONPOSITIVE_COMMENTS_MARK)) {
              for (Element e : toAppend) {
                Node adoptNode = myWebXML.adoptNode(e
                    .cloneNode(true));
                if (a != childNodes2.getLength() - 1) {
                  try {
                    myWebXML.getDocumentElement()
                        .insertBefore(adoptNode,
                            childNodes.item(a + 1));
                  } catch (DOMException ex) {
                    mn.getParentNode().appendChild(
                        adoptNode);
                  }
                } else {
                  myWebXML.appendChild(adoptNode);
                }
              }
              inserted = true;
            }
          }
        }
        if (!inserted) {
          myWebXML.getDocumentElement().appendChild(
              myWebXML.createComment(ONPOSITIVE_COMMENTS_MARK));
          myWebXML.getDocumentElement().appendChild(
              myWebXML.createTextNode("\n"));
          for (Element e : toAppend) {
            Node adoptNode = myWebXML.adoptNode(e.cloneNode(true));
            myWebXML.getDocumentElement().appendChild(adoptNode);
          }
        }
      }
      StringWriter writer = new StringWriter();
      Result outputTarget = new StreamResult(writer);
      ;
      Transformer newTransformer = TransformerFactory.newInstance()
          .newTransformer();
      newTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
      newTransformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
          "yes");
      newTransformer.transform(new DOMSource(myWebXML), outputTarget);
      document.set(writer.toString());
    } catch (Exception e) {
      throw new IOException(e.getMessage());
    }

    fileBuffer.commit(monitor, true);
    if (dispose) {
      FileBuffers.getTextFileBufferManager().disconnect(fullPath,
          LocationKind.IFILE, monitor);
    }
  }
View Full Code Here

    if (!file.exists()) {
      throw new FileNotFoundException();
    }
    IPath fullPath = file.getFullPath();
    boolean dispose = false;
    ITextFileBuffer fileBuffer = (ITextFileBuffer) FileBuffers
        .getTextFileBufferManager().getTextFileBuffer(fullPath,
            LocationKind.IFILE);
    if (fileBuffer == null) {
      FileBuffers.getTextFileBufferManager().connect(fullPath,
          LocationKind.IFILE, monitor);
      fileBuffer = (ITextFileBuffer) FileBuffers
          .getTextFileBufferManager().getTextFileBuffer(fullPath,
              LocationKind.IFILE);
      dispose = true;
    }
    IDocument document = fileBuffer.getDocument();
    try {
      DocumentBuilderFactory newInstance2 = getBuilder();
      DocumentBuilderFactory newInstance = newInstance2;
      DocumentBuilder newDocumentBuilder = newInstance
          .newDocumentBuilder();
      newDocumentBuilder.setEntityResolver(new EntityResolver() {

        public InputSource resolveEntity(String publicId,
            String systemId) throws SAXException, IOException {
          return new InputSource(new StringReader(""));
        }
      });
      newInstance.setValidating(false);
      newInstance.setXIncludeAware(false);
      newInstance.setNamespaceAware(false);
      newInstance.setExpandEntityReferences(false);
      Document parse = newDocumentBuilder.parse(conf.openStream());
      Document myWebXML = newDocumentBuilder.parse(new InputSource(
          new StringReader(document.get())));
      NodeList childNodes = parse.getDocumentElement().getChildNodes();
      for (int a = 0; a < childNodes.getLength(); a++) {
        Node n = childNodes.item(a);
        if (n instanceof Element) {
          Element k = (Element) n;
          Element el = find(myWebXML, k);
          if (el != null) {
            myWebXML.getDocumentElement().removeChild(el);
          }

        }
      }
      StringWriter writer = new StringWriter();
      Result outputTarget = new StreamResult(writer);
      Transformer newTransformer = TransformerFactory.newInstance()
          .newTransformer();
      newTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
      newTransformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
          "yes");
      newTransformer.transform(new DOMSource(myWebXML), outputTarget);
      document.set(writer.toString());
    } catch (Exception e) {
      throw new IOException(e.getMessage());
    }

    fileBuffer.commit(monitor, true);
    if (dispose) {
      FileBuffers.getTextFileBufferManager().disconnect(fullPath,
          LocationKind.IFILE, monitor);
    }
View Full Code Here

    if (!file.exists()) {
      return false;
    }
    IPath fullPath = file.getFullPath();
    boolean dispose = false;
    ITextFileBuffer fileBuffer = (ITextFileBuffer) FileBuffers
        .getTextFileBufferManager().getTextFileBuffer(fullPath,
            LocationKind.IFILE);
    if (fileBuffer == null) {
      try {
        FileBuffers.getTextFileBufferManager().connect(fullPath,
            LocationKind.IFILE, new NullProgressMonitor());
      } catch (CoreException e) {
        return false;
      }
      fileBuffer = (ITextFileBuffer) FileBuffers
          .getTextFileBufferManager().getTextFileBuffer(fullPath,
              LocationKind.IFILE);
      dispose = true;
    }
    IDocument document = fileBuffer.getDocument();
    try {
      DocumentBuilderFactory newInstance = getBuilder();
      DocumentBuilder newDocumentBuilder = newInstance
          .newDocumentBuilder();
      newDocumentBuilder.setEntityResolver(new EntityResolver() {
View Full Code Here

        IPath fullPath = resource.getFullPath();

        ITextFileBufferManager tfbm = FileBuffers.getTextFileBufferManager();

        ITextFileBuffer fileBuff = tfbm.getTextFileBuffer(fullPath,
            LocationKind.IFILE);
        if (fileBuff != null)
            return fileBuff;
        else {
            try {
View Full Code Here

    return scopes;
  }

  private IFile getFile(IStructuredDocument document) {
    IFile f = null;
    final ITextFileBuffer buffer = FileBufferModelManager.getInstance().getBuffer(document);
    if (buffer != null) {
      final IPath path = buffer.getLocation();
      if (path.segmentCount() > 1) {
        f = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
      }
      if (f != null && f.isAccessible()) {
        return f;
View Full Code Here

      // 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);
View Full Code Here

TOP

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

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.