use of org.eclipse.jface.text.ITextViewer in project webtools.sourceediting by eclipse.
the class OpenFileHyperlinkTracker method paintControl.
/*
* @see PaintListener#paintControl(PaintEvent)
*/
public void paintControl(PaintEvent event) {
if (fActiveRegion == null)
return;
ITextViewer viewer = getTextViewer();
if (viewer == null)
return;
StyledText text = viewer.getTextWidget();
if (text == null || text.isDisposed())
return;
int offset = 0;
int length = 0;
if (viewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
IRegion widgetRange = extension.modelRange2WidgetRange(fActiveRegion);
if (widgetRange == null)
return;
offset = widgetRange.getOffset();
length = widgetRange.getLength();
} else {
IRegion region = viewer.getVisibleRegion();
if (!includes(region, fActiveRegion))
return;
offset = fActiveRegion.getOffset() - region.getOffset();
length = fActiveRegion.getLength();
}
// support for bidi
Point minLocation = getMinimumLocation(text, offset, length);
Point maxLocation = getMaximumLocation(text, offset, length);
int x1 = minLocation.x;
int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
int y = minLocation.y + text.getLineHeight() - 1;
GC gc = event.gc;
if (fColor != null && !fColor.isDisposed())
gc.setForeground(fColor);
gc.drawLine(x1, y, x2, y);
}
use of org.eclipse.jface.text.ITextViewer in project webtools.sourceediting by eclipse.
the class OpenFileHyperlinkTracker method uninstall.
public void uninstall() {
if (fCursor != null) {
fCursor.dispose();
fCursor = null;
}
ITextViewer textViewer = getTextViewer();
if (textViewer == null)
return;
textViewer.removeTextInputListener(this);
IDocument document = textViewer.getDocument();
if (document != null)
document.removeDocumentListener(this);
IPreferenceStore preferenceStore = getNewPreferenceStore();
if (preferenceStore != null)
preferenceStore.removePropertyChangeListener(this);
StyledText text = textViewer.getTextWidget();
if (text == null || text.isDisposed())
return;
text.removeKeyListener(this);
text.removeMouseListener(this);
text.removeMouseMoveListener(this);
text.removeFocusListener(this);
text.removePaintListener(this);
}
use of org.eclipse.jface.text.ITextViewer in project webtools.sourceediting by eclipse.
the class Highlighter method getDocumentRangeFromWidgetRange.
/**
* Adjust the given widget offset and length so that they are the
* textviewer document's offset and length, taking into account what is
* actually visible in the document.
*
* @param offset
* @param length
* @return a region containing the offset and length within the
* textviewer's document or null if the offset is not within the
* document
*/
private IRegion getDocumentRangeFromWidgetRange(int offset, int length) {
IRegion styleRegion = null;
ITextViewer viewer = getTextViewer();
if (viewer instanceof ITextViewerExtension5) {
// get document range, taking into account folding regions in
// viewer
ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
styleRegion = extension.widgetRange2ModelRange(new Region(offset, length));
} else {
// get document range, taking into account viewer visible region
// get visible region in viewer
IRegion vr = null;
if (viewer != null)
vr = viewer.getVisibleRegion();
else
vr = new Region(0, getDocument().getLength());
// care
if (offset <= vr.getLength()) {
// Adjust the offset to be within visible region
styleRegion = new Region(offset + vr.getOffset(), length);
}
}
return styleRegion;
}
use of org.eclipse.jface.text.ITextViewer in project webtools.sourceediting by eclipse.
the class JSPJavaCompletionProposalComputer method computeCompletionProposals.
/**
* <p>Return a list of proposed code completions based on the specified
* location within the document that corresponds to the current cursor
* position within the text-editor control.</p>
*
* @see org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLCompletionProposalComputer#computeCompletionProposals(org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
public List computeCompletionProposals(CompletionProposalInvocationContext context, IProgressMonitor monitor) {
List results = new ArrayList(0);
if (isValidContext(context)) {
ITextViewer viewer = context.getViewer();
int documentPosition = context.getInvocationOffset();
IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, documentPosition);
// get results from JSP completion processor
results = computeJavaCompletionProposals(viewer, documentPosition, 0);
IDOMNode xNode = null;
IStructuredDocumentRegion flat = null;
if (treeNode instanceof IDOMNode) {
xNode = (IDOMNode) treeNode;
flat = xNode.getFirstStructuredDocumentRegion();
if (flat != null && flat.getType() == DOMJSPRegionContexts.JSP_CONTENT) {
flat = flat.getPrevious();
}
}
// this is in case it's a <%@, it will be a region container...
ITextRegion openRegion = null;
if (flat != null && flat instanceof ITextRegionContainer) {
ITextRegionList v = ((ITextRegionContainer) flat).getRegions();
if (v.size() > 0)
openRegion = v.get(0);
}
// ADD CDATA PROPOSAL IF IT'S AN XML-JSP TAG
if (flat != null && flat.getType() != DOMJSPRegionContexts.JSP_SCRIPTLET_OPEN && flat.getType() != DOMJSPRegionContexts.JSP_DECLARATION_OPEN && flat.getType() != DOMJSPRegionContexts.JSP_EXPRESSION_OPEN && flat.getType() != DOMRegionContext.BLOCK_TEXT && (openRegion != null && openRegion.getType() != DOMJSPRegionContexts.JSP_DIRECTIVE_OPEN) && !inAttributeRegion(flat, documentPosition)) {
// determine if cursor is before or after selected range
int adjustedDocPosition = documentPosition;
int realCaretPosition = viewer.getTextWidget().getCaretOffset();
int selectionLength = viewer.getSelectedRange().y;
if (documentPosition > realCaretPosition) {
adjustedDocPosition -= selectionLength;
}
CustomCompletionProposal cdataProposal = createCDATAProposal(adjustedDocPosition, selectionLength);
results.add(cdataProposal);
}
}
return results;
}
use of org.eclipse.jface.text.ITextViewer in project dbeaver by dbeaver.
the class GenerateUUIDHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart == null) {
return null;
}
IResultSetController rsc = activePart.getAdapter(IResultSetController.class);
if (rsc != null && UIUtils.hasFocus(rsc.getControl())) {
IResultSetSelection selection = rsc.getSelection();
if (selection != null && !selection.isEmpty()) {
for (Object cell : selection.toArray()) {
DBDAttributeBinding attr = selection.getElementAttribute(cell);
ResultSetRow row = selection.getElementRow(cell);
if (row != null && attr != null) {
ResultSetValueController valueController = new ResultSetValueController(rsc, attr, row, IValueController.EditType.NONE, null);
DBDValueHandler valueHandler = valueController.getValueHandler();
String uuid = generateUUID();
valueController.updateValue(uuid, false);
}
}
rsc.redrawData(false, false);
rsc.updateEditControls();
}
} else {
ITextViewer textViewer = activePart.getAdapter(ITextViewer.class);
if (textViewer != null) {
ISelection selection = textViewer.getSelectionProvider().getSelection();
if (selection instanceof TextSelection) {
try {
int offset = ((TextSelection) selection).getOffset();
int length = ((TextSelection) selection).getLength();
String uuid = generateUUID();
textViewer.getDocument().replace(offset, length, uuid);
textViewer.getSelectionProvider().setSelection(new TextSelection(offset + uuid.length(), 0));
} catch (BadLocationException e) {
DBWorkbench.getPlatformUI().showError("Insert UUID", "Error inserting UUID in text editor", e);
}
}
}
}
return null;
}
Aggregations