Java Code Examples for org.eclipse.jface.text.source.SourceViewer#setDocument()

The following examples show how to use org.eclipse.jface.text.source.SourceViewer#setDocument() . 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: ParameterizeTextView.java    From http4e with Apache License 2.0 6 votes vote down vote up
private StyledText buildEditorText( Composite parent){
   final SourceViewer sourceViewer = new SourceViewer(parent, null, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
   final HConfiguration sourceConf = new HConfiguration(HContentAssistProcessor.PARAM_PROCESSOR);
   sourceViewer.configure(sourceConf);
   sourceViewer.setDocument(DocumentUtils.createDocument1());

   sourceViewer.getControl().addKeyListener(new KeyAdapter() {

      public void keyPressed( KeyEvent e){
         // if ((e.character == ' ') && ((e.stateMask & SWT.CTRL) != 0)) {
         if (Utils.isAutoAssistInvoked(e)) {
            IContentAssistant ca = sourceConf.getContentAssistant(sourceViewer);
            ca.showPossibleCompletions();
         }
      }
   });

   return sourceViewer.getTextWidget();
}
 
Example 2
Source File: TypeScriptTemplatePreferencePage.java    From typescript.java with MIT License 6 votes vote down vote up
protected SourceViewer createViewer(Composite parent) {
	IDocument document= new Document();
	JavaScriptTextTools tools= JSDTTypeScriptUIPlugin.getDefault().getJavaTextTools();
	tools.setupJavaDocumentPartitioner(document, IJavaScriptPartitions.JAVA_PARTITIONING);
	IPreferenceStore store= JSDTTypeScriptUIPlugin.getDefault().getCombinedPreferenceStore();
	SourceViewer viewer= new JavaSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
	SimpleJavaSourceViewerConfiguration configuration= new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaScriptPartitions.JAVA_PARTITIONING, false);
	viewer.configure(configuration);
	viewer.setEditable(false);
	viewer.setDocument(document);

	Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
	viewer.getTextWidget().setFont(font);
	new TypeScriptSourcePreviewerUpdater(viewer, configuration, store);
	
	Control control= viewer.getControl();
	GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
	control.setLayoutData(data);
	
	return viewer;
}
 
Example 3
Source File: JavaTemplatePreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected SourceViewer createViewer(Composite parent) {
	IDocument document= new Document();
	JavaTextTools tools= JavaPlugin.getDefault().getJavaTextTools();
	tools.setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING);
	IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
	SourceViewer viewer= new JavaSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
	SimpleJavaSourceViewerConfiguration configuration= new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, false);
	viewer.configure(configuration);
	viewer.setEditable(false);
	viewer.setDocument(document);

	Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
	viewer.getTextWidget().setFont(font);
	new JavaSourcePreviewerUpdater(viewer, configuration, store);

	Control control= viewer.getControl();
	GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
	control.setLayoutData(data);

	return viewer;
}
 
Example 4
Source File: SyntaxColoringPreferencePage.java    From editorconfig-eclipse with Apache License 2.0 6 votes vote down vote up
private Control createPreviewer(Composite parent) {

		IPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] { fOverlayStore,
				EditorConfigUIPlugin.getDefault().getCombinedPreferenceStore() });
		fPreviewViewer = new SourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
		fColorManager = new EditorConfigColorManager(false);
		EditorConfigSourceViewerConfiguration configuration = new EditorConfigSourceViewerConfiguration(fColorManager,
				store, null, IEditorConfigPartitions.EDITOR_CONFIG_PARTITIONING);
		fPreviewViewer.configure(configuration);
		Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_CONFIG_EDITOR_TEXT_FONT);
		fPreviewViewer.getTextWidget().setFont(font);
		new SourcePreviewerUpdater(fPreviewViewer, configuration, store);
		fPreviewViewer.setEditable(false);

		String content = loadPreviewContentFromFile("EditorConfigEditorColorSettingPreviewCode.txt"); //$NON-NLS-1$
		IDocument document = new Document(content);
		EditorConfigDocumentSetupParticipant.setupDocument(document);
		fPreviewViewer.setDocument(document);

		return fPreviewViewer.getControl();
	}
 
Example 5
Source File: ResponseView.java    From http4e with Apache License 2.0 5 votes vote down vote up
private StyledText buildEditorText( Composite parent){
   final SourceViewer sourceViewer = new SourceViewer(parent, null, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);

   final XMLConfiguration sourceConf = new XMLConfiguration(new ColorManagerAdaptor(ResourceUtils.getResourceCache()));
   sourceViewer.configure(sourceConf);
   sourceViewer.setDocument(DocumentUtils.createDocument2());

   return sourceViewer.getTextWidget();
}
 
Example 6
Source File: SWTHelloWorld.java    From http4e with Apache License 2.0 5 votes vote down vote up
private static StyledText buildEditorText( Composite parent){
   final SourceViewer sourceViewer = new SourceViewer(parent, null, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);

   final XMLConfiguration sourceConf = new XMLConfiguration(new ColorManagerAdaptor(ResourceUtils.getResourceCache()));
   sourceViewer.configure(sourceConf);
   sourceViewer.setDocument(DocumentUtils.createDocument2());

   return sourceViewer.getTextWidget();
}
 
Example 7
Source File: RequestView.java    From http4e with Apache License 2.0 5 votes vote down vote up
private StyledText buildEditorText( Composite parent){
   final SourceViewer sourceViewer = new SourceViewer(parent, null, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);

   final XMLConfiguration sourceConf = new XMLConfiguration(new ColorManagerAdaptor(ResourceUtils.getResourceCache()));
   sourceViewer.configure(sourceConf);
   sourceViewer.setDocument(DocumentUtils.createDocument2());

   return sourceViewer.getTextWidget();
}
 
Example 8
Source File: SWTStyledTextExample.java    From http4e with Apache License 2.0 5 votes vote down vote up
private static StyledText buildEditorText( Composite parent){
   final SourceViewer sourceViewer = new SourceViewer(parent, null, SWT.MULTI | SWT.V_SCROLL | SWT.WRAP);

   final XMLConfiguration sourceConf = new XMLConfiguration(new ColorManagerAdaptor(ResourceUtils.getResourceCache()));
   sourceViewer.configure(sourceConf);
   sourceViewer.setDocument(DocumentUtils.createDocument2());

   return sourceViewer.getTextWidget();
}
 
Example 9
Source File: TypeScriptTemplatePreferencePage.java    From typescript.java with MIT License 5 votes vote down vote up
protected void updateViewerInput() {
	IStructuredSelection selection= (IStructuredSelection) getTableViewer().getSelection();
	SourceViewer viewer= getViewer();
	
	if (selection.size() == 1 && selection.getFirstElement() instanceof TemplatePersistenceData) {
		TemplatePersistenceData data= (TemplatePersistenceData) selection.getFirstElement();
		Template template= data.getTemplate();
		String contextId= template.getContextTypeId();
		TemplateContextType type= JSDTTypeScriptUIPlugin.getDefault().getTemplateContextRegistry().getContextType(contextId);
		fTemplateProcessor.setContextType(type);
		
		IDocument doc= viewer.getDocument();
		
		String start= null;
		if ("javadoc".equals(contextId)) { //$NON-NLS-1$
			start= "/**" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$
		} else
			start= ""; //$NON-NLS-1$
		
		doc.set(start + template.getPattern());
		int startLen= start.length();
		viewer.setDocument(doc, startLen, doc.getLength() - startLen);

	} else {
		viewer.getDocument().set(""); //$NON-NLS-1$
	}		
}
 
Example 10
Source File: AbstractFormatterPreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param composite
 */
public SourceViewer createSourcePreview(Composite composite, IScriptFormatterFactory factory)
{
	IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
	// TODO - Note that we pass the factory's preferences store and not calling to this.getPrefereceStore.
	// In case we decide to unify the preferences into the this plugin, we might need to change this.
	IPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] { factory.getPreferenceStore(),
			generalTextStore });
	SourceViewer fPreviewViewer = createPreviewViewer(composite, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL
			| SWT.BORDER, store);
	if (fPreviewViewer == null)
	{
		return null;
	}
	SourceViewerConfiguration configuration = (SourceViewerConfiguration) factory
			.createSimpleSourceViewerConfiguration(fColorManager, store, null, false);
	fPreviewViewer.configure(configuration);
	if (fPreviewViewer.getTextWidget().getTabs() == 0)
	{
		fPreviewViewer.getTextWidget().setTabs(4);
	}
	new ScriptSourcePreviewerUpdater(fPreviewViewer, configuration, store);
	fPreviewViewer.setEditable(false);
	IDocument document = new Document();
	fPreviewViewer.setDocument(document);
	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);
	return fPreviewViewer;
}
 
Example 11
Source File: JavaTemplatePreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void updateViewerInput() {
	IStructuredSelection selection= (IStructuredSelection) getTableViewer().getSelection();
	SourceViewer viewer= getViewer();

	if (selection.size() == 1 && selection.getFirstElement() instanceof TemplatePersistenceData) {
		TemplatePersistenceData data= (TemplatePersistenceData) selection.getFirstElement();
		Template template= data.getTemplate();
		String contextId= template.getContextTypeId();
		TemplateContextType type= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(contextId);
		fTemplateProcessor.setContextType(type);

		IDocument doc= viewer.getDocument();

		String start= null;
		if ("javadoc".equals(contextId)) { //$NON-NLS-1$
			start= "/**" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$
		} else
			start= ""; //$NON-NLS-1$

		doc.set(start + template.getPattern());
		int startLen= start.length();
		viewer.setDocument(doc, startLen, doc.getLength() - startLen);

	} else {
		viewer.getDocument().set(""); //$NON-NLS-1$
	}
}
 
Example 12
Source File: ExpressionBuilder.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the source viewer to be used by this editor.
 * 
 * @param parent
 *            the parent control
 * @return the source viewer
 */
protected SourceViewer createSourceViewer( Composite parent )
{
	IVerticalRuler ruler = createVerticalRuler( );
	Composite composite = new Composite( parent, SWT.BORDER
			| SWT.LEFT_TO_RIGHT );

	composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
	composite.setLayout( UIUtil.createGridLayoutWithoutMargin( ) );

	int styles = SWT.V_SCROLL
			| SWT.H_SCROLL
			| SWT.MULTI
			| SWT.BORDER
			| SWT.FULL_SELECTION;

	SourceViewer viewer = new SourceViewer( composite, ruler, styles );

	viewer.configure( sourceViewerConfiguration );

	updateStyledTextColors( viewer.getTextWidget( ) );

	JSEditorInput editorInput = new JSEditorInput( expression,
			getEncoding( ) );
	JSDocumentProvider documentProvider = new JSDocumentProvider( );

	try
	{
		documentProvider.connect( editorInput );
	}
	catch ( CoreException e )
	{
		ExceptionHandler.handle( e );
	}

	viewer.setDocument( documentProvider.getDocument( editorInput ),
			ruler == null ? null : ruler.getModel( ) );

	return viewer;
}
 
Example 13
Source File: LangTemplatePreferencePage.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected SourceViewer createViewer(Composite parent) {
	SourceViewer viewer = new LangSourceViewer(parent, null, null, false, 
		SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
	
	viewer.configure(createPreviewerSourceViewerConfiguration());
	viewer.setEditable(false);
	viewer.setDocument(createViewerDocument());
	return viewer;
}
 
Example 14
Source File: ContractConstraintExpressionWizardPageTest.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    constraint = ProcessFactory.eINSTANCE.createContractConstraint();
    constraint.setExpression("");
    final Contract c = ProcessFactory.eINSTANCE.createContract();
    c.getConstraints().add(constraint);
    final ContractInput name = ProcessFactory.eINSTANCE.createContractInput();
    name.setName("name");
    c.getInputs().add(name);
    composite = realm.createComposite();
    final SourceViewer sourceViewer = new SourceViewer(composite, null, SWT.NONE);
    sourceViewer.setDocument(new Document());
    when(groovyViewer.getSourceViewer()).thenReturn(sourceViewer);
    when(editorFactory.newInstance()).thenReturn(editor);
    when(groovySourceViewerFactory.createSourceViewer(any(Composite.class), any(BonitaGroovyEditor.class))).thenReturn(groovyViewer);
    wizardPage = new ContractConstraintExpressionWizardPage(constraint,
            c.getInputs(),
            groovySourceViewerFactory,
            editorFactory,
            browserFactory);
    final ContractConstraintExpressionWizard wizard = new ContractConstraintExpressionWizard(constraint, null);
    final WizardDialog wizardContainer = new WizardDialog(composite.getShell(), wizard) {

        @Override
        protected Control createContents(final Composite parent) {
            return null;
        }
    };
    wizardContainer.create();
    assertThat(wizardContainer.getShell()).isNotNull();
    wizard.setContainer(wizardContainer);
    wizardPage.setWizard(wizard);
}