本文整理汇总了Java中org.eclipse.xtext.ui.editor.XtextEditor类的典型用法代码示例。如果您正苦于以下问题:Java XtextEditor类的具体用法?Java XtextEditor怎么用?Java XtextEditor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XtextEditor类属于org.eclipse.xtext.ui.editor包,在下文中一共展示了XtextEditor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openXtextEditor
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
/**
* Obtains or opens {@link XtextEditor} for provided {@link Resource} and editor id. Upon activation or opening of
* the editor waits a moment for editor to become active.
*
* @param uri
* URI to be opened
* @param editorExtensionID
* {String} defining the id of the editor extension to use
* @return {@link Optional} instance of {@link XtextEditor} for given {@link Resource}.
*/
public static final Optional<XtextEditor> openXtextEditor(URI uri, String editorExtensionID) {
String platformStr = uri.toString().replace("platform:/resource/", "");
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformStr));
Optional<IWorkbenchPage> page = getActivePage();
Optional<IEditorPart> internalFileEditor = getFileEditor(file, page.get(), editorExtensionID);
if ((page.isPresent() && internalFileEditor.isPresent()) == false) {
logger.warn("Cannot obtain editor components for " + file.getRawLocationURI());
return Optional.empty();
}
IEditorPart ieditorPart = internalFileEditor.get();
if (ieditorPart instanceof XtextEditor == false) {
logger.warn("cannot obtain Xtext editor for file " + file.getRawLocation());
return Optional.empty();
}
waitForEditorToBeActive(ieditorPart, page.get());
return Optional.ofNullable((XtextEditor) ieditorPart);
}
示例2: tryValidateManifestInEditor
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
private void tryValidateManifestInEditor(final IResourceDelta delta) {
if (isWorkbenchRunning()) {
Display.getDefault().asyncExec(() -> {
final IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
if (null != window) {
final IWorkbenchPage page = window.getActivePage();
for (final IEditorReference editorRef : page.getEditorReferences()) {
if (isEditorForResource(editorRef, delta.getResource())) {
final IWorkbenchPart part = editorRef.getPart(true);
if (part instanceof XtextEditor) {
editorCallback.afterSave((XtextEditor) part);
return;
}
}
}
}
});
}
}
示例3: newValidationJob
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
private ValidationJob newValidationJob(final XtextEditor editor) {
final IXtextDocument document = editor.getDocument();
final IAnnotationModel annotationModel = editor.getInternalSourceViewer().getAnnotationModel();
final IssueResolutionProvider issueResolutionProvider = getService(editor, IssueResolutionProvider.class);
final MarkerTypeProvider markerTypeProvider = getService(editor, MarkerTypeProvider.class);
final MarkerCreator markerCreator = getService(editor, MarkerCreator.class);
final IValidationIssueProcessor issueProcessor = new CompositeValidationIssueProcessor(
new AnnotationIssueProcessor(document, annotationModel, issueResolutionProvider),
new MarkerIssueProcessor(editor.getResource(), markerCreator, markerTypeProvider));
return editor.getDocument().modify(resource -> {
final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
return new ValidationJob(resourceValidator, editor.getDocument(), issueProcessor, ALL);
});
}
示例4: getLaunchConfigFromEditor
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
protected LaunchConfig getLaunchConfigFromEditor(ExecutionEvent event) {
XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event);
if (activeXtextEditor == null) {
return null;
}
final ITextSelection selection = (ITextSelection) activeXtextEditor.getSelectionProvider().getSelection();
return activeXtextEditor.getDocument().priorityReadOnly(new IUnitOfWork<LaunchConfig, XtextResource>() {
@Override
public LaunchConfig exec(XtextResource xTextResource) throws Exception {
EObject lc = eObjectAtOffsetHelper.resolveContainedElementAt(xTextResource, selection.getOffset());
return findParentLaunchConfig(lc);
}
});
}
示例5: valuesForAttributes
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
/**
* Retrieve the object's values for the given EAttributes.
*
* @param attributes
* the EAttributes
* @return List<Pair<EAttribute, Object>> the attribute+values - possibly containing null entries
*/
private List<AttributeValuePair> valuesForAttributes(final EList<EAttribute> attributes) {
final URI elementUri = xtextElementSelectionListener.getSelectedElementUri();
XtextEditor editor = xtextElementSelectionListener.getEditor();
if (editor != null && elementUri != null) {
return editor.getDocument().readOnly(new IUnitOfWork<List<AttributeValuePair>, XtextResource>() {
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public List<AttributeValuePair> exec(final XtextResource state) throws Exception {
final EObject eObject = state.getEObject(elementUri.fragment());
List<AttributeValuePair> pairs = Lists.transform(attributes, new Function<EAttribute, AttributeValuePair>() {
public AttributeValuePair apply(final EAttribute from) {
return new AttributeValuePair(from, eObject.eGet(from));
}
});
return pairs;
}
});
}
return newArrayList();
}
示例6: getActiveXtextEditor
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
/** {@inheritDoc} */
public XtextEditor getActiveXtextEditor() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
if (workbenchWindow == null) {
return null;
}
IWorkbenchPage activePage = workbenchWindow.getActivePage();
if (activePage == null) {
return null;
}
IEditorPart activeEditor = activePage.getActiveEditor();
if (activeEditor instanceof XtextEditor) {
return (XtextEditor) activeEditor;
// return null;
}
// XtextEditor xtextEditor = (XtextEditor) activeEditor.getAdapter(XtextEditor.class);
// return xtextEditor;
return null;
}
示例7: mockSelectedElement
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
/**
* Mocks XtextEditor and XtextElementSelectionListener to return an element selection that has:
* - given EAttribute with a specific value (AttributeValuePair)
* - given EStructuralFeature
* - given EOperation.
*
* @param attributeValuePair
* EAttribute with a specific value
* @param feature
* the EStructuralFeature
* @param operation
* the EOperation
* @return the EClass of the "selected" element
*/
@SuppressWarnings("unchecked")
private EClass mockSelectedElement(final AttributeValuePair attributeValuePair, final EStructuralFeature feature, final EOperation operation) {
EClass mockSelectionEClass = mock(EClass.class);
when(mockSelectionListener.getSelectedElementType()).thenReturn(mockSelectionEClass);
// Mockups for returning AttributeValuePair
URI elementUri = URI.createURI("");
when(mockSelectionListener.getSelectedElementUri()).thenReturn(elementUri);
XtextEditor mockEditor = mock(XtextEditor.class);
when(mockSelectionListener.getEditor()).thenReturn(mockEditor);
IXtextDocument mockDocument = mock(IXtextDocument.class);
when(mockEditor.getDocument()).thenReturn(mockDocument);
when(mockDocument.<ArrayList<AttributeValuePair>> readOnly(any(IUnitOfWork.class))).thenReturn(newArrayList(attributeValuePair));
// Mockups for returning EOperation
BasicEList<EOperation> mockEOperationsList = new BasicEList<EOperation>();
mockEOperationsList.add(operation);
when(mockSelectionEClass.getEAllOperations()).thenReturn(mockEOperationsList);
// Mockups for returning EStructuralFeature
BasicEList<EStructuralFeature> mockEStructuralFeatureList = new BasicEList<EStructuralFeature>();
mockEStructuralFeatureList.add(feature);
mockEStructuralFeatureList.add(attributeValuePair.getAttribute());
when(mockSelectionEClass.getEAllStructuralFeatures()).thenReturn(mockEStructuralFeatureList);
return mockSelectionEClass;
}
示例8: getDisplay
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
private Display getDisplay() {
XtextEditor editor = this.editor;
if (editor == null) {
return null;
}
IWorkbenchPartSite site = editor.getSite();
if (site == null) {
return null;
}
Shell shell = site.getShell();
if (shell == null || shell.isDisposed()) {
return null;
}
Display display = shell.getDisplay();
if (display == null || display.isDisposed()) {
return null;
}
return display;
}
示例9: install
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
/**
* Install this reconciler on the given editor and presenter.
*
* @param editor
* the editor
* @param sourceViewer
* the source viewer
* @param presenter
* the highlighting presenter
*/
@Override
public void install(final XtextEditor editor, final XtextSourceViewer sourceViewer, final HighlightingPresenter presenter) {
synchronized (fReconcileLock) {
cleanUpAfterReconciliation = false; // prevents a potentially already running reconciliation process to clean up after itself
}
this.presenter = presenter;
this.editor = editor;
this.sourceViewer = sourceViewer;
if (calculator != null) {
if (editor == null) {
((IXtextDocument) sourceViewer.getDocument()).addModelListener(this);
} else if (editor.getDocument() != null) {
editor.getDocument().addModelListener(this);
}
sourceViewer.addTextInputListener(this);
}
refresh();
}
示例10: loadCycleInfo
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
private void loadCycleInfo(final int offset, final int length, XtextEditor editor, final IDocument doc) {
final ILocationInFileProvider locationInFileProvider = Z80Activator.getInstance().getInjector(Z80Activator.ORG_EFRY_Z80EDITOR_Z80).getInstance(ILocationInFileProvider.class);
editor.getDocument().readOnly(new IUnitOfWork<Boolean, XtextResource>() {
@Override
public Boolean exec(XtextResource state) throws Exception {
Z80OperationTypeWalker operationInstructions = new Z80OperationTypeWalker(state, locationInFileProvider, offset, offset + length);
Z80CycleCalculator calc = new Z80CycleCalculator();
for (Operation o : operationInstructions) {
ITextRegion region = locationInFileProvider.getFullTextRegion(o);
calc.addOperation(o, doc.get(region.getOffset(), region.getLength()));
}
label.setText(calc.getHtmlFormattedText());
return Boolean.TRUE;
}
});
}
示例11: initializeImageMaps
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
private static final void initializeImageMaps() {
if(imagesInitialized)
return;
annotationImagesFixable.put(XtextEditor.ERROR_ANNOTATION_TYPE, get(OBJ_FIXABLE_ERROR));
annotationImagesFixable.put(XtextEditor.WARNING_ANNOTATION_TYPE, get(OBJ_FIXABLE_WARNING));
annotationImagesFixable.put(XtextEditor.INFO_ANNOTATION_TYPE, get(OBJ_FIXABLE_INFO));
//XXX cp uncommented
// ISharedImages sharedImages= PlatformUI.getWorkbench().getSharedImages();
// Image error = sharedImages.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
// Image warning = sharedImages.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
// Image info = sharedImages.getImage(ISharedImages.IMG_OBJS_INFO_TSK);
annotationImagesNonFixable.put(XtextEditor.ERROR_ANNOTATION_TYPE, get(OBJ_DESC_ERROR));
annotationImagesNonFixable.put(XtextEditor.WARNING_ANNOTATION_TYPE, get(OBJ_DESC_EXCLAMATION));
annotationImagesNonFixable.put(XtextEditor.INFO_ANNOTATION_TYPE, get(OBJ_DESC_INFORMATION));
Display display = Display.getCurrent();
annotationImagesDeleted.put(XtextEditor.ERROR_ANNOTATION_TYPE, new Image(display, get(OBJ_DESC_ERROR), SWT.IMAGE_GRAY));
annotationImagesDeleted.put(XtextEditor.WARNING_ANNOTATION_TYPE, new Image(display, get(OBJ_DESC_EXCLAMATION), SWT.IMAGE_GRAY));
annotationImagesDeleted.put(XtextEditor.INFO_ANNOTATION_TYPE, new Image(display, get(OBJ_DESC_INFORMATION), SWT.IMAGE_GRAY));
imagesInitialized = true;
}
示例12: execute
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
public Object execute(final ExecutionEvent event) throws ExecutionException {
final XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
if (xtextEditor != null) {
final IXtextDocument document = xtextEditor.getDocument();
document.readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
final QuickOutlinePopup quickOutlinePopup = createPopup(xtextEditor.getEditorSite().getShell());
quickOutlinePopup.setEditor(xtextEditor);
quickOutlinePopup.setInput(document);
quickOutlinePopup.setEvent((Event) event.getTrigger());
quickOutlinePopup.open();
}
});
}
return null;
}
示例13: execute
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
if (editor != null) {
final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
editor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
EObject target = eObjectAtOffsetHelper.resolveElementAt(state, selection.getOffset());
findReferences(target);
}
});
}
} catch (Exception e) {
LOG.error(Messages.FindReferencesHandler_3, e);
}
return null;
}
示例14: getDisplay
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
private Display getDisplay() {
XtextEditor editor = this.editor;
if (editor == null){
if(sourceViewer != null)
return sourceViewer.getControl().getDisplay();
return null;
}
IWorkbenchPartSite site = editor.getSite();
if (site == null)
return null;
Shell shell = site.getShell();
if (shell == null || shell.isDisposed())
return null;
Display display = shell.getDisplay();
if (display == null || display.isDisposed())
return null;
return display;
}
示例15: execute
import org.eclipse.xtext.ui.editor.XtextEditor; //导入依赖的package包/类
public Object execute(ExecutionEvent event) throws ExecutionException {
XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
if (xtextEditor != null) {
ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection();
IRegion region = new Region(selection.getOffset(), selection.getLength());
ISourceViewer internalSourceViewer = xtextEditor.getInternalSourceViewer();
IHyperlink[] hyperlinks = getDetector().detectHyperlinks(internalSourceViewer, region, false);
if (hyperlinks != null && hyperlinks.length > 0) {
IHyperlink hyperlink = hyperlinks[0];
hyperlink.open();
}
}
return null;
}