p2izing the editor
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor.designproposal2 / src / eu / etaxonomy / taxeditor / designproposal2 / view / MySourceViewerConfig.java
1 package eu.etaxonomy.taxeditor.designproposal2.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.SWT;
14 import org.eclipse.swt.graphics.Color;
15 import org.eclipse.swt.graphics.RGB;
16 import org.eclipse.swt.widgets.Display;
17
18 import com.swtdesigner.SWTResourceManager;
19
20 public class MySourceViewerConfig extends SourceViewerConfiguration {
21 private MyRuleScanner scanner;
22 private static Color DEFAULT_TAG_COLOR =
23 new Color(Display.getCurrent(), new RGB(0, 0, 0));
24
25 public MySourceViewerConfig() {
26 }
27
28 protected MyRuleScanner getTagScanner() {
29 if (scanner == null) {
30 scanner = new MyRuleScanner();
31 scanner.setDefaultReturnToken(
32 new Token(
33 new TextAttribute(DEFAULT_TAG_COLOR,
34 null,
35 0,
36 SWTResourceManager.getFont("Georgia", 11, SWT.BOLD | SWT.ITALIC))
37 ));
38 }
39 return scanner;
40 }
41
42 /**
43 * Define reconciler for MyEditor
44 */
45 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
46 PresentationReconciler reconciler = new PresentationReconciler();
47 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getTagScanner());
48 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
49 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
50 return reconciler;
51 }
52
53 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
54
55 ContentAssistant assistant = new ContentAssistant();
56 assistant.setContentAssistProcessor(
57 new MyCompletionProcessor(),
58 IDocument.DEFAULT_CONTENT_TYPE);
59 assistant.enableAutoActivation(true);
60 assistant.setAutoActivationDelay(50);
61 assistant.setProposalPopupOrientation(
62 IContentAssistant.PROPOSAL_OVERLAY);
63 assistant.setStatusLineVisible(true);
64 assistant.setStatusMessage("Create a nomenclatural or taxonomic relationship");
65 assistant.setProposalSelectorBackground(
66 new Color(Display.getCurrent(), new RGB(255, 255, 255)));
67 assistant.setInformationControlCreator(
68 getInformationControlCreator(sourceViewer)); // this is what pops up the yellow context box
69 return assistant;
70 }
71 }