diff dwtx/jface/text/contentassist/ContentAssistSubjectControlAdapter.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtx/jface/text/contentassist/ContentAssistSubjectControlAdapter.d	Sat Aug 23 19:10:48 2008 +0200
@@ -0,0 +1,417 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module dwtx.jface.text.contentassist.ContentAssistSubjectControlAdapter;
+
+import dwt.dwthelper.utils;
+
+
+
+
+
+import dwt.custom.StyledText;
+import dwt.custom.VerifyKeyListener;
+import dwt.events.KeyListener;
+import dwt.events.SelectionListener;
+import dwt.graphics.Point;
+import dwt.widgets.Control;
+import dwtx.core.runtime.Assert;
+import dwtx.jface.contentassist.IContentAssistSubjectControl;
+import dwtx.jface.contentassist.ISubjectControlContextInformationPresenter;
+import dwtx.jface.contentassist.ISubjectControlContextInformationValidator;
+import dwtx.jface.text.IDocument;
+import dwtx.jface.text.IEventConsumer;
+import dwtx.jface.text.ITextViewer;
+import dwtx.jface.text.ITextViewerExtension;
+import dwtx.jface.text.contentassist.ContextInformationPopup.ContextFrame;
+
+
+/**
+ * This content assist adapter delegates the calls either to
+ * a text viewer or to a content assist subject control.
+ *
+ * @since 3.0
+ */
+final class ContentAssistSubjectControlAdapter : IContentAssistSubjectControl {
+
+    /**
+     * The text viewer which is used as content assist subject control.
+     */
+    private ITextViewer fViewer;
+
+    /**
+     * The content assist subject control.
+     */
+    private IContentAssistSubjectControl fContentAssistSubjectControl;
+
+
+    /**
+     * Creates an adapter for the given content assist subject control.
+     *
+     * @param contentAssistSubjectControl the content assist subject control
+     */
+    ContentAssistSubjectControlAdapter(IContentAssistSubjectControl contentAssistSubjectControl) {
+        Assert.isNotNull(contentAssistSubjectControl);
+        fContentAssistSubjectControl= contentAssistSubjectControl;
+    }
+
+    /**
+     * Creates an adapter for the given text viewer.
+     *
+     * @param viewer the text viewer
+     */
+    public ContentAssistSubjectControlAdapter(ITextViewer viewer) {
+        Assert.isNotNull(viewer);
+        fViewer= viewer;
+    }
+
+    /*
+     * @see IContentAssistSubjectControl#getLineHeight()
+     */
+    public int getLineHeight() {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.getLineHeight();
+        
+        return fViewer.getTextWidget().getLineHeight(getCaretOffset());
+    }
+
+    /*
+     * @see IContentAssistSubjectControl#getControl()
+     */
+    public Control getControl() {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.getControl();
+        return fViewer.getTextWidget();
+    }
+
+    /*
+     * @see IContentAssistSubjectControl#getLocationAtOffset(int)
+     */
+    public Point getLocationAtOffset(int offset) {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.getLocationAtOffset(offset);
+        return fViewer.getTextWidget().getLocationAtOffset(offset);
+    }
+
+    /*
+     * @see IContentAssistSubjectControl#getWidgetSelectionRange()
+     */
+    public Point getWidgetSelectionRange() {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.getWidgetSelectionRange();
+        return fViewer.getTextWidget().getSelectionRange();
+    }
+
+    /*
+     * @see IContentAssistSubjectControl#getSelectedRange()
+     */
+    public Point getSelectedRange() {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.getSelectedRange();
+        return fViewer.getSelectedRange();
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#getCaretOffset()
+     */
+    public int getCaretOffset() {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.getCaretOffset();
+        return fViewer.getTextWidget().getCaretOffset();
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#getLineDelimiter()
+     */
+    public String getLineDelimiter() {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.getLineDelimiter();
+        return fViewer.getTextWidget().getLineDelimiter();
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#addKeyListener(dwt.events.KeyListener)
+     */
+    public void addKeyListener(KeyListener keyListener) {
+        if (fContentAssistSubjectControl !is null)
+            fContentAssistSubjectControl.addKeyListener(keyListener);
+        else
+            fViewer.getTextWidget().addKeyListener(keyListener);
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#removeKeyListener(dwt.events.KeyListener)
+     */
+    public void removeKeyListener(KeyListener keyListener) {
+        if (fContentAssistSubjectControl !is null)
+            fContentAssistSubjectControl.removeKeyListener(keyListener);
+        else
+            fViewer.getTextWidget().removeKeyListener(keyListener);
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#getDocument()
+     */
+    public IDocument getDocument() {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.getDocument();
+        return fViewer.getDocument();
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#prependVerifyKeyListener(VerifyKeyListener)
+     */
+    public bool prependVerifyKeyListener(VerifyKeyListener verifyKeyListener) {
+        if (fContentAssistSubjectControl !is null) {
+            return fContentAssistSubjectControl.prependVerifyKeyListener(verifyKeyListener);
+        } else if (fViewer instanceof ITextViewerExtension) {
+            ITextViewerExtension e= (ITextViewerExtension) fViewer;
+            e.prependVerifyKeyListener(verifyKeyListener);
+            return true;
+        } else {
+
+            StyledText textWidget= fViewer.getTextWidget();
+            if (Helper.okToUse(textWidget)) {
+                textWidget.addVerifyKeyListener(verifyKeyListener);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#appendVerifyKeyListener(dwt.custom.VerifyKeyListener)
+     */
+    public bool appendVerifyKeyListener(VerifyKeyListener verifyKeyListener) {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.appendVerifyKeyListener(verifyKeyListener);
+        else if (fViewer instanceof ITextViewerExtension) {
+            ITextViewerExtension extension= (ITextViewerExtension)fViewer;
+            extension.appendVerifyKeyListener(verifyKeyListener);
+            return true;
+        } else {
+            StyledText textWidget= fViewer.getTextWidget();
+            if (Helper.okToUse(textWidget)) {
+                textWidget.addVerifyKeyListener(verifyKeyListener);
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#removeVerifyKeyListener(dwt.custom.VerifyKeyListener)
+     */
+    public void removeVerifyKeyListener(VerifyKeyListener verifyKeyListener) {
+        if (fContentAssistSubjectControl !is null) {
+            fContentAssistSubjectControl.removeVerifyKeyListener(verifyKeyListener);
+        } else if (fViewer instanceof ITextViewerExtension) {
+            ITextViewerExtension extension= (ITextViewerExtension) fViewer;
+            extension.removeVerifyKeyListener(verifyKeyListener);
+        } else {
+            StyledText textWidget= fViewer.getTextWidget();
+            if (Helper.okToUse(textWidget))
+                textWidget.removeVerifyKeyListener(verifyKeyListener);
+        }
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#setEventConsumer(dwtx.jface.text.contentassist.ContentAssistant.InternalListener)
+     */
+    public void setEventConsumer(IEventConsumer eventConsumer) {
+        if (fContentAssistSubjectControl !is null)
+            fContentAssistSubjectControl.setEventConsumer(eventConsumer);
+        else
+            fViewer.setEventConsumer(eventConsumer);
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#setSelectedRange(int, int)
+     */
+    public void setSelectedRange(int i, int j) {
+        if (fContentAssistSubjectControl !is null)
+            fContentAssistSubjectControl.setSelectedRange(i, j);
+        else
+            fViewer.setSelectedRange(i, j);
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#revealRange(int, int)
+     */
+    public void revealRange(int i, int j) {
+        if (fContentAssistSubjectControl !is null)
+            fContentAssistSubjectControl.revealRange(i, j);
+        else
+            fViewer.revealRange(i, j);
+    }
+
+    /*
+     * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#canAddVerifyKeyListener()
+     */
+    public bool supportsVerifyKeyListener() {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.supportsVerifyKeyListener();
+        return true;
+    }
+    /**
+     * Returns the characters which when typed by the user should automatically
+     * initiate proposing completions. The position is used to determine the
+     * appropriate content assist processor to invoke.
+     *
+     * @param contentAssistant the content assistant
+     * @param offset a document offset
+     * @return the auto activation characters
+     * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
+     */
+    public char[] getCompletionProposalAutoActivationCharacters(ContentAssistant contentAssistant, int offset) {
+        if (fContentAssistSubjectControl !is null)
+            return contentAssistant.getCompletionProposalAutoActivationCharacters(fContentAssistSubjectControl, offset);
+        return contentAssistant.getCompletionProposalAutoActivationCharacters(fViewer, offset);
+    }
+
+    /**
+     * Returns the characters which when typed by the user should automatically
+     * initiate the presentation of context information. The position is used
+     * to determine the appropriate content assist processor to invoke.
+     *
+     * @param contentAssistant the content assistant
+     * @param offset a document offset
+     * @return the auto activation characters
+     *
+     * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters()
+     */
+    char[] getContextInformationAutoActivationCharacters(ContentAssistant contentAssistant, int offset) {
+        if (fContentAssistSubjectControl !is null)
+            return contentAssistant.getContextInformationAutoActivationCharacters(fContentAssistSubjectControl, offset);
+        return contentAssistant.getContextInformationAutoActivationCharacters(fViewer, offset);
+    }
+
+    /**
+    * Creates and returns a completion proposal popup for the given content assistant.
+    *
+    * @param contentAssistant the content assistant
+    * @param controller the additional info controller
+    * @return the completion proposal popup
+    */
+    CompletionProposalPopup createCompletionProposalPopup(ContentAssistant contentAssistant, AdditionalInfoController controller) {
+        if (fContentAssistSubjectControl !is null)
+            return new CompletionProposalPopup(contentAssistant, fContentAssistSubjectControl, controller);
+        return new CompletionProposalPopup(contentAssistant, fViewer, controller);
+
+    }
+
+    /**
+     * Creates and returns a context info popup for the given content assistant.
+     *
+     * @param contentAssistant the content assistant
+     * @return the context info popup or <code>null</code>
+     */
+    ContextInformationPopup createContextInfoPopup(ContentAssistant contentAssistant) {
+        if (fContentAssistSubjectControl !is null)
+            return new ContextInformationPopup(contentAssistant, fContentAssistSubjectControl);
+        return new ContextInformationPopup(contentAssistant, fViewer);
+
+    }
+
+    /**
+     * Returns the context information validator that should be used to
+     * determine when the currently displayed context information should
+     * be dismissed. The position is used to determine the appropriate
+     * content assist processor to invoke.
+     *
+     * @param contentAssistant the content assistant
+     * @param offset a document offset
+     * @return an validator
+     */
+    public IContextInformationValidator getContextInformationValidator(ContentAssistant contentAssistant, int offset) {
+        if (fContentAssistSubjectControl !is null)
+            return contentAssistant.getContextInformationValidator(fContentAssistSubjectControl, offset);
+        return contentAssistant.getContextInformationValidator(fViewer, offset);
+    }
+
+    /**
+     * Returns the context information presenter that should be used to
+     * display context information. The position is used to determine the
+     * appropriate content assist processor to invoke.
+     *
+     * @param contentAssistant the content assistant
+     * @param offset a document offset
+     * @return a presenter
+     */
+    public IContextInformationPresenter getContextInformationPresenter(ContentAssistant contentAssistant, int offset) {
+        if (fContentAssistSubjectControl !is null)
+            return contentAssistant.getContextInformationPresenter(fContentAssistSubjectControl, offset);
+        return contentAssistant.getContextInformationPresenter(fViewer, offset);
+    }
+
+    /**
+     * Installs this adapter's information validator on the given context frame.
+     *
+     * @param frame the context frame
+     */
+    public void installValidator(ContextFrame frame) {
+        if (fContentAssistSubjectControl !is null) {
+            if (frame.fValidator instanceof ISubjectControlContextInformationValidator)
+                ((ISubjectControlContextInformationValidator)frame.fValidator).install(frame.fInformation, fContentAssistSubjectControl, frame.fOffset);
+        } else
+            frame.fValidator.install(frame.fInformation, fViewer, frame.fOffset);
+    }
+
+    /**
+     * Installs this adapter's information presenter on the given context frame.
+     *
+     * @param frame the context frame
+     */
+    public void installContextInformationPresenter(ContextFrame frame) {
+        if (fContentAssistSubjectControl !is null) {
+            if (frame.fPresenter instanceof ISubjectControlContextInformationPresenter)
+                ((ISubjectControlContextInformationPresenter)frame.fValidator).install(frame.fInformation, fContentAssistSubjectControl, frame.fBeginOffset);
+        } else
+            frame.fPresenter.install(frame.fInformation, fViewer, frame.fBeginOffset);
+    }
+
+    /**
+     * Returns an array of context information objects computed based
+     * on the specified document position. The position is used to determine
+     * the appropriate content assist processor to invoke.
+     *
+     * @param contentAssistant the content assistant
+     * @param offset a document offset
+     * @return an array of context information objects
+     * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
+     */
+    public IContextInformation[] computeContextInformation(ContentAssistant contentAssistant, int offset) {
+        if (fContentAssistSubjectControl !is null)
+            return contentAssistant.computeContextInformation(fContentAssistSubjectControl, offset);
+        return contentAssistant.computeContextInformation(fViewer, offset);
+    }
+
+    /*
+     * @see IContentAssistSubjectControl#addSelectionListener(SelectionListener)
+     */
+    public bool addSelectionListener(SelectionListener selectionListener) {
+        if (fContentAssistSubjectControl !is null)
+            return fContentAssistSubjectControl.addSelectionListener(selectionListener);
+        fViewer.getTextWidget().addSelectionListener(selectionListener);
+        return true;
+    }
+
+    /*
+     * @see IContentAssistSubjectControl#removeSelectionListener(SelectionListener)
+     */
+    public void removeSelectionListener(SelectionListener selectionListener) {
+        if (fContentAssistSubjectControl !is null)
+            fContentAssistSubjectControl.removeSelectionListener(selectionListener);
+        else
+            fViewer.getTextWidget().removeSelectionListener(selectionListener);
+    }
+}