本文整理汇总了Java中org.eclipse.xtext.ui.editor.utils.EditorUtils类的典型用法代码示例。如果您正苦于以下问题:Java EditorUtils类的具体用法?Java EditorUtils怎么用?Java EditorUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EditorUtils类属于org.eclipse.xtext.ui.editor.utils包,在下文中一共展示了EditorUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: activateEditor
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
@Override
public void activateEditor(final IWorkbenchPage page, final IStructuredSelection selection) {
if (null != selection && !selection.isEmpty()) {
final Object firstElement = selection.getFirstElement();
if (firstElement instanceof ResourceNode) {
final File fileResource = ((ResourceNode) firstElement).getResource();
if (fileResource.exists() && fileResource.isFile()) {
final URI uri = URI.createFileURI(fileResource.getAbsolutePath());
final IResource resource = externalLibraryWorkspace.getResource(uri);
if (resource instanceof IFile) {
final IEditorInput editorInput = EditorUtils.createEditorInput(new URIBasedStorage(uri));
final IEditorPart editor = page.findEditor(editorInput);
if (null != editor) {
page.bringToTop(editor);
return;
}
}
}
}
}
super.activateEditor(page, selection);
}
示例2: getLaunchConfigFromEditor
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的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);
}
});
}
示例3: open
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
/**
* If a platform plugin URI is given, a read-only Xtext editor is opened and returned. {@inheritDoc}
*
* @see {@link org.eclipse.emf.common.util.URI#isPlatformPlugin()}
*/
@Override
public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) {
IEditorPart result = super.open(uri, crossReference, indexInList, select);
if (result == null && (uri.isPlatformPlugin() || OSGI_RESOURCE_URL_PROTOCOL.equals(uri.scheme()))) {
final IModelLocation modelLocation = getModelLocation(uri.trimFragment());
if (modelLocation != null) {
PlatformPluginStorage storage = new PlatformPluginStorage(modelLocation);
IEditorInput editorInput = new XtextReadonlyEditorInput(storage);
IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
try {
IEditorPart editor = IDE.openEditor(activePage, editorInput, editorID);
selectAndReveal(editor, uri, crossReference, indexInList, select);
return EditorUtils.getXtextEditor(editor);
} catch (WrappedException e) {
LOG.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause()); //$NON-NLS-1$ //$NON-NLS-2$
} catch (PartInitException partInitException) {
LOG.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
return result;
}
示例4: execute
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的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;
}
示例5: selectAndReveal
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
protected void selectAndReveal(IEditorPart openEditor, final URI uri, final EReference crossReference,
final int indexInList, final boolean select) {
final XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor);
if (xtextEditor != null) {
if (uri.fragment() != null) {
xtextEditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource resource) throws Exception {
if (resource != null) {
EObject object = resource.getEObject(uri.fragment());
ITextRegion location = (crossReference != null) ? locationProvider.getSignificantTextRegion(object,
crossReference, indexInList) : locationProvider.getSignificantTextRegion(object);
if (select) {
xtextEditor.selectAndReveal(location.getOffset(), location.getLength());
} else {
xtextEditor.reveal(location.getOffset(), location.getLength());
}
}
}
});
}
}
}
示例6: execute
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的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;
}
示例7: open
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
public IEditorPart open(URI uri, EReference crossReference, int indexInList, boolean select) {
Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator();
if (storages != null && storages.hasNext()) {
try {
IStorage storage = storages.next().getFirst();
// TODO we should create a JarEntryEditorInput if storage is a NonJavaResource from jdt to match the editor input used when double clicking on the same resource in a jar.
IEditorInput editorInput = (storage instanceof IFile) ? new FileEditorInput((IFile) storage)
: new XtextReadonlyEditorInput(storage);
IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
IEditorPart editor = IDE.openEditor(activePage, editorInput, editorID);
selectAndReveal(editor, uri, crossReference, indexInList, select);
return EditorUtils.getXtextEditor(editor);
} catch (WrappedException e) {
logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause());
} catch (PartInitException partInitException) {
logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException);
}
}
return null;
}
示例8: selectAndReveal
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
protected void selectAndReveal(IEditorPart openEditor, final URI uri, final EReference crossReference,
final int indexInList, final boolean select) {
final XtextEditor xtextEditor = EditorUtils.getXtextEditor(openEditor);
if (xtextEditor != null) {
xtextEditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource resource) throws Exception {
if (resource != null) {
EObject object = findEObjectByURI(uri, resource);
if (object != null) {
ITextRegion location = (crossReference != null) ? locationProvider
.getSignificantTextRegion(object, crossReference, indexInList)
: locationProvider.getSignificantTextRegion(object);
if (select)
xtextEditor.selectAndReveal(location.getOffset(), location.getLength());
}
}
}
});
}
}
示例9: execute
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的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;
}
示例10: getQualifiedName
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
@Override
protected String getQualifiedName(ExecutionEvent event) {
XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor(event);
if (activeXtextEditor == null) {
return null;
}
final ITextSelection selection = getTextSelection(activeXtextEditor);
return activeXtextEditor.getDocument().readOnly(new IUnitOfWork<String, XtextResource>() {
public String exec(XtextResource xTextResource) throws Exception {
EObject context = getContext(selection, xTextResource);
EObject selectedElement = getSelectedName(selection, xTextResource);
return getQualifiedName(selectedElement, context);
}
});
}
示例11: getSelectionURI
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
private URI getSelectionURI(ISelection currentSelection) {
if (currentSelection instanceof IStructuredSelection) {
IStructuredSelection iss = (IStructuredSelection) currentSelection;
if (iss.size() == 1) {
EObjectNode node = (EObjectNode) iss.getFirstElement();
return node.getEObjectURI();
}
} else if (currentSelection instanceof TextSelection) {
// Selection may be stale, get latest from editor
XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor();
TextSelection ts = (TextSelection) xtextEditor.getSelectionProvider().getSelection();
return xtextEditor.getDocument().readOnly(resource -> {
EObject e = new EObjectAtOffsetHelper().resolveContainedElementAt(resource, ts.getOffset());
return EcoreUtil2.getURI(e);
});
}
return null;
}
示例12: draw
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
private void draw() {
XtextEditor editor = EditorUtils.getActiveXtextEditor();
if (editor != null && (hoveredElement != null || !selectedElements.isEmpty())) {
ISourceViewer isv = editor.getInternalSourceViewer();
styledText = isv.getTextWidget();
drawSelection();
} else {
clear();
}
}
示例13: CFGraph
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
/**
* Constructor
*/
public CFGraph() {
locFileProvider = new DefaultLocationInFileProvider();
editor = EditorUtils.getActiveXtextEditor();
styledText = editor.getInternalSourceViewer().getTextWidget();
layoutDone = false;
}
示例14: execute
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
if (xtextEditor != null && xtextEditor.getEditorInput() instanceof XtextReadonlyEditorInput) {
return null;
}
return super.execute(event);
}
示例15: createTextAttribute
import org.eclipse.xtext.ui.editor.utils.EditorUtils; //导入依赖的package包/类
protected TextAttribute createTextAttribute(String id, TextStyle defaultTextStyle) {
TextStyle textStyle = new TextStyle();
preferencesAccessor.populateTextStyle(id, textStyle, defaultTextStyle);
int style = textStyle.getStyle();
Font fontFromFontData = EditorUtils.fontFromFontData(textStyle.getFontData());
return new TextAttribute(
EditorUtils.colorFromRGB(textStyle.getColor()),
EditorUtils.colorFromRGB(textStyle.getBackgroundColor()),
style, fontFromFontData);
}