Search in sources :

Example 51 with ITextViewer

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);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 52 with ITextViewer

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);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IDocument(org.eclipse.jface.text.IDocument) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 53 with ITextViewer

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;
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) ITypedRegion(org.eclipse.jface.text.ITypedRegion) IRegion(org.eclipse.jface.text.IRegion) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 54 with ITextViewer

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;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ArrayList(java.util.ArrayList) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) List(java.util.List) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 55 with ITextViewer

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;
}
Also used : TextSelection(org.eclipse.jface.text.TextSelection) IResultSetSelection(org.jkiss.dbeaver.ui.controls.resultset.IResultSetSelection) DBDValueHandler(org.jkiss.dbeaver.model.data.DBDValueHandler) ResultSetRow(org.jkiss.dbeaver.ui.controls.resultset.ResultSetRow) IResultSetController(org.jkiss.dbeaver.ui.controls.resultset.IResultSetController) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) ITextViewer(org.eclipse.jface.text.ITextViewer) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) ResultSetValueController(org.jkiss.dbeaver.ui.controls.resultset.ResultSetValueController) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ITextViewer (org.eclipse.jface.text.ITextViewer)75 BadLocationException (org.eclipse.jface.text.BadLocationException)13 IDocument (org.eclipse.jface.text.IDocument)13 Region (org.eclipse.jface.text.Region)13 StyledText (org.eclipse.swt.custom.StyledText)13 IRegion (org.eclipse.jface.text.IRegion)11 ArrayList (java.util.ArrayList)9 Point (org.eclipse.swt.graphics.Point)9 Test (org.junit.Test)9 ITextSelection (org.eclipse.jface.text.ITextSelection)8 IEditorPart (org.eclipse.ui.IEditorPart)8 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)6 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)6 Document (org.eclipse.jface.text.Document)5 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)5 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)5 Display (org.eclipse.swt.widgets.Display)5 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)5 List (java.util.List)4 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)4