View | Details | Raw Unified | Return to bug 266131
Collapse All | Expand All

(-)src/org/eclipse/mtj/internal/ui/editors/jad/source/JADSourceViewerConfiguration.java (-2 / +3 lines)
Lines 22-28 Link Here
22
import org.eclipse.jface.text.source.ISourceViewer;
22
import org.eclipse.jface.text.source.ISourceViewer;
23
import org.eclipse.jface.text.source.SourceViewerConfiguration;
23
import org.eclipse.jface.text.source.SourceViewerConfiguration;
24
import org.eclipse.mtj.internal.ui.editors.jad.source.contentassist.CompletionProcessor;
24
import org.eclipse.mtj.internal.ui.editors.jad.source.contentassist.CompletionProcessor;
25
import org.eclipse.mtj.internal.ui.editors.jad.source.rules.Scanner;
25
import org.eclipse.mtj.internal.ui.editors.jad.source.rules.JadScanner;
26
26
27
/**
27
/**
28
 * This class bundles the configuration space of {@link JADSourceEditor}
28
 * This class bundles the configuration space of {@link JADSourceEditor}
Lines 64-72 Link Here
64
            ISourceViewer sourceViewer) {
64
            ISourceViewer sourceViewer) {
65
65
66
        PresentationReconciler pr = new PresentationReconciler();
66
        PresentationReconciler pr = new PresentationReconciler();
67
        DefaultDamagerRepairer ddr = new DefaultDamagerRepairer(new Scanner());
67
        DefaultDamagerRepairer ddr = new DefaultDamagerRepairer(new JadScanner());
68
        pr.setRepairer(ddr, IDocument.DEFAULT_CONTENT_TYPE);
68
        pr.setRepairer(ddr, IDocument.DEFAULT_CONTENT_TYPE);
69
        pr.setDamager(ddr, IDocument.DEFAULT_CONTENT_TYPE);
69
        pr.setDamager(ddr, IDocument.DEFAULT_CONTENT_TYPE);
70
70
        return pr;
71
        return pr;
71
    }
72
    }
72
}
73
}
(-)src/org/eclipse/mtj/internal/ui/editors/jad/source/rules/JadScanner.java (+102 lines)
Line 0 Link Here
1
/**
2
 * Copyright (c) 2008 Motorola.
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 *     Diego Sandin (Motorola) - Initial implementation
11
 */
12
package org.eclipse.mtj.internal.ui.editors.jad.source.rules;
13
14
import org.eclipse.jface.resource.ColorRegistry;
15
import org.eclipse.jface.text.TextAttribute;
16
import org.eclipse.jface.text.rules.IRule;
17
import org.eclipse.jface.text.rules.IWhitespaceDetector;
18
import org.eclipse.jface.text.rules.IWordDetector;
19
import org.eclipse.jface.text.rules.RuleBasedScanner;
20
import org.eclipse.jface.text.rules.SingleLineRule;
21
import org.eclipse.jface.text.rules.Token;
22
import org.eclipse.jface.text.rules.WhitespaceRule;
23
import org.eclipse.jface.text.rules.WordRule;
24
import org.eclipse.mtj.core.project.midp.DescriptorPropertyDescription;
25
import org.eclipse.mtj.internal.ui.editors.jad.form.JADAttributesRegistry;
26
import org.eclipse.mtj.ui.editors.jad.IJADDescriptorsProvider;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.graphics.RGB;
29
30
/**
31
 * A scanner programmed with a sequence of rules specific to the JAD file.
32
 * 
33
 * @author Diego Madruga Sandin
34
 */
35
public class JadScanner extends RuleBasedScanner {
36
37
	/**
38
	 * Symbolic name for the keyword colors
39
	 */
40
	private static final String KEYWORD_COLOR= "mtj.jad.keyword.color"; //$NON-NLS-1$
41
	/**
42
	 * Symbolic name for value colors
43
	 */
44
    private static final String VALUE_COLOR= "mtj.jad.value.color"; //$NON-NLS-1$
45
46
    
47
    // This is probably not the best way to handle the colors for this scanner
48
    // it will do until the colors are integrated with preferences.
49
    private static final ColorRegistry colorRegistry = new ColorRegistry();
50
    static{
51
    	colorRegistry.put(KEYWORD_COLOR, new RGB(127,0, 85));
52
    	colorRegistry.put(VALUE_COLOR, new RGB(0,0, 0));
53
    }
54
    
55
    /**
56
     * Creates a new Scanner
57
     */
58
    public JadScanner() {
59
60
    	IWordDetector detector = new IWordDetector() {
61
            public boolean isWordPart(char c) {
62
                if (c == ':') {
63
                    return false;
64
                } 
65
                if (c == '-' ){
66
                	return true;
67
                }
68
                return Character.isJavaIdentifierPart(c);
69
            }
70
            public boolean isWordStart(char c) {
71
                return Character.isJavaIdentifierStart(c);
72
            }
73
        };
74
        
75
        final Token keyword = new Token(new TextAttribute(colorRegistry.get(KEYWORD_COLOR), null, SWT.BOLD ));
76
        final Token key = new Token(new TextAttribute(colorRegistry.get(KEYWORD_COLOR), null, SWT.NONE));
77
        
78
        WordRule rule = new WordRule(detector,key);
79
80
//      add tokens for each reserved word 
81
       IJADDescriptorsProvider[] providers = JADAttributesRegistry.getAllJADDescriptorProviders();
82
       for (int i = 0; i < providers.length; i++) {
83
    	   DescriptorPropertyDescription[] descriptions = providers[i].getDescriptorPropertyDescriptions();
84
    	   for (int j = 0; j < descriptions.length; j++) {
85
    		   rule.addWord( descriptions[j].getPropertyName(), keyword);
86
    	   }
87
       }
88
89
		Token string = new Token(new TextAttribute(colorRegistry.get(VALUE_COLOR)));
90
91
		// Rule for Values  
92
		SingleLineRule singleLineRule = new SingleLineRule(":", null, string, '\\'); //$NON-NLS-1$
93
    	// Add generic whitespace rule.
94
        WhitespaceRule whiteSpaceRule = new WhitespaceRule(new IWhitespaceDetector() {
95
            public boolean isWhitespace(char c) {
96
                return Character.isWhitespace(c);
97
            }
98
        });
99
        
100
        setRules(new IRule[] { rule, singleLineRule, whiteSpaceRule });
101
    }
102
}
(-)src/org/eclipse/mtj/internal/ui/editors/jad/form/JADAttributesRegistry.java (-1 / +26 lines)
Lines 21-26 Link Here
21
import org.eclipse.core.runtime.IConfigurationElement;
21
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.Status;
24
import org.eclipse.mtj.core.project.midp.DescriptorPropertyDescription;
25
import org.eclipse.mtj.core.project.midp.DescriptorPropertyDescription;
25
import org.eclipse.mtj.core.sdk.device.midp.IMIDPDevice;
26
import org.eclipse.mtj.core.sdk.device.midp.IMIDPDevice;
26
import org.eclipse.mtj.internal.core.util.log.MTJLogger;
27
import org.eclipse.mtj.internal.core.util.log.MTJLogger;
Lines 106-111 Link Here
106
     */
107
     */
107
    private static Map<String, JADAttributesConfigElement[]> genericPageJADAttrMap = new HashMap<String, JADAttributesConfigElement[]>();
108
    private static Map<String, JADAttributesConfigElement[]> genericPageJADAttrMap = new HashMap<String, JADAttributesConfigElement[]>();
108
109
110
	private static IJADDescriptorsProvider[] JADDescriptorproviders;
111
109
    /**
112
    /**
110
     * @param pageID the target page's ID
113
     * @param pageID the target page's ID
111
     * @param device the device user used
114
     * @param device the device user used
Lines 164-170 Link Here
164
    }
167
    }
165
168
166
    /**
169
    /**
167
     * @return
170
     * Get all the JAD attributes registered. This includes elements that are vendor specific 
171
     * as well as those coming from specifications.
172
     * 
173
     * @return array of JADAttributesConfigElement  
168
     */
174
     */
169
    private static JADAttributesConfigElement[] getAllJADAttributeElements() {
175
    private static JADAttributesConfigElement[] getAllJADAttributeElements() {
170
        if (allJADAttrElements == null) {
176
        if (allJADAttrElements == null) {
Lines 174-179 Link Here
174
        return allJADAttrElements;
180
        return allJADAttrElements;
175
    }
181
    }
176
182
183
    public static IJADDescriptorsProvider[]  getAllJADDescriptorProviders(){
184
    	JADAttributesConfigElement[] configs = getAllJADAttributeElements();
185
    	
186
		if (JADDescriptorproviders == null) {
187
			JADDescriptorproviders = new IJADDescriptorsProvider[configs.length];
188
			try {
189
				for (int i = 0; i < configs.length; i++) {
190
					JADDescriptorproviders[i] = configs[i]
191
							.getJadDescriptorsProvider();
192
				}
193
			} catch (CoreException ex) {
194
				MTJUIPlugin.getDefault().getLog().log(
195
						new Status(IStatus.WARNING, MTJUIPlugin.getPluginId(),
196
								"Unable to read the JAD descriptor", ex)); //$NON-NLS-1$
197
			}
198
		}
199
    	return JADDescriptorproviders;
200
    }
201
    
177
    /**
202
    /**
178
     * @param elements config elements
203
     * @param elements config elements
179
     * @param pageID editor page ID
204
     * @param pageID editor page ID

Return to bug 266131