Index: src/org/eclipse/mtj/internal/ui/editors/jad/form/pages/JADSourceEditorPage.java =================================================================== --- src/org/eclipse/mtj/internal/ui/editors/jad/form/pages/JADSourceEditorPage.java (revision 1380) +++ src/org/eclipse/mtj/internal/ui/editors/jad/form/pages/JADSourceEditorPage.java (working copy) @@ -45,6 +45,10 @@ public JADSourceEditorPage(JADFormEditor editor) { super(); initialize(editor); +// JADConfiguration configuration = SourceViewerConfigurationFactory.createSourceViewerConfiguration(editor, ColorManager.getDefault()); +// if (configuration != null) { +// setSourceViewerConfiguration(configuration); +// } } /* Index: src/org/eclipse/mtj/internal/ui/MTJUIMessages.java =================================================================== --- src/org/eclipse/mtj/internal/ui/MTJUIMessages.java (revision 1380) +++ src/org/eclipse/mtj/internal/ui/MTJUIMessages.java (working copy) @@ -272,6 +272,7 @@ public static String EditorPreferencePage_folding_label; public static String EditorPreferencePage_generalTextEditor_link; public static String EditorPreferencePage_localization_tab_title; + public static String EditorPreferencePage_jad_tab_title; public static String EnableLocalizationAction_dialog_title; public static String ErrorTextWithContinueDialog_continue_label; @@ -830,6 +831,12 @@ public static String XMLSyntaxColorTab_process_label; public static String XMLSyntaxColorTab_tags_label; public static String XMLSyntaxColorTab_text_label; + + public static String JAD_Properties; + public static String JAD_Values; + public static String JAD_UserDefinedKey; + public static String JAD_UserDefinedValue; + public static String JAD_Assignment; public static String buttonBarBlock_button_add; public static String buttonBarBlock_button_remove; @@ -1007,7 +1014,7 @@ public static String NewMidletProjectWizardPageOne_workingSetGroup_selection; public static String NewMidletProjectWizardPageOne_workingSetGroup_select_button; public static String NewMidletProjectWizardPageOne_title; - + public static String NewMidletProjectWizardPageTwo_description; public static String NewMidletProjectWizardPageTwo_propertiesGroup_contents; public static String NewMidletProjectWizardPageTwo_propertiesGroup_midletName; @@ -1056,7 +1063,6 @@ public static String NewMidletProjectWizardPageLibrary_HintTextGroup_title; public static String ConfigurationSection_Description; - static { // initialize resource bundle Index: src/org/eclipse/mtj/internal/ui/preferences/JADSyntaxColorTab.java =================================================================== --- src/org/eclipse/mtj/internal/ui/preferences/JADSyntaxColorTab.java (revision 0) +++ src/org/eclipse/mtj/internal/ui/preferences/JADSyntaxColorTab.java (revision 0) @@ -0,0 +1,67 @@ +package org.eclipse.mtj.internal.ui.preferences; + +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.mtj.internal.ui.MTJUIMessages; +import org.eclipse.mtj.internal.ui.editor.JADConfiguration; +import org.eclipse.mtj.internal.ui.editor.context.JADDocumentSetupParticipant; +import org.eclipse.mtj.internal.ui.editor.text.ChangeAwareSourceViewerConfiguration; +import org.eclipse.mtj.internal.ui.editor.text.IColorManager; +import org.eclipse.mtj.internal.ui.editor.text.IMTJColorConstants; + +public class JADSyntaxColorTab extends SyntaxColorTab { + + private static final String[][] COLOR_STRINGS = new String[][] { + { MTJUIMessages.JAD_Properties, + IMTJColorConstants.P_JAD_PROPERTY }, + { MTJUIMessages.JAD_Values, + IMTJColorConstants.P_JAD_VALUE }, + { MTJUIMessages.JAD_UserDefinedKey, + IMTJColorConstants.P_JAD_USER_KEY }, + { MTJUIMessages.JAD_UserDefinedValue, + IMTJColorConstants.P_JAD_USER_VALUE }, + { MTJUIMessages.JAD_Assignment, + IMTJColorConstants.P_JAD_ASSIGNMENT } }; + + public JADSyntaxColorTab(IColorManager manager) { + super(manager); + } + + protected IDocument getDocument() { + StringBuffer buffer = new StringBuffer(); + String delimiter = System.getProperty("line.separator"); //$NON-NLS-1$ + buffer.append("MIDlet-1: %midlet"); //$NON-NLS-1$ + buffer.append(delimiter); + buffer.append("MIDlet-Jar-URL: %jar"); //$NON-NLS-1$ + buffer.append(delimiter); + buffer.append("MIDlet-Name: %name"); //$NON-NLS-1$ + buffer.append(delimiter); + buffer.append("MIDlet-Version: 1.0.0"); //$NON-NLS-1$ + buffer.append(delimiter); + buffer.append("MicroEdition-Configuration: configuration.example"); //$NON-NLS-1$ + buffer.append(delimiter); + buffer.append("MicroEdition-Profile: profile.example"); //$NON-NLS-1$ + buffer.append(delimiter); + buffer.append("User_New_Key: Value"); //$NON-NLS-1$ + IDocument document = new Document(buffer.toString()); + new JADDocumentSetupParticipant().setup(document); + return document; + } + + /* (non-Javadoc) + * @see org.eclipse.mtj.internal.ui.preferences.SyntaxColorTab#getColorStrings() + */ + @Override + protected String[][] getColorStrings() { + return COLOR_STRINGS; + } + + /* (non-Javadoc) + * @see org.eclipse.mtj.internal.ui.preferences.SyntaxColorTab#getSourceViewerConfiguration() + */ + @Override + protected ChangeAwareSourceViewerConfiguration getSourceViewerConfiguration() { + return new JADConfiguration(fColorManager); + } + +} Index: src/org/eclipse/mtj/internal/ui/preferences/EditorPreferencePage.java =================================================================== --- src/org/eclipse/mtj/internal/ui/preferences/EditorPreferencePage.java (revision 1380) +++ src/org/eclipse/mtj/internal/ui/preferences/EditorPreferencePage.java (working copy) @@ -40,6 +40,7 @@ private ColorManager fColorManager; private XMLSyntaxColorTab fXMLTab; + private JADSyntaxColorTab fJADTab; /** * Create the EditorPreferencePage. @@ -56,6 +57,7 @@ public void dispose() { fColorManager.disposeColors(false); fXMLTab.dispose(); + fJADTab.dispose(); super.dispose(); } @@ -71,6 +73,7 @@ @Override public boolean performOk() { fXMLTab.performOk(); + fJADTab.performOk(); MTJUIPlugin.getDefault().savePluginPreferences(); return super.performOk(); } @@ -80,9 +83,16 @@ */ private void createXMLTab(TabFolder folder) { fXMLTab = new XMLSyntaxColorTab(fColorManager); - TabItem item = new TabItem(folder, SWT.NONE); - item.setText(MTJUIMessages.EditorPreferencePage_localization_tab_title); - item.setControl(fXMLTab.createContents(folder)); + TabItem xmlItem = new TabItem(folder, SWT.NONE); + xmlItem.setText(MTJUIMessages.EditorPreferencePage_localization_tab_title); + xmlItem.setControl(fXMLTab.createContents(folder)); + } + + private void createJADTab(TabFolder folder) { + fJADTab = new JADSyntaxColorTab(fColorManager); + TabItem jadItem = new TabItem(folder, SWT.NONE); + jadItem.setText(MTJUIMessages.EditorPreferencePage_jad_tab_title); + jadItem.setControl(fJADTab.createContents(folder)); } /* (non-Javadoc) @@ -126,6 +136,7 @@ folder.setLayoutData(new GridData(GridData.FILL_BOTH)); createXMLTab(folder); + createJADTab(folder); Dialog.applyDialogFont(getControl()); @@ -138,6 +149,7 @@ @Override protected void performDefaults() { fXMLTab.performDefaults(); + fJADTab.performDefaults(); super.performDefaults(); } } Index: src/org/eclipse/mtj/internal/ui/messages.properties =================================================================== --- src/org/eclipse/mtj/internal/ui/messages.properties (revision 1380) +++ src/org/eclipse/mtj/internal/ui/messages.properties (working copy) @@ -63,6 +63,7 @@ EditorPreferencePage_folding_label=&Enable folding when opening a new editor EditorPreferencePage_generalTextEditor_link=See 'Text Editors' for the general text editor preferences. EditorPreferencePage_localization_tab_title=&Localization Data Highlighting +EditorPreferencePage_jad_tab_title=&JAD Highlighting EnableLocalizationAction_dialog_title=Localization Wizard ErrorTextWithContinueDialog_continue_label=Continue ExceptionHandler_displayMessageDialog_message=See error log for more details. @@ -234,6 +235,11 @@ XMLSyntaxColorTab_process_label=Processing instructions XMLSyntaxColorTab_tags_label=Tags XMLSyntaxColorTab_text_label=Text +JAD_Properties=Properties +JAD_Values=Values +JAD_UserDefinedKey=User keys +JAD_UserDefinedValue=User values +JAD_Assignment=Assignment L10nAddLocaleAction_text=Locale L10nAddLocaleEntryAction_initialKey=key Index: src/org/eclipse/mtj/internal/ui/editor/text/IMTJColorConstants.java =================================================================== --- src/org/eclipse/mtj/internal/ui/editor/text/IMTJColorConstants.java (revision 1380) +++ src/org/eclipse/mtj/internal/ui/editor/text/IMTJColorConstants.java (working copy) @@ -34,5 +34,11 @@ String P_STRING = "editor.color.string"; //$NON-NLS-1$ String P_DEFAULT = "editor.color.default"; //$NON-NLS-1$ String P_TAG = "editor.color.tag"; //$NON-NLS-1$ + + String P_JAD_PROPERTY = "editor.color.jad_properties"; //$NON-NLS-1$ + String P_JAD_VALUE = "editor.color.jad_value"; //$NON-NLS-1$ + String P_JAD_USER_KEY = "editor.color.jad_user_key"; //$NON-NLS-1$ + String P_JAD_USER_VALUE = "editor.color.jad_user_value"; //$NON-NLS-1$ + String P_JAD_ASSIGNMENT = "editor.color.jad_assignment"; //$NON-NLS-1$ -} +} \ No newline at end of file Index: src/org/eclipse/mtj/internal/ui/editor/JADConfiguration.java =================================================================== --- src/org/eclipse/mtj/internal/ui/editor/JADConfiguration.java (revision 0) +++ src/org/eclipse/mtj/internal/ui/editor/JADConfiguration.java (revision 0) @@ -0,0 +1,217 @@ +package org.eclipse.mtj.internal.ui.editor; + +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.quickassist.IQuickAssistAssistant; +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.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.jface.text.source.ISourceViewer; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.mtj.internal.ui.editor.context.JADPartitionScanner; +import org.eclipse.mtj.internal.ui.editor.text.BaseMTJScanner; +import org.eclipse.mtj.internal.ui.editor.text.ChangeAwareSourceViewerConfiguration; +import org.eclipse.mtj.internal.ui.editor.text.IColorManager; +import org.eclipse.mtj.internal.ui.editor.text.IMTJColorConstants; +import org.eclipse.mtj.internal.ui.editor.text.MTJQuickAssistAssistant; + +public class JADConfiguration extends ChangeAwareSourceViewerConfiguration { + + private class JADPropertyScanner extends BaseMTJScanner { + + private Token fJADProperty; + + public JADPropertyScanner() { + super(fColorManager); + } + + @Override + public boolean affectsTextPresentation(String property) { + return property.startsWith(IMTJColorConstants.P_JAD_PROPERTY) + || property.startsWith(IMTJColorConstants.P_JAD_USER_KEY); + } + + @Override + protected Token getTokenAffected(PropertyChangeEvent event) { + if (event.getProperty().startsWith(IMTJColorConstants.P_JAD_PROPERTY)) + return fJADProperty; + return (Token) fDefaultReturnToken; + } + + @Override + protected void initialize() { + fJADProperty = new Token(createTextAttribute(IMTJColorConstants.P_JAD_PROPERTY)); + IRule[] rules = new IRule[7]; + rules[0] = new SingleLineRule("MIDlet-Version", ":", fJADProperty); //$NON-NLS-1$ //$NON-NLS-2$ + rules[1] = new SingleLineRule("MIDlet-Vendor", ":", fJADProperty); //$NON-NLS-1$ //$NON-NLS-2$ + rules[2] = new SingleLineRule("MIDlet-Jar-URL", ":", fJADProperty); //$NON-NLS-1$ //$NON-NLS-2$ + rules[3] = new SingleLineRule("MicroEdition-Configuration", ":", fJADProperty); //$NON-NLS-1$ //$NON-NLS-2$ + rules[4] = new SingleLineRule("MicroEdition-Profile", ":", fJADProperty); //$NON-NLS-1$ //$NON-NLS-2$ + rules[5] = new SingleLineRule("MIDlet-Name", ":", fJADProperty); //$NON-NLS-1$ //$NON-NLS-2$ + rules[6] = new WhitespaceRule(new JADWhiteSpaceDetector()); + + setRules(rules); + setDefaultReturnToken(new Token( + createTextAttribute(IMTJColorConstants.P_JAD_USER_KEY))); + } + } + + private class JADValueScanner extends BaseMTJScanner { + private Token fJADValue; + private Token fJADAssignment; + + public JADValueScanner() { + super(fColorManager); + } + + @Override + public boolean affectsTextPresentation(String property) { + return property.startsWith(IMTJColorConstants.P_JAD_ASSIGNMENT) + || property.startsWith(IMTJColorConstants.P_JAD_VALUE) + || property.startsWith(IMTJColorConstants.P_JAD_USER_VALUE); + } + + @Override + protected Token getTokenAffected(PropertyChangeEvent event) { + if (event.getProperty().startsWith(IMTJColorConstants.P_JAD_ASSIGNMENT)) + return fJADAssignment; + if (event.getProperty().startsWith(IMTJColorConstants.P_JAD_VALUE)) + return fJADValue; + return (Token) fDefaultReturnToken; + } + + @Override + protected void initialize() { + IRule[] rules = new IRule[2]; + fJADAssignment = new Token(createTextAttribute(IMTJColorConstants.P_JAD_ASSIGNMENT)); + rules[0] = new WordRule(new JADAssignmentDetector(), fJADAssignment); + + fJADValue = new Token(createTextAttribute(IMTJColorConstants.P_JAD_VALUE)); +// WordRule rule = new WordRule(new JADKeywordDetector()); +// rule.addWord(Constants.BUNDLE_NATIVECODE_LANGUAGE, fAttributeToken); +// rule.addWord(Constants.BUNDLE_NATIVECODE_OSNAME, fAttributeToken); +// rule.addWord(Constants.BUNDLE_NATIVECODE_OSVERSION, fAttributeToken); +// rule.addWord(Constants.BUNDLE_NATIVECODE_PROCESSOR, fAttributeToken); +// rule.addWord(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE, fAttributeToken); +// rule.addWord(Constants.BUNDLE_VERSION_ATTRIBUTE, fAttributeToken); +// rule.addWord(Constants.EXCLUDE_DIRECTIVE, fAttributeToken); +// rule.addWord(Constants.FRAGMENT_ATTACHMENT_DIRECTIVE, fAttributeToken); +// rule.addWord(Constants.INCLUDE_DIRECTIVE, fAttributeToken); +// rule.addWord(Constants.MANDATORY_DIRECTIVE, fAttributeToken); +// rule.addWord(Constants.RESOLUTION_DIRECTIVE, fAttributeToken); +// rule.addWord(Constants.SINGLETON_DIRECTIVE, fAttributeToken); +// rule.addWord(Constants.USES_DIRECTIVE, fAttributeToken); +// rule.addWord(Constants.VERSION_ATTRIBUTE, fAttributeToken); +// rule.addWord(Constants.VISIBILITY_DIRECTIVE, fAttributeToken); +// rule.addWord(ICoreConstants.FRIENDS_DIRECTIVE, fAttributeToken); +// rule.addWord(ICoreConstants.INTERNAL_DIRECTIVE, fAttributeToken); +// rule.addWord(ICoreConstants.PACKAGE_SPECIFICATION_VERSION, fAttributeToken); + + setRules(rules); + setDefaultReturnToken(new Token( + createTextAttribute(IMTJColorConstants.P_JAD_USER_VALUE))); + } + } + + private class JADWhiteSpaceDetector implements IWhitespaceDetector { + public boolean isWhitespace(char c) { + return (c == ' ' || c == '\t' || c == '\n' || c == '\r'); + } + } + + private class JADAssignmentDetector implements IWordDetector { + public boolean isWordStart(char c) { + return c == ':'; + } + + public boolean isWordPart(char c) { + return false; + } + } + + private class JADKeywordDetector implements IWordDetector { + public boolean isWordStart(char c) { + return Character.isJavaIdentifierStart(c); + } + + public boolean isWordPart(char c) { + return c != ':' && !Character.isSpaceChar(c); + } + } + + private MTJQuickAssistAssistant fQuickAssistant; + private JADPropertyScanner fPropertyScanner; + private JADValueScanner fValueScanner; + + + public JADConfiguration(IColorManager colorManager, MTJSourcePage page) { + super(page, colorManager); + fPropertyScanner = new JADPropertyScanner(); + fValueScanner = new JADValueScanner(); + } + + public JADConfiguration(IColorManager colorManager) { + this(colorManager, null); + } + + @Override + public void adaptToPreferenceChange(PropertyChangeEvent event) { + if(affectsColorPresentation(event)) { + fColorManager.handlePropertyChangeEvent(event); + } + fPropertyScanner.adaptToPreferenceChange(event); + fValueScanner.adaptToPreferenceChange(event); + } + + @Override + public boolean affectsColorPresentation(PropertyChangeEvent event) { + String property = event.getProperty(); + return property.equals(IMTJColorConstants.P_JAD_ASSIGNMENT) + || property.equals(IMTJColorConstants.P_JAD_PROPERTY) + || property.equals(IMTJColorConstants.P_JAD_USER_KEY) + || property.equals(IMTJColorConstants.P_JAD_USER_VALUE) + || property.equals(IMTJColorConstants.P_JAD_VALUE); + } + + @Override + public boolean affectsTextPresentation(PropertyChangeEvent event) { + String property = event.getProperty(); + return property.startsWith(IMTJColorConstants.P_JAD_ASSIGNMENT) + || property.startsWith(IMTJColorConstants.P_JAD_PROPERTY) + || property.startsWith(IMTJColorConstants.P_JAD_USER_KEY) + || property.startsWith(IMTJColorConstants.P_JAD_USER_VALUE) + || property.startsWith(IMTJColorConstants.P_JAD_VALUE); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getConfiguredContentTypes(org.eclipse.jface.text.source.ISourceViewer) + */ + @Override + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + return new String[] { IDocument.DEFAULT_CONTENT_TYPE, + JADPartitionScanner.JAD_HEADER }; + } + + @Override + public void dispose() { + if (fQuickAssistant != null) { + fQuickAssistant.dispose(); + } + } + + @Override + public IQuickAssistAssistant getQuickAssistAssistant( + ISourceViewer sourceViewer) { + if (sourceViewer.isEditable()) { + if (fQuickAssistant == null) { + fQuickAssistant = new MTJQuickAssistAssistant(); + } + return fQuickAssistant; + } + return null; + } + +} Index: src/org/eclipse/mtj/internal/ui/editor/context/JADPartitionScanner.java =================================================================== --- src/org/eclipse/mtj/internal/ui/editor/context/JADPartitionScanner.java (revision 0) +++ src/org/eclipse/mtj/internal/ui/editor/context/JADPartitionScanner.java (revision 0) @@ -0,0 +1,19 @@ +package org.eclipse.mtj.internal.ui.editor.context; + +import org.eclipse.jface.text.rules.IPredicateRule; +import org.eclipse.jface.text.rules.RuleBasedPartitionScanner; +import org.eclipse.jface.text.rules.SingleLineRule; +import org.eclipse.jface.text.rules.Token; + +public class JADPartitionScanner extends RuleBasedPartitionScanner { + + public static final String JAD_HEADER = "__mf_jad_header_value"; //$NON-NLS-1$ + + public static final String[] PARTITIONS = new String[] {JAD_HEADER}; + + public JADPartitionScanner() { + IPredicateRule[] rules = new IPredicateRule[1]; + rules[0] = new SingleLineRule(":", null, new Token(JAD_HEADER), '\\', true, true); //$NON-NLS-1$ + setPredicateRules(rules); + } +} Index: src/org/eclipse/mtj/internal/ui/editor/context/JADDocumentSetupParticipant.java =================================================================== --- src/org/eclipse/mtj/internal/ui/editor/context/JADDocumentSetupParticipant.java (revision 0) +++ src/org/eclipse/mtj/internal/ui/editor/context/JADDocumentSetupParticipant.java (revision 0) @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2005,2008 IBM Corporation and others. + * + * 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: + * IBM Corporation - initial API and implementation + * Diego Sandin (Motorola) - Adapted code from org.eclipse.pde.ui + */ +package org.eclipse.mtj.internal.ui.editor.context; + +import org.eclipse.core.filebuffers.IDocumentSetupParticipant; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentPartitioner; +import org.eclipse.jface.text.rules.FastPartitioner; + +/** + * @since 0.9.1 + */ +public class JADDocumentSetupParticipant implements IDocumentSetupParticipant { + + public static final String JAD_PARTITIONING = "_mtj_jad_partitioning"; //$NON-NLS-1$ + + /* (non-Javadoc) + * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument) + */ + public void setup(IDocument document) { + IDocumentPartitioner partitioner = createDocumentPartitioner(); + if (partitioner != null) { + partitioner.connect(document); + document.setDocumentPartitioner(partitioner); + } + } + + /** + * @return + */ + private IDocumentPartitioner createDocumentPartitioner() { + return new FastPartitioner(new JADPartitionScanner(), + JADPartitionScanner.PARTITIONS); + } + +} Index: src/org/eclipse/mtj/internal/ui/editor/SourceViewerConfigurationFactory.java =================================================================== --- src/org/eclipse/mtj/internal/ui/editor/SourceViewerConfigurationFactory.java (revision 1380) +++ src/org/eclipse/mtj/internal/ui/editor/SourceViewerConfigurationFactory.java (working copy) @@ -25,6 +25,10 @@ if (sourcePage instanceof L10nSourcePage) { return new XMLConfiguration(colorManager, sourcePage); } + + if (sourcePage instanceof /*TODO*/Object) { + return new JADConfiguration(colorManager, sourcePage); + } return null; }