diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssist.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssist.java index 3e49477597e2e61c74e951f3dbd54301d8c4c618..a4f403db1c054c1a226503d0a21955f87ce7fd1f 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssist.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/FieldAssist.java @@ -17,8 +17,6 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.base.ui.fieldassist; -import org.eclipse.jface.bindings.keys.KeyStroke; -import org.eclipse.jface.bindings.keys.ParseException; import org.eclipse.jface.fieldassist.ContentProposalAdapter; import org.eclipse.jface.fieldassist.IContentProposal; import org.eclipse.jface.fieldassist.IContentProposalListener; @@ -37,7 +35,7 @@ import org.eclipse.swt.widgets.Text; * @author doebber * @author $Author: hoelzl $ * @version $Rev: 18709 $ - * @ConQAT.Rating RED Hash: + * @ConQAT.Rating YELLOW Hash: 7CF69F2D99AF737A905EC1FA352EF278 */ public class FieldAssist { @@ -45,29 +43,19 @@ public class FieldAssist { private final Text field; /** - * ProposalProvider wrapper class that takes care of proper insertion. This - * is intended to be transparent to the implementor. - */ - private final AF3ContentProposalProvider provider; - - /** The keystroke the field assist is activated for. */ - private KeyStroke keystroke; - - /** - * Default keystroke for assist activation. Used if no other keystroke - * specified. + * Stores the custom proposal provider implemented for the concrete + * application. */ - public static final String DEFAULT_KEYSTROKE = "Ctrl+Space"; + private IProposalProvider concreteProvider; /** - * Array of chars the assist is activated for. A typical example in Java - * would be '.' as an auto activation char. + * ProposalProvider wrapper class that takes care of proper insertion. This + * is intended to be transparent to the implementor. */ - private char[] autoActivationChars; + private final AF3ContentProposalProvider provider; /** - * Constructor. Sufficient for most applications. Initializes with default - * keystroke and no auto activation chars. + * Constructor. */ public FieldAssist(Text field, IProposalProvider provider) { this.field = field; @@ -75,30 +63,13 @@ public class FieldAssist { initialize(); } - /** Constructor. Provides additional parameters which may be null. */ - public FieldAssist(Text field, IProposalProvider provider, - KeyStroke keystroke, char[] autoActivationChars) { - this.field = field; - this.provider = new AF3ContentProposalProvider(provider); - this.keystroke = keystroke; - this.autoActivationChars = autoActivationChars; - initialize(); - } - /** Initializes the FieldAssist object. */ private void initialize() { provider.setFiltering(true); - if (keystroke == null) { - try { - keystroke = KeyStroke.getInstance(DEFAULT_KEYSTROKE); - } catch (ParseException e) { - // Should not happen - e.printStackTrace(); - } - } ContentProposalAdapter adapter = new ContentProposalAdapter(field, - new TextContentAdapter(), provider, keystroke, - autoActivationChars); + new TextContentAdapter(), provider, + concreteProvider.getKeystroke(), + concreteProvider.getAutoActivationChars()); adapter.setPropagateKeys(true); adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE); adapter.addContentProposalListener(new IContentProposalListener() { @@ -127,25 +98,19 @@ public class FieldAssist { private final class AF3ContentProposalProvider extends SimpleContentProposalProvider { - /** - * Stores the custom proposal provider implemented for the concrete - * application. - */ - private IProposalProvider concreteProvider; - /** * Constructor for static proposals. Is never called but required by the * compiler. */ public AF3ContentProposalProvider(String[] proposals) { super(proposals); - this.concreteProvider = new StaticProposalProvider(proposals); + concreteProvider = new StaticProposalProvider(proposals); } /** Constructor. */ public AF3ContentProposalProvider(IProposalProvider provider) { super(new String[0]); - this.concreteProvider = provider; + concreteProvider = provider; } /** {@inheritDoc} */ @@ -162,10 +127,20 @@ public class FieldAssist { /** Finds the beginning of the word the cursor is placed in. */ private int findBeginningOfWord(String contents, int position) { int tmp = Math.max(0, position - 1); - while (tmp > 0 && !Character.isWhitespace(contents.charAt(tmp))) { - // TODO include operators like '+' to be handled as whitespace + while (tmp > 0 && !Character.isWhitespace(contents.charAt(tmp)) + && !isAdditionalWhitespace(contents.charAt(tmp))) { tmp--; } return tmp; } + + /** Tests for match with additional whitespace characters. */ + private boolean isAdditionalWhitespace(char charAt) { + for (char c : concreteProvider.getAdditionalWhitespaceChars()) { + if (c == charAt) { + return true; + } + } + return false; + } } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/IProposalProvider.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/IProposalProvider.java index f4fd88ad6f74672f447401276a0ee254c8608be8..8fc3e80c81136027c41bab19a50e3d8274d95e10 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/IProposalProvider.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/IProposalProvider.java @@ -17,6 +17,8 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +--------------------------------------------------------------------------*/ package org.fortiss.tooling.base.ui.fieldassist; +import org.eclipse.jface.bindings.keys.KeyStroke; + /** * Interface defining the {@link IProposalProvider} necessary to add custom * field assist to text widgets. @@ -24,7 +26,7 @@ package org.fortiss.tooling.base.ui.fieldassist; * @author doebber * @author $Author: hoelzl $ * @version $Rev: 18709 $ - * @ConQAT.Rating RED Hash: + * @ConQAT.Rating YELLOW Hash: 01D3A9BF965A2B25DD796569E355C483 */ public interface IProposalProvider { @@ -35,4 +37,20 @@ public interface IProposalProvider { */ public String[] getProposals(String currentWord); + /** The keystroke the field assist is activated for. */ + public KeyStroke getKeystroke(); + + /** + * Array of chars the assist is activated for. A typical example in Java + * would be '.' as an auto activation char. + */ + public char[] getAutoActivationChars(); + + /** + * Returns an array of chars other than 'space' that will be used to + * determine the beginning of the word to propose for. Typical examples + * might be '.', '=' or any operands. + */ + public char[] getAdditionalWhitespaceChars(); + } diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/ProposalProviderBase.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/ProposalProviderBase.java new file mode 100644 index 0000000000000000000000000000000000000000..4696a909d715081e2361a5c1e912817a591ec010 --- /dev/null +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/ProposalProviderBase.java @@ -0,0 +1,62 @@ +/*--------------------------------------------------------------------------+ +$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $ +| | +| Copyright 2012 ForTISS GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.base.ui.fieldassist; + +import org.eclipse.jface.bindings.keys.KeyStroke; +import org.eclipse.jface.bindings.keys.ParseException; + +/** + * + * @author doebber + * @author $Author: hoelzl $ + * @version $Rev: 18709 $ + * @ConQAT.Rating YELLOW Hash: E6F1B7DFA2427668639A84CD869EF6CC + */ +public abstract class ProposalProviderBase implements IProposalProvider { + + /** + * Default keystroke for assist activation. Used if no other keystroke + * specified. + */ + public static final String DEFAULT_KEYSTROKE = "Ctrl+Space"; + + /** {@inheritDoc} */ + @Override + public KeyStroke getKeystroke() { + KeyStroke key = null; + try { + key = KeyStroke.getInstance(DEFAULT_KEYSTROKE); + } catch (ParseException e) { + // Should not happen + e.printStackTrace(); + } + return key; + } + + /** {@inheritDoc} */ + @Override + public char[] getAutoActivationChars() { + return null; + } + + /** {@inheritDoc} */ + @Override + public char[] getAdditionalWhitespaceChars() { + return new char[0]; + } +} diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/StaticProposalProvider.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/StaticProposalProvider.java index ba714341e4dc5ead64dc572c27c86d38e631eddc..5903dbad80628c7c4ddc747a574aaed537bac7a8 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/StaticProposalProvider.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/fieldassist/StaticProposalProvider.java @@ -23,9 +23,9 @@ package org.fortiss.tooling.base.ui.fieldassist; * @author doebber * @author $Author: hoelzl $ * @version $Rev: 18709 $ - * @ConQAT.Rating RED Hash: + * @ConQAT.Rating YELLOW Hash: B8C599E7ED32A31EDF996CF140A91067 */ -public final class StaticProposalProvider implements IProposalProvider { +public final class StaticProposalProvider extends ProposalProviderBase { /** Stores the array of proposals. */ private String[] proposals;