Package org.eclipse.wst.sse.core.internal.provisional

Examples of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel


  public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
    Object textEditor = getActiveTextEditor();
    if (!(textEditor instanceof ITextEditorExtension3 && ((ITextEditorExtension3) textEditor).getInsertMode() == ITextEditorExtension3.SMART_INSERT))
      return;

    IStructuredModel model = null;
    try {
      model = StructuredModelManager.getModelManager().getExistingModelForRead(document);

      if (model != null) {
        if (command.text != null) {
          smartInsertForEndTag(command, document, model);
          smartRemoveEndTag(command, document, model);
          if (command.text.equals("%") && isPreferenceEnabled(JSPUIPreferenceNames.TYPING_COMPLETE_SCRIPTLETS)) { //$NON-NLS-1$
            // scriptlet - add end %>
            IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset);
            if (node != null && prefixedWith(document, command.offset, "<") && !node.getSource().endsWith("%>")) { //$NON-NLS-1$ //$NON-NLS-2$
              command.text += " %>"; //$NON-NLS-1$
              command.shiftsCaret = false;
              command.caretOffset = command.offset + 1;
              command.doit = false;
            }
          }
          if (command.text.equals("{") && isPreferenceEnabled(JSPUIPreferenceNames.TYPING_COMPLETE_EL_BRACES)) { //$NON-NLS-1$
            IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset);
            if (node != null && (prefixedWith(document, command.offset, "$") || prefixedWith(document, command.offset, "#")) && //$NON-NLS-1$ //$NON-NLS-2$
                  !node.getSource().endsWith("}")) { //$NON-NLS-1$ //$NON-NLS-2$
              command.text += " }"; //$NON-NLS-1$
              command.shiftsCaret = false;
              command.caretOffset = command.offset + 1;
              command.doit = false;
            }
          }
        }
      }
    }
    finally {
      if (model != null)
        model.releaseFromRead();
    }
  }
View Full Code Here


    return type;
  }

  private IFile getFile() {
    IModelManager modelManager = StructuredModelManager.getModelManager();
    IStructuredModel model = null;
    IFile file = null;
    if(modelManager != null) {
      try {
        model = modelManager.getExistingModelForRead(getDocument());
        if (model != null) {
          String baseLocation = model.getBaseLocation();
          // The baseLocation may be a path on disk or relative to the
          // workspace root. Don't translate on-disk paths to
          // in-workspace resources.
          IPath basePath = new Path(baseLocation);
          if (basePath.segmentCount() > 1 && !basePath.toFile().exists()) {
            file = ResourcesPlugin.getWorkspace().getRoot().getFile(basePath);
          }
        }
      }
      finally {
        if (model != null) {
          model.releaseFromRead();
        }
      }
    }
    return file;
  }
View Full Code Here

  /**
   * @return
   */
  private String getURI() {
    IStructuredModel model = null;
    try {
      model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
      if (model != null && !(IModelManager.UNMANAGED_MODEL.equals(model.getBaseLocation()))) {
        return model.getBaseLocation();
      }
    }
    finally {
      if (model != null) {
        model.releaseFromRead();
      }
    }
    return null;
  }
View Full Code Here

   * is needed for
   * @return {@link JSPTranslator} associated with the given <code>jspFilePath</code>, or
   * <code>null</code> if none can be found.
   */
  private static JSPTranslator getJSPTranslator(IFile jspFile) {
    IStructuredModel model = null;
    JSPTranslator translator = null;
    try {
      model = StructuredModelManager.getModelManager().getModelForRead(jspFile);
      if(model instanceof IDOMModel) {
        IDOMDocument doc = ((IDOMModel)model).getDocument();
        ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
        JSPTranslationAdapter adapter = (JSPTranslationAdapter)doc.getAdapterFor(IJSPTranslation.class);
       
        //don't want to persist a translator that has not already been requested
        if(adapter != null && adapter.hasTranslation()) {
          translator = adapter.getJSPTranslation().getTranslator();
        }
      }
    } catch (IOException e) {
      Logger.logException("Could not get translator for " + jspFile.getName() + //$NON-NLS-1$
          " because could not read model for same.", e); //$NON-NLS-1$
    } catch (CoreException e) {
      Logger.logException("Could not get translator for " + jspFile.getName() + //$NON-NLS-1$
          " because could not read model for same.", e); //$NON-NLS-1$
    } finally {
      if(model != null) {
        model.releaseFromRead();
      }
    }
   
    return translator;
  }
View Full Code Here

   * @param fileString
   *            file system path
   * @return returns IFile if fileString exists in the workspace
   */
  protected IFile getFile(String fileString) {
    IStructuredModel model = null;
    IFile file = null;
    try {
      model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
      if (model != null) {
        // use the base location to obtain the in-workspace IFile
        IFile modelFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(model.getBaseLocation()));
        if (modelFile != null) {
          // find the referenced file's location on disk
          URIResolver resolver = model.getResolver();
          if (resolver != null) {
            String filesystemLocation = resolver.getLocationByURI(fileString);
            if (filesystemLocation != null) {
              IFile[] workspaceFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(filesystemLocation));
              // favor a workspace file in the same project
              for (int i = 0; i < workspaceFiles.length && file == null; i++) {
                if (workspaceFiles[i].getProject().equals(modelFile.getProject())) {
                  file = workspaceFiles[i];
                }
              }
              // if none were in the same project, just pick one
              if (file == null && workspaceFiles.length > 0) {
                file = workspaceFiles[0];
              }
            }
          }
        }
      }
    }
    catch (Exception e) {
      Logger.log(Logger.WARNING, e.getMessage());
    }
    finally {
      if (model != null) {
        model.releaseFromRead();
      }
    }
    if (file == null && fileString.startsWith("/")) { //$NON-NLS-1$
      file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileString));
    }
View Full Code Here

      // the contents of the resource
      ModelInfo info = getModelInfoFor((IEditorInput) element);
      if (info == null) {
        throw new IllegalArgumentException("no corresponding model info found"); //$NON-NLS-1$
      }
      IStructuredModel model = info.fStructuredModel;
      if (model != null) {
        if (!fReuseModelDocument && element instanceof IStorageEditorInput) {
          Reader reader = null;
          IStructuredDocument innerdocument = null;
          try {
            // update document from input's contents

            CodedReaderCreator codedReaderCreator = new CodedReaderCreator(calculateID((IStorageEditorInput) element), Utilities.getMarkSupportedStream(((IStorageEditorInput) element).getStorage().getContents()));
            reader = codedReaderCreator.getCodedReader();

            innerdocument = model.getStructuredDocument();

            int originalLengthToReplace = innerdocument.getLength();

            /*
             * TODO_future: we could implement with sequential
             * rewrite, if we don't pickup automatically from
             * FileBuffer support, so not so much has to be pulled
             * into memory (as an extra big string), but we need
             * to carry that API through so that StructuredModel
             * is not notified until done.
             */

            // innerdocument.startSequentialRewrite(true);
            // innerdocument.replaceText(this, 0,
            // innerdocument.getLength(), "");
            StringBuffer stringBuffer = new StringBuffer();
            int bufferSize = 2048;
            char[] buffer = new char[bufferSize];
            int nRead = 0;
            boolean eof = false;
            while (!eof) {
              nRead = reader.read(buffer, 0, bufferSize);
              if (nRead == -1) {
                eof = true;
              }
              else {
                stringBuffer.append(buffer, 0, nRead);
                // innerdocument.replaceText(this,
                // innerdocument.getLength(), 0, new
                // String(buffer, 0, nRead));
              }
            }
            // ignore read-only settings if reverting whole
            // document
            innerdocument.replaceText(this, 0, originalLengthToReplace, stringBuffer.toString(), true);
            model.setDirtyState(false);

          }
          catch (CoreException e) {
            Logger.logException(e);
          }
          catch (IOException e) {
            Logger.logException(e);
          }
          finally {
            if (reader != null) {
              try {
                reader.close();
              }
              catch (IOException e1) {
                // would be highly unusual
                Logger.logException(e1);
              }
            }
            // if (innerdocument != null) {
            // innerdocument.stopSequentialRewrite();
            // }
          }

        }
        document = model.getStructuredDocument();
      }
    }
    return document;
  }
View Full Code Here

    if (request != null) {
      IStructuredDocumentRegion region = request.getDocumentRegion();
      if (region != null) {
        IDocument document = region.getParentDocument();
        IStructuredModel model = null;
        try {
          model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
          if (model != null) {
            String location = model.getBaseLocation();
            if (location != null) {
              baselocation = new Path(location);
            }
          }
        }
        finally {
          if (model != null)
            model.releaseFromRead();
        }
      }
    }
    return baselocation;
  }
View Full Code Here

    return info;
  }

  public void createModelInfo(IEditorInput input) {
    if (getModelInfoFor(input) == null) {
      IStructuredModel structuredModel = selfCreateModel(input);
      if (structuredModel != null) {
        createModelInfo(input, structuredModel, true);
      }
    }
  }
View Full Code Here

    }
    return charset;
  }

  public IStructuredModel getModel(IEditorInput element) {
    IStructuredModel result = null;
    ModelInfo info = getModelInfoFor(element);
    if (info != null) {
      result = info.fStructuredModel;
    }
    return result;
View Full Code Here

    catch (CoreException noStorageExc) {
      if (logExceptions)
        Logger.logException(NLS.bind(SSEUIMessages._32concat_EXC_, new Object[]{input.getName()}), noStorageExc);
    }

    IStructuredModel model = null;
    try {
      // first parameter must be unique
      model = StructuredModelManager.getModelManager().getModelForEdit(id, contents, null);
      model.setBaseLocation(calculateBaseLocation(input));
    }
    catch (IOException e) {
      if (logExceptions)
        Logger.logException(NLS.bind(SSEUIMessages._32concat_EXC_, new Object[]{input}), e);
    }
View Full Code Here

TOP

Related Classes of org.eclipse.wst.sse.core.internal.provisional.IStructuredModel

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.