1 package org.simantics.document.ui;
\r
3 import org.eclipse.jface.text.BadLocationException;
\r
4 import org.eclipse.jface.text.IDocument;
\r
5 import org.eclipse.jface.text.ITextSelection;
\r
6 import org.eclipse.jface.text.ITextViewer;
\r
7 import org.eclipse.jface.text.contentassist.ICompletionProposal;
\r
8 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
\r
9 import org.eclipse.jface.text.contentassist.IContextInformation;
\r
10 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
\r
12 public class CSSCompletionAssistProcessor implements IContentAssistProcessor {
\r
14 private String lastError = "";
\r
15 private CSSTextEditorEnvironment environment;
\r
17 public CSSCompletionAssistProcessor(CSSTextEditorEnvironment environment) {
\r
18 this.environment = environment;
\r
22 public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int tmpOffset) {
\r
23 ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection();
\r
24 // adjust offset to end of normalized selection
\r
25 if (selection.getOffset() == tmpOffset)
\r
26 tmpOffset = selection.getOffset() + selection.getLength();
\r
27 final int offset = tmpOffset;
\r
28 IDocument document = viewer.getDocument();
\r
29 String tmpPrefix = "";
\r
31 tmpPrefix = getPrefix(document, offset);
\r
32 } catch (BadLocationException e) {
\r
33 e.printStackTrace();
\r
35 environment.updateEnvironment(document);
\r
36 return environment.getCompletionProposals(tmpPrefix, offset);
\r
39 private static String getPrefix(IDocument doc, int offset) throws BadLocationException {
\r
40 if (doc == null || offset >= doc.getLength())
\r
44 while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)) || doc.getChar(offset) == '.')
\r
47 return doc.get(offset + 1, length);
\r
51 public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
\r
55 private static final char[] AUTO_ACTIVATION_CHARS = new char[] { '.', '(' };
\r
58 public char[] getCompletionProposalAutoActivationCharacters() {
\r
59 return AUTO_ACTIVATION_CHARS;
\r
63 public char[] getContextInformationAutoActivationCharacters() {
\r
68 public String getErrorMessage() {
\r
73 public IContextInformationValidator getContextInformationValidator() {
\r