org.eclipse.jface.text.IAutoEditStrategy Java Examples

The following examples show how to use org.eclipse.jface.text.IAutoEditStrategy. 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: AbstractEditStrategyProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public List<IAutoEditStrategy> getStrategies(final ISourceViewer sourceViewer,final String contentType) {
	final List<IAutoEditStrategy> strategies = Lists.newArrayList();
	configure(new IEditStrategyAcceptor() {
		@Override
		public void accept(IAutoEditStrategy strategy, String type) {
			if (type == null || contentType.equals(type)) {
				if (strategy instanceof ISourceViewerAware) {
					((ISourceViewerAware) strategy).setSourceViewer(sourceViewer);
				}
				if (strategy instanceof VerifyKeyListener) {
					sourceViewer.getTextWidget().addVerifyKeyListener((VerifyKeyListener) strategy);
				}
				strategies.add(strategy);
			}
		}
	});
	return strategies;
}
 
Example #2
Source File: TypeScriptSourceViewerConfiguration.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
	String partitioning = getConfiguredDocumentPartitioning(sourceViewer);
	if (IJavaScriptPartitions.JAVA_DOC.equals(contentType)
			|| IJavaScriptPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType)
			|| IJavaScriptPartitions.JAVASCRIPT_TEMPLATE_LITERAL.equals(contentType)) {
		return new IAutoEditStrategy[] { new JSDocAutoIndentStrategy(partitioning) };
	} else if (IJavaScriptPartitions.JAVA_STRING.equals(contentType))
		return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning),
				new JavaStringAutoIndentStrategy(partitioning) };
	else if (IJavaScriptPartitions.JAVA_CHARACTER.equals(contentType)
			|| IDocument.DEFAULT_CONTENT_TYPE.equals(contentType))
		return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning),
				new TypeScriptAutoIndentStrategy(partitioning, getTypeScriptFile(), sourceViewer) };
	else
		return new IAutoEditStrategy[] {
				new TypeScriptAutoIndentStrategy(partitioning, getTypeScriptFile(), sourceViewer) };
}
 
Example #3
Source File: UiBinderXmlSourceViewerConfiguration.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer,
    String contentType) {

  if (contentType == ICSSPartitions.STYLE) {
    IAutoEditStrategy[] autoEditStrategies = cssSourceViewerConfiguration.getAutoEditStrategies(
        sourceViewer, contentType);

    for (int i = 0; i < autoEditStrategies.length; i++) {
      // Replace any StructuredAutoEditStrategyCSS with the one that works
      // with inlined CSS
      if (autoEditStrategies[i] instanceof StructuredAutoEditStrategyCSS) {
        autoEditStrategies[i] = new StructuredAutoEditStrategyInlinedCss();
      }
    }

    return autoEditStrategies;
  }

  return super.getAutoEditStrategies(sourceViewer, contentType);
}
 
Example #4
Source File: AutoEditStrategyProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void configureMultilineComments(IEditStrategyAcceptor acceptor) {
	// To avoid JSDocEditStrategy handling /***+ multiline3andMoreAsterisks instance is added
	IAutoEditStrategy multiline3andMoreAsterisks = multiLineTerminals.newInstance("/***", " * ", " */");
	JSDocEditStrategy jsdoc = new JSDocEditStrategy();
	injector.injectMembers(jsdoc);
	IAutoEditStrategy multiline = multiLineTerminals.newInstance("/*", " * ", " */");
	IAutoEditStrategy singleline = singleLineTerminals.newInstance("/*", " */", new SupressingMLCommentPredicate());

	acceptor.accept(singleline, IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(singleLineTerminals.newInstance("/*", " */"), REG_EX_PARTITION);

	acceptor.accept(multiline3andMoreAsterisks, IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(multiline3andMoreAsterisks, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
	acceptor.accept(multiline3andMoreAsterisks, REG_EX_PARTITION);

	acceptor.accept(jsdoc, IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(jsdoc, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
	acceptor.accept(jsdoc, JS_DOC_PARTITION);
	acceptor.accept(jsdoc, REG_EX_PARTITION);

	acceptor.accept(multiline, IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(multiline, TerminalsTokenTypeToPartitionMapper.COMMENT_PARTITION);
	acceptor.accept(multiline, JS_DOC_PARTITION);
	acceptor.accept(multiline, REG_EX_PARTITION);
}
 
Example #5
Source File: PropertiesFileSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
	IAutoEditStrategy[] autoEditStrategies= super.getAutoEditStrategies(sourceViewer, contentType);

	if (fTextEditor == null)
		return autoEditStrategies;

	try {
		if (!PropertiesFileDocumentProvider.isJavaPropertiesFile(fTextEditor.getEditorInput())) {
			return autoEditStrategies;
		}
		List<IAutoEditStrategy> stratergies= new ArrayList<IAutoEditStrategy>();
		for (int i= 0; i < autoEditStrategies.length; i++) {
			stratergies.add(autoEditStrategies[i]);
		}
		stratergies.add(new PropertiesFileAutoEditStrategy(((IFileEditorInput)fTextEditor.getEditorInput()).getFile(), sourceViewer));
		return stratergies.toArray(new IAutoEditStrategy[stratergies.size()]);
	} catch (CoreException e) {
		JavaPlugin.log(e);
		return autoEditStrategies;
	}
}
 
Example #6
Source File: AbstractLangSourceViewerConfiguration.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
	if(IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) {
		return array(new AutoEditStrategyAdapter(
			LangUIPlugin_Actual.createAutoEditStrategy(contentType, new VerifyKeyRecorder(sourceViewer))
		));
	} else {
		return super.getAutoEditStrategies(sourceViewer, contentType);
	}
}
 
Example #7
Source File: TexSourceViewerConfiguration.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
    //return super.getAutoEditStrategies(sourceViewer, contentType);
    if (autoIndentStrategy == null) {
        autoIndentStrategy = new TexAutoIndentStrategy();
    }
    return new IAutoEditStrategy[] {autoIndentStrategy};
}
 
Example #8
Source File: ModulaSourceViewerConfiguration.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public IAutoEditStrategy[] getAutoEditStrategies( ISourceViewer sourceViewer
                                                , String contentType ) 
{
    IAutoEditStrategy strategy =  IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)
                               ?  new ModulaAutoEditStrategy()
                               :  new DefaultIndentLineAutoEditStrategy();
    return new IAutoEditStrategy[] { strategy };
}
 
Example #9
Source File: DotAutoEditStrategyProvider.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configure(IEditStrategyAcceptor acceptor) {
	super.configure(acceptor);
	configureAngleBrackets(acceptor);

	/*
	 * TODO: verify why the strategy has to added to both content types
	 */
	IAutoEditStrategy strategy = new DotAutoEditStrategy();
	acceptor.accept(strategy, IDocument.DEFAULT_CONTENT_TYPE);
	acceptor.accept(strategy,
			DotTerminalsTokenTypeToPartitionMapper.HTML_STRING_PARTITION);
}
 
Example #10
Source File: GWTSourceViewerConfiguration.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer,
    String contentType) {
  if (GWTPartitions.JSNI_METHOD.equals(contentType)) {
    // Get project's formatting settings
    IJavaProject javaProject = ((GWTJavaEditor) getEditor()).getInputJavaProject();
    Map<?, ?> prefs = (javaProject != null ? javaProject.getOptions(true)
        : JavaCore.getOptions());
    return new IAutoEditStrategy[] {new JsniAutoEditStrategy(prefs)};
  }
  return super.getAutoEditStrategies(sourceViewer, contentType);
}
 
Example #11
Source File: JavaSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
	String partitioning= getConfiguredDocumentPartitioning(sourceViewer);
	if (IJavaPartitions.JAVA_DOC.equals(contentType) || IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType))
		return new IAutoEditStrategy[] { new JavaDocAutoIndentStrategy(partitioning) };
	else if (IJavaPartitions.JAVA_STRING.equals(contentType))
		return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaStringAutoIndentStrategy(partitioning, getProject()) };
	else if (IJavaPartitions.JAVA_CHARACTER.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType))
		return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaAutoIndentStrategy(partitioning, getProject(), sourceViewer) };
	else
		return new IAutoEditStrategy[] { new JavaAutoIndentStrategy(partitioning, getProject(), sourceViewer) };
}
 
Example #12
Source File: XMLSourceViewerConfiguration.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType)
{
	return new IAutoEditStrategy[] { new RubyRegexpAutoIndentStrategy(contentType, this, sourceViewer, XMLPlugin
			.getDefault().getPreferenceStore()) };
}
 
Example #13
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void setTabsToSpacesConverter(IAutoEditStrategy converter) {
    viewer.setTabsToSpacesConverter(converter);
}
 
Example #14
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void removeAutoEditStrategy(IAutoEditStrategy strategy, String contentType) {
    viewer.removeAutoEditStrategy(strategy, contentType);
}
 
Example #15
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void prependAutoEditStrategy(IAutoEditStrategy strategy, String contentType) {
    viewer.prependAutoEditStrategy(strategy, contentType);
}
 
Example #16
Source File: SimpleJavaSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
	return null;
}
 
Example #17
Source File: CommonSourceViewerConfiguration.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType)
{
	return new IAutoEditStrategy[] { new RubyRegexpAutoIndentStrategy(contentType, this, sourceViewer,
			CommonEditorPlugin.getDefault().getPreferenceStore()) };
}
 
Example #18
Source File: HTMLSourceViewerConfiguration.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
	return new IAutoEditStrategy[] { new RubyRegexpAutoIndentStrategy(contentType, this, sourceViewer, HTMLPlugin.getDefault().getPreferenceStore()) };
}
 
Example #19
Source File: CSSSourceViewerConfiguration.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
	return new IAutoEditStrategy[] { new RubyRegexpAutoIndentStrategy(contentType, this, sourceViewer, CSSPlugin.getDefault().getPreferenceStore()) };
}
 
Example #20
Source File: JSSourceViewerConfiguration.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType)
{
	return new IAutoEditStrategy[] { new JSAutoIndentStrategy(contentType, this, sourceViewer, JSPlugin
			.getDefault().getPreferenceStore()) };
}
 
Example #21
Source File: XtextSourceViewerConfiguration.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
	List<IAutoEditStrategy> strategies = editStrategyProvider.getStrategies(sourceViewer, contentType);
	return strategies.toArray(new IAutoEditStrategy[strategies.size()]);
}
 
Example #22
Source File: ReadOnlySourceViewerConfiguration.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
	return null;
}
 
Example #23
Source File: ImpexSourceViewerConfig.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 3 votes vote down vote up
@Override
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
       
	IAutoEditStrategy strategy= (IDocument.DEFAULT_CONTENT_TYPE.equalsIgnoreCase(contentType) ? new ImpexBracesAutoEditStrategy() : new DefaultIndentLineAutoEditStrategy());
       
	IAutoEditStrategy headerStr = (ImpexDocumentPartitioner.IMPEX_HEADER.equalsIgnoreCase(contentType) ? new ImpexBracesAutoEditStrategy() : new DefaultIndentLineAutoEditStrategy());
       
	return new IAutoEditStrategy[] { strategy, headerStr };
}
 
Example #24
Source File: AbstractEditStrategyProvider.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public void accept(IAutoEditStrategy strategy, String contentType);