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