org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor. 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: GamlEditTemplateDialog.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
protected SourceViewer createViewer(final Composite parent) {
	final Builder editorBuilder = configuration.getEmbeddedEditorFactory().newEditor(resourceProvider);
	editorBuilder.processIssuesBy((issues, monitor) -> {
		IStatus result = Status.OK_STATUS;
		final StringBuilder messages = new StringBuilder();
		for (final Issue issue : issues) {
			if (issue.getSeverity() == Severity.ERROR) {
				if (messages.length() != 0) {
					messages.append('\n');
				}
				messages.append(issue.getMessage());
			}
		}
		if (messages.length() != 0) {
			result = createErrorStatus(messages.toString(), null);
		}
		final IStatus toBeUpdated = result;
		getShell().getDisplay().asyncExec(() -> updateStatus(toBeUpdated));
	});
	final EmbeddedEditor handle = editorBuilder.withParent(parent);
	partialModelEditor = handle.createPartialEditor(getPrefix(), data.getTemplate().getPattern(), "", true);
	return handle.getViewer();
}
 
Example #2
Source File: EditTemplateDialog.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected SourceViewer createViewer(Composite parent) {
	Builder editorBuilder = configuration.getEmbeddedEditorFactory().newEditor(resourceProvider);
	editorBuilder.processIssuesBy(new IValidationIssueProcessor() {
		@Override
		public void processIssues(List<Issue> issues, IProgressMonitor monitor) {
			IStatus result = Status.OK_STATUS;
			StringBuilder messages = new StringBuilder();
			for(Issue issue: issues) {
				if (issue.getSeverity() == Severity.ERROR) {
					if (messages.length() != 0)
						messages.append('\n');
					messages.append(issue.getMessage());
				}
			}
			if (messages.length() != 0) {
				result = createErrorStatus(messages.toString(), null);
			}
			final IStatus toBeUpdated = result;
			getShell().getDisplay().asyncExec(new Runnable() {
				@Override
				public void run() {
					updateStatus(toBeUpdated);
				}
			});
		}
	});
	EmbeddedEditor handle = editorBuilder.withParent(parent);
	partialModelEditor = handle.createPartialEditor(getPrefix(), fTemplate.getPattern(), "", true);
	return handle.getViewer();
}
 
Example #3
Source File: XtendFormatterPreview.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public XtendFormatterPreview forEmbeddedEditor(EmbeddedEditor editorHandle) {
	if (this.editorHandle != null) {
		throw new IllegalStateException("This formatter preview is already binded to an embedet editor");
	}
	this.editorHandle = editorHandle;
	this.modelAccess = editorHandle.createPartialEditor();
	this.marginPainter = new MarginPainter(editorHandle.getViewer());
	final RGB rgb = PreferenceConverter.getColor(preferenceStoreAccess.getPreferenceStore(),
			AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR);
	marginPainter.setMarginRulerColor(EditorUtils.colorFromRGB(rgb));
	editorHandle.getViewer().addPainter(marginPainter);
	return this;
}
 
Example #4
Source File: XtendPreviewFactory.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public XtendFormatterPreview createNewPreview(Composite composite, String previewContent) {
	XtendFormatterPreview formatterPreview = new XtendFormatterPreview();
	memberInjector.injectMembers(formatterPreview);
	EmbeddedEditor embeddedEditor = editorFactory.newEditor(resourceProvider)
			.withResourceValidator(IResourceValidator.NULL).readOnly().withParent(composite);
	return formatterPreview.forEmbeddedEditor(embeddedEditor).withPreviewContent(previewContent);
}
 
Example #5
Source File: StatechartDefinitionSection.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected EmbeddedEditor createSpecificationEditor() {
	ContextScopeHandler.defineContext(EMBEDDED_TEXT_EDITOR_SCOPE, TEXT_EDITOR_SCOPE);
	EmbeddedEditor embeddedEditor = createEmbeddedEditor();
	embeddedEditor.createPartialEditor();
	GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(embeddedEditor.getViewer().getControl());
	StyledText text = embeddedEditor.getViewer().getTextWidget();
	text.setAlwaysShowScrollBars(false);
	text.setSelection(0);
	text.setKeyBinding(SWT.MOD1 | SWT.KEY_MASK & 'a', ST.SELECT_ALL);
	initXtextSelectionProvider(text);
	initContextMenu(text);
	text.addModifyListener((event) -> editorPart.firePropertyChange(IEditorPart.PROP_DIRTY));
	text.setEnabled(editorPart.isEditable());
	return embeddedEditor;
}
 
Example #6
Source File: WizardPreviewProvider.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private void createEditor() {
	EmbeddedEditor editor = editorFactory.newEditor(this::createTempResource).withParent(this);

	editor.getViewer().getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

	// Initialize the document
	editor.createPartialEditor(true);

	editorDocument = editor.getDocument();
	sourceViewer = editor.getViewer();

	configureSourceViewer(sourceViewer);

	// Clear content
	editorDocument.set("");
}
 
Example #7
Source File: AdvancedTemplatesPreferencePage.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected SourceViewer createViewer(Composite parent) {
	EmbeddedEditor handle = configuration.getEmbeddedEditorFactory().newEditor(resourceProvider).readOnly().withParent(parent);
	partialEditor = handle.createPartialEditor(true);
	return handle.getViewer();
}
 
Example #8
Source File: StatechartDefinitionSection.java    From statecharts with Eclipse Public License 1.0 4 votes vote down vote up
protected EmbeddedEditor createEmbeddedEditor() {
	Injector embeddedEditorInjector = getEmbeddedStatechartSpecificationInjector();
	EmbeddedEditorFactory instance = embeddedEditorInjector.getInstance(EmbeddedEditorFactory.class);
	IEditedResourceProvider provider = getXtextResourceProvider(embeddedEditorInjector);
	return instance.newEditor(provider).showErrorAndWarningAnnotations().withParent(this);
}