1d1e6cd6d19f0fd3a74d37247cb68ac6f9e59a4d
[public/netxms.git] / src / java / netxms-eclipse / AgentManager / src / org / netxms / ui / eclipse / agentmanager / widgets / internal / AgentConfigSourceViewerConfiguration.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2011 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.ui.eclipse.agentmanager.widgets.internal;
20
21 import org.eclipse.jface.text.IDocument;
22 import org.eclipse.jface.text.presentation.IPresentationReconciler;
23 import org.eclipse.jface.text.presentation.PresentationReconciler;
24 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
25 import org.eclipse.jface.text.rules.IRule;
26 import org.eclipse.jface.text.rules.IWordDetector;
27 import org.eclipse.jface.text.rules.PatternRule;
28 import org.eclipse.jface.text.rules.RuleBasedScanner;
29 import org.eclipse.jface.text.source.ISourceViewer;
30 import org.eclipse.jface.text.source.SourceViewerConfiguration;
31
32 /**
33 * Source viewer configuration for agent config
34 */
35 public class AgentConfigSourceViewerConfiguration extends SourceViewerConfiguration
36 {
37 private static final IWordDetector configWordDetector = new IWordDetector() {
38 @Override
39 public boolean isWordPart(char c)
40 {
41 return Character.isLetterOrDigit(c) || (c == '$') || (c == '_');
42 }
43
44 @Override
45 public boolean isWordStart(char c)
46 {
47 return Character.isLetter(c) || (c == '$') || (c == '_');
48 }
49 };
50
51 private static final String[] configKeywords = {
52 "Action", //$NON-NLS-1$
53 "ActionShellExec", //$NON-NLS-1$
54 "CodePage", //$NON-NLS-1$
55 "ConfigIncludeDir", //$NON-NLS-1$
56 "ControlServers", //$NON-NLS-1$
57 "CreateCrashDumps", //$NON-NLS-1$
58 "DumpDirectory", //$NON-NLS-1$
59 "EnableActions", //$NON-NLS-1$
60 "EnabledCiphers", //$NON-NLS-1$
61 "EnableProxy", //$NON-NLS-1$
62 "EnableSNMPProxy", //$NON-NLS-1$
63 "EnableSubagentAutoload", //$NON-NLS-1$
64 "EnableWatchdog", //$NON-NLS-1$
65 "ExecTimeout", //$NON-NLS-1$
66 "ExternalList", //$NON-NLS-1$
67 "ExternalParameter", //$NON-NLS-1$
68 "ExternalParameterShellExec", //$NON-NLS-1$
69 "ExternalSubAgent", //$NON-NLS-1$
70 "FileStore", //$NON-NLS-1$
71 "ListenAddress", //$NON-NLS-1$
72 "ListenPort", //$NON-NLS-1$
73 "LogFile", //$NON-NLS-1$
74 "LogHistorySize", //$NON-NLS-1$
75 "LogRotationMode", //$NON-NLS-1$
76 "LogUnresolvedSymbols", //$NON-NLS-1$
77 "MasterServers", //$NON-NLS-1$
78 "MaxLogSize", //$NON-NLS-1$
79 "MaxSessions", //$NON-NLS-1$
80 "PlatformSuffix", //$NON-NLS-1$
81 "RequireAuthentication", //$NON-NLS-1$
82 "RequireEncryption", //$NON-NLS-1$
83 "Servers", //$NON-NLS-1$
84 "SessionIdleTimeout", //$NON-NLS-1$
85 "SharedSecret", //$NON-NLS-1$
86 "SNMPTimeout", //$NON-NLS-1$
87 "StartupDelay", //$NON-NLS-1$
88 "SubAgent", //$NON-NLS-1$
89 "WaitForProcess" //$NON-NLS-1$
90 };
91
92 private static final IRule[] codeRules = {
93 new KeywordRule(configWordDetector, AgentConfigTextAttributeProvider.getTextAttributeToken(AgentConfigTextAttributeProvider.KEYWORD),
94 AgentConfigTextAttributeProvider.getTextAttributeToken(AgentConfigTextAttributeProvider.DEFAULT), configKeywords)
95 };
96
97 /**
98 * Creates source viewer configuration for agent config
99 */
100 public AgentConfigSourceViewerConfiguration()
101 {
102 super();
103 }
104
105 /* (non-Javadoc)
106 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getTabWidth(org.eclipse.jface.text.source.ISourceViewer)
107 */
108 @Override
109 public int getTabWidth(ISourceViewer sourceViewer)
110 {
111 return 8;
112 }
113
114 /* (non-Javadoc)
115 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredContentTypes(org.eclipse.jface.text.source.ISourceViewer)
116 */
117 @Override
118 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer)
119 {
120 return AgentConfigDocument.CONTENT_TYPES;
121 }
122
123 /* (non-Javadoc)
124 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer)
125 */
126 @Override
127 public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer)
128 {
129 PresentationReconciler reconciler = new PresentationReconciler();
130
131 RuleBasedScanner scanner = new RuleBasedScanner();
132 scanner.setRules(codeRules);
133 scanner.setDefaultReturnToken(AgentConfigTextAttributeProvider.getTextAttributeToken(AgentConfigTextAttributeProvider.DEFAULT));
134 DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
135 reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
136 reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
137
138 dr = new DefaultDamagerRepairer(new SingleTokenScanner(AgentConfigTextAttributeProvider.getTextAttribute(AgentConfigTextAttributeProvider.COMMENT)));
139 reconciler.setDamager(dr, AgentConfigDocument.CONTENT_COMMENTS);
140 reconciler.setRepairer(dr, AgentConfigDocument.CONTENT_COMMENTS);
141
142 dr = new DefaultDamagerRepairer(new SingleTokenScanner(AgentConfigTextAttributeProvider.getTextAttribute(AgentConfigTextAttributeProvider.SECTION)));
143 reconciler.setDamager(dr, AgentConfigDocument.CONTENT_SECTION);
144 reconciler.setRepairer(dr, AgentConfigDocument.CONTENT_SECTION);
145
146 scanner = new RuleBasedScanner();
147 scanner.setRules(new IRule[] { new PatternRule("\"", "\n", AgentConfigTextAttributeProvider.getTextAttributeToken(AgentConfigTextAttributeProvider.ERROR), (char)0, false) }); //$NON-NLS-1$ //$NON-NLS-2$
148 scanner.setDefaultReturnToken(AgentConfigTextAttributeProvider.getTextAttributeToken(AgentConfigTextAttributeProvider.STRING));
149 dr = new DefaultDamagerRepairer(scanner);
150 reconciler.setDamager(dr, AgentConfigDocument.CONTENT_STRING);
151 reconciler.setRepairer(dr, AgentConfigDocument.CONTENT_STRING);
152
153 return reconciler;
154 }
155 }