Java Code Examples for org.eclipse.jface.text.IDocumentPartitioner#connect()

The following examples show how to use org.eclipse.jface.text.IDocumentPartitioner#connect() . 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: CompositeDocumentProvider.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void connect(Object element) throws CoreException {
	super.connect(element);

	IDocument document = getDocument(element);
	if (document != null) {
		CompositePartitionScanner partitionScanner = new CompositePartitionScanner(defaultPartitioningConfiguration.createSubPartitionScanner(),
				primaryPartitioningConfiguration.createSubPartitionScanner(), partitionerSwitchStrategy);
		IDocumentPartitioner partitioner = new ExtendedFastPartitioner(partitionScanner, TextUtils.combine(new String[][] { CompositePartitionScanner.SWITCHING_CONTENT_TYPES,
				defaultPartitioningConfiguration.getContentTypes(), primaryPartitioningConfiguration.getContentTypes() }));
		partitionScanner.setPartitioner((IExtendedPartitioner) partitioner);
		partitioner.connect(document);
		document.setDocumentPartitioner(partitioner);
		CommonEditorPlugin.getDefault().getDocumentScopeManager()
				.registerConfigurations(document, new IPartitioningConfiguration[] { defaultPartitioningConfiguration, primaryPartitioningConfiguration });
	}
}
 
Example 2
Source File: HTMLDocumentProvider.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void connect(Object element) throws CoreException {
	super.connect(element);

	IDocument document = getDocument(element);
	if (document != null) {
		CompositePartitionScanner partitionScanner = new CompositePartitionScanner(HTMLSourceConfiguration
				.getDefault().createSubPartitionScanner(), new NullSubPartitionScanner(),
				new NullPartitionerSwitchStrategy());
		IDocumentPartitioner partitioner = new ExtendedFastPartitioner(partitionScanner, HTMLSourceConfiguration
				.getDefault().getContentTypes());
		partitionScanner.setPartitioner((IExtendedPartitioner) partitioner);
		partitioner.connect(document);
		document.setDocumentPartitioner(partitioner);
		CommonEditorPlugin.getDefault().getDocumentScopeManager().registerConfiguration(document,
				HTMLSourceConfiguration.getDefault());
	}
}
 
Example 3
Source File: ResultPage.java    From tlaplus with MIT License 6 votes vote down vote up
/**
    * Gets the data provider for the current page
    */
   @Override
public void loadData() throws CoreException {
   	final TLCOutputSourceRegistry modelCheckSourceRegistry = TLCOutputSourceRegistry.getModelCheckSourceRegistry();
   	final TLCModelLaunchDataProvider provider = modelCheckSourceRegistry.getProvider(getModel());
	if (provider != null) {
		provider.addDataPresenter(this);
	} else {
		// no data provider
		reinit();
	}

	// constant expression
	final Document document = new Document(getModel().getEvalExpression());
	final IDocumentPartitioner partitioner = new TLAFastPartitioner(
			TLAEditorActivator.getDefault().getTLAPartitionScanner(), TLAPartitionScanner.TLA_PARTITION_TYPES);
	document.setDocumentPartitioner(TLAPartitionScanner.TLA_PARTITIONING, partitioner);
	partitioner.connect(document);
	if (expressionEvalInput != null) {
		expressionEvalInput.setDocument(document);
	}
}
 
Example 4
Source File: EvaluateConstantExpressionPage.java    From tlaplus with MIT License 6 votes vote down vote up
/**
    * Gets the data provider for the current page
    */
   @Override
public void loadData() throws CoreException {
	final TLCOutputSourceRegistry modelCheckSourceRegistry = TLCOutputSourceRegistry.getModelCheckSourceRegistry();
	final TLCModelLaunchDataProvider provider = modelCheckSourceRegistry.getProvider(getModel());
	if (provider != null) {
		provider.addDataPresenter(this);
	} else {
		// no data provider
		m_expressionOutput.getTextWidget().setText("");
	}
   	
	final Document document = new Document(getModel().getEvalExpression());
	final IDocumentPartitioner partitioner = new TLAFastPartitioner(
			TLAEditorActivator.getDefault().getTLAPartitionScanner(), TLAPartitionScanner.TLA_PARTITION_TYPES);
	document.setDocumentPartitioner(TLAPartitionScanner.TLA_PARTITIONING, partitioner);
	partitioner.connect(document);
	m_expressionInput.setDocument(document);
}
 
Example 5
Source File: PartitionUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets document's partitioner. 
 *
 * @param document the document to be processed
 * @param partitioningType the partitioning for which to set the partitioner
 * @param partitioner the document's new partitioner
 * 
 * @see org.eclipse.jface.text.IDocumentExtension3#setDocumentPartitioner(IDocument,String,IDocumentPartitioner)
 * @see IDocumentPartitioningListener
 */
public static void setDocumentPartitioning( IDocument document
                                          , String partitioningType
                                          , IDocumentPartitioner partitioner ) 
{
    // Setting the partitioner will trigger a partitionChanged listener that
    // will attempt to use the partitioner to initialize the document's
    // partitions. Therefore, need to connect first.
    partitioner.connect(document);
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 extension3= (IDocumentExtension3) document;
        extension3.setDocumentPartitioner(partitioningType, partitioner);
    } else {
        document.setDocumentPartitioner(partitioner);
    }
}
 
Example 6
Source File: DocumentProvider.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected IDocument createDocument(Object element) throws CoreException {
	
	IDocument document = super.createDocument(element);
	//IDocumentPartitioner partitioner = createDocumentPartitioner();
	IDocumentPartitioner partitioner = new ImpexDocumentPartitioner();
	
	if ((document instanceof IDocumentExtension3)) {
		IDocumentExtension3 extension3 = (IDocumentExtension3) document;
		extension3.setDocumentPartitioner(Activator.IMPEX_PARTITIONING, partitioner);
	}
	else {
		document.setDocumentPartitioner(partitioner);
	}
	
	partitioner.connect(document);
	return document;
}
 
Example 7
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected IDocument createDocument(Object element) throws CoreException {
	IDocument document = null;
	if (isWorkspaceExternalEditorInput(element)) {
		document= createEmptyDocument();
		if (setDocumentContent(document, (IEditorInput) element, getEncoding(element))) {
			setupDocument(element, document);
		}
	} else {
		document = super.createDocument(element);
	}
	if (document != null) {
		IDocumentPartitioner partitioner = documentPartitioner.get();
		partitioner.connect(document);
		document.setDocumentPartitioner(partitioner);
	}
	return document;
}
 
Example 8
Source File: DocumentUtils.java    From http4e with Apache License 2.0 6 votes vote down vote up
public static IDocument createDocument1(){
   IDocument doc = new Document(){
      public String getDefaultLineDelimiter(){
         return String.valueOf(AssistConstants.LINE_DELIM_NL) /*super.getDefaultLineDelimiter()*/;
      }
   };
   IDocumentPartitioner partitioner = new DefaultPartitioner(
         new HPartitionScanner(), 
         new String[] {
             HPartitionScanner.COMMENT,
             HPartitionScanner.PROPERTY_VALUE});
   partitioner.connect(doc);
   doc.setDocumentPartitioner(partitioner);
   
   return doc;  
}
 
Example 9
Source File: PropertiesFileDocumentSetupParticipant.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param document the document
 * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
 */
public static void setupDocument(IDocument document) {
	IDocumentPartitioner partitioner= createDocumentPartitioner();
	if (document instanceof IDocumentExtension3) {
		IDocumentExtension3 extension3= (IDocumentExtension3) document;
		extension3.setDocumentPartitioner(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, partitioner);
	} else {
		document.setDocumentPartitioner(partitioner);
	}
	partitioner.connect(document);
}
 
Example 10
Source File: EclipseUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static void setupDocumentPartitioner(IDocument document, String partitioning, 
		IDocumentPartitioner partitioner) {
	assertNotNull(document);
	assertNotNull(partitioning);
	assertNotNull(partitioner);
	
	partitioner.connect(document);
	if (document instanceof IDocumentExtension3) {
		IDocumentExtension3 extension3 = (IDocumentExtension3) document;
		extension3.setDocumentPartitioner(partitioning, partitioner);
	} else {
		document.setDocumentPartitioner(partitioner);
	}
}
 
Example 11
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 12
Source File: PartitionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	document = get(XtextDocument.class);
	IDocumentPartitioner partitioner = get(IDocumentPartitioner.class);
	partitioner.connect(document);
	document.setDocumentPartitioner(partitioner);
}
 
Example 13
Source File: ImportAwareActionTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  this.document = this.<XtextDocument>get(XtextDocument.class);
  IDocumentPartitioner partitioner = this.<IDocumentPartitioner>get(IDocumentPartitioner.class);
  partitioner.connect(this.document);
  this.document.setDocumentPartitioner(partitioner);
}
 
Example 14
Source File: TLADocumentSetupParticipant.java    From tlaplus with MIT License 5 votes vote down vote up
public void setup(IDocument document) {
    if (document instanceof IDocumentExtension3) {
        IDocumentExtension3 extension3= (IDocumentExtension3) document;
        IDocumentPartitioner partitioner= new TLAFastPartitioner(TLAEditorActivator.getDefault().getTLAPartitionScanner(), TLAPartitionScanner.TLA_PARTITION_TYPES);
                                            // Changed from FastPartitioner by LL on 12 Aug 2012
        extension3.setDocumentPartitioner(TLAPartitionScanner.TLA_PARTITIONING, partitioner);
        partitioner.connect(document);
    }
}
 
Example 15
Source File: JSDocumentProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see DocumentProvider#createDocument(java.lang.Object)
 */
protected IDocument createDocument( Object element ) throws CoreException
{
	IDocument document = super.createDocument( element );
	if ( document != null )
	{
		IDocumentPartitioner partitioner = new DefaultPartitioner( new JSPartitionScanner( ),
				colorTokens );
		partitioner.connect( document );
		document.setDocumentPartitioner( partitioner );
	}
	return document;
}
 
Example 16
Source File: StructuredDocumentCloner.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public IStructuredDocument clone(IDocument original) {
  IModelManager modelManager = StructuredModelManager.getModelManager();
  String modelId = getModelId(original);
  if (modelId == null) {
    GWTPluginLog.logError("Could not get a model ID for the document to be formatted.");
    return null;
  }

  /*
   * The XML formatter requires a managed model (discovered by it crashing
   * when given an unmanaged model.) Unfortunately, we cannot create a managed
   * in-memory (i.e. non-file backed) model via IModelManager API (there is
   * one method that may work, but it is deprecated.) Instead, we copy the
   * existing model into a temp model with ID "temp".
   */
  try {
    IStructuredModel modelClone = modelManager.copyModelForEdit(modelId,
        "structuredDocumentClonerModel" + nextId.getAndIncrement());
    modelClone.setBaseLocation(getModelBaseLocation(original));

    IStructuredDocument documentClone = modelClone.getStructuredDocument();
    documentClone.set(original.get());

    // Create and connect the partitioner to the document
    IDocumentPartitioner tempPartitioner = documentPartitionerFactory.createDocumentPartitioner();
    ((IDocumentExtension3) documentClone).setDocumentPartitioner(
        partitioning, tempPartitioner);
    tempPartitioner.connect(documentClone);

    // Save the cloned model so we can release it later
    modelClones.put(documentClone, modelClone);

    return documentClone;
  } catch (ResourceInUse e1) {
    GWTPluginLog.logError(e1,
        "Could not copy the original model to be formatted.");
    return null;
  }
}
 
Example 17
Source File: IDEFileReportDocumentProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected IDocument createDocument( Object element ) throws CoreException
{
	IDocument document = super.createDocument( element );
	if ( document != null )
	{
		IDocumentPartitioner partitioner = new FastPartitioner( new XMLPartitionScanner( ),
				new String[]{
						XMLPartitionScanner.XML_TAG,
						XMLPartitionScanner.XML_COMMENT
				} );
		partitioner.connect( document );
		document.setDocumentPartitioner( partitioner );
	}
	return document;
}
 
Example 18
Source File: XMLDocumentProvider.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
protected IDocument createDocument(Object element) throws CoreException {
  IDocument document = super.createDocument(element);
  if (document != null) {
    IDocumentPartitioner partitioner = new DefaultPartitioner(new XMLPartitionScanner(),
            new String[] { XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT });
    partitioner.connect(document);
    document.setDocumentPartitioner(partitioner);
  }
  return document;
}
 
Example 19
Source File: StyledTextXtextAdapter.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected void initXtextDocument(XtextFakeResourceContext context) {
	getXtextDocument().setInput(context.getFakeResource());
	IDocumentPartitioner partitioner = getDocumentPartitioner().get();
	partitioner.connect(getXtextDocument());
	getXtextDocument().setDocumentPartitioner(partitioner);
}
 
Example 20
Source File: CommonFormatterUtils.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Format a given input string that is in the given file path (or should be injected to).<br>
 * This method will try to determine the content type and the project's formatter settings by the file path and run
 * the right formatter in order to generate a formatted output.
 * 
 * @param filePath
 * @param input
 * @return The formatted output, or the given input in case the input could not be formatted.
 */
public static String format(IPath filePath, String input)
{
	if (filePath == null || input == null || input.trim().length() == 0)
	{
		return input;
	}
	IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(filePath.lastSegment());
	if (contentType != null)
	{
		// Format the string before returning it
		IScriptFormatterFactory factory = ScriptFormatterManager.getSelected(contentType.getId());
		if (factory != null)
		{
			IDocument document = new Document(input);
			IPartitioningConfiguration partitioningConfiguration = (IPartitioningConfiguration) factory
					.getPartitioningConfiguration();
			CompositePartitionScanner partitionScanner = new CompositePartitionScanner(
					partitioningConfiguration.createSubPartitionScanner(), new NullSubPartitionScanner(),
					new NullPartitionerSwitchStrategy());
			IDocumentPartitioner partitioner = new ExtendedFastPartitioner(partitionScanner,
					partitioningConfiguration.getContentTypes());
			partitionScanner.setPartitioner((IExtendedPartitioner) partitioner);
			partitioner.connect(document);
			document.setDocumentPartitioner(partitioner);

			final String lineDelimiter = TextUtilities.getDefaultLineDelimiter(document);
			IResource parentResource = ResourcesPlugin.getWorkspace().getRoot()
					.findMember(filePath.removeLastSegments(1));
			if (parentResource != null)
			{
				IProject project = parentResource.getProject();
				Map<String, String> preferences = factory
						.retrievePreferences(new PreferencesLookupDelegate(project));
				TextEdit formattedTextEdit = factory.createFormatter(lineDelimiter, preferences).format(input, 0,
						input.length(), 0, false, null, StringUtil.EMPTY);
				try
				{
					formattedTextEdit.apply(document);
					input = document.get();
				}
				catch (Exception e)
				{
					IdeLog.logError(CommonEditorPlugin.getDefault(),
							"Error while formatting the file template code", e); //$NON-NLS-1$
				}
			}
		}
	}
	return input;
}