diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences')
9 files changed, 0 insertions, 2732 deletions
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/EncodingSettings.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/EncodingSettings.java deleted file mode 100644 index e2bbd570e4..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/EncodingSettings.java +++ /dev/null @@ -1,359 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import java.util.Vector; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.wst.sse.core.internal.encoding.CommonCharsetNames; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * EncodingSettings is a composite that can be used to display the set of - * encoding values that are available to the user. The list of encoding values - * is based off the SupportedJavaEncoding class. As the user selects an - * encoding from the combo box, the readonly field below it changes to show - * the IANA tag for that particular encoding description. The labels for the - * widgets are configurable and the initial value to display to the user can - * be set using the setIANATag(). The currently selected entry's IANA tag can - * be retrieved with getIANATag(). Entries displayed to the user can be added - * and removed. - */ -public class EncodingSettings extends Composite { - - private class ComboListener implements ModifyListener { - public void modifyText(ModifyEvent e) { - int i = encodingCombo.getSelectionIndex(); - if ((i >= 0) && (i < ianaVector.size())) { - ianaText.setText((String) (ianaVector.elementAt(encodingCombo.getSelectionIndex()))); - } - } - } - - private static String ENCODING_LABEL = XMLUIMessages.EncodingSettings_1; - - private static String IANA_LABEL = XMLUIMessages.EncodingSettings_0; - - private ModifyListener comboListener = new ComboListener(); - protected Combo encodingCombo; - protected Label encodingLabel, ianaLabel; - protected Text ianaText; - protected Vector ianaVector; - - /** - * Method EncodingSettings. - * - * @param parent - */ - public EncodingSettings(Composite parent) { - super(parent, SWT.NONE); - init(IANA_LABEL, ENCODING_LABEL); - } - - /** - * Method EncodingSettings. - * - * @param parent - * @param encodingLabel - - * text label to use beside the locale sensitive description of - * the currently selected encoding - */ - public EncodingSettings(Composite parent, String encodingLabel) { - super(parent, SWT.NONE); - init(IANA_LABEL, encodingLabel); - } - - /** - * Method EncodingSettings. - * - * @param parent - * @param ianaLabel = - * text label to use beside the display only IANA field - * @param encodingLabel - - * text label to use beside the locale sensitive description of - * the currently selected encoding - */ - public EncodingSettings(Composite parent, String ianaLabel, String encodingLabel) { - super(parent, SWT.NONE); - init(ianaLabel, encodingLabel); - } - - /** - * Method addEntry. Add an entry to the end of the Encoding Combobox - * - * @param description - - * encoding description to display - * @param ianaTag - - * IANA tag for the description - */ - public void addEntry(String description, String ianaTag) { - encodingCombo.add(description); - ianaVector.add(ianaTag); - } - - /** - * Method addEntry. Add an entry to the Encoding Combobox at index index - * - * @param description - - * encoding description to display - * @param ianaTag - - * IANA tag for the description - * @param index - - * index into the combo to add to - */ - public void addEntry(String description, String ianaTag, int index) { - if (index == ianaVector.size()) { - // just add to the end - addEntry(description, ianaTag); - return; - } - - if ((0 <= index) && (index < ianaVector.size())) { - encodingCombo.add(description, index); - ianaVector.add(index, ianaTag); - } - } - - protected Combo createComboBox(Composite parent, boolean isReadOnly) { - int style = isReadOnly == true ? SWT.READ_ONLY : SWT.DROP_DOWN; - - Combo combo = new Combo(parent, style); - - GridData data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - combo.setLayoutData(data); - return combo; - } - - /** - * Helper method for creating labels. - */ - protected Label createLabel(Composite parent, String text) { - Label label = new Label(parent, SWT.LEFT); - label.setText(text); - - GridData data = new GridData(); - data.horizontalAlignment = GridData.FILL; - label.setLayoutData(data); - return label; - } - - protected Text createTextField(Composite parent, int width) { - Text text = new Text(parent, SWT.SINGLE | SWT.READ_ONLY); - - GridData data = new GridData(); - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - data.widthHint = width; - text.setLayoutData(data); - - return text; - } - - /** - * @see org.eclipse.swt.widgets.Widget#dispose() - */ - public void dispose() { - encodingCombo.removeModifyListener(comboListener); - super.dispose(); - } - - private void fillCombo() { - try { - String[] ianaTags = CommonCharsetNames.getCommonCharsetNames(); - int totalNum = ianaTags.length; - for (int i = 0; i < totalNum; i++) { - String iana = ianaTags[i]; - String enc = CommonCharsetNames.getDisplayString(iana); - - if (enc != null) { - encodingCombo.add(enc); - } - else { - Logger.log(Logger.WARNING, "CommonCharsetNames.getDisplayString(" + iana + ") returned null"); //$NON-NLS-1$ //$NON-NLS-2$ - encodingCombo.add(iana); - } - ianaVector.add(iana); - } - } - catch (Exception e) { - // e.printStackTrace(); - // MessageDialog.openError(getShell(), "Resource exception", - // "Unable to obtain encoding strings. Check resource file"); - // XMLEncodingPlugin.getPlugin().getMsgLogger().write(e.toString()); - // XMLEncodingPlugin.getPlugin().getMsgLogger().writeCurrentThread(); - Logger.log(Logger.ERROR, "Exception", e); //$NON-NLS-1$ - } - } - - /** - * <code>getEncoding</code> Get the descriptive encoding name that was - * selected. - * - * @return a <code>String</code> value - */ - public String getEncoding() { - return encodingCombo.getText(); - } - - /** - * Method getEncodingCombo. Returns the combo used to display the encoding - * descriptions. - * - * @return Combo - */ - public Combo getEncodingCombo() { - return encodingCombo; - } - - /** - * <code>getIANATag</code> Get the IANA tag equivalent of the selected - * descriptive encoding name - * - * @return a <code>String</code> value - */ - public String getIANATag() { - int i = encodingCombo.getSelectionIndex(); - if (i >= 0) { - return (String) (ianaVector.elementAt(i)); - } - return ""; //$NON-NLS-1$ - } - - protected void init(String ianaLabelStr, String encodingLabelStr) { - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - setLayout(layout); - GridData data = new GridData(); - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - setLayoutData(data); - - encodingLabel = createLabel(this, encodingLabelStr); - encodingCombo = createComboBox(this, true); - ianaLabel = createLabel(this, ianaLabelStr); - ianaText = createTextField(this, 20); - ianaVector = new Vector(); - - fillCombo(); - resetToDefaultEncoding(); - encodingCombo.addModifyListener(comboListener); - } - - /** - * <code>isEncodingInList</code> Checks whether the encoding name is in - * the combo - * - * @param enc - * a <code>string</code> value. The encoding name. - * @return a <code>boolean</code> value. TRUE if encoding is in list. - * FALSE if encoding is not in list. - */ - public boolean isEncodingInList(String enc) { - int i = encodingCombo.indexOf(enc); - if (i >= 0) { - return true; - } - return false; - } - - /** - * <code>isIANATagInList</code> Checks whether the IANA tag is in the - * combo - * - * @param ianaTag - * a <code>string</code> value. The IANA tag. - * @return a <code>boolean</code> value. TRUE if tag is in list. FALSE - * if tag is not in list. - */ - public boolean isIANATagInList(String ianaTag) { - int i = ianaVector.indexOf(ianaTag); - if (i >= 0) { - return true; - } - return false; - } - - /** - * Method removeEntry. Removes both the description and the IANA tag at - * the specified index - * - * @param index - */ - public void removeEntry(int index) { - if ((0 <= index) && (index < ianaVector.size())) { - encodingCombo.remove(index); - ianaVector.remove(index); - } - } - - /** - * Method resetToDefaultEncoding. Reset the control to the default - * encoding. Currently UTF-8 - */ - public void resetToDefaultEncoding() { - String defaultIANATag = "UTF-8"; //$NON-NLS-1$ - ianaText.setText(defaultIANATag); - setIANATag(defaultIANATag); - } - - /** - * Method setEnabled. Enable/disable the EncodingSettings composite. - * - * @param enabled - */ - public void setEnabled(boolean enabled) { - encodingCombo.setEnabled(enabled); - encodingLabel.setEnabled(enabled); - ianaLabel.setEnabled(enabled); - ianaText.setEnabled(enabled); - } - - /** - * <code>setEncoding</code> Set the selection in the combo to the - * descriptive encoding name. - * - * @param enc - * a <code>string</code> value. Note this is not the IANA - * tag. - */ - public void setEncoding(String enc) { - encodingCombo.setText(enc); - encodingCombo.select(encodingCombo.indexOf(enc)); - } - - /** - * <code>setIANATag</code> Set the IANA tag for the combo - * - * @param ianaTag - * a <code>string</code> value. The IANA tag. - */ - public void setIANATag(String ianaTag) { - int i = ianaVector.indexOf(ianaTag); - if (i >= 0) { - encodingCombo.select(i); - } - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/WorkbenchDefaultEncodingSettings.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/WorkbenchDefaultEncodingSettings.java deleted file mode 100644 index e7930edb9e..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/WorkbenchDefaultEncodingSettings.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.wst.sse.core.internal.encoding.CommonCharsetNames; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; - -/** - * WorkbenchDefaultEncodingSettings is an extension of EncodingSettings. This - * composite contains EncodingSettings for users to select the encoding they - * desire as well as a checkbox for users to select to use the default - * workbench encoding instead. - * - * @see org.eclipse.wst.xml.ui.internal.preferences.EncodingSettings - */ -public class WorkbenchDefaultEncodingSettings extends Composite { - - private final static int INDENT = 15; - private static final String WORKBENCH_DEFAULT = ""; //$NON-NLS-1$ - private EncodingSettings fEncodingSettings; - private String fNonDefaultIANA = null; - private Button fUseDefaultButton; - - public WorkbenchDefaultEncodingSettings(Composite parent) { - super(parent, SWT.NONE); - createControls(); - } - - private void createControls() { - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - layout.marginWidth = 0; - setLayout(layout); - GridData data = new GridData(); - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - data.grabExcessHorizontalSpace = true; - setLayoutData(data); - - Composite defaultEncodingComposite = new Composite(this, SWT.NONE); - layout = new GridLayout(); - layout.marginWidth = 0; - layout.marginHeight = 0; - data = new GridData(GridData.FILL_BOTH); - defaultEncodingComposite.setLayout(layout); - defaultEncodingComposite.setLayoutData(data); - - fUseDefaultButton = new Button(defaultEncodingComposite, SWT.CHECK); - fUseDefaultButton.setText(XMLUIMessages.WorkbenchDefaultEncodingSettings_0); - - fUseDefaultButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - handleUseDefaultButtonSelected(); - } - }); - - fEncodingSettings = new EncodingSettings(this); - ((GridLayout) fEncodingSettings.getLayout()).marginWidth = 0; - ((GridData) fEncodingSettings.getLayoutData()).horizontalIndent = INDENT; - - } - - private Combo getEncodingCombo() { - return fEncodingSettings.getEncodingCombo(); - } - - /** - * <code>getIANATag</code> Get the IANA tag equivalent of the selected - * descriptive encoding name. Returns empty string if using workbench - * encoding. - * - * @return a <code>String</code> value - */ - public String getIANATag() { - if (!isDefault()) { - return fEncodingSettings.getIANATag(); - } - return WORKBENCH_DEFAULT; - } - - private String getWorkbenchEncoding() { - return ResourcesPlugin.getEncoding(); - } - - void handleUseDefaultButtonSelected() { - if (fUseDefaultButton.getSelection()) { - fNonDefaultIANA = fEncodingSettings.getIANATag(); - String workbenchValue = getWorkbenchEncoding(); - workbenchValue = CommonCharsetNames.getIanaPreferredCharsetName(workbenchValue); - fEncodingSettings.setIANATag(workbenchValue); - } - else if (fNonDefaultIANA != null) { - fEncodingSettings.setIANATag(fNonDefaultIANA); - } - getEncodingCombo().setEnabled(!fUseDefaultButton.getSelection()); - fEncodingSettings.setEnabled(!fUseDefaultButton.getSelection()); - } - - private boolean isDefault() { - return fUseDefaultButton.getSelection(); - } - - /** - * <code>setEncoding</code> Set the selection in the combo to the - * descriptive encoding name. Selects use workbench encoding if ianaTag is - * null or empty string. - * - */ - public void setIANATag(String ianaTag) { - if ((ianaTag == null) || ianaTag.equals(WORKBENCH_DEFAULT)) { - fUseDefaultButton.setSelection(true); - handleUseDefaultButtonSelected(); - } - else { - fUseDefaultButton.setSelection(false); - handleUseDefaultButtonSelected(); - if (!isDefault()) { - fEncodingSettings.setIANATag(ianaTag); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLColorPage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLColorPage.java deleted file mode 100644 index 4f29d750f1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLColorPage.java +++ /dev/null @@ -1,288 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * Benjamin Muskalla, b.muskalla@gmx.net - [158660] character entities should have their own syntax highlighting preference - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import java.util.ArrayList; -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.Iterator; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IModelManager; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore; -import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore.OverlayKey; -import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractColorPage; -import org.eclipse.wst.sse.ui.internal.preferences.ui.StyledTextColorPicker; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; -import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; - -/** - * @deprecated - */ -public class XMLColorPage extends AbstractColorPage { - - protected Control createContents(Composite parent) { - Composite pageComponent = createComposite(parent, 1); - ((GridData) pageComponent.getLayoutData()).horizontalAlignment = GridData.HORIZONTAL_ALIGN_FILL; - - super.createContents(pageComponent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.XML_PREFWEBX_STYLES_HELPID); - return pageComponent; - } - - /** - * Set up all the style preference keys in the overlay store - */ - protected OverlayKey[] createOverlayStoreKeys() { - ArrayList overlayKeys = new ArrayList(); - - ArrayList styleList = new ArrayList(); - initStyleList(styleList); - Iterator i = styleList.iterator(); - while (i.hasNext()) { - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, (String) i.next())); - } - - OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; - overlayKeys.toArray(keys); - return keys; - } - - protected IPreferenceStore doGetPreferenceStore() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } - - public String getSampleText() { - return XMLUIMessages.Sample_XML_doc; // = "<?xml - // version=\"1.0\"?>\n<?customProcessingInstruction\n\tXML - // processor - // specific\n\tcontent - // ?>\n<!DOCTYPE - // colors\n\tPUBLIC - // \"//IBM/XML/COLORS/\" - // \"colors.dtd\">\n<colors>\n\t<!-- - // begin color definitions - // -->\n\t<color - // name=\"plaintext\" - // foreground=\"#000000\"\n\t\tbackground=\"#D4D0C8\"/>\n\t<color - // name=\"bold\" - // foreground=\"#000000\"\n\t\tbackground=\"#B3ACA0\">\n\t<![CDATA[<123456789>]]>\n\tNormal - // text content.\n\t<color - // name=\"inverse\" - // foreground=\"#F0F0F0\"\n\t\tbackground=\"#D4D0C8\"/>\n\n</colors>\n"; - } - - protected void initCommonContextStyleMap(Dictionary contextStyleMap) { - - contextStyleMap.put(DOMRegionContext.XML_COMMENT_OPEN, IStyleConstantsXML.COMMENT_BORDER); - contextStyleMap.put(DOMRegionContext.XML_COMMENT_TEXT, IStyleConstantsXML.COMMENT_TEXT); - contextStyleMap.put(DOMRegionContext.XML_COMMENT_CLOSE, IStyleConstantsXML.COMMENT_BORDER); - - contextStyleMap.put(DOMRegionContext.XML_TAG_OPEN, IStyleConstantsXML.TAG_BORDER); - contextStyleMap.put(DOMRegionContext.XML_END_TAG_OPEN, IStyleConstantsXML.TAG_BORDER); - contextStyleMap.put(DOMRegionContext.XML_TAG_NAME, IStyleConstantsXML.TAG_NAME); - contextStyleMap.put(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - contextStyleMap.put(DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - contextStyleMap.put(DOMRegionContext.XML_TAG_CLOSE, IStyleConstantsXML.TAG_BORDER); - contextStyleMap.put(DOMRegionContext.XML_EMPTY_TAG_CLOSE, IStyleConstantsXML.TAG_BORDER); - - contextStyleMap.put(DOMRegionContext.XML_DECLARATION_OPEN, IStyleConstantsXML.DECL_BORDER); - contextStyleMap.put(DOMRegionContext.XML_DECLARATION_CLOSE, IStyleConstantsXML.DECL_BORDER); - contextStyleMap.put(DOMRegionContext.XML_ELEMENT_DECLARATION, IStyleConstantsXML.DECL_BORDER); - contextStyleMap.put(DOMRegionContext.XML_ELEMENT_DECL_CLOSE, IStyleConstantsXML.DECL_BORDER); - - contextStyleMap.put(DOMRegionContext.XML_CHAR_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - contextStyleMap.put(DOMRegionContext.XML_ENTITY_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - contextStyleMap.put(DOMRegionContext.XML_PE_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - - contextStyleMap.put(DOMRegionContext.XML_CONTENT, IStyleConstantsXML.XML_CONTENT); - } - - protected void initCommonDescriptions(Dictionary descriptions) { - - // create descriptions for hilighting types - descriptions.put(IStyleConstantsXML.COMMENT_BORDER, XMLUIMessages.Comment_Delimiters_UI_); // = - // "Comment - // Delimiters" - descriptions.put(IStyleConstantsXML.COMMENT_TEXT, XMLUIMessages.Comment_Content_UI_); // = - // "Comment - // Content" - descriptions.put(IStyleConstantsXML.TAG_BORDER, XMLUIMessages.Tag_Delimiters_UI_); // = - // "Tag - // Delimiters" - descriptions.put(IStyleConstantsXML.TAG_NAME, XMLUIMessages.Tag_Names_UI_); // = - // "Tag - // Names" - descriptions.put(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, XMLUIMessages.Attribute_Names_UI_); // = - // "Attribute - // Names" - descriptions.put(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, XMLUIMessages.Attribute_Values_UI_); // = - // "Attribute - // Values" - descriptions.put(IStyleConstantsXML.DECL_BORDER, XMLUIMessages.Declaration_Delimiters_UI_); // = - // "Declaration - // Delimiters" - descriptions.put(IStyleConstantsXML.XML_CONTENT, XMLUIMessages.Content_UI_); // = - // "Content" - descriptions.put(IStyleConstantsXML.ENTITY_REFERENCE, XMLUIMessages.Entity_Reference_UI_); //$NON-NLS-1$ = "Entity References" - } - - protected void initCommonStyleList(ArrayList list) { - - // list.add(IStyleConstantsXML.CDATA_BORDER); - // list.add(IStyleConstantsXML.CDATA_TEXT); - // list.add(IStyleConstantsXML.PI_BORDER); - // list.add(IStyleConstantsXML.PI_CONTENT); - - list.add(IStyleConstantsXML.TAG_BORDER); - list.add(IStyleConstantsXML.TAG_NAME); - list.add(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - list.add(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - list.add(IStyleConstantsXML.COMMENT_BORDER); - list.add(IStyleConstantsXML.COMMENT_TEXT); - list.add(IStyleConstantsXML.DECL_BORDER); - list.add(IStyleConstantsXML.XML_CONTENT); - list.add(IStyleConstantsXML.ENTITY_REFERENCE); - } - - protected void initContextStyleMap(Dictionary contextStyleMap) { - - initCommonContextStyleMap(contextStyleMap); - initDocTypeContextStyleMap(contextStyleMap); - contextStyleMap.put(DOMRegionContext.XML_CDATA_OPEN, IStyleConstantsXML.CDATA_BORDER); - contextStyleMap.put(DOMRegionContext.XML_CDATA_TEXT, IStyleConstantsXML.CDATA_TEXT); - contextStyleMap.put(DOMRegionContext.XML_CDATA_CLOSE, IStyleConstantsXML.CDATA_BORDER); - - contextStyleMap.put(DOMRegionContext.XML_PI_OPEN, IStyleConstantsXML.PI_BORDER); - contextStyleMap.put(DOMRegionContext.XML_PI_CONTENT, IStyleConstantsXML.PI_CONTENT); - contextStyleMap.put(DOMRegionContext.XML_PI_CLOSE, IStyleConstantsXML.PI_BORDER); - - } - - protected void initDescriptions(Dictionary descriptions) { - - initCommonDescriptions(descriptions); - initDocTypeDescriptions(descriptions); - descriptions.put(IStyleConstantsXML.CDATA_BORDER, XMLUIMessages.CDATA_Delimiters_UI_); // = - // "CDATA - // Delimiters" - descriptions.put(IStyleConstantsXML.CDATA_TEXT, XMLUIMessages.CDATA_Content_UI_); // = - // "CDATA - // Content" - descriptions.put(IStyleConstantsXML.PI_BORDER, XMLUIMessages.Processing_Instruction_Del_UI_); // = - // "Processing - // Instruction - // Delimiters" - descriptions.put(IStyleConstantsXML.PI_CONTENT, XMLUIMessages.Processing_Instruction_Con_UI__UI_); // = - // "Processing - // Instruction - // Content" - } - - protected void initDocTypeContextStyleMap(Dictionary contextStyleMap) { - - contextStyleMap.put(DOMRegionContext.XML_ELEMENT_DECL_NAME, IStyleConstantsXML.DOCTYPE_NAME); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_DECLARATION, IStyleConstantsXML.TAG_NAME); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_DECLARATION_CLOSE, IStyleConstantsXML.DECL_BORDER); - - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_NAME, IStyleConstantsXML.DOCTYPE_NAME); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBLIC, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBREF, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSTEM, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - contextStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSREF, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - } - - protected void initDocTypeDescriptions(Dictionary descriptions) { - - // create descriptions for hilighting types for DOCTYPE related items - descriptions.put(IStyleConstantsXML.DOCTYPE_NAME, XMLUIMessages.DOCTYPE_Name_UI_); // = - // "DOCTYPE - // Name" - descriptions.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID, XMLUIMessages.DOCTYPE_SYSTEM_PUBLIC_Keyw_UI_); // = - // "DOCTYPE - // SYSTEM/PUBLIC - // Keyword" - descriptions.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF, XMLUIMessages.DOCTYPE_Public_Reference_UI_); // = - // "DOCTYPE - // Public - // Reference" - descriptions.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF, XMLUIMessages.DOCTYPE_System_Reference_UI_); // = - // "DOCTYPE - // System - // Reference" - } - - protected void initDocTypeStyleList(ArrayList list) { - - list.add(IStyleConstantsXML.DOCTYPE_NAME); - list.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - list.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - list.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - } - - protected void initStyleList(ArrayList list) { - initCommonStyleList(list); - initDocTypeStyleList(list); - list.add(IStyleConstantsXML.CDATA_BORDER); - list.add(IStyleConstantsXML.CDATA_TEXT); - list.add(IStyleConstantsXML.PI_BORDER); - list.add(IStyleConstantsXML.PI_CONTENT); - } - - public boolean performOk() { - // required since the superclass *removes* existing preferences before - // saving its own - super.performOk(); - - SSEUIPlugin.getDefault().savePluginPreferences(); - return true; - } - - protected void setupPicker(StyledTextColorPicker picker) { - IModelManager mmanager = StructuredModelManager.getModelManager(); - picker.setParser(mmanager.createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML).getParser()); - - Dictionary descriptions = new Hashtable(); - initDescriptions(descriptions); - - Dictionary contextStyleMap = new Hashtable(); - initContextStyleMap(contextStyleMap); - - ArrayList styleList = new ArrayList(); - initStyleList(styleList); - - picker.setContextStyleMap(contextStyleMap); - picker.setDescriptions(descriptions); - picker.setStyleList(styleList); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.preferences.ui.AbstractColorPage#savePreferences() - */ - protected void savePreferences() { - XMLUIPlugin.getDefault().savePluginPreferences(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLFilesPreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLFilesPreferencePage.java deleted file mode 100644 index 355885acc1..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLFilesPreferencePage.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; -import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferencePage; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; - -public class XMLFilesPreferencePage extends AbstractPreferencePage { - protected EncodingSettings fEncodingSettings = null; - - protected Combo fEndOfLineCode = null; - private Vector fEOLCodes = null; - private Combo fDefaultSuffix = null; - private List fValidExtensions = null; - private Button fWarnNoGrammar = null; - - protected Control createContents(Composite parent) { - Composite composite = (Composite) super.createContents(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_FILES_HELPID); - createContentsForCreatingOrSavingGroup(composite); - createContentsForCreatingGroup(composite); - createContentsForValidatingGroup(composite); - - setSize(composite); - loadPreferences(); - - return composite; - } - - protected void createContentsForCreatingGroup(Composite parent) { - Group creatingGroup = createGroup(parent, 2); - creatingGroup.setText(XMLUIMessages.Creating_files); - - // Default extension for New file Wizard - createLabel(creatingGroup, XMLUIMessages.XMLFilesPreferencePage_ExtensionLabel); - fDefaultSuffix = createDropDownBox(creatingGroup); - String[] validExtensions = (String[]) getValidExtensions().toArray(new String[0]); - Arrays.sort(validExtensions); - fDefaultSuffix.setItems(validExtensions); - fDefaultSuffix.addSelectionListener(this); - - Label label = createLabel(creatingGroup, XMLUIMessages.Encoding_desc); - ((GridData) label.getLayoutData()).horizontalSpan = 2; - fEncodingSettings = new EncodingSettings(creatingGroup, XMLUIMessages.Encoding); - ((GridData) fEncodingSettings.getLayoutData()).horizontalSpan = 2; - } - - protected void createContentsForCreatingOrSavingGroup(Composite parent) { - Group creatingOrSavingGroup = createGroup(parent, 2); - creatingOrSavingGroup.setText(XMLUIMessages.Creating_or_saving_files); - - Label label = createLabel(creatingOrSavingGroup, XMLUIMessages.End_of_line_code_desc); - ((GridData) label.getLayoutData()).horizontalSpan = 2; - ((GridData) label.getLayoutData()).grabExcessHorizontalSpace = true; - - createLabel(creatingOrSavingGroup, XMLUIMessages.End_of_line_code); - fEndOfLineCode = createDropDownBox(creatingOrSavingGroup); - populateLineDelimiters(); - } - - protected void createContentsForValidatingGroup(Composite parent) { - Group validatingGroup = createGroup(parent, 2); - validatingGroup.setText(XMLUIMessages.Validating_files); - - if (fWarnNoGrammar == null) { - fWarnNoGrammar = createCheckBox(validatingGroup, XMLUIMessages.Warn_no_grammar_specified); - } - } - - public void dispose() { - fDefaultSuffix.removeModifyListener(this); - super.dispose(); - } - - protected void doSavePreferenceStore() { - XMLCorePlugin.getDefault().savePluginPreferences(); // model - } - - /** - * Get content type associated with this new file wizard - * - * @return IContentType - */ - protected IContentType getContentType() { - return Platform.getContentTypeManager().getContentType(ContentTypeIdForXML.ContentTypeID_XML); - } - - /** - * Get list of valid extensions - * - * @return List - */ - private List getValidExtensions() { - if (fValidExtensions == null) { - IContentType type = getContentType(); - fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); - } - return fValidExtensions; - } - - /** - * Return the currently selected line delimiter preference - * - * @return a line delimiter constant from CommonEncodingPreferenceNames - */ - private String getCurrentEOLCode() { - int i = fEndOfLineCode.getSelectionIndex(); - if (i >= 0) { - return (String) (fEOLCodes.elementAt(i)); - } - return ""; //$NON-NLS-1$ - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.preferences.ui.AbstractPreferencePage#getModelPreferences() - */ - protected Preferences getModelPreferences() { - return XMLCorePlugin.getDefault().getPluginPreferences(); - } - - protected void initializeValues() { - initializeValuesForCreatingOrSavingGroup(); - initializeValuesForCreatingGroup(); - initializeValuesForValidatingGroup(); - } - - protected void initializeValuesForCreatingGroup() { - String suffix = getModelPreferences().getString(XMLCorePreferenceNames.DEFAULT_EXTENSION); - fDefaultSuffix.setText(suffix); - - String encoding = getModelPreferences().getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - - fEncodingSettings.setIANATag(encoding); - } - - protected void initializeValuesForCreatingOrSavingGroup() { - String endOfLineCode = getModelPreferences().getString(CommonEncodingPreferenceNames.END_OF_LINE_CODE); - - if (endOfLineCode.length() > 0) { - setCurrentEOLCode(endOfLineCode); - } - else { - setCurrentEOLCode(CommonEncodingPreferenceNames.NO_TRANSLATION); - } - } - - protected void initializeValuesForValidatingGroup() { - boolean warnNoGrammarButtonSelected = getModelPreferences().getBoolean(XMLCorePreferenceNames.WARN_NO_GRAMMAR); - - - if (fWarnNoGrammar != null) { - fWarnNoGrammar.setSelection(warnNoGrammarButtonSelected); - } - } - - protected void performDefaults() { - performDefaultsForCreatingOrSavingGroup(); - performDefaultsForCreatingGroup(); - performDefaultsForValidatingGroup(); - - super.performDefaults(); - } - - protected void performDefaultsForCreatingGroup() { - String suffix = getModelPreferences().getDefaultString(XMLCorePreferenceNames.DEFAULT_EXTENSION); - fDefaultSuffix.setText(suffix); - - String encoding = getModelPreferences().getDefaultString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - - fEncodingSettings.setIANATag(encoding); - // fEncodingSettings.resetToDefaultEncoding(); - } - - protected void performDefaultsForCreatingOrSavingGroup() { - String endOfLineCode = getModelPreferences().getDefaultString(CommonEncodingPreferenceNames.END_OF_LINE_CODE); - - if (endOfLineCode.length() > 0) { - setCurrentEOLCode(endOfLineCode); - } - else { - setCurrentEOLCode(CommonEncodingPreferenceNames.NO_TRANSLATION); - } - } - - protected void performDefaultsForValidatingGroup() { - boolean warnNoGrammarButtonSelected = getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.WARN_NO_GRAMMAR); - - if (fWarnNoGrammar != null) { - fWarnNoGrammar.setSelection(warnNoGrammarButtonSelected); - } - } - - public boolean performOk() { - boolean result = super.performOk(); - - doSavePreferenceStore(); - - return result; - } - - /** - * Populates the vector containing the line delimiter to display string - * mapping and the combobox displaying line delimiters - */ - private void populateLineDelimiters() { - fEOLCodes = new Vector(); - fEndOfLineCode.add(XMLUIMessages.EOL_Unix); - fEOLCodes.add(CommonEncodingPreferenceNames.LF); - - fEndOfLineCode.add(XMLUIMessages.EOL_Mac); - fEOLCodes.add(CommonEncodingPreferenceNames.CR); - - fEndOfLineCode.add(XMLUIMessages.EOL_Windows); - fEOLCodes.add(CommonEncodingPreferenceNames.CRLF); - - fEndOfLineCode.add(XMLUIMessages.EOL_NoTranslation); - fEOLCodes.add(CommonEncodingPreferenceNames.NO_TRANSLATION); - } - - /** - * Select the line delimiter in the eol combobox - * - */ - private void setCurrentEOLCode(String eolCode) { - // Clear the current selection. - fEndOfLineCode.clearSelection(); - fEndOfLineCode.deselectAll(); - - int i = fEOLCodes.indexOf(eolCode); - if (i >= 0) { - fEndOfLineCode.select(i); - } - } - - protected void storeValues() { - storeValuesForCreatingOrSavingGroup(); - storeValuesForCreatingGroup(); - storeValuesForValidatingGroup(); - } - - protected void storeValuesForCreatingGroup() { - String suffix = fDefaultSuffix.getText(); - getModelPreferences().setValue(XMLCorePreferenceNames.DEFAULT_EXTENSION, suffix); - - getModelPreferences().setValue(CommonEncodingPreferenceNames.OUTPUT_CODESET, fEncodingSettings.getIANATag()); - } - - protected void storeValuesForCreatingOrSavingGroup() { - String eolCode = getCurrentEOLCode(); - getModelPreferences().setValue(CommonEncodingPreferenceNames.END_OF_LINE_CODE, eolCode); - } - - protected void storeValuesForValidatingGroup() { - if (fWarnNoGrammar != null) { - boolean warnNoGrammarButtonSelected = fWarnNoGrammar.getSelection(); - getModelPreferences().setValue(XMLCorePreferenceNames.WARN_NO_GRAMMAR, warnNoGrammarButtonSelected); - } - } - - protected void validateValues() { - boolean isValid = false; - Iterator i = getValidExtensions().iterator(); - while (i.hasNext() && !isValid) { - String extension = (String) i.next(); - isValid = extension.equalsIgnoreCase(fDefaultSuffix.getText()); - } - - if (!isValid) { - setErrorMessage(NLS.bind(XMLUIMessages.XMLFilesPreferencePage_ExtensionError, getValidExtensions().toString())); - setValid(false); - } - else { - setErrorMessage(null); - setValid(true); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java deleted file mode 100644 index 4d9b7d382d..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSourcePreferencePage.java +++ /dev/null @@ -1,371 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import java.util.Vector; - -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractPreferencePage; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; - -public class XMLSourcePreferencePage extends AbstractPreferencePage implements ModifyListener, SelectionListener, IWorkbenchPreferencePage { - private final int MIN_INDENTATION_SIZE = 0; - private final int MAX_INDENTATION_SIZE = 16; - - // Content Assist - protected Button fAutoPropose; - protected Label fAutoProposeLabel; - protected Text fAutoProposeText; - private Combo fSuggestionStrategyCombo; - private Vector fSuggestionStrategies = null; - protected Button fClearAllBlankLines; - - // Formatting - protected Label fLineWidthLabel; - protected Text fLineWidthText; - protected Button fSplitMultiAttrs; - private Button fIndentUsingTabs; - private Button fIndentUsingSpaces; - private Spinner fIndentationSize; - private Button fPreservePCDATAContent; - private Button fAlignEndBracket; - - // grammar constraints - protected Button fUseInferredGrammar; - - protected Control createContents(Composite parent) { - Composite composite = (Composite) super.createContents(parent); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.XML_PREFWEBX_SOURCE_HELPID); - - createContentsForFormattingGroup(composite); - createContentsForContentAssistGroup(composite); - createContentsForGrammarConstraintsGroup(composite); - setSize(composite); - loadPreferences(); - - return composite; - } - - protected void createContentsForContentAssistGroup(Composite parent) { - Group contentAssistGroup = createGroup(parent, 2); - contentAssistGroup.setText(XMLUIMessages.Content_assist_UI_); - - fAutoPropose = createCheckBox(contentAssistGroup, XMLUIMessages.Automatically_make_suggest_UI_); - ((GridData) fAutoPropose.getLayoutData()).horizontalSpan = 2; - fAutoPropose.addSelectionListener(this); - - fAutoProposeLabel = createLabel(contentAssistGroup, XMLUIMessages.Prompt_when_these_characte_UI_); - fAutoProposeText = createTextField(contentAssistGroup); - - createLabel(contentAssistGroup, XMLUIMessages.Suggestion_Strategy); - fSuggestionStrategyCombo = new Combo(contentAssistGroup, SWT.READ_ONLY); - fSuggestionStrategies = new Vector(); - fSuggestionStrategyCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fSuggestionStrategyCombo.add(XMLUIMessages.Suggestion_Strategy_Lax); - fSuggestionStrategies.add(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_LAX); - fSuggestionStrategyCombo.add(XMLUIMessages.Suggestion_Strategy_Strict); - fSuggestionStrategies.add(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_STRICT); - } - - protected void createContentsForFormattingGroup(Composite parent) { - Group formattingGroup = createGroup(parent, 2); - formattingGroup.setText(XMLUIMessages.Formatting_UI_); - - fLineWidthLabel = createLabel(formattingGroup, XMLUIMessages.Line_width__UI_); - fLineWidthText = new Text(formattingGroup, SWT.SINGLE | SWT.BORDER); - GridData gData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.BEGINNING); - gData.widthHint = 25; - fLineWidthText.setLayoutData(gData); - fLineWidthText.addModifyListener(this); - - fSplitMultiAttrs = createCheckBox(formattingGroup, XMLUIMessages.Split_multiple_attributes); - ((GridData) fSplitMultiAttrs.getLayoutData()).horizontalSpan = 2; - fAlignEndBracket = createCheckBox(formattingGroup, XMLUIMessages.Align_final_bracket); - ((GridData) fAlignEndBracket.getLayoutData()).horizontalSpan = 2; - fPreservePCDATAContent = createCheckBox(formattingGroup, XMLUIMessages.Preserve_PCDATA_Content); - ((GridData) fPreservePCDATAContent.getLayoutData()).horizontalSpan = 2; - fClearAllBlankLines = createCheckBox(formattingGroup, XMLUIMessages.Clear_all_blank_lines_UI_); - ((GridData) fClearAllBlankLines.getLayoutData()).horizontalSpan = 2; - - fIndentUsingTabs = createRadioButton(formattingGroup, XMLUIMessages.Indent_using_tabs); - ((GridData) fIndentUsingTabs.getLayoutData()).horizontalSpan = 2; - - fIndentUsingSpaces = createRadioButton(formattingGroup, XMLUIMessages.Indent_using_spaces); - ((GridData) fIndentUsingSpaces.getLayoutData()).horizontalSpan = 2; - - createLabel(formattingGroup, XMLUIMessages.Indentation_size); - fIndentationSize = new Spinner(formattingGroup, SWT.READ_ONLY | SWT.BORDER); - GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); - fIndentationSize.setLayoutData(gd); - fIndentationSize.setToolTipText(XMLUIMessages.Indentation_size_tip); - fIndentationSize.setMinimum(MIN_INDENTATION_SIZE); - fIndentationSize.setMaximum(MAX_INDENTATION_SIZE); - fIndentationSize.setIncrement(1); - fIndentationSize.setPageIncrement(4); - fIndentationSize.addModifyListener(this); - } - - protected void createContentsForGrammarConstraintsGroup(Composite parent) { - Group grammarConstraintsGroup = createGroup(parent, 1); - grammarConstraintsGroup.setText(XMLUIMessages.Grammar_Constraints); - grammarConstraintsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); - - fUseInferredGrammar = createCheckBox(grammarConstraintsGroup, XMLUIMessages.Use_inferred_grammar_in_absence_of); - } - - protected IPreferenceStore doGetPreferenceStore() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } - - protected void doSavePreferenceStore() { - XMLUIPlugin.getDefault().savePluginPreferences(); // editor - XMLCorePlugin.getDefault().savePluginPreferences(); // model - } - - protected void enableValues() { - if (fAutoPropose != null) { - if (fAutoPropose.getSelection()) { - fAutoProposeLabel.setEnabled(true); - fAutoProposeText.setEnabled(true); - } - else { - fAutoProposeLabel.setEnabled(false); - fAutoProposeText.setEnabled(false); - } - } - } - - protected Preferences getModelPreferences() { - return XMLCorePlugin.getDefault().getPluginPreferences(); - } - - /** - * Return the currently selected suggestion strategy preference - * - * @return a suggestion strategy constant from XMLUIPreferenceNames - */ - private String getCurrentSuggestionStrategy() { - int i = fSuggestionStrategyCombo.getSelectionIndex(); - if (i >= 0) { - return (String) (fSuggestionStrategies.elementAt(i)); - } - return ""; //$NON-NLS-1$ - } - - protected void initializeValues() { - initializeValuesForFormattingGroup(); - initializeValuesForContentAssistGroup(); - initializeValuesForGrammarConstraintsGroup(); - } - - protected void initializeValuesForContentAssistGroup() { - // Content Assist - fAutoPropose.setSelection(getPreferenceStore().getBoolean(XMLUIPreferenceNames.AUTO_PROPOSE)); - fAutoProposeText.setText(getPreferenceStore().getString(XMLUIPreferenceNames.AUTO_PROPOSE_CODE)); - String suggestionStrategy = getPreferenceStore().getString(XMLUIPreferenceNames.SUGGESTION_STRATEGY); - if (suggestionStrategy.length() > 0) { - setCurrentSuggestionStrategy(suggestionStrategy); - } - else { - setCurrentSuggestionStrategy(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_LAX); - } - } - - protected void initializeValuesForFormattingGroup() { - // Formatting - fLineWidthText.setText(getModelPreferences().getString(XMLCorePreferenceNames.LINE_WIDTH)); - fSplitMultiAttrs.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS)); - fAlignEndBracket.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET)); - fClearAllBlankLines.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES)); - fPreservePCDATAContent.setSelection(getModelPreferences().getBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT)); - - if (XMLCorePreferenceNames.TAB.equals(getModelPreferences().getString(XMLCorePreferenceNames.INDENTATION_CHAR))) { - fIndentUsingTabs.setSelection(true); - fIndentUsingSpaces.setSelection(false); - } - else { - fIndentUsingSpaces.setSelection(true); - fIndentUsingTabs.setSelection(false); - } - - fIndentationSize.setSelection(getModelPreferences().getInt(XMLCorePreferenceNames.INDENTATION_SIZE)); - } - - protected void initializeValuesForGrammarConstraintsGroup() { - fUseInferredGrammar.setSelection(getPreferenceStore().getBoolean(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR)); - } - - protected void performDefaults() { - performDefaultsForFormattingGroup(); - performDefaultsForContentAssistGroup(); - performDefaultsForGrammarConstraintsGroup(); - - validateValues(); - enableValues(); - - super.performDefaults(); - } - - protected void performDefaultsForContentAssistGroup() { - // Content Assist - fAutoPropose.setSelection(getPreferenceStore().getDefaultBoolean(XMLUIPreferenceNames.AUTO_PROPOSE)); - fAutoProposeText.setText(getPreferenceStore().getDefaultString(XMLUIPreferenceNames.AUTO_PROPOSE_CODE)); - String suggestionStrategy = getPreferenceStore().getDefaultString(XMLUIPreferenceNames.SUGGESTION_STRATEGY); - if (suggestionStrategy.length() > 0) { - setCurrentSuggestionStrategy(suggestionStrategy); - } - else { - setCurrentSuggestionStrategy(XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_LAX); - } - } - - protected void performDefaultsForFormattingGroup() { - // Formatting - fLineWidthText.setText(getModelPreferences().getDefaultString(XMLCorePreferenceNames.LINE_WIDTH)); - fSplitMultiAttrs.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS)); - fAlignEndBracket.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.ALIGN_END_BRACKET)); - fClearAllBlankLines.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES)); - fPreservePCDATAContent.setSelection(getModelPreferences().getDefaultBoolean(XMLCorePreferenceNames.PRESERVE_CDATACONTENT)); - - if (XMLCorePreferenceNames.TAB.equals(getModelPreferences().getDefaultString(XMLCorePreferenceNames.INDENTATION_CHAR))) { - fIndentUsingTabs.setSelection(true); - fIndentUsingSpaces.setSelection(false); - } - else { - fIndentUsingSpaces.setSelection(true); - fIndentUsingTabs.setSelection(false); - } - fIndentationSize.setSelection(getModelPreferences().getDefaultInt(XMLCorePreferenceNames.INDENTATION_SIZE)); - } - - protected void performDefaultsForGrammarConstraintsGroup() { - fUseInferredGrammar.setSelection(getPreferenceStore().getDefaultBoolean(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR)); - } - - public boolean performOk() { - boolean result = super.performOk(); - - doSavePreferenceStore(); - - return result; - } - - /** - * Set a suggestion strategy in suggestion strategy combo box - * - * @param strategy - */ - private void setCurrentSuggestionStrategy(String strategy) { - // Clear the current selection. - fSuggestionStrategyCombo.clearSelection(); - fSuggestionStrategyCombo.deselectAll(); - - int i = fSuggestionStrategies.indexOf(strategy); - if (i >= 0) { - fSuggestionStrategyCombo.select(i); - } - } - - protected void storeValues() { - storeValuesForFormattingGroup(); - storeValuesForContentAssistGroup(); - storeValuesForGrammarConstraintsGroup(); - } - - protected void storeValuesForContentAssistGroup() { - // Content Assist - getPreferenceStore().setValue(XMLUIPreferenceNames.AUTO_PROPOSE, fAutoPropose.getSelection()); - getPreferenceStore().setValue(XMLUIPreferenceNames.AUTO_PROPOSE_CODE, fAutoProposeText.getText()); - getPreferenceStore().setValue(XMLUIPreferenceNames.SUGGESTION_STRATEGY, getCurrentSuggestionStrategy()); - } - - protected void storeValuesForFormattingGroup() { - // Formatting - getModelPreferences().setValue(XMLCorePreferenceNames.LINE_WIDTH, fLineWidthText.getText()); - getModelPreferences().setValue(XMLCorePreferenceNames.SPLIT_MULTI_ATTRS, fSplitMultiAttrs.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.ALIGN_END_BRACKET, fAlignEndBracket.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.CLEAR_ALL_BLANK_LINES, fClearAllBlankLines.getSelection()); - getModelPreferences().setValue(XMLCorePreferenceNames.PRESERVE_CDATACONTENT, fPreservePCDATAContent.getSelection()); - - if (fIndentUsingTabs.getSelection()) { - getModelPreferences().setValue(XMLCorePreferenceNames.INDENTATION_CHAR, XMLCorePreferenceNames.TAB); - } - else { - getModelPreferences().setValue(XMLCorePreferenceNames.INDENTATION_CHAR, XMLCorePreferenceNames.SPACE); - } - getModelPreferences().setValue(XMLCorePreferenceNames.INDENTATION_SIZE, fIndentationSize.getSelection()); - } - - protected void storeValuesForGrammarConstraintsGroup() { - getPreferenceStore().setValue(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR, fUseInferredGrammar.getSelection()); - } - - protected void validateValues() { - boolean isError = false; - String widthText = null; - - if (fLineWidthText != null) { - try { - widthText = fLineWidthText.getText(); - int formattingLineWidth = Integer.parseInt(widthText); - if ((formattingLineWidth < WIDTH_VALIDATION_LOWER_LIMIT) || (formattingLineWidth > WIDTH_VALIDATION_UPPER_LIMIT)) { - throw new NumberFormatException(); - } - } - catch (NumberFormatException nfexc) { - setInvalidInputMessage(widthText); - setValid(false); - isError = true; - } - } - - int indentSize = 0; - if (fIndentationSize != null) { - try { - indentSize = fIndentationSize.getSelection(); - if ((indentSize < MIN_INDENTATION_SIZE) || (indentSize > MAX_INDENTATION_SIZE)) { - throw new NumberFormatException(); - } - } - catch (NumberFormatException nfexc) { - setInvalidInputMessage(Integer.toString(indentSize)); - setValid(false); - isError = true; - } - } - - if (!isError) { - setErrorMessage(null); - setValid(true); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSyntaxColoringPage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSyntaxColoringPage.java deleted file mode 100644 index 644fef27db..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLSyntaxColoringPage.java +++ /dev/null @@ -1,870 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.preference.ColorSelector; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.ListViewer; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerComparator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.ACC; -import org.eclipse.swt.accessibility.AccessibleAdapter; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.custom.SashForm; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.events.TraverseEvent; -import org.eclipse.swt.events.TraverseListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.PreferencesUtil; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.ui.internal.SSEUIMessages; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore; -import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore.OverlayKey; -import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper; -import org.eclipse.wst.sse.ui.internal.util.EditorUtility; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; -import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; - -import com.ibm.icu.text.Collator; - -/** - * A preference page to configure our XML syntax color. It resembles the JDT - * and CDT pages far more than our original color page while retaining the - * extra "click-to-find" functionality. - */ -public final class XMLSyntaxColoringPage extends PreferencePage implements IWorkbenchPreferencePage { - - private Button fBold; - private Label fForegroundLabel; - private Label fBackgroundLabel; - private Button fClearStyle; - private Map fContextToStyleMap; - private Color fDefaultForeground = null; - private Color fDefaultBackground = null; - private IStructuredDocument fDocument; - private ColorSelector fForegroundColorEditor; - private ColorSelector fBackgroundColorEditor; - private Button fItalic; - private OverlayPreferenceStore fOverlayStore; - private Button fStrike; - private Collection fStylePreferenceKeys; - private StructuredViewer fStylesViewer = null; - private Map fStyleToDescriptionMap; - private StyledText fText; - private Button fUnderline; - - // activate controls based on the given local color type - private void activate(String namedStyle) { - Color foreground = fDefaultForeground; - Color background = fDefaultBackground; - if (namedStyle == null) { - fClearStyle.setEnabled(false); - fBold.setEnabled(false); - fItalic.setEnabled(false); - fStrike.setEnabled(false); - fUnderline.setEnabled(false); - fForegroundLabel.setEnabled(false); - fBackgroundLabel.setEnabled(false); - fForegroundColorEditor.setEnabled(false); - fBackgroundColorEditor.setEnabled(false); - fBold.setSelection(false); - fItalic.setSelection(false); - fStrike.setSelection(false); - fUnderline.setSelection(false); - } - else { - TextAttribute attribute = getAttributeFor(namedStyle); - fClearStyle.setEnabled(true); - fBold.setEnabled(true); - fItalic.setEnabled(true); - fStrike.setEnabled(true); - fUnderline.setEnabled(true); - fForegroundLabel.setEnabled(true); - fBackgroundLabel.setEnabled(true); - fForegroundColorEditor.setEnabled(true); - fBackgroundColorEditor.setEnabled(true); - fBold.setSelection((attribute.getStyle() & SWT.BOLD) != 0); - fItalic.setSelection((attribute.getStyle() & SWT.ITALIC) != 0); - fStrike.setSelection((attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0); - fUnderline.setSelection((attribute.getStyle() & TextAttribute.UNDERLINE) != 0); - if (attribute.getForeground() != null) { - foreground = attribute.getForeground(); - } - if (attribute.getBackground() != null) { - background = attribute.getBackground(); - } - } - - fForegroundColorEditor.setColorValue(foreground.getRGB()); - fBackgroundColorEditor.setColorValue(background.getRGB()); - } - - /** - * Color the text in the sample area according to the current preferences - */ - void applyStyles() { - if (fText == null || fText.isDisposed()) - return; - IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion(); - while (documentRegion != null) { - ITextRegionList regions = documentRegion.getRegions(); - for (int i = 0; i < regions.size(); i++) { - ITextRegion currentRegion = regions.get(i); - // lookup the local coloring type and apply it - String namedStyle = (String) fContextToStyleMap.get(currentRegion.getType()); - if (namedStyle == null) - continue; - TextAttribute attribute = getAttributeFor(namedStyle); - if (attribute == null) - continue; - StyleRange style = new StyleRange(documentRegion.getStartOffset(currentRegion), currentRegion.getTextLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle()); - style.strikeout = (attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0; - style.underline = (attribute.getStyle() & TextAttribute.UNDERLINE) != 0; - fText.setStyleRange(style); - } - documentRegion = documentRegion.getNext(); - } - } - - Button createCheckbox(Composite parent, String label) { - Button button = new Button(parent, SWT.CHECK); - button.setText(label); - button.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - return button; - } - - /** - * Creates composite control and sets the default layout data. - */ - private Composite createComposite(Composite parent, int numColumns) { - Composite composite = new Composite(parent, SWT.NULL); - - // GridLayout - GridLayout layout = new GridLayout(); - layout.numColumns = numColumns; - layout.makeColumnsEqualWidth = false; - layout.marginHeight = 0; - layout.marginWidth = 0; - composite.setLayout(layout); - - // GridData - GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); - composite.setLayoutData(data); - return composite; - } - - protected Control createContents(final Composite parent) { - initializeDialogUnits(parent); - - fDefaultForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND); - fDefaultBackground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); - Composite pageComponent = createComposite(parent, 2); - PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.XML_PREFWEBX_STYLES_HELPID); - - Link link = new Link(pageComponent, SWT.WRAP); - link.setText(SSEUIMessages.SyntaxColoring_Link); - link.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null); - } - }); - - GridData linkData= new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1); - linkData.widthHint= 150; // only expand further if anyone else requires it - link.setLayoutData(linkData); - - new Label(pageComponent, SWT.NONE).setLayoutData(new GridData()); - new Label(pageComponent, SWT.NONE).setLayoutData(new GridData()); - - SashForm editor = new SashForm(pageComponent, SWT.VERTICAL); - GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData2.horizontalSpan = 2; - editor.setLayoutData(gridData2); - SashForm top = new SashForm(editor, SWT.HORIZONTAL); - Composite styleEditor = createComposite(top, 1); - ((GridLayout) styleEditor.getLayout()).marginRight = 5; - ((GridLayout) styleEditor.getLayout()).marginLeft = 0; - createLabel(styleEditor, XMLUIMessages.SyntaxColoringPage_0); - fStylesViewer = createStylesViewer(styleEditor); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData.horizontalIndent = 0; - Iterator iterator = fStyleToDescriptionMap.values().iterator(); - while (iterator.hasNext()) { - gridData.widthHint = Math.max(gridData.widthHint, convertWidthInCharsToPixels(iterator.next().toString().length())); - } - gridData.heightHint = convertHeightInCharsToPixels(5); - fStylesViewer.getControl().setLayoutData(gridData); - - Composite editingComposite = createComposite(top, 1); - ((GridLayout) styleEditor.getLayout()).marginLeft = 5; - createLabel(editingComposite, ""); //$NON-NLS-1$ - Button enabler = createCheckbox(editingComposite, XMLUIMessages.SyntaxColoringPage_2); - enabler.setEnabled(false); - enabler.setSelection(true); - Composite editControls = createComposite(editingComposite, 2); - ((GridLayout) editControls.getLayout()).marginLeft = 20; - - fForegroundLabel = createLabel(editControls, SSEUIMessages.Foreground_UI_); - ((GridData) fForegroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER; - fForegroundLabel.setEnabled(false); - - fForegroundColorEditor = new ColorSelector(editControls); - Button fForegroundColor = fForegroundColorEditor.getButton(); - GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false); - fForegroundColor.setLayoutData(gd); - fForegroundColorEditor.setEnabled(false); - - fBackgroundLabel = createLabel(editControls, SSEUIMessages.Background_UI_); - ((GridData) fBackgroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER; - fBackgroundLabel.setEnabled(false); - - fBackgroundColorEditor = new ColorSelector(editControls); - Button fBackgroundColor = fBackgroundColorEditor.getButton(); - gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false); - fBackgroundColor.setLayoutData(gd); - fBackgroundColorEditor.setEnabled(false); - - fBold = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_3); - fBold.setEnabled(false); - ((GridData) fBold.getLayoutData()).horizontalSpan = 2; - fItalic = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_4); - fItalic.setEnabled(false); - ((GridData) fItalic.getLayoutData()).horizontalSpan = 2; - fStrike = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_5); - fStrike.setEnabled(false); - ((GridData) fStrike.getLayoutData()).horizontalSpan = 2; - fUnderline = createCheckbox(editControls, XMLUIMessages.SyntaxColoringPage_6); - fUnderline.setEnabled(false); - ((GridData) fUnderline.getLayoutData()).horizontalSpan = 2; - fClearStyle = new Button(editingComposite, SWT.PUSH); - fClearStyle.setText(SSEUIMessages.Restore_Default_UI_); //$NON-NLS-1$ = "Restore Default" - fClearStyle.setLayoutData(new GridData(SWT.BEGINNING)); - ((GridData) fClearStyle.getLayoutData()).horizontalIndent = 20; - fClearStyle.setEnabled(false); - - Composite sampleArea = createComposite(editor, 1); - - ((GridLayout) sampleArea.getLayout()).marginLeft = 5; - ((GridLayout) sampleArea.getLayout()).marginTop = 5; - createLabel(sampleArea, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:" - SourceViewer viewer = new SourceViewer(sampleArea, null, SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY); - fText = viewer.getTextWidget(); - GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData3.widthHint = convertWidthInCharsToPixels(20); - gridData3.heightHint = convertHeightInCharsToPixels(5); - gridData3.horizontalSpan = 2; - fText.setLayoutData(gridData3); - fText.setEditable(false); - fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$ - fText.addKeyListener(getTextKeyListener()); - fText.addSelectionListener(getTextSelectionListener()); - fText.addMouseListener(getTextMouseListener()); - fText.addTraverseListener(getTraverseListener()); - setAccessible(fText, SSEUIMessages.Sample_text__UI_); - fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor(ContentTypeIdForXML.ContentTypeID_XML); - fDocument.set(getExampleText()); - viewer.setDocument(fDocument); - - top.setWeights(new int[]{1, 1}); - editor.setWeights(new int[]{1, 1}); - PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.XML_PREFWEBX_STYLES_HELPID); - - fStylesViewer.setInput(getStylePreferenceKeys()); - - applyStyles(); - - fStylesViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - if (!event.getSelection().isEmpty()) { - Object o = ((IStructuredSelection) event.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - activate(namedStyle); - if (namedStyle == null) - return; - } - } - }); - - fForegroundColorEditor.addListener(new IPropertyChangeListener() { - public void propertyChange(PropertyChangeEvent event) { - if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) { - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[0]; - // open color dialog to get new color - String newValue = ColorHelper.toRGBString(fForegroundColorEditor.getColorValue()); - - if (!newValue.equals(oldValue)) { - stylePrefs[0] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - } - } - } - } - }); - - fBackgroundColorEditor.addListener(new IPropertyChangeListener() { - public void propertyChange(PropertyChangeEvent event) { - if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) { - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[1]; - // open color dialog to get new color - String newValue = ColorHelper.toRGBString(fBackgroundColorEditor.getColorValue()); - - if (!newValue.equals(oldValue)) { - stylePrefs[1] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - activate(namedStyle); - } - } - } - } - }); - - fBold.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - // get current (newly old) style - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[2]; - String newValue = String.valueOf(fBold.getSelection()); - if (!newValue.equals(oldValue)) { - stylePrefs[2] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - } - } - } - }); - - fItalic.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - // get current (newly old) style - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[3]; - String newValue = String.valueOf(fItalic.getSelection()); - if (!newValue.equals(oldValue)) { - stylePrefs[3] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - } - } - } - }); - - fStrike.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - // get current (newly old) style - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[4]; - String newValue = String.valueOf(fStrike.getSelection()); - if (!newValue.equals(oldValue)) { - stylePrefs[4] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - } - } - } - }); - - fUnderline.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - super.widgetSelected(e); - // get current (newly old) style - Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); - String namedStyle = o.toString(); - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - String oldValue = stylePrefs[5]; - String newValue = String.valueOf(fUnderline.getSelection()); - if (!newValue.equals(oldValue)) { - stylePrefs[5] = newValue; - String newPrefString = ColorHelper.packStylePreferences(stylePrefs); - getOverlayStore().setValue(namedStyle, newPrefString); - applyStyles(); - fText.redraw(); - } - } - } - }); - - fClearStyle.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (fStylesViewer.getSelection().isEmpty()) - return; - String namedStyle = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement().toString(); - getOverlayStore().setToDefault(namedStyle); - applyStyles(); - fText.redraw(); - activate(namedStyle); - } - }); - - return pageComponent; - } - - private Label createLabel(Composite parent, String text) { - Label label = new Label(parent, SWT.WRAP); - label.setText(text); - GridData data = new GridData(SWT.FILL, SWT.FILL, false, false); - label.setLayoutData(data); - label.setBackground(parent.getBackground()); - return label; - } - - // protected Label createDescriptionLabel(Composite parent) { - // return null; - // } - - /** - * Set up all the style preference keys in the overlay store - */ - private OverlayKey[] createOverlayStoreKeys() { - List overlayKeys = new ArrayList(); - - Iterator i = getStylePreferenceKeys().iterator(); - while (i.hasNext()) { - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, (String) i.next())); - } - - OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; - overlayKeys.toArray(keys); - return keys; - } - - /** - * Creates the List viewer where we see the various syntax element display - * names--would it ever be a Tree like JDT's? - * - * @param parent - * @return - */ - private StructuredViewer createStylesViewer(Composite parent) { - StructuredViewer stylesViewer = new ListViewer(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); - stylesViewer.setComparator(new ViewerComparator(Collator.getInstance())); - stylesViewer.setLabelProvider(new LabelProvider() { - public String getText(Object element) { - Object description = fStyleToDescriptionMap.get(element); - if (description != null) - return description.toString(); - return super.getText(element); - } - }); - stylesViewer.setContentProvider(new ITreeContentProvider() { - public void dispose() { - } - - public Object[] getChildren(Object parentElement) { - return getStylePreferenceKeys().toArray(); - } - - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); - } - - public Object getParent(Object element) { - return getStylePreferenceKeys(); - } - - public boolean hasChildren(Object element) { - return false; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - }); - return stylesViewer; - } - - public void dispose() { - if (fOverlayStore != null) { - fOverlayStore.stop(); - } - super.dispose(); - } - - protected IPreferenceStore doGetPreferenceStore() { - return XMLUIPlugin.getDefault().getPreferenceStore(); - } - - private TextAttribute getAttributeFor(String namedStyle) { - TextAttribute ta = new TextAttribute(fDefaultForeground, fDefaultBackground, SWT.NORMAL); - - if (namedStyle != null && fOverlayStore != null) { - // note: "namedStyle" *is* the preference key - String prefString = getOverlayStore().getString(namedStyle); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - RGB foreground = ColorHelper.toRGB(stylePrefs[0]); - RGB background = ColorHelper.toRGB(stylePrefs[1]); - - int fontModifier = SWT.NORMAL; - - if (stylePrefs.length > 2) { - boolean on = Boolean.valueOf(stylePrefs[2]).booleanValue(); - if (on) - fontModifier = fontModifier | SWT.BOLD; - } - if (stylePrefs.length > 3) { - boolean on = Boolean.valueOf(stylePrefs[3]).booleanValue(); - if (on) - fontModifier = fontModifier | SWT.ITALIC; - } - if (stylePrefs.length > 4) { - boolean on = Boolean.valueOf(stylePrefs[4]).booleanValue(); - if (on) - fontModifier = fontModifier | TextAttribute.STRIKETHROUGH; - } - if (stylePrefs.length > 5) { - boolean on = Boolean.valueOf(stylePrefs[5]).booleanValue(); - if (on) - fontModifier = fontModifier | TextAttribute.UNDERLINE; - } - - ta = new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, fontModifier); - } - } - return ta; - } - - private String getExampleText() { - return XMLUIMessages.Sample_XML_doc; - } - - private String getNamedStyleAtOffset(int offset) { - // ensure the offset is clean - if (offset >= fDocument.getLength()) - return getNamedStyleAtOffset(fDocument.getLength() - 1); - else if (offset < 0) - return getNamedStyleAtOffset(0); - IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion(); - while (documentRegion != null && !documentRegion.containsOffset(offset)) { - documentRegion = documentRegion.getNext(); - } - if (documentRegion != null) { - // find the ITextRegion's Context at this offset - ITextRegion interest = documentRegion.getRegionAtCharacterOffset(offset); - if (interest == null) - return null; - if (offset > documentRegion.getTextEndOffset(interest)) - return null; - String regionContext = interest.getType(); - if (regionContext == null) - return null; - // find the named style (internal/selectable name) for that - // context - String namedStyle = (String) fContextToStyleMap.get(regionContext); - if (namedStyle != null) { - return namedStyle; - } - } - return null; - } - - private OverlayPreferenceStore getOverlayStore() { - return fOverlayStore; - } - - private Collection getStylePreferenceKeys() { - if (fStylePreferenceKeys == null) { - List styles = new ArrayList(); - styles.add(IStyleConstantsXML.DOCTYPE_NAME); - styles.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - styles.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - styles.add(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - styles.add(IStyleConstantsXML.CDATA_BORDER); - styles.add(IStyleConstantsXML.CDATA_TEXT); - styles.add(IStyleConstantsXML.PI_BORDER); - styles.add(IStyleConstantsXML.PI_CONTENT); - styles.add(IStyleConstantsXML.TAG_BORDER); - styles.add(IStyleConstantsXML.TAG_NAME); - styles.add(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - styles.add(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - styles.add(IStyleConstantsXML.COMMENT_BORDER); - styles.add(IStyleConstantsXML.COMMENT_TEXT); - styles.add(IStyleConstantsXML.DECL_BORDER); - styles.add(IStyleConstantsXML.XML_CONTENT); - styles.add(IStyleConstantsXML.ENTITY_REFERENCE); - fStylePreferenceKeys = styles; - } - return fStylePreferenceKeys; - } - - private KeyListener getTextKeyListener() { - return new KeyListener() { - public void keyPressed(KeyEvent e) { - if (e.widget instanceof StyledText) { - int x = ((StyledText) e.widget).getCaretOffset(); - selectColorAtOffset(x); - } - } - - public void keyReleased(KeyEvent e) { - if (e.widget instanceof StyledText) { - int x = ((StyledText) e.widget).getCaretOffset(); - selectColorAtOffset(x); - } - } - }; - } - - private MouseListener getTextMouseListener() { - return new MouseListener() { - public void mouseDoubleClick(MouseEvent e) { - } - - public void mouseDown(MouseEvent e) { - } - - public void mouseUp(MouseEvent e) { - if (e.widget instanceof StyledText) { - int x = ((StyledText) e.widget).getCaretOffset(); - selectColorAtOffset(x); - } - } - }; - } - - private SelectionListener getTextSelectionListener() { - return new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - selectColorAtOffset(e.x); - if (e.widget instanceof StyledText) { - ((StyledText) e.widget).setSelection(e.x); - } - } - - public void widgetSelected(SelectionEvent e) { - selectColorAtOffset(e.x); - if (e.widget instanceof StyledText) { - ((StyledText) e.widget).setSelection(e.x); - } - } - }; - } - - private TraverseListener getTraverseListener() { - return new TraverseListener() { - /** - * @see org.eclipse.swt.events.TraverseListener#keyTraversed(TraverseEvent) - */ - public void keyTraversed(TraverseEvent e) { - if (e.widget instanceof StyledText) { - if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) - e.doit = true; - } - } - }; - } - - public void init(IWorkbench workbench) { - setDescription(SSEUIMessages.SyntaxColoring_Description); - - fStyleToDescriptionMap = new HashMap(); - fContextToStyleMap = new HashMap(); - - initStyleToDescriptionMap(); - initRegionContextToStyleMap(); - - fOverlayStore = new OverlayPreferenceStore(getPreferenceStore(), createOverlayStoreKeys()); - fOverlayStore.load(); - fOverlayStore.start(); - } - - private void initRegionContextToStyleMap() { - fContextToStyleMap.put(DOMRegionContext.XML_COMMENT_OPEN, IStyleConstantsXML.COMMENT_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_COMMENT_TEXT, IStyleConstantsXML.COMMENT_TEXT); - fContextToStyleMap.put(DOMRegionContext.XML_COMMENT_CLOSE, IStyleConstantsXML.COMMENT_BORDER); - - fContextToStyleMap.put(DOMRegionContext.XML_TAG_OPEN, IStyleConstantsXML.TAG_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_END_TAG_OPEN, IStyleConstantsXML.TAG_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_TAG_NAME, IStyleConstantsXML.TAG_NAME); - fContextToStyleMap.put(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME, IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - fContextToStyleMap.put(DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - fContextToStyleMap.put(DOMRegionContext.XML_TAG_CLOSE, IStyleConstantsXML.TAG_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_EMPTY_TAG_CLOSE, IStyleConstantsXML.TAG_BORDER); - - fContextToStyleMap.put(DOMRegionContext.XML_DECLARATION_OPEN, IStyleConstantsXML.DECL_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_DECLARATION_CLOSE, IStyleConstantsXML.DECL_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_ELEMENT_DECLARATION, IStyleConstantsXML.DECL_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_ELEMENT_DECL_CLOSE, IStyleConstantsXML.DECL_BORDER); - - fContextToStyleMap.put(DOMRegionContext.XML_CONTENT, IStyleConstantsXML.XML_CONTENT); - fContextToStyleMap.put(DOMRegionContext.XML_CDATA_OPEN, IStyleConstantsXML.CDATA_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_CDATA_TEXT, IStyleConstantsXML.CDATA_TEXT); - fContextToStyleMap.put(DOMRegionContext.XML_CDATA_CLOSE, IStyleConstantsXML.CDATA_BORDER); - - fContextToStyleMap.put(DOMRegionContext.XML_PI_OPEN, IStyleConstantsXML.PI_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_PI_CONTENT, IStyleConstantsXML.PI_CONTENT); - fContextToStyleMap.put(DOMRegionContext.XML_PI_CLOSE, IStyleConstantsXML.PI_BORDER); - fContextToStyleMap.put(DOMRegionContext.XML_ELEMENT_DECL_NAME, IStyleConstantsXML.DOCTYPE_NAME); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_DECLARATION, IStyleConstantsXML.TAG_NAME); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_DECLARATION_CLOSE, IStyleConstantsXML.DECL_BORDER); - - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_NAME, IStyleConstantsXML.DOCTYPE_NAME); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBLIC, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_PUBREF, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSTEM, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - fContextToStyleMap.put(DOMRegionContext.XML_DOCTYPE_EXTERNAL_ID_SYSREF, IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - - fContextToStyleMap.put(DOMRegionContext.XML_CHAR_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - fContextToStyleMap.put(DOMRegionContext.XML_ENTITY_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - fContextToStyleMap.put(DOMRegionContext.XML_PE_REFERENCE, IStyleConstantsXML.ENTITY_REFERENCE); - } - - private void initStyleToDescriptionMap() { - fStyleToDescriptionMap.put(IStyleConstantsXML.CDATA_BORDER, XMLUIMessages.CDATA_Delimiters_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.CDATA_TEXT, XMLUIMessages.CDATA_Content_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.PI_BORDER, XMLUIMessages.Processing_Instruction_Del_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.PI_CONTENT, XMLUIMessages.Processing_Instruction_Con_UI__UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.COMMENT_BORDER, XMLUIMessages.Comment_Delimiters_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.COMMENT_TEXT, XMLUIMessages.Comment_Content_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.TAG_BORDER, XMLUIMessages.Tag_Delimiters_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.TAG_NAME, XMLUIMessages.Tag_Names_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, XMLUIMessages.Attribute_Names_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, XMLUIMessages.Attribute_Values_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.DECL_BORDER, XMLUIMessages.Declaration_Delimiters_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.XML_CONTENT, XMLUIMessages.Content_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.DOCTYPE_NAME, XMLUIMessages.DOCTYPE_Name_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID, XMLUIMessages.DOCTYPE_SYSTEM_PUBLIC_Keyw_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF, XMLUIMessages.DOCTYPE_Public_Reference_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF, XMLUIMessages.DOCTYPE_System_Reference_UI_); - fStyleToDescriptionMap.put(IStyleConstantsXML.ENTITY_REFERENCE, XMLUIMessages.Entity_Reference_UI_); - } - - protected void performDefaults() { - super.performDefaults(); - getOverlayStore().loadDefaults(); - applyStyles(); - fStylesViewer.setSelection(StructuredSelection.EMPTY); - activate(null); - fText.redraw(); - } - - public boolean performOk() { - getOverlayStore().propagate(); - - XMLUIPlugin.getDefault().savePluginPreferences(); - SSEUIPlugin.getDefault().savePluginPreferences(); - return true; - } - - private void selectColorAtOffset(int offset) { - String namedStyle = getNamedStyleAtOffset(offset); - if (namedStyle != null) { - fStylesViewer.setSelection(new StructuredSelection(namedStyle)); - fStylesViewer.reveal(namedStyle); - } - else { - fStylesViewer.setSelection(StructuredSelection.EMPTY); - } - activate(namedStyle); - } - - /** - * Specifically set the reporting name of a control for accessibility - */ - private void setAccessible(Control control, String name) { - if (control == null) - return; - final String n = name; - control.getAccessible().addAccessibleListener(new AccessibleAdapter() { - public void getName(AccessibleEvent e) { - if (e.childID == ACC.CHILDID_SELF) - e.result = n; - } - }); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTemplatePreferencePage.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTemplatePreferencePage.java deleted file mode 100644 index 810b5997e3..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLTemplatePreferencePage.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.contentassist.ContentAssistant; -import org.eclipse.jface.text.contentassist.IContentAssistant; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.jface.text.templates.ContextTypeRegistry; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.templates.TemplatePreferencePage; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; - - -/** - * Preference page for XML templates - */ -public class XMLTemplatePreferencePage extends TemplatePreferencePage { - - class XMLEditTemplateDialog extends EditTemplateDialog { - public XMLEditTemplateDialog(Shell parent, Template template, boolean edit, boolean isNameModifiable, ContextTypeRegistry registry) { - super(parent, template, edit, isNameModifiable, registry); - } - - protected SourceViewer createViewer(Composite parent) { - SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() { - StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXML(); - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return baseConfiguration.getConfiguredContentTypes(sourceViewer); - } - - public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { - return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType); - } - - public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { - ContentAssistant assistant = new ContentAssistant(); - assistant.enableAutoActivation(true); - assistant.enableAutoInsert(true); - assistant.setContentAssistProcessor(getTemplateProcessor(), IDocument.DEFAULT_CONTENT_TYPE); - return assistant; - } - }; - return doCreateViewer(parent, sourceViewerConfiguration); - } - } - - public XMLTemplatePreferencePage() { - XMLUIPlugin xmlEditorPlugin = XMLUIPlugin.getDefault(); - - setPreferenceStore(xmlEditorPlugin.getPreferenceStore()); - setTemplateStore(xmlEditorPlugin.getTemplateStore()); - setContextTypeRegistry(xmlEditorPlugin.getTemplateContextRegistry()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) - */ - protected Control createContents(Composite ancestor) { - Control c = super.createContents(ancestor); - PlatformUI.getWorkbench().getHelpSystem().setHelp(c, IHelpContextIds.XML_PREFWEBX_TEMPLATES_HELPID); - return c; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.texteditor.templates.TemplatePreferencePage#createViewer(org.eclipse.swt.widgets.Composite) - */ - protected SourceViewer createViewer(Composite parent) { - SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() { - StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXML(); - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return baseConfiguration.getConfiguredContentTypes(sourceViewer); - } - - public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { - return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType); - } - }; - return doCreateViewer(parent, sourceViewerConfiguration); - } - - SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) { - SourceViewer viewer = null; - String contentTypeID = ContentTypeIdForXML.ContentTypeID_XML; - viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - ((StructuredTextViewer) viewer).getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$ - IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(contentTypeID); - IDocument document = scratchModel.getStructuredDocument(); - viewer.configure(viewerConfiguration); - viewer.setDocument(document); - return viewer; - } - - /** - * Creates the edit dialog. Subclasses may override this method to provide - * a custom dialog. - * - * @param template - * the template being edited - * @param edit - * whether the dialog should be editable - * @param isNameModifiable - * whether the template name may be modified - * @return the created or modified template, or <code>null</code> if the - * edition failed - * @since 3.1 - */ - protected Template editTemplate(Template template, boolean edit, boolean isNameModifiable) { - EditTemplateDialog dialog = new XMLEditTemplateDialog(getShell(), template, edit, isNameModifiable, getContextTypeRegistry()); - if (dialog.open() == Window.OK) { - return dialog.getTemplate(); - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.texteditor.templates.TemplatePreferencePage#isShowFormatterSetting() - */ - protected boolean isShowFormatterSetting() { - // template formatting has not been implemented - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.preference.IPreferencePage#performOk() - */ - public boolean performOk() { - boolean ok = super.performOk(); - XMLUIPlugin.getDefault().savePluginPreferences(); - return ok; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java deleted file mode 100644 index 97d5f41102..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java +++ /dev/null @@ -1,127 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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 - * Benjamin Muskalla, b.muskalla@gmx.net - [158660] character entities should have their own syntax highlighting preference - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML; - -/** - * Sets default values for XML UI preferences - */ -public class XMLUIPreferenceInitializer extends AbstractPreferenceInitializer { - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() - */ - public void initializeDefaultPreferences() { - IPreferenceStore store = XMLUIPlugin.getDefault().getPreferenceStore(); - - store.setDefault(XMLUIPreferenceNames.AUTO_PROPOSE, true); - store.setDefault(XMLUIPreferenceNames.AUTO_PROPOSE_CODE, "<="); //$NON-NLS-1$ - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=140946 - store.setDefault(XMLUIPreferenceNames.SUGGESTION_STRATEGY, XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_STRICT); - store.setDefault(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR, true); - - // XML Style Preferences - String NOBACKGROUNDBOLD = " | null | false"; //$NON-NLS-1$ - String JUSTITALIC = " | null | false | true"; //$NON-NLS-1$ - String styleValue = ColorHelper.getColorString(127, 0, 127) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, styleValue); - - styleValue = ColorHelper.getColorString(42, 0, 255) + JUSTITALIC; - store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, styleValue); - - styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ - store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS, styleValue); // specified - // value - // is - // black; - // leaving - // as - // widget - // default - - styleValue = ColorHelper.getColorString(63, 95, 191) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.COMMENT_BORDER, styleValue); - store.setDefault(IStyleConstantsXML.COMMENT_TEXT, styleValue); - - styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.DECL_BORDER, styleValue); - - styleValue = ColorHelper.getColorString(0, 0, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.DOCTYPE_NAME, styleValue); - store.setDefault(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF, styleValue); - - styleValue = ColorHelper.getColorString(128, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID, styleValue); - - styleValue = ColorHelper.getColorString(63, 127, 95) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF, styleValue); - - styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ - store.setDefault(IStyleConstantsXML.XML_CONTENT, styleValue); // specified - // value - // is - // black; - // leaving - // as - // widget - // default - - styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.TAG_BORDER, styleValue); - - styleValue = ColorHelper.getColorString(63, 127, 127) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.TAG_NAME, styleValue); - - styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.PI_BORDER, styleValue); - - styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ - store.setDefault(IStyleConstantsXML.PI_CONTENT, styleValue); // specified - // value - // is - // black; - // leaving - // as - // widget - // default - - styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.CDATA_BORDER, styleValue); - - styleValue = ColorHelper.getColorString(0, 0, 0) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.CDATA_TEXT, styleValue); - - styleValue = ColorHelper.getColorString(42, 0, 255) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.ENTITY_REFERENCE, styleValue); - - // set default new xml file template to use in new file wizard - /* - * Need to find template name that goes with default template id (name - * may change for differnt language) - */ - String templateName = ""; //$NON-NLS-1$ - Template template = XMLUIPlugin.getDefault().getTemplateStore().findTemplateById("org.eclipse.wst.xml.ui.internal.templates.xmldeclaration"); //$NON-NLS-1$ - if (template != null) - templateName = template.getName(); - store.setDefault(XMLUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName); - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java deleted file mode 100644 index 293e5781cb..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceNames.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 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 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.preferences; - -/** - * Preference keys for XML UI - */ -public class XMLUIPreferenceNames { - - public final static String SUGGESTION_STRATEGY_VALUE_LAX = "Lax"; //$NON-NLS-1$ - public final static String SUGGESTION_STRATEGY_VALUE_STRICT = "Strict"; //$NON-NLS-1$ - /** - * A named preference that controls if code assist gets auto activated. - * <p> - * Value is of type <code>Boolean</code>. - * </p> - */ - public static final String AUTO_PROPOSE = getAutoProposeKey(); - - private static String getAutoProposeKey() { - return "autoPropose";//$NON-NLS-1$ - } - - /** - * A named preference that holds the characters that auto activate code - * assist. - * <p> - * Value is of type <code>String</code>. All characters that trigger - * auto code assist. - * </p> - */ - public static final String AUTO_PROPOSE_CODE = getAutoProposeCodeKey(); - - private static String getAutoProposeCodeKey() { - return "autoProposeCode";//$NON-NLS-1$ - } - - /** - * The key to store customized templates. - * <p> - * Value is of type <code>String</code>. - * </p> - */ - public static final String TEMPLATES_KEY = getTemplatesKey(); - - private static String getTemplatesKey() { - return "org.eclipse.wst.sse.ui.custom_templates"; //$NON-NLS-1$ - } - - /** - * A named preference that controls whether or grammar should be inferred - * or not. - * <p> - * Value is of type <code>Boolean</code>. - * </p> - */ - public static final String USE_INFERRED_GRAMMAR = getUseInferredGrammarKey(); - - private static String getUseInferredGrammarKey() { - return "useInferredGrammar"; //$NON-NLS-1$ - } - - /** - * A named preference that holds the characters that auto activate code - * assist. - * <p> - * Value is of type <code>String</code>. All characters that trigger - * auto code assist. - * </p> - */ - public static final String SUGGESTION_STRATEGY = getSuggestionStrategeyKey(); - - private static String getSuggestionStrategeyKey() { - return "suggestionStrategy";//$NON-NLS-1$ - } - - /** - * The key to store the last template name used in new DTD file wizard. - * Template name is stored instead of template id because user-created - * templates do not have template ids. - * <p> - * Value is of type <code>String</code>. - * </p> - */ - public static final String NEW_FILE_TEMPLATE_NAME = "newFileTemplateName"; //$NON-NLS-1$ -} |