org.eclipse.jface.text.source.SourceViewer#setDocument ( )源码实例Demo

下面列出了org.eclipse.jface.text.source.SourceViewer#setDocument ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: http4e   文件: ParameterizeTextView.java
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();
}
 
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;
}
 
@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;
}
 
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();
	}
 
源代码5 项目: http4e   文件: ResponseView.java
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();
}
 
源代码6 项目: http4e   文件: SWTHelloWorld.java
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();
}
 
源代码7 项目: http4e   文件: RequestView.java
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();
}
 
源代码8 项目: http4e   文件: SWTStyledTextExample.java
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();
}
 
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$
	}		
}
 
/**
 * @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;
}
 
@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$
	}
}
 
源代码12 项目: birt   文件: ExpressionBuilder.java
/**
 * 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;
}
 
源代码13 项目: goclipse   文件: LangTemplatePreferencePage.java
@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;
}
 
/**
 * @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);
}