Index: src/org/eclipse/mtj/internal/ui/editors/jad/source/JADSourceViewerConfiguration.java =================================================================== --- src/org/eclipse/mtj/internal/ui/editors/jad/source/JADSourceViewerConfiguration.java (revision 1116) +++ src/org/eclipse/mtj/internal/ui/editors/jad/source/JADSourceViewerConfiguration.java (working copy) @@ -22,7 +22,7 @@ import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.mtj.internal.ui.editors.jad.source.contentassist.CompletionProcessor; -import org.eclipse.mtj.internal.ui.editors.jad.source.rules.Scanner; +import org.eclipse.mtj.internal.ui.editors.jad.source.rules.JadScanner; /** * This class bundles the configuration space of {@link JADSourceEditor} @@ -64,9 +64,10 @@ ISourceViewer sourceViewer) { PresentationReconciler pr = new PresentationReconciler(); - DefaultDamagerRepairer ddr = new DefaultDamagerRepairer(new Scanner()); + DefaultDamagerRepairer ddr = new DefaultDamagerRepairer(new JadScanner()); pr.setRepairer(ddr, IDocument.DEFAULT_CONTENT_TYPE); pr.setDamager(ddr, IDocument.DEFAULT_CONTENT_TYPE); + return pr; } } Index: src/org/eclipse/mtj/internal/ui/editors/jad/source/rules/JadScanner.java =================================================================== --- src/org/eclipse/mtj/internal/ui/editors/jad/source/rules/JadScanner.java (revision 0) +++ src/org/eclipse/mtj/internal/ui/editors/jad/source/rules/JadScanner.java (revision 0) @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2008 Motorola. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Diego Sandin (Motorola) - Initial implementation + */ +package org.eclipse.mtj.internal.ui.editors.jad.source.rules; + +import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.rules.IRule; +import org.eclipse.jface.text.rules.IWhitespaceDetector; +import org.eclipse.jface.text.rules.IWordDetector; +import org.eclipse.jface.text.rules.RuleBasedScanner; +import org.eclipse.jface.text.rules.SingleLineRule; +import org.eclipse.jface.text.rules.Token; +import org.eclipse.jface.text.rules.WhitespaceRule; +import org.eclipse.jface.text.rules.WordRule; +import org.eclipse.mtj.core.project.midp.DescriptorPropertyDescription; +import org.eclipse.mtj.internal.ui.editors.jad.form.JADAttributesRegistry; +import org.eclipse.mtj.ui.editors.jad.IJADDescriptorsProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.RGB; + +/** + * A scanner programmed with a sequence of rules specific to the JAD file. + * + * @author Diego Madruga Sandin + */ +public class JadScanner extends RuleBasedScanner { + + /** + * Symbolic name for the keyword colors + */ + private static final String KEYWORD_COLOR= "mtj.jad.keyword.color"; //$NON-NLS-1$ + /** + * Symbolic name for value colors + */ + private static final String VALUE_COLOR= "mtj.jad.value.color"; //$NON-NLS-1$ + + + // This is probably not the best way to handle the colors for this scanner + // it will do until the colors are integrated with preferences. + private static final ColorRegistry colorRegistry = new ColorRegistry(); + static{ + colorRegistry.put(KEYWORD_COLOR, new RGB(127,0, 85)); + colorRegistry.put(VALUE_COLOR, new RGB(0,0, 0)); + } + + /** + * Creates a new Scanner + */ + public JadScanner() { + + IWordDetector detector = new IWordDetector() { + public boolean isWordPart(char c) { + if (c == ':') { + return false; + } + if (c == '-' ){ + return true; + } + return Character.isJavaIdentifierPart(c); + } + public boolean isWordStart(char c) { + return Character.isJavaIdentifierStart(c); + } + }; + + final Token keyword = new Token(new TextAttribute(colorRegistry.get(KEYWORD_COLOR), null, SWT.BOLD )); + final Token key = new Token(new TextAttribute(colorRegistry.get(KEYWORD_COLOR), null, SWT.NONE)); + + WordRule rule = new WordRule(detector,key); + +// add tokens for each reserved word + IJADDescriptorsProvider[] providers = JADAttributesRegistry.getAllJADDescriptorProviders(); + for (int i = 0; i < providers.length; i++) { + DescriptorPropertyDescription[] descriptions = providers[i].getDescriptorPropertyDescriptions(); + for (int j = 0; j < descriptions.length; j++) { + rule.addWord( descriptions[j].getPropertyName(), keyword); + } + } + + Token string = new Token(new TextAttribute(colorRegistry.get(VALUE_COLOR))); + + // Rule for Values + SingleLineRule singleLineRule = new SingleLineRule(":", null, string, '\\'); //$NON-NLS-1$ + // Add generic whitespace rule. + WhitespaceRule whiteSpaceRule = new WhitespaceRule(new IWhitespaceDetector() { + public boolean isWhitespace(char c) { + return Character.isWhitespace(c); + } + }); + + setRules(new IRule[] { rule, singleLineRule, whiteSpaceRule }); + } +} Index: src/org/eclipse/mtj/internal/ui/editors/jad/form/JADAttributesRegistry.java =================================================================== --- src/org/eclipse/mtj/internal/ui/editors/jad/form/JADAttributesRegistry.java (revision 1116) +++ src/org/eclipse/mtj/internal/ui/editors/jad/form/JADAttributesRegistry.java (working copy) @@ -21,6 +21,7 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.mtj.core.project.midp.DescriptorPropertyDescription; import org.eclipse.mtj.core.sdk.device.midp.IMIDPDevice; import org.eclipse.mtj.internal.core.util.log.MTJLogger; @@ -106,6 +107,8 @@ */ private static Map genericPageJADAttrMap = new HashMap(); + private static IJADDescriptorsProvider[] JADDescriptorproviders; + /** * @param pageID the target page's ID * @param device the device user used @@ -164,7 +167,10 @@ } /** - * @return + * Get all the JAD attributes registered. This includes elements that are vendor specific + * as well as those coming from specifications. + * + * @return array of JADAttributesConfigElement */ private static JADAttributesConfigElement[] getAllJADAttributeElements() { if (allJADAttrElements == null) { @@ -174,6 +180,25 @@ return allJADAttrElements; } + public static IJADDescriptorsProvider[] getAllJADDescriptorProviders(){ + JADAttributesConfigElement[] configs = getAllJADAttributeElements(); + + if (JADDescriptorproviders == null) { + JADDescriptorproviders = new IJADDescriptorsProvider[configs.length]; + try { + for (int i = 0; i < configs.length; i++) { + JADDescriptorproviders[i] = configs[i] + .getJadDescriptorsProvider(); + } + } catch (CoreException ex) { + MTJUIPlugin.getDefault().getLog().log( + new Status(IStatus.WARNING, MTJUIPlugin.getPluginId(), + "Unable to read the JAD descriptor", ex)); //$NON-NLS-1$ + } + } + return JADDescriptorproviders; + } + /** * @param elements config elements * @param pageID editor page ID