-package org.simantics.document.ui;\r
-\r
-import org.eclipse.jface.text.BadLocationException;\r
-import org.eclipse.jface.text.IDocument;\r
-import org.eclipse.jface.text.ITextSelection;\r
-import org.eclipse.jface.text.ITextViewer;\r
-import org.eclipse.jface.text.contentassist.ICompletionProposal;\r
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;\r
-import org.eclipse.jface.text.contentassist.IContextInformation;\r
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;\r
-\r
-public class CSSCompletionAssistProcessor implements IContentAssistProcessor {\r
- \r
- private String lastError = "";\r
- private CSSTextEditorEnvironment environment;\r
- \r
- public CSSCompletionAssistProcessor(CSSTextEditorEnvironment environment) {\r
- this.environment = environment;\r
- }\r
-\r
- @Override\r
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int tmpOffset) {\r
- ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection();\r
- // adjust offset to end of normalized selection\r
- if (selection.getOffset() == tmpOffset)\r
- tmpOffset = selection.getOffset() + selection.getLength();\r
- final int offset = tmpOffset;\r
- IDocument document = viewer.getDocument();\r
- String tmpPrefix = "";\r
- try {\r
- tmpPrefix = getPrefix(document, offset);\r
- } catch (BadLocationException e) {\r
- e.printStackTrace();\r
- }\r
- environment.updateEnvironment(document);\r
- return environment.getCompletionProposals(tmpPrefix, offset);\r
- }\r
- \r
- private static String getPrefix(IDocument doc, int offset) throws BadLocationException {\r
- if (doc == null || offset >= doc.getLength())\r
- return "";\r
-\r
- int length= 0;\r
- while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)) || doc.getChar(offset) == '.')\r
- length++;\r
-\r
- return doc.get(offset + 1, length);\r
- }\r
- \r
- @Override\r
- public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {\r
- return null;\r
- }\r
-\r
- private static final char[] AUTO_ACTIVATION_CHARS = new char[] { '.', '(' };\r
- \r
- @Override\r
- public char[] getCompletionProposalAutoActivationCharacters() {\r
- return AUTO_ACTIVATION_CHARS;\r
- }\r
-\r
- @Override\r
- public char[] getContextInformationAutoActivationCharacters() {\r
- return null;\r
- }\r
-\r
- @Override\r
- public String getErrorMessage() {\r
- return lastError;\r
- }\r
-\r
- @Override\r
- public IContextInformationValidator getContextInformationValidator() {\r
- return null;\r
- }\r
-\r
-}\r
+package org.simantics.document.ui;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+
+public class CSSCompletionAssistProcessor implements IContentAssistProcessor {
+
+ private String lastError = "";
+ private CSSTextEditorEnvironment environment;
+
+ public CSSCompletionAssistProcessor(CSSTextEditorEnvironment environment) {
+ this.environment = environment;
+ }
+
+ @Override
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int tmpOffset) {
+ ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection();
+ // adjust offset to end of normalized selection
+ if (selection.getOffset() == tmpOffset)
+ tmpOffset = selection.getOffset() + selection.getLength();
+ final int offset = tmpOffset;
+ IDocument document = viewer.getDocument();
+ String tmpPrefix = "";
+ try {
+ tmpPrefix = getPrefix(document, offset);
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ environment.updateEnvironment(document);
+ return environment.getCompletionProposals(tmpPrefix, offset);
+ }
+
+ private static String getPrefix(IDocument doc, int offset) throws BadLocationException {
+ if (doc == null || offset >= doc.getLength())
+ return "";
+
+ int length= 0;
+ while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)) || doc.getChar(offset) == '.')
+ length++;
+
+ return doc.get(offset + 1, length);
+ }
+
+ @Override
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
+ return null;
+ }
+
+ private static final char[] AUTO_ACTIVATION_CHARS = new char[] { '.', '(' };
+
+ @Override
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return AUTO_ACTIVATION_CHARS;
+ }
+
+ @Override
+ public char[] getContextInformationAutoActivationCharacters() {
+ return null;
+ }
+
+ @Override
+ public String getErrorMessage() {
+ return lastError;
+ }
+
+ @Override
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+
+}