p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor.prototype1 / src / eu / etaxonomy / taxeditor / prototype1 / view / MySourceViewerConfig.java
1 package eu.etaxonomy.taxeditor.prototype1.view;
2
3 import org.eclipse.jface.text.IDocument;
4 import org.eclipse.jface.text.TextAttribute;
5 import org.eclipse.jface.text.contentassist.ContentAssistant;
6 import org.eclipse.jface.text.contentassist.IContentAssistant;
7 import org.eclipse.jface.text.presentation.IPresentationReconciler;
8 import org.eclipse.jface.text.presentation.PresentationReconciler;
9 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
10 import org.eclipse.jface.text.rules.Token;
11 import org.eclipse.jface.text.source.ISourceViewer;
12 import org.eclipse.jface.text.source.SourceViewerConfiguration;
13 import org.eclipse.swt.graphics.Color;
14 import org.eclipse.swt.graphics.RGB;
15 import org.eclipse.swt.widgets.Display;
16
17 public class MySourceViewerConfig extends SourceViewerConfiguration {
18 private MyRuleScanner scanner;
19 private static Color DEFAULT_TAG_COLOR =
20 new Color(Display.getCurrent(), new RGB(0, 0, 200));
21
22 public MySourceViewerConfig() {
23
24 }
25
26 protected MyRuleScanner getTagScanner() {
27 if (scanner == null) {
28 scanner = new MyRuleScanner();
29 scanner.setDefaultReturnToken(
30 new Token(new TextAttribute(DEFAULT_TAG_COLOR)));
31 }
32 return scanner;
33 }
34
35 /**
36 * Define reconciler for MyEditor
37 */
38 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
39 PresentationReconciler reconciler = new PresentationReconciler();
40 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getTagScanner());
41 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
42 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
43 return reconciler;
44 }
45
46 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
47
48 ContentAssistant assistant = new ContentAssistant();
49 assistant.setContentAssistProcessor(
50 new MyCompletionProcessor(),
51 IDocument.DEFAULT_CONTENT_TYPE);
52 assistant.enableAutoActivation(true);
53 assistant.setAutoActivationDelay(50);
54 assistant.setProposalPopupOrientation(
55 IContentAssistant.PROPOSAL_OVERLAY);
56 assistant.setStatusLineVisible(true);
57 assistant.setStatusMessage("Create a nomenclatural or taxonomic relationship");
58 assistant.setProposalSelectorBackground(
59 new Color(Display.getCurrent(), new RGB(255, 255, 255)));
60 assistant.setInformationControlCreator(
61 getInformationControlCreator(sourceViewer)); // this is what pops up the yellow context box
62 return assistant;
63 }
64 }