Java Code Examples for org.eclipse.jface.text.IDocumentExtension3#getDocumentPartitioner()

The following examples show how to use org.eclipse.jface.text.IDocumentExtension3#getDocumentPartitioner() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PyPartitionScanner.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks if the partitioner is correctly set in the document.
 * @return the partitioner that is set in the document
 */
public static IDocumentPartitioner checkPartitionScanner(IDocument document,
        IGrammarVersionProvider grammarVersionProvider) {
    if (document == null) {
        return null;
    }

    IDocumentExtension3 docExtension = (IDocumentExtension3) document;
    IDocumentPartitioner partitioner = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE);
    if (partitioner == null) {
        addPartitionScanner(document, grammarVersionProvider);
        //get it again for the next check
        partitioner = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE);
    }
    if (!(partitioner instanceof PyPartitioner)) {
        Log.log("Partitioner should be subclass of PyPartitioner. It is " + partitioner.getClass());
    }

    return partitioner;
}
 
Example 2
Source File: PyPartitionScanner.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see http://help.eclipse.org/help31/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_documents.htm
 * @see http://jroller.com/page/bobfoster -  Saturday July 16, 2005
 * @param document the document where we want to add the partitioner
 * @return the added document partitioner (or null)
 */
public static IDocumentPartitioner addPartitionScanner(IDocument document,
        IGrammarVersionProvider grammarVersionProvider) {
    if (document != null) {
        IDocumentExtension3 docExtension = (IDocumentExtension3) document;
        IDocumentPartitioner curr = docExtension.getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE);

        if (curr == null) {
            //set the new one
            PyPartitioner partitioner = createPyPartitioner();
            partitioner.connect(document);
            docExtension.setDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE, partitioner);
            return partitioner;
        } else {
            return curr;
        }
    }
    return null;
}
 
Example 3
Source File: PartitionUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the partitioner for the given partitioning or <code>null</code> if
 * no partitioner is registered.
 *
 * @param document the document to be processed
 * @param  partitioningType the partitioning for which to set the partitioner
 * @return the partitioner for the given partitioning
 * 
 * @see org.eclipse.jface.text.IDocumentExtension3#getDocumentPartitioner(IDocument,String)
 */
public static IDocumentPartitioner getPartitioner( IDocument document
                                                 , String partitioningType ) 
{
    IDocumentPartitioner result = null;
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 extension = (IDocumentExtension3) document;
        result = extension.getDocumentPartitioner(partitioningType);
    } else if (document != null){
        result = document.getDocumentPartitioner();
    }
    return result;
}
 
Example 4
Source File: ParsingUtils.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param document the document we want to get info on
 * @param i the document offset we're interested in
 * @return the content type at that position (according to IPythonPartitions)
 *
 * Uses the default if the partitioner is not set in the document (for testing purposes)
 */
public static String getContentType(IDocument document, int i) {
    IDocumentExtension3 docExtension = (IDocumentExtension3) document;
    IDocumentPartitionerExtension2 partitioner = (IDocumentPartitionerExtension2) docExtension
            .getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE);

    if (partitioner != null) {
        return partitioner.getContentType(i, true);
    }
    return getContentType(document.get(), i);
}
 
Example 5
Source File: LangDocumentPartitionerSetup.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public void setupPartitioningIfNotSet(IDocument document) {
	if(document instanceof IDocumentExtension3) {
		IDocumentExtension3 extension3 = (IDocumentExtension3) document;
		
		String partitioning = TextSettings_Actual.PARTITIONING_ID;
		
		if(extension3.getDocumentPartitioner(partitioning) == null) {
			IDocumentPartitioner partitioner = createDocumentPartitioner();
			partitioner.connect(document);
			extension3.setDocumentPartitioner(partitioning, partitioner);
		}
	}
}
 
Example 6
Source File: EditorAction.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public void run(IAction action) {
  if (targetEditor == null) {
    GWTPluginLog.logWarning("targetEditor is null");
    return;
  }

  IEditorInput editorInput = targetEditor.getEditorInput();
  IResource resource = (IResource) editorInput.getAdapter(IResource.class);
  ITextEditor javaEditor = (ITextEditor) targetEditor;
  ITextSelection sel = (ITextSelection) javaEditor.getSelectionProvider().getSelection();
  IDocument document = javaEditor.getDocumentProvider().getDocument(
      javaEditor.getEditorInput());

  IDocumentExtension3 document3 = (IDocumentExtension3) document;
  IDocumentPartitioner gwtPartitioner = document3.getDocumentPartitioner(GWTPartitions.GWT_PARTITIONING);

  String[] partitionings = document3.getPartitionings();
  String partitioning = (gwtPartitioner != null
      ? GWTPartitions.GWT_PARTITIONING : IJavaPartitions.JAVA_PARTITIONING);

  ITypedRegion[] types;
  try {
    types = TextUtilities.computePartitioning(document, partitioning,
        sel.getOffset(), sel.getLength(), false);
  } catch (BadLocationException e) {
    GWTPluginLog.logError(e);
    return;
  }

  String msg = "File: " + resource.getName();

  msg += "\nPartitionings: ";
  for (String part : partitionings) {
    msg += "\n" + part;
  }

  msg += "\n\nContent types: ";
  for (ITypedRegion type : types) {
    msg += "\n" + type.getType();
  }

  msg += "\n\nSelection range: (offset = " + sel.getOffset() + ", length = "
      + sel.getLength() + ")";

  MessageDialog.openInformation(targetEditor.getSite().getShell(),
      "Selection Info", msg);
}